Skip to content

fix(agents): sessions_send replies are lost when the requester turn ends during handoff - #162299

Merged
steipete merged 4 commits into
mainfrom
steipete/team-harness-announce-admission
Oct 1, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/team-harness-announce-admission

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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 logs sessions_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:

  1. Handoff race: startSessionsSendReplyFlow detached 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.
  2. Settlement guard: after custody transferred, the target's accepted in-process agent turn still carried the requester's participant guard (assertContextCurrent via agent-run-dispatch.ts → agent-run-execution-phase.ts). Closing the requester therefore rejected the target's completion settlement and deferred peer dispatch. Accepted in-process agent dispatch 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

  • Live, on an isolated Gateway with a real OpenAI model and the embedded runtime: session A sends to B with timeoutSeconds: 0 and 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.
  • On a busy production Gateway over three days: 42 "This turn has ended" announce admission failures.
  • Real-Gateway regressions in server.agent-input-authority.test.ts close 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 in sessions-send-tool.admission.test.ts fail on base.
  • 92 focused tests pass. One existing Gateway RPC timeout in server-plugin-in-process-dispatch.continuation.test.ts:182 reproduces identically without this change. Core and affected test types, lint, oxfmt, deslop, and git diff --check pass. Codex autoreview through P2 is scoped-clean for both commits.
  • Test cost: the admission file takes 386 s wall with --maxWorkers=1 on a heavily loaded host, of which 157 s is worker compilation. It reuses the existing suite-level Gateways.

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.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 5:17 AM ET / 09:17 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: 50505c2e04704f0ced28ecb59c76bb9bfc9e25a7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with relevant lifecycle regressions and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate is exempt for the supplied MEMBER author. The captured body reports after-fix native and peer delivery on an isolated real Gateway; inspected production guards and existing final-write rejection coverage establish no unresolved authority-chain proof requirement. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate is exempt for the supplied MEMBER author. The captured body reports after-fix native and peer delivery on an isolated real Gateway; inspected production guards and existing final-write rejection coverage establish no unresolved authority-chain proof requirement. No stored-data contract changes.
Evidence reviewed 7 items Pinned introduced change: Reviewed the merge-base-to-head delta at the supplied pinned revisions. The checkout matches the original PR head; the stale test merge was not used to infer removal of current-main behavior.
Current main still needs the fix: Current main still detaches continuation capture without an admission promise and supplies the participant-sensitive context guard to accepted agent turns. Comparing these two production files against the pinned base returned no differences. The supplied latest release, v2026.9.7, predates this branch; no merged replacement fixing this handoff was established.
Admission and retained-source boundaries: The new source guard includes captured operator authority. Participant and invocation checks remain in admission; the retained source continues checking operator authority and Gateway identity. Completion and dispatch also retain lifecycle, cancellation, and exact run-owner fences.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -2, Tests +231, Docs +4. Total +233 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 49 51 -2
Tests 4 257 26 +231
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 310 77 +233

Review metrics

Metric Value Why it matters
Production versus regression coverage production -2 lines, tests +231 lines The repair reuses existing authority owners; added coverage targets capture ordering and child settlement through the Gateway.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Accepted cross-session replies are silently lost in an active agent workflow, with repeated production failures reported.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor proof gate is exempt for the supplied MEMBER author. The captured body reports after-fix native and peer delivery on an isolated real Gateway; inspected production guards and existing final-write rejection coverage establish no unresolved authority-chain proof requirement. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta at the supplied pinned revisions. The checkout matches the original PR head; the stale test merge was not used to infer removal of current-main behavior. (50505c2e0470)
  • Current main still needs the fix: Current main still detaches continuation capture without an admission promise and supplies the participant-sensitive context guard to accepted agent turns. Comparing these two production files against the pinned base returned no differences. The supplied latest release, v2026.9.7, predates this branch; no merged replacement fixing this handoff was established. (src/agents/tools/sessions-send-reply-flow.ts:31, c1f5fbe63970)
  • Admission and retained-source boundaries: The new source guard includes captured operator authority. Participant and invocation checks remain in admission; the retained source continues checking operator authority and Gateway identity. Completion and dispatch also retain lifecycle, cancellation, and exact run-owner fences. (src/gateway/server-plugin-in-process-dispatch.ts:282, 50505c2e0470)
  • Regression coverage matches both leaks: The admission regression holds actual authority capture and checks that the tool cannot return early. Four Gateway cases exercise native and peer replies with requester closure before child dispatch or completion, releasing the original source hold before asserting delivery. Existing cases check rejected admission and Gateway retirement without transcript mutation. These tests were inspected, not executed during this read-only review. (src/gateway/server.agent-input-authority.test.ts:69, 50505c2e0470)
  • Forbidden final effects remain covered: The existing real-Gateway continuation suite uses registered version-2 plugin tools and an actual file write. Revoked ownership, reassignment, and a replacement user turn reject before that write. The merged supporting work is fix: preserve owner access after child follow-up results #160018; its proof covers this retained-owner contract rather than the newly repaired handoff race. (src/gateway/server.sessions-send-owner-continuation.test.ts:82, 50505c2e0470)
  • Captured runtime evidence: The supplied PR body reports an isolated Gateway with a real OpenAI model and embedded runtime: after session A ends, B’s reply reaches A through both native custody and legacy peer paths, without announce admission failures. It reports 92 focused passing tests and an independently reproduced pre-existing RPC timeout. These are contributor-reported results, not executions performed by this review. (50505c2e0470)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-01T02:28:36.311Z sha e9142b0 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T06:28:03.241Z sha 5c666df :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T06:59:33.268Z sha 553e633 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 1, 2026
@steipete steipete self-assigned this Oct 1, 2026
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.
@steipete
steipete merged commit 57d4719 into main Oct 1, 2026
184 of 185 checks passed
@steipete
steipete deleted the steipete/team-harness-announce-admission branch October 1, 2026 09:36
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant