Repository navigation
fix(agents): prevent writer claim errors in launched turns - #170077
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR clears the caller’s transcript writer context before launching an independent agent turn through in-process Gateway dispatch. Example: A turn in agent:main:dashboard:incognito-caller launches agent:main:launched.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep open: this maintainer-authored PR addresses inherited transcript ownership that current main still permits, with no definite introduced correctness defect found. Priority: P1 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherAgent tools and subagent launchers enter shared Gateway dispatch with caller identity and request guards; dispatch authorizes the request and hands execution to the host-owned turn facade and receiving transcript owner. flowchart TD
A[Caller agent tool] --> B[In-process Gateway dispatch]
B --> C[Capture caller authority]
C --> D[Detach caller transcript context]
D --> E[Host turn facade]
E --> F[Receiving turn writer]
F --> G[Transcript storage]
Technical reviewBest possible solution: Keep isolation at the shared launch boundary while preserving explicit caller admission guards and the receiving turn’s independently acquired writer authority. Do we have a high-confidence way to reproduce the issue? Source establishes caller-context inheritance and foreign-actor rejection, and the author reports a failing-before/passing-after regression; no current-main runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Reusing the existing isolation helper at the common typed/raw dispatch boundary is a focused root-cause repair, and the retained consumer detaches cover work outside independent agent launches. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3c1191dc6f74. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: No concrete bypass was found; the unresolved cross-session authority composition is tracked in the merge risk. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +69. Total +72 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 2:27 PM ET / 18:27 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
… writer (openclaw#170077) Backport adaptation: the regression test uses the release branch assertCommitAllowed writer claim instead of main-only session actors. (cherry picked from commit 6b2bfd1)
… writer (openclaw#170077) Backport note: production change only; the main regression test depends on the session actor owner (openclaw#168602), which is not on this release line. (cherry picked from commit 6b2bfd1) (cherry picked from commit 26c1509) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: turns started by
sessions_sendand subagent follow-ups can fail with "session writer claim changed before transcript persistence" even while the session row still names the failing run as its active writer.User Impact
Launched agent turns establish their own transcript writer instead of failing because they inherited another session's writer context.
Why This Change Was Made
The caller's
ownedTranscriptWriteContextsurvives asynchronous in-process dispatch. Its session actor belongs to the caller's session, so the strict actor lookup rejects the launched session before consulting its row. This also makes caught compaction-preflight reads silently degrade.withInProcessGatewayDispatchis the shared owner for typed and raw in-processagentdispatch. BothcallAgentToolGatewayRequest(send, resume, and agent-step) and the native subagent dispatcher (ordinary, visible, and ACP launches) converge here. The dispatch now detaches transcript ownership alongside the existing operator-tool authority isolation before invoking the launch. The mismatch throw is unchanged, with no catch-and-ignore behavior or new wrapper.Removed consumer detaches: none. The existing detaches have work outside an
agentlaunch that this boundary cannot subsume:sessions-send-reply-flow.tssend.subagent-registry-run-wait.tsagent.wait, terminal observation, reconciliation, completion, and retry bookkeeping.subagent-registry-lifecycle-wake.tssubagent-registry-lifecycle-cleanup.tsmedia-generate-background-shared.tsOther existing detaches cover direct chat/session creation, session-event delivery, cron admission, update notices, worker-result settlement, and local placement/prompt lifecycles; these also operate outside this
agentdispatch boundary.Evidence
Production reports involved send-started turns and subagent follow-ups whose session rows still held their own writer claims. The regression uses synthetic sessions and a real in-memory actor, then launches through the production dispatch and host turn facade with the existing service fixture. It checks a B-scoped actor lookup after an async boundary, both with and without operator-tool authority, and verifies that the caller retains its own context afterward. A direct cross-session lookup still rejects.
Before the production change, both regression cases failed with
SessionTranscriptWriterClaimReboundErrorattranscript-write-context.ts:210. Afterward they passed in 70 ms and 8 ms. The initial fixture key was corrected to a valid in-memory session key before recording that baseline; no production guard was changed to make the test pass.All six existing dispatch suites passed (102 tests). Commands:
pnpm test src/gateway/<file> --maxWorkers=1. Wall times include runner, compiler, import, and teardown overhead.server-plugin-in-process-dispatch.authorization.test.tsserver-plugin-in-process-dispatch.commit-guards.test.tsserver-plugin-in-process-dispatch.continuation.test.tsserver-plugin-in-process-dispatch.scopes.test.tsserver-plugin-in-process-dispatch.session-reads.test.tsserver-plugin-in-process-dispatch.session-scopes.test.tsThe existing database-backed authorization, sharing, and session-creation fixtures and shared worker/compiler preparation account for the long full-suite times. The new regression adds no Gateway boot, real timer, sleep, or polling.
pnpm tsgo:corepassed.gateway-servergraph passed in 21.6 s. The changed-paths router also selected unrelated graphs; that expansion was canceled after the relevant graph passed.git diff --checkpassed.eslint-plugin-soliddependency in the existing lint workspace; installing its already-pinned dependencies fixed the tool prerequisite without changing manifests or the lockfile.