Skip to content

fix(sessions): fence transcript writes by admitted run - #121003

Merged
steipete merged 4 commits into
mainfrom
steipete/session-writer-claim
Aug 9, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/session-writer-claim

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Nothing durable recorded WHICH run owns a session's transcript writes. A wedged run that lost its lane slot could still write (its SessionManager snapshot intact), and its successor had no supersession path — the production incident showed successors failing on lease timeouts every 30 minutes with no recorded reason. Silent zombies are the worst bug class.

Why This Change Was Made

Durable activeWriterRunId claim CAS'd at lane admission with the {sessionId, lifecycleRevision} pair; every run-owned transcript write validates the claim inside the SQLite transaction (async guarded turns, sync SessionManager writes, CLI writes, delivery mirrors); a superseding admission records a sticky superseded terminal outcome for the live prior run before exact-run cancellation — supersession is always visible, never silent. Stale claims from dead processes are CAS'd over without ceremony. Leases, stale-parent rebasing (claim holders keep rebasing), lifecycleRunId, placements, and heartbeat gating are intentionally unchanged. This is the designed replacement for the session-write lease, which a follow-up PR deletes.

User Impact

A stuck run can no longer silently corrupt or contend its session; the successor supersedes it with a recorded outcome visible in tasks/TUI/session activity.

Evidence

Transcript suite 67 tests incl. in-transaction fence rejection; admission incident-order integration test; terminal outcome/merge 41; embedded terminal/lifecycle/registry 47; tasks 121; subagents 191; gateway wait reconstruction 8; plugin projection 26; full changed gate (typecheck/lint/surface/dead-code/storage/cycles); codex autoreview clean. Production +473/−104 — growth justified by the new ownership boundary (Repair Doctrine: recorded fact at the owning boundary).

Exact-head CI and ClawSweeper review surfaced related guard, propagation, ordering, and stale-expectation gaps. The completed follow-up extracts a leaf terminal-outcome type contract, regenerates the intentional Plugin SDK API manifest, keeps the admitted fence private across context-engine target adoption, restores it at attempt dispatch, fences CLI streamed/abort/final transcript recording, commits the replacement claim before recording and cancelling its incumbent, and adds exact failure-order assertions. Current totals: production +555/−128, tests +622/−28, generated baseline +77/−77. Focused repair proof: claim/order 2, prompt-state 13, CLI recorder 9, CLI dispatch 43; post-rebase proof: transcript 67, writer claim 1, terminal outcome 41, attempt lock/teardown 44, delivery mirror 336, attempt stream 10, SDK projection 1, Madge 0 cycles, exact API baseline, and fresh branch autoreview clean.

Named follow-ups (coordinator-tracked): fence the remaining non-turn writers (session-manager-branching, sqlite-checkpoint, sqlite-message-cut, worker transcript-commit session-row write); delete the session-write lease.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling labels Aug 9, 2026
@steipete steipete self-assigned this Aug 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 08:39
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 9, 2026
@steipete
steipete force-pushed the steipete/session-writer-claim branch from 1a1e781 to 9d5309d Compare August 9, 2026 08:54
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete force-pushed the steipete/session-writer-claim branch 2 times, most recently from 65c8744 to 1a4af69 Compare August 9, 2026 09:34
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 9, 2026, 5:44 AM ET / 09:44 UTC.

ClawSweeper review

What this changes

This PR adds a durable admitted-run claim intended to prevent stale agent runs from writing to a session transcript and to record supersession visibly.

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Keep open: three P1 paths still allow a superseded run to bypass or prematurely disrupt the new transcript-writer ownership invariant.

Priority: P1
Reviewed head: 1a4af69775cadd16abd13f030bc7544978359fe4

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Three direct P1 gaps prevent the proposed durable writer-ownership guarantee from holding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body’s test claims remain supplemental to the required owner-boundary repair.
Patch quality 🧂 unranked krab (1/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body’s test claims remain supplemental to the required owner-boundary repair.
Evidence reviewed 6 items Current main lacks a writer fence: Current main retains admission validation but has no durable admitted-run writer claim, so the central behavior remains necessary.
Embedded prompt state drops the new fence: The changed lane controller attaches writer fields, but prompt-state construction converts the target to a public context-engine target that omits them before dispatch.
CLI recorder remains unfenced: The new fields are passed to the final CLI run, but the earlier streamed CLI transcript recorder and abort-time flush use the unguarded asynchronous append path.
Findings 3 actionable findings [P1] Carry the admitted writer fence into the embedded attempt
[P1] Fence the CLI dispatch transcript recorder
[P1] Commit the replacement claim before cancelling its incumbent
Security None None.

How this fits together

Session-lane admission selects the run that may persist a session’s transcript. That private ownership fact must survive prompt setup, CLI and delivery write paths, and SQLite transactions so stale output is rejected and supersession is visible.

flowchart LR
A[Run enters session lane] --> B[Durable writer claim]
B --> C[Prompt and dispatch state]
C --> D[Transcript write paths]
D --> E{Writer claim matches?}
E -->|yes| F[Persist transcript]
E -->|no| G[Reject stale write]
B --> H[Record and cancel prior run]
Loading

Before merge

  • Carry the admitted writer fence into the embedded attempt (P1) - The new fields are attached here, but prompt-state construction immediately narrows the target to ContextEngineSessionTarget, which excludes both fields before attempt dispatch. The SessionManager and owned transcript writes therefore run unfenced from the outset, allowing a superseded run to append.
  • Fence the CLI dispatch transcript recorder (P1) - Only the final runCliAgent call receives the fence. The earlier recorder, including its abort-time flush, retains no fence and calls the asynchronous append path that does not validate either expected writer field, so a cancelled CLI child can append after replacement admission.
  • Commit the replacement claim before cancelling its incumbent (P1) - This path records and cancels the current writer before the replacement’s session-row update commits. A concurrent ordinary session-row mutation can reject that update, leaving the old run terminated without any admitted successor writer.
  • Resolve merge risk (P1) - Merging before the three repaired paths are covered can still admit stale transcript writes or cancel the incumbent without a successfully admitted replacement.
  • Resolve merge risk (P1) - The durable session-state change requires a fresh exact-head green run after the repair.
  • Improve patch quality - Retain the private fence through prompt state, dispatch, and rebased targets.
  • Improve patch quality - Fence and transactionally validate streamed CLI recorder and abort-flush writes.
  • Improve patch quality - Commit the replacement claim before cancelling the incumbent and add conflict-order regression coverage.

Findings

  • [P1] Carry the admitted writer fence into the embedded attempt — src/agents/embedded-agent-runner/run/lane-controller.ts:159-164
  • [P1] Fence the CLI dispatch transcript recorder — src/agents/embedded-agent-runner/cli-backend-dispatch.ts:197-202
  • [P1] Commit the replacement claim before cancelling its incumbent — src/agents/embedded-agent-runner/run/session-bootstrap.ts:269-301
Agent review details

Security

None.

PR surface

Source +390, Tests +463, Generated 0. Total +853 across 54 files.

View PR surface stats
Area Files Added Removed Net
Source 41 512 122 +390
Tests 12 491 28 +463
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 77 77 0
Other 0 0 0 0
Total 54 1080 227 +853

Review metrics

Metric Value Why it matters
Production versus test delta production +511/-122; tests +492/-28; generated baseline +77/-77 The substantial production growth is intended to establish a durable ownership boundary, so its end-to-end invariant needs focused repair proof before merge.

Stored data model

Persistent data-model change detected: serialized state: src/agents/embedded-agent-runner/run/session-bootstrap.ts, serialized state: src/agents/subagent-registry.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-contract.ts, serialized state: src/config/sessions/session-accessor.sqlite-transcript-write.ts, serialized state: src/config/sessions/session-accessor.transcript-turn.ts, serialized state: src/config/sessions/session-accessor.types.ts, and 14 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the complete writer boundary (recommended)
    Preserve and transactionally enforce the admitted-run fence on embedded, CLI, and rebased paths, then cancel an incumbent only after the replacement claim commits.

Technical review

Best possible solution:

Keep a private admitted-writer fence through prompt setup, dispatch, rebased targets, CLI recording, and transactional writes; commit the replacement claim before recording or cancelling the displaced run.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a normal embedded attempt loses its writer fence during prompt-state construction; separately, a CLI recorder and a failed concurrent-claim sequence provide focused regression paths.

Is this the best way to solve the issue?

No. A durable writer claim is the right owner boundary, but this branch does not carry it through all ordinary writers or commit it before cancelling the prior owner.

Full review comments:

  • [P1] Carry the admitted writer fence into the embedded attempt — src/agents/embedded-agent-runner/run/lane-controller.ts:159-164
    The new fields are attached here, but prompt-state construction immediately narrows the target to ContextEngineSessionTarget, which excludes both fields before attempt dispatch. The SessionManager and owned transcript writes therefore run unfenced from the outset, allowing a superseded run to append.
    Confidence: 0.97
  • [P1] Fence the CLI dispatch transcript recorder — src/agents/embedded-agent-runner/cli-backend-dispatch.ts:197-202
    Only the final runCliAgent call receives the fence. The earlier recorder, including its abort-time flush, retains no fence and calls the asynchronous append path that does not validate either expected writer field, so a cancelled CLI child can append after replacement admission.
    Confidence: 0.96
  • [P1] Commit the replacement claim before cancelling its incumbent — src/agents/embedded-agent-runner/run/session-bootstrap.ts:269-301
    This path records and cancels the current writer before the replacement’s session-row update commits. A concurrent ordinary session-row mutation can reject that update, leaving the old run terminated without any admitted successor writer.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 135278c8968f.

Labels

Label changes:

  • add P1: The patch leaves direct stale-run transcript-write paths and a failed-admission cancellation race in a session-state reliability fix.
  • add merge-risk: 🚨 session-state: It changes the durable owner of session transcript writes and can otherwise allow stale or ownerless session state.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: The patch leaves direct stale-run transcript-write paths and a failed-admission cancellation race in a session-state reliability fix.
  • merge-risk: 🚨 session-state: It changes the durable owner of session transcript writes and can otherwise allow stale or ownerless session state.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body’s test claims remain supplemental to the required owner-boundary repair.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the writer-claim implementation commits and is the current assignee; deeper historical attribution was unavailable from the partial checkout. (role: recent session-runtime contributor; confidence: medium; commits: 338eb98599a6, 47ec7f1d313e, 1a4af69775ca; files: src/agents/embedded-agent-runner/run/session-bootstrap.ts, src/agents/embedded-agent-runner/run/lane-controller.ts, src/config/sessions/session-accessor.sqlite-transcript-write.ts)

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.

@steipete
steipete force-pushed the steipete/session-writer-claim branch from 0f261e6 to e7b3a39 Compare August 9, 2026 10:12
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for e7b3a39ce94441289a73f9c237034a6eae3f233f:

  • The replacement writer claim now commits before the incumbent's sticky superseded outcome and exact-run cancellation. Failed admission leaves the incumbent live.
  • The private admitted-writer fence survives context-engine target adoption/rebasing, is restored at embedded attempt dispatch, and scopes CLI streamed, abort-flush, and final transcript writes.
  • Focused repair proof passed: writer takeover/failed claim 2, prompt-state adoption 13, CLI recorder 9, CLI dispatch 43. Broader proof passed: transcript 67, terminal outcome 41, attempt lock/teardown 44, delivery mirror 336, attempt stream 10, SDK projection 1, Madge 0 cycles, exact Plugin SDK API baseline, diff check, and fresh branch autoreview.
  • Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/31307787362. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 121003 passed in hosted_exact_or_recent_parent mode using that exact-head hosted evidence; no Testbox lease was allocated.
  • ClawSweeper's three prior-head P1 findings and every Rank-up move are implemented. Exact-head re-review is requested and queued at fix(sessions): fence transcript writes by admitted run #121003 (comment); publisher delay is non-blocking under repository policy.
  • Surface: production +555/−128, tests +622/−28, generated baseline +77/−77. Production growth establishes the durable ownership boundary.

Known follow-ups remain the coordinator-tracked non-turn writers and deletion of the session-write lease.

@steipete
steipete merged commit c9b346e into main Aug 9, 2026
123 checks passed
@steipete
steipete deleted the steipete/session-writer-claim branch August 9, 2026 10:32
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant