Skip to content

fix(agents): prevent writer claim errors in launched turns - #170077

Merged
steipete merged 1 commit into
mainfrom
steipete/session-writer-claim-changed-ac4b72
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/session-writer-claim-changed-ac4b72

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: turns started by sessions_send and 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 ownedTranscriptWriteContext survives 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.

withInProcessGatewayDispatch is the shared owner for typed and raw in-process agent dispatch. Both callAgentToolGatewayRequest (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 agent launch that this boundary cannot subsume:

Consumer Why its detach remains
sessions-send-reply-flow.ts Owns the whole detached reply flow, including waits and same-session delivery through send.
subagent-registry-run-wait.ts Owns agent.wait, terminal observation, reconciliation, completion, and retry bookkeeping.
subagent-registry-lifecycle-wake.ts Owns wake-batch persistence and settlement around any later agent launch.
subagent-registry-lifecycle-cleanup.ts Owns cleanup admission, durable lifecycle updates, and requester delivery through final settlement.
media-generate-background-shared.ts Owns background generation, completion delivery, and retained completion state.

Other 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 agent dispatch 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 SessionTranscriptWriterClaimReboundError at transcript-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.

File Wall time Passed tests
server-plugin-in-process-dispatch.authorization.test.ts 181.10 s 38
server-plugin-in-process-dispatch.commit-guards.test.ts 166.05 s 4
server-plugin-in-process-dispatch.continuation.test.ts 199.28 s 13
server-plugin-in-process-dispatch.scopes.test.ts 257.96 s 30
server-plugin-in-process-dispatch.session-reads.test.ts 234.78 s 6
server-plugin-in-process-dispatch.session-scopes.test.ts 340.89 s 11

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

  • Production types: pnpm tsgo:core passed.
  • Test types: the gateway-server graph passed in 21.6 s. The changed-paths router also selected unrelated graphs; that expansion was canceled after the relevant graph passed.
  • Targeted type-aware lint, formatting, and git diff --check passed.
  • The initial lint attempt found a missing eslint-plugin-solid dependency in the existing lint workspace; installing its already-pinned dependencies fixed the tool prerequisite without changing manifests or the lockfile.
  • PR CI provides the remaining broad proof; CI timing is pending.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

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

  • Before: The launched turn inherits the caller’s actor, and its actor lookup throws SessionTranscriptWriterClaimReboundError.
  • After: The launch begins without the caller’s transcript context, allowing the receiving turn to establish its own writer.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused repair has clear value and no definite correctness finding, but supplied execution evidence does not qualify the changed authority composition.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Send-started turns and subagent follow-ups can fail before replying because they inherit another session’s transcript writer.
Reason: The maintainer-authored change restores independent-turn ownership using the existing boundary and helper without introducing another API or state owner.

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
Reviewed head: 95281f16c00245ab5009c15e5fea14c6898139b8

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied regression mocks turn execution and checks context lookup rather than input commit or transcript persistence; provide redacted Gateway output or an authorized production-owner harness showing successful independent execution, revoked-caller rejection before acceptance, and replaced-writer rejection before append, while preserving accepted work’s custody contract and redacting IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - No concrete bypass was found; the unresolved cross-session authority composition is tracked in the merge risk.
  • Resolve merge risk - Before merge, establish that clearing ambient transcript and CLI-history authority preserves rejection of a revoked caller before input commit and a replaced receiving writer before transcript append.

Findings

None.

Tests

  • Missing end-to-end proof: Missing final-effect qualification through actual input commit and transcript append for an allowed launch, a caller revoked before acceptance, and a replaced receiving writer.
Agent review details

How this fits together

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

Technical review

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

Maintainer options:

  1. Hold for authority qualification (recommended)
    Keep this PR open until the real admission and transcript owners demonstrate successful independent execution and rejection of revoked caller and replaced writer authority before their respective writes.

Provenance checked

  • Autonomous in-process agent dispatch keeps the original intent (53dcaae: Autonomous launches must not retain the caller’s human tool authority into subsequent model-selected work.)
  • Conditional operator-tool context isolation changes intended behavior with a stated reason (f2e5268: The supplied provenance associates these lines with operator upload controls; the PR preserves tool-authority isolation and explains why transcript isolation must also run without ambient tool authority.)

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete bypass was found; the unresolved cross-session authority composition is tracked in the merge risk.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 48c022a adds src/gateway/server-plugin-in-process-dispatch.ts:152 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 48c022a42c13; files: src/gateway/server-plugin-in-process-dispatch.ts)
  • Shakker: Raw commit 715077a adds src/gateway/server-plugin-in-process-dispatch.ts:517 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 715077a3befb; files: src/gateway/server-plugin-in-process-dispatch.ts)
  • Vincent Koc: Raw commit da27b33 adds src/gateway/server-plugin-in-process-dispatch.ts:612 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: da27b336c0e9; files: src/gateway/server-plugin-in-process-dispatch.ts)

PR surface

Source +3, Tests +69. Total +72 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 4 +3
Tests 1 69 0 +69
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 76 4 +72

Labels

Label changes:

  • add P1: Inherited writer context can terminate sessions_send targets and independently launched subagents before they produce a reply.
  • add merge-risk: 🚨 security-boundary: The change clears authority-bearing transcript and CLI-history context across session launches without supplied final-effect qualification.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P1: Inherited writer context can terminate sessions_send targets and independently launched subagents before they produce a reply.
  • merge-risk: 🚨 security-boundary: The change clears authority-bearing transcript and CLI-history context across session launches without supplied final-effect qualification.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof for revoked caller authority before input commit and replaced receiving-writer authority before transcript I/O.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 12, 2026, 2:27 PM ET / 18:27 UTC.

@steipete
steipete merged commit 6b2bfd1 into main Oct 12, 2026
122 of 125 checks passed
@steipete
steipete deleted the steipete/session-writer-claim-changed-ac4b72 branch October 12, 2026 20:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
… writer (#170077)

Backport note: production change only; the main regression test depends on the
session actor owner (#168602), which is not on this release line.

(cherry picked from commit 6b2bfd1)
@clawsweeper clawsweeper Bot mentioned this pull request Oct 15, 2026
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Oct 16, 2026
… 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)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
… 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant