Repository navigation
Description
Summary
The caller wake is bounded by a 15-second window per caller. The code and the docs say the bound is "one running wake plus one pending per caller". That holds only inside the window the running wake claimed. A wake turn that runs longer than its window does not hold the next one: an ending that arrives in a later window starts a second wake at once, and a third in the window after that. Nothing is parked. The caller then runs several wake turns in parallel on the same work, and each is a billed turn.
Context
Why it happens. The idempotency key of a wake is caller_wake:{caller}:{int(now // 15)} (_bucket_for and _idempotency_key, src/backend/services/caller_wake_service.py:163-168). maybe_wake_caller claims that key (:617). The park added for #4536 runs only when the claim finds the same key in flight (:624). An ending in a later window computes a different key, so the claim is new and the wake is dispatched, although a wake for this caller is still running.
Reproduced on dev (d481847cc) with the harness of tests/unit/test_4536_wake_window.py (the real maybe_wake_caller, the real idempotency claim, SQLite, an in-memory Redis):
- Ending A arrives. Wake 1 is dispatched and held open, as a wake turn that is still running.
- The clock moves 11 s, into the next window. Ending B arrives.
- The clock moves 15 s more. Ending C arrives.
Result: wakes_dispatched=3, wakes_running_at_once=3, no parked marker, no parked audit row. Control: an ending that arrives in the same window as the running wake is parked and no second wake starts, as #4536 intends.
The existing suite cannot see this. It pins the clock in the middle of one window: "Mid-bucket, so nothing in a test crosses a window boundary by accident" (tests/unit/test_4536_wake_window.py:61-62).
Seen live on a client instance on v1.0.5 (2026-11-20, UTC). One scheduled run made three async chat_with_agent calls. Wakes for their endings started at 07:02:10 (it ran 4 minutes), 07:02:29 (it ran 81 s) and 07:02:31, in three consecutive windows, while the scheduled run itself still ran. The third found the agent at its limit and was recorded as a failed caller_wake execution: "Agent at capacity (3/3 parallel tasks running)". An earlier wake of the same run had delegated again, so one scheduled run produced four wake turns.
Impact
- Several turns of one agent work on the same task at once. When that work writes files or posts messages, they can do it twice.
- Each extra wake is a billed turn. In the live case a wake that did real work used up to about 125,000 tokens of context.
- At capacity the extra wake is a failed execution, which a monitor that counts failed runs reports.
- This is the normal case, not an edge. Every wake turn we saw that started ran longer than 15 seconds (17 seconds to 4 minutes).
Where the bound is stated
src/backend/services/caller_wake_service.py:56(module text)docs/memory/requirements/core-agent.md:2213docs/memory/feature-flows/agent-to-agent-collaboration.md:350docs/user-docs/collaboration/agent-network.md:26anddocs/user-docs/faq/collaboration.md:39("a run that ends while a wake is still running is held and delivered once that wake ends")
Acceptance Criteria
- While a wake turn runs for a caller, an ending for that caller in any later window starts no second wake. It is parked and delivered once when the running wake ends, or it folds into that wake when it ended before the wake's claim.
- At most one
caller_waketurn runs per caller at a time, with at most one pending. This holds for endings in consecutive windows, for a wake that outlives several windows, and for a wake that delegates again and whose callee ends in a later window. - What bug(wake): a fast callee's ending is dropped by the 15 s wake window, so a delegate→wake loop stalls silently #4536 fixed still holds: a finished wake releases its hold and the next ending wakes at once; a sweep inside one window is one wake; a parked ending survives a restart or a cancelled holder.
- A test moves the clock across a window boundary while a wake is held. It is red on today's
devand green after the fix. - The five places above state the rule as built.
Technical Notes
- Direction. Hold per caller while a wake runs, not per time window: for example a second claim
caller_wake:{caller}:running, taken at dispatch and released where the window key is released today. An ending that finds it in flight goes through the existing_parkand_drain_missed. The window key can stay as it is for folding a sweep. - Stale hold. The wake row's own terminal already drains the parked marker (
maybe_wake_calleron acaller_wakerow), and every terminal writer reaches it. The same place can release the per-caller hold, so a restart in the middle of a wake does not leave it held. - The shape of the failing test, with the names of
test_4536_wake_window.py. I ran it as a separate file that imports that harness:
def test_an_ending_in_a_later_window_starts_no_second_wake(world, monkeypatch):
clock = {"t": NOW}
monkeypatch.setattr(_WAKE, "time", SimpleNamespace(time=lambda: clock["t"]))
async def go():
world.gate["event"] = asyncio.Event() # wake 1 stays running
a = _callee_run(); _end(a)
first = asyncio.ensure_future(_WAKE.maybe_wake_caller(a))
await asyncio.sleep(0.2)
assert len(world.held) == 1
clock["t"] = NOW + 11 # the next window
b = _callee_run(); _end(b)
second = asyncio.ensure_future(_WAKE.maybe_wake_caller(b))
await asyncio.sleep(0.2)
clock["t"] = NOW + 26 # the window after it
c = _callee_run(); _end(c)
third = asyncio.ensure_future(_WAKE.maybe_wake_caller(c))
await asyncio.sleep(0.2)
running = len(world.held)
world.gate["event"].set()
await asyncio.gather(first, second, third)
assert running == 1, f"{running} wake turns were running at once for one caller"
asyncio.run(go())Today it fails with AssertionError: 3 wake turns were running at once for one caller.
- Related: bug(wake): a fast callee's ending is dropped by the 15 s wake window, so a delegate→wake loop stalls silently #4536 (closed: the park inside one window), bug(wake): a sync agent-to-agent call still wakes the caller, billing a second turn for an answer it already has #4538 (open: a waited call still wakes the caller), bug(delegation): wake-on-ending and reminder turns inherit the chain depth, so an autonomous delegate→wake→delegate run stops after ~8 rounds #4357 (the hourly wake budget), PR feat(wake): caller is woken when its delegated run ends, default on (ent#1102, ent#790) #4269 (it added the window).
Activity
webmixgamer commentedon Nov 23, 2026
Product ruling (2026-11-23): one more criterion for this issue. A wake that is refused because the caller is at capacity is parked and delivered later, like any other ending that arrives while a wake runs. It is not recorded as a failed
caller_wakeexecution.webmixgamer commentedon Nov 23, 2026
/claim
github-actions commentedon Nov 23, 2026
Claimed by @webmixgamer. Label
status-in-progressadded.Next steps:
feature/4733-<short-slug>Fixes #4733fix(wake): one wake per caller at a time, and a wake refused at capac…