Skip to content

bug(wake): a running wake holds only its own 15 s window, so endings in later windows start more wake turns on the same caller at once #4733

Open

Description

@webmixgamer

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):

  1. Ending A arrives. Wake 1 is dispatched and held open, as a wake turn that is still running.
  2. The clock moves 11 s, into the next window. Ending B arrives.
  3. 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:2213
  • docs/memory/feature-flows/agent-to-agent-collaboration.md:350
  • docs/user-docs/collaboration/agent-network.md:26 and docs/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_wake turn 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 dev and 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 _park and _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_caller on a caller_wake row), 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.

Activity

  1. added
    priority-p2
    type-bug
    theme-reliability
    status-ready
    on Nov 23, 2026
  2. webmixgamer commented on Nov 23, 2026

    @webmixgamer
    ContributorAuthor

    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_wake execution.

  3. webmixgamer commented on Nov 23, 2026

    @webmixgamer
    ContributorAuthor

    /claim

  4. added
    status-in-progress
    and removed
    status-ready
    on Nov 23, 2026
  5. github-actions commented on Nov 23, 2026

    @github-actions

    Claimed by @webmixgamer. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/4733-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #4733
  6. added
    status-in-dev
    and removed
    status-in-progress
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2status-in-devtheme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions