# Deterministic wakes, reports, and memory for long-running agents

Author: Chris Chabot
Canonical URL: https://chabot.dev/blog/deterministic-wakes-reports-and-memory-for-long-running-agents/
Published: 2026-11-21

How deterministic code can own wakes, reports and memory for long-running agents, with event batching and cold resets timed by the prompt-cache lifetime.

Connect a long-running agent to GitHub and production error tracking, and the first noisy outage exposes per-event waking immediately. An agent woken 100 times a second by a flood of events pays to re-read a large context on every wake. Rate-limiting or dropping webhooks at the edge stops the wake storm, but providers do not reliably retry, so dropped deliveries are gone for good.

Per-event waking is one symptom of a wider problem once agents run for months instead of a single coding session. Prompt instructions work well enough across ten or twenty turns, while the rules sit fresh in context and a human is watching the transcript. Over hundreds of turns, as I saw with an earlier project coordinator, prompt discipline erodes predictably: agents report done over unfinished work, pack status updates with internal IDs, and fill long-term memory with transient status. The fix is a hard split of responsibility. Deterministic code owns records, counts, and the decision to speak; models propose actions and write prose.

I built this split into the project layer of my personal agent platform, where each project pairs a manager agent with long-lived staff agents that own whole areas of a product, such as a repository path, a service, or an external account. When I surveyed about thirty agent products in November 2026, none shipped role-owning staff or a batching event inbox for a standing manager. The system is designed, built, and benchmarked locally, though no live model turn has run through it yet. Deterministic code in the project service enforces three boundaries across the lifecycle: when an agent wakes, what its reports may claim, and what its memory may hold, all timed around the prompt-cache lifetime.

## Event ingestion and cache-timed wakes

Keeping every event without flooding the agent means separating the durable write from the decision to interrupt. Incoming webhooks hit an always-on edge hub on Cloudflare Workers and Durable Objects, which verifies signatures, deduplicates deliveries, and commits each event before answering 2xx. From there, events sync to a local SQLite store beside the manager and fold by fingerprint into counted groups, so a thousand copies of one server error collapse into a single group with a count while two pull requests stay separate. Urgency comes strictly from typed provider fields, never payload text, preventing noisy log lines or untrusted issue titles from triggering an immediate wake.

A pure function computes the next wake, delivering one batch per wake on an adaptive interval capped at the prompt-cache lifetime minus three minutes, or 27 minutes on a 30-minute cache. Leaving an active manager idle past expiry means paying full price to re-read a context that could have stayed warm, so the cache TTL sets the upper bound while batching absorbs bursts. Owner messages bypass the buffer immediately. In a local intake benchmark, 120,000 events over 60 simulated seconds were all acknowledged, folded into one group, and written in 60 SQLite transactions.

## Staff ownership and validated reports

Most multi-agent setups treat delegation as spawning disposable sub-agents with narrow prompts and discarding them once a task finishes. That pattern fits isolated side work well, which is why this platform still supports disposable helpers, but it falls apart for ongoing product ownership. A PM manages software engineers, and a software engineer owns a whole area in all its complexity, with all its multitude of tasks. Left to prompt text, models collapse that boundary and spin up throwaway helpers for work that belongs to a permanent owner. To keep those roles separate, the distinction is held across data, tools, and prompts at once: hiring a staff member requires binding it to an owned area, helpers receive none of the project tools, and a build check fails if any prompt or tool description contradicts that separation.

Models have a familiar habit of marking work finished while listing loose ends a few lines down, so staff reports are parsed rather than trusted at face value. Any report submitted as done with a non-empty "Not done" section is stored as progress. One level up, the manager's update to the owner is a typed record capped at 120 words, rejected if it contains record IDs, hashes, file paths, or test counts. Before a scheduled update runs, the service hashes a scorecard of current project state; when that hash matches the previous update, nothing is sent and nobody is woken, sparing both the owner and the prompt cache from empty check-ins.

## Memory boundaries and cold resets

In that earlier system, roughly a third of live memory entries ended up as working state, mostly because an agent with no scratchpad writes its next steps into memory. The platform prevents that drift by giving each kind of knowledge one explicit home across five stores: conversation context for active work, replaceable working notes for plans and open loops, durable records for work items and reports, instructions for roles and operating rules, and memory strictly for facts a fresh session needs and cannot cheaply recover elsewhere.

A pure reducer keeps memory clean without adding another wall of prompt rules. Every memory write passes through deterministic checks that reject status updates, imperatives, and secrets. Provenance stays out of the caller's hands as well. Instead of accepting a self-reported source from the model, the service inspects the conversation span that triggered the tool call and stamps the entry as owner for the owner's own words, verified when observed in a durable record, or inferred for everything else. An agent can still save what it deduced from an external document or event, without promoting an inference into an owner preference.

Memory loading runs on the same prompt-cache clock as event batching. While a manager's session is warm, updates never rewrite earlier turns, since mutating history invalidates the cached prefix; changed entries append at the next turn boundary. Once an idle manager sits quiet past the prompt-cache lifetime, keeping the accumulated transcript buys nothing because the next wake pays a cold read regardless. At that point, the service drops the stale conversation from context and rebuilds the manager cold from durable records, memory, and working notes.
