Repository navigation
fix(wake): a caller that waits is not woken, and a call can decline its wake (#4538) - #4766
Conversation
…ts wake (#4538) The caller wake is for a caller that got a receipt. It also fired for a caller that held the call open and already had the answer, and a caller that polled in its own turn could not decline it. A call now says so itself, and the dispatch records it for the callee row ("call terms": an idempotency row keyed on the callee execution id, so no column and no migration): - `wake: false` on POST /task and /chat, and on the `wake` parameter of `chat_with_agent` and every `chat_with_<agent>` tool, starts no wake when that run ends. The receipt answers `wake_on_ending: {effective: false, source: "call"}`, which the MCP server prints as `wake: "none"`, `wake_reason: "caller_declined"`. - `caller_wait_ms` says how long a sync caller waits (the MCP server sends its own ceiling). A run that ends 5 s or more before that deadline was answered inline and wakes nobody; one that outlives it keeps its wake. A backend handler that gives up first moves the deadline before it re-reads the row. Only positive evidence stands a wake down: a call that declares neither, and terms that are missing, unreadable, half-written or unparsable, wake as before. `wake` stays out of the MCP idempotency key. Behind a wake parked for a free slot (the #4745 follow-ups), each with a test that failed first: - every slot release now drains the parked wake, after the backlog drain, from the release callback CapacityManager registers. That covers a terminate, a cleanup release and a run whose terminal lands before its own `finally` releases the slot; - a wake refused with no run of the caller left running is parked again instead of ending as a FAILED row; - after a capacity park the ending is dispatched again only when the meter was read and shows a free slot. An unreadable meter looped refused wakes until the hourly budget ran out (120 FAILED rows for one ending in the test); - a delivery cancelled before it holds the caller puts its marker back; - `release_admission`'s release-then-drain is pinned. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…#4538, #4674) `maybe_wake_caller` runs for every terminal, and a cleanup sweep runs it hundreds of times in one cycle. Its row read, subscription read, hold claim, live-wake read, pending-ask read and standing-depth read were written directly inside `async def`, so each one blocked the worker. They go through `asyncio.to_thread` now. The sync-on-loop baseline entry for caller_wake_service.py goes from 6 to none (regenerated with `check_sync_on_loop.py --write`). A row that cannot be read is logged at warning: it is an ending nobody is woken for. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Feature flow step 11 (call terms: carried, stamped, kept, read, re-opened, receipt), the slot-release drain in step 9, the requirement for every slot release delivering a parked wake, the execution architecture note, and the user docs: `wake: false`, `caller_declined`, no wake after an inline answer, and what a plain REST sync caller has to send. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ls that fire no callback, a later claim mark (#4538) From the pre-landing review, each with a test that failed first: - The inline margin was 5 s, the same as the sync waiter's database poll: a run ending on another worker could be stood down as "answered inline" while its reply left after the caller gave up. It is 10 s, and a test pins it at the poll plus 5 s or more. - The stale-slot reclaim and `force_release` remove slots without the release callback, so they drain a parked wake themselves, under the same guard. - The release drain takes the marker only when the meter shows a free slot. The callback also fires for the backlog's sentinel swap, which frees nothing, and re-ran the whole hook on every such release. - A delivery's claim is marked at the dispatch, not at the hold: a cancel during the budget check or the reads before the wake row exists puts the ending back. Tests: the time-based ones run on a frozen clock; the terms-write failure test now proves the write was attempted and that the wake fires; the real-thread tests assert what they name. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…note on chat_with_agent (#4538) Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
✅ Nightly unit-suite clean when this PR is merged into |
# Conflicts: # scripts/ci/sync_on_loop_baseline.json
|
Release note for the merge train: this should ship in the same release as #4606, or before it. #4606 writes a wake's reply into the person's Chat thread when the delegation came from their turn there. An agent that answers every wake with a fixed one-line no-op today (the usual workaround for the wake that #4538 lets a call decline) will post that line into the person's thread as soon as #4606 ships. With this PR the caller sends For a mixed rollout: on REST |
|
merge-train note (validated at One fit question went to the operator at Gate 1 and was ruled acceptable (recorded on #4538): a REST sync One ask, not blocking the merge: the body lists limits with no follow-up issue (the REST sync gap above; no opt-out on loop iterations and |
|
Follow-ups filed and named in the PR body:
The remaining limits in the body are design bounds, not gaps: the 10 s margin, the 24 h life of a call's terms, and a re-send that only changes |
Summary
The caller wake is for a caller that got a receipt. It also fired for a caller that held the call open and already had the answer, and a caller that polled in its own turn could not decline it. Each such wake is a billed turn that adds nothing.
wake: falsedeclines the wake for one call, sync or async: onPOST /api/agents/{name}/taskand/chat, and as thewakeparameter ofchat_with_agentand every dedicatedchat_with_<agent>tool. The receipt sayswake: "none",wake_reason: "caller_declined".wake: trueis the default, never a force: the owner's switch stays authoritative.caller_wait_ms; the MCP server sends its own ceiling,MCP_CHAT_TIMEOUT_MS, on every sync call). A run that ends at least 10 s before that wait is over wakes nobody.wake: falseorcaller_wait_ms. Terms that are missing, unreadable, half-written or unparsable also wake. The plain REST sync gap was ruled acceptable for this PR (the ruling is on bug(wake): a sync agent-to-agent call still wakes the caller, billing a second turn for an answer it already has #4538) and is tracked in bug(wake): three gaps left by the per-call wake opt-out — a plain REST sync call, a schedule an agent triggers, and receipts that say nothing about the wake #4790.No DB migration, no new route. The call's word is kept as an
idempotency_keysrow keyed on the callee execution id, so it survives the backlog drain, the pull claim and every other re-dispatch from the row.Behind a parked wake (the follow-ups from #4745)
Each has a test that failed before the fix.
release_admissionreleases, then drainsSET NX, so a newer parked ending wins; never once the wake is being dispatched)caller_wake_service.pygoes 6 → noneOne drain at the slot release.
CapacityManager._on_slot_released, the callback already registered onSlotServicefor the backlog, now also drains a caller wake parked for a free slot: after the backlog drain, under its own guard, and only when the meter shows a free slot. The stale-slot reclaim andforce_release, which remove slots without the callback, drain too. A test makes the wake drain raise and checks that the release and the backlog drain still happen.TARGET_ARCHITECTURE check (
capacity_manager.py)EXISTSper slot release, the same class asslot_service's own client (refactor: synchronous database, Docker and Redis calls run inside async request handlers #4413).idempotency_keys), not Redis, apart from the existing parked-ending hint.Stated limits
get_execution_result.MCP_CHAT_TIMEOUT_MSraised above the calling client's own gateway timeout makes "answered inline" false for a run ending in the gap.agent.task.*events still gets that turn on a declined call. The answer wake for an ask is untouched.trigger_agent_scheduletakes no opt-out (tracked in bug(wake): three gaps left by the per-call wake opt-out — a plain REST sync call, a schedule an agent triggers, and receipts that say nothing about the wake #4790).fan_outreceipts carry no wake field. The MCP server's ownqueued_timeoutreceipt carries none either (both tracked in bug(wake): three gaps left by the per-call wake opt-out — a plain REST sync call, a schedule an agent triggers, and receipts that say nothing about the wake #4790).wakereplays the first call and its receipt (wakeis not in the idempotency key). The approved run of a request that waited for approval wakes by default.list_recent_executions).caller_wait_ms, so its sync calls wake as before until it is rebuilt.Changes
services/caller_wake_service.py,services/chat_execution_service.py,services/capacity_manager.py,services/idempotency_service.py,db/idempotency.py(peekreturns the snapshot),models.py(wake,caller_wait_msonParallelTaskRequestandChatMessageRequest).tools/chat.ts,tools/dynamic-agents.ts,client.ts(additive).core-agent.md§9.1.1), the agent-to-agent collaboration flow (step 11),architecture/execution.md, user docs (Agent Network, FAQ, chat API reference, MCP server reference).scripts/ci/sync_on_loop_baseline.json: regenerated with--write.Deploy: rebuild backend and mcp-server. No migration, no base-image change.
Test Plan
cd tests && pytest unit/test_4538_wake_opt_out.py unit/test_4538_parked_wake_release.py unit/test_3127_pull_chat.py -qcd src/mcp-server && node --import tsx --test src/chat-wake-opt-out.test.ts src/wake.test.tstest_a_sync_call_answered_inside_the_callers_wait_starts_no_wake);wake: falseon an async call starts no wake and the receipt says so (test_a_declined_async_call_starts_no_wake_and_its_receipt_says_so, and the MCPcaller_declinedtest); a sync call that outlives the wait keeps its wake (test_a_sync_call_that_outlived_the_callers_wait_keeps_its_wake); the dedicated tool passeswakethrough (dropping the declaration or the pass-through line turnsthe dedicated chat_with_<agent> tool passes wake throughred).tool-visibility.test.ts, which fails the same way without this change on the machine the tests ran onwake: falseshowscaller_declinedand starts no wake; a sync call answered inline starts no wake; a sync call past the 25 s wait gets a receipt and then its wake. The audit rows showskipped_declinedwithcaller_declinedandanswered_inline.Fixes #4538
🤖 Generated with Claude Code