Repository navigation
fix(agents): sessions_send replies are lost when the requester turn ends during handoff - #162299
Conversation
Hold the requesting tool invocation until the existing continuation owner has retained reply authority. Keep child result observation detached so a completed requester turn cannot race asynchronous announce admission. Cover delayed authority capture through the sessions_send entry point using the existing source-route fixtures, and document reply lifetime behavior.
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 5:17 AM ET / 09:17 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR retains background session replies before returning from sessions_send and lets accepted child work finish after the requester’s turn ends. Merge readiness✅ Ready for maintainer review This remains a useful fix: current main retains both failure paths. No introduced correctness or security defect was found, and the prior review has no outstanding findings. Priority: P1 Review scores
Verification
How this fits togetherThe sessions_send tool lets one agent session request work from another. Gateway admission and completion custody carry the accepted result back to the requester while enforcing current access and execution ownership. flowchart TD
A[Requester session] --> B[Session send tool]
B --> C[Gateway admission checks]
C --> D[Accepted child work]
B --> E[Retained reply custody]
D --> E
E --> F[Current access and ownership checks]
F --> G[Requester reply turn]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -2, Tests +231, Docs +4. Total +233 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep reply custody with the existing continuation owner through child settlement, while preserving admission checks and live revocation fences. Do we have a high-confidence way to reproduce the issue? Yes, from source: a zero-wait send can return before continuation capture completes, and accepted child settlement can encounter the requester’s closed participant guard. The reported live reproduction and focused regressions match those paths; this review did not execute them. Is this the best way to solve the issue? Yes. Awaiting custody transfer and using retained source authority for accepted work repairs the existing lifetime boundary without adding a competing owner, configuration option, or stored-data migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c1f5fbe63970. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
…-announce-admission
Bind accepted in-process agent turns to retained source authority instead of their requester's turn-scoped participant guard. Keep participant checks at admission and captured operator checks on source and creation guards. Exercise native and peer sessions_send replies when the requester closes before dispatch or completion, after releasing its original source hold.
|
Merged via squash.
|
…nds during handoff (openclaw#162299) * fix(agents): await sessions_send reply custody transfer Hold the requesting tool invocation until the existing continuation owner has retained reply authority. Keep child result observation detached so a completed requester turn cannot race asynchronous announce admission. Cover delayed authority capture through the sessions_send entry point using the existing source-route fixtures, and document reply lifetime behavior. * test(agents): await reply admission in continuation proofs * fix(agents): retain reply authority through child settlement Bind accepted in-process agent turns to retained source authority instead of their requester's turn-scoped participant guard. Keep participant checks at admission and captured operator checks on source and creation guards. Exercise native and peer sessions_send replies when the requester closes before dispatch or completion, after releasing its original source hold.
What Problem This Solves
Fixes: a nonblocking
sessions_send(or a wait that times out into a background reply) is accepted, but when the requester's turn ends before the target finishes, the reply never reaches the requester and the Gateway logssessions_send announce flow admission failed ... error="This turn has ended; ask again in a new turn.".User Impact
Replies from sessions an agent messaged without waiting reach the requester even when the requester's turn ends first, through both native completion custody and the legacy peer path. Access revocation, Gateway replacement, archived/deleted sessions, and run ownership still stop the reply.
Why This Change Was Made
There were two leaks of the requester's turn-scoped authority:
startSessionsSendReplyFlowdetached the requester-authority capture together with result observation, so the tool could return and the requester turn could end while capture was still in flight. The reply starter now returns an admission promise that resolves once the detached flow runs inside its custody/continuation scope, and every caller awaits it. Result observation stays detached.assertContextCurrentviaagent-run-dispatch.ts→agent-run-execution-phase.ts). Closing the requester therefore rejected the target's completion settlement and deferred peer dispatch. Accepted in-processagentdispatch is now bound to the retained source authority, which includes captured operator checks. Participant and invocation checks stay at admission, and revocation, Gateway, session, and run-ownership checks are unchanged.Production LOC across both commits: -2.
Evidence
timeoutSeconds: 0and ends its turn, and B completes afterwards. Before the second commit, B's reply was rejected with "This turn has ended" and never reached A. With this branch, both the native custody path and the legacy peer path deliver B's reply to A, and the log has no admission failures.server.agent-input-authority.test.tsclose A's participant, admission, and original source hold before releasing B, and assert delivery on both paths. They fail on the previous head. The delayed-capture regressions insessions-send-tool.admission.test.tsfail on base.server-plugin-in-process-dispatch.continuation.test.ts:182reproduces identically without this change. Core and affected test types, lint, oxfmt, deslop, andgit diff --checkpass. Codex autoreview through P2 is scoped-clean for both commits.--maxWorkers=1on a heavily loaded host, of which 157 s is worker compilation. It reuses the existing suite-level Gateways.