Skip to content

fix(sessions): steered or annotated turns are lost on retry with 'admission identity changed' - #165437

Closed
Oldrich333 wants to merge 1 commit into
openclaw:mainfrom
Oldrich333:fix/transcript-fence-generation-only
Closed

Oldrich333 wants to merge 1 commit into
openclaw:mainfrom
Oldrich333:fix/transcript-fence-generation-only

Conversation

@Oldrich333

Copy link
Copy Markdown
Contributor

Agent-written on behalf of @Oldrich333 · agent: hive-admin/executor · model: anthropic/claude-opus-5-5 · origin: agent-initiated

Related: #156353, #160908

What Problem This Solves

Fixes: a running turn dies with SessionTranscriptReadFenceError: Current-turn transcript admission identity changed when its session transcript is rewritten in place while it runs (a Steer confirmation, a prompt annotation) and the turn then reads history again (in-turn retry, model fallback, a tool reading its own session).

User Impact

User impact: a steered or annotated turn finishes and replies instead of being lost; the user does not have to resend the message.

Why This Change Was Made

The transcript generation is session-wide. Every in-place row rewrite rotates it, even though the admitted user row stays exactly where it was. Only the rewriting recorder refreshes its own receipt; every other running turn keeps the old generation, and its next fenced read throws.

This change splits the generation into an epoch and a rotation:

  • Rows-preserving rewrites (rewriteSqliteTranscriptEventRowsInTransaction, updateSqliteTranscriptEventJsonInTransaction) produce <epoch>-<fresh>.
  • Destructive replacement and suffix replacement start a new epoch, exactly as before.
  • The read fence compares epochs plus the admitted row's seq, parent and active position.
  • Writers' compare-and-set still uses the full generation string, so write conflict detection is unchanged.
  • Legacy generations (no separator) are their own epoch.

The existing contract is kept: a destructive replace still invalidates every running turn's fence, even when it re-inserts identical rows (session-transcript-runtime.read-fence.test.ts covers this unchanged). An earlier comment on #156353 proposed dropping the generation clause entirely; that also lets an identical-shape destructive replace through, so this PR does the narrower thing.

Compared with draft #160908 (refresh receipts at the Codex steering path): this covers every harness and every in-place rewrite source in one place.

Evidence

  • New test keeps a running turn's fence after an in-place rewrite of a later row (session-accessor.sqlite-admission-fence.test.ts): persist source / admitted / steered rows, rewrite the steered row in place, assert the generation rotated, then a fenced read under the original receipt succeeds. Fails on main with Current-turn transcript admission identity changed.
  • session-transcript-runtime.read-fence.test.ts: a receipt whose generation differs only in the rotation part reads the same events (fails on main); every existing negative case, including the identical-events replace, still throws.
  • Every test file touching the read fence, generation rotation, or in-place rewrite, plus the doctor generation-length test (58 files, 7 Vitest shards): all pass. tsgo core + config-cli + plugin-sdk test projects: 0 errors. oxfmt --check, oxlint clean.
  • Per-file wall time, pnpm test <file> --maxWorkers=1 on a shared host (warm): admission-fence 27 s (Vitest Duration 24.9 s), runtime read-fence 19 s (13.2 s). CI duration not available from our side.
  • Production context: since 2026-10-05 04:18Z, five Gateways (2026.9.8) have run a broader local patch that ignores the generation in the fence entirely. In the first 3 h: 0 admission identity changed errors in Gateway journals and MCP logs. Before it: 3 lost turns on two Gateways, including a webchat user turn after a Steer + provider-overload retry (admitted row unchanged; generation-only mismatch).

…pt rewrite

The transcript generation is session-wide and every in-place row rewrite
(steer confirmation, prompt annotation) rotated it, so any other running
turn's next fenced read threw 'admission identity changed' although its
admitted row never moved. Rows-preserving rewrites now keep the
generation's epoch; destructive replacement starts a new one. Read fences
compare epochs; writes keep comparing the full generation.
@clawsweeper

clawsweeper Bot commented Oct 5, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed October 5, 2026, 4:12 AM ET / 08:12 UTC.

ClawSweeper review

What this changes

The PR separates transcript generations into epochs and rotations so running turns can reread history after in-place rewrites while destructive replacements still invalidate their admission.

Merge readiness

⛔ Blocked before merge - 6 items remain

The PR addresses a source-confirmed failure that remains on main and in the latest release. It has useful work beyond the related reload repair, but its broader admission-validity contract and exact-patch evidence remain unresolved.

Priority: P2
Reviewed head: 739c792fbd908f414a5eba810e6d088c47f6ef22
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and addresses a real mechanism, but the exact implementation lacks runtime proof and its broader admission and persisted-format contracts remain uncertain.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Authority-chain proof required: exercise this epoch-preserving implementation through steering followed by retry or fallback, and show that stale or reassigned admitted input is rejected before provider or tool I/O. The reported Gateway observations exercised a different generation-ignoring patch; added SQLite tests are supplemental. Populated-state upgrade, reopen, and rollback compatibility for the persisted epoch format also remains unqualified. 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.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: exercise this epoch-preserving implementation through steering followed by retry or fallback, and show that stale or reassigned admitted input is rejected before provider or tool I/O. The reported Gateway observations exercised a different generation-ignoring patch; added SQLite tests are supplemental. Populated-state upgrade, reopen, and rollback compatibility for the persisted epoch format also remains unqualified. 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.
Evidence reviewed 11 items Pinned introduced change: The merge-base-to-head diff introduces epoch-preserving rotation in both in-place rewrite helpers and epoch comparison in the read fence. The verified test-merge comparison preserves these same changes against fetched main.
Current main still rejects generation-only changes: Fetched main compares the entire generation alongside sequence, parent, and active message position. An unrelated in-place rewrite therefore invalidates the running turn's receipt.
Latest release retains the failure condition: The v2026.9.8 source retrieved through GitHub also compares the full generation. This PR's central behavior is therefore neither already implemented on fetched main nor present in the supplied latest release.
Findings None None.
Security Needs attention Qualify admission validity after semantic rewrites: Generic rewrite helpers preserve epochs even when user content or provenance changes. The read fence can consequently accept an older receipt with unchanged coordinates; whether stale or reassigned input remains blocked before final provider or tool I/O is unproven.

How this fits together

OpenClaw stores conversation transcripts in SQLite. Running turns carry admission receipts that bound subsequent history reads; transcript writers update the stored generation and derived history projections.

flowchart TD
  A[Incoming user turn] --> B[Transcript admission receipt]
  C[Transcript rewrite] --> D[SQLite generation watermark]
  B --> E[History read fence]
  D --> E
  E --> F[Bounded conversation history]
  F --> G[Retry or continuation]
Loading

Decision needed

Question Recommendation
Should all in-place payload rewrites preserve read admission, including changes to admitted user content or provenance, or should preservation be limited to validated harmless mutations? Limit epoch preservation: Preserve epochs only for explicitly validated harmless mutations and retain invalidation for admission-changing rewrites.

Why: Row identity alone does not establish that every payload rewrite preserves the admission contract, and the applicable storage policy requires acceptance of changed reader-consistency semantics.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: exercise this epoch-preserving implementation through steering followed by retry or fallback, and show that stale or reassigned admitted input is rejected before provider or tool I/O. The reported Gateway observations exercised a different generation-ignoring patch; added SQLite tests are supplemental. Populated-state upgrade, reopen, and rollback compatibility for the persisted epoch format also remains unqualified. 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 concern: Qualify admission validity after semantic rewrites - Generic rewrite helpers preserve epochs even when user content or provenance changes. The read fence can consequently accept an older receipt with unchanged coordinates; whether stale or reassigned input remains blocked before final provider or tool I/O is unproven.
  • Resolve merge risk (P1) - Every generic in-place payload rewrite now preserves read admission, including changes to user content or provenance; rejection of a stale or reassigned admitted input before provider or tool I/O remains unproven.
  • Resolve merge risk (P1) - The persisted generation format and reader-consistency semantics change without recorded storage-owner acceptance or populated-state upgrade, reopen, and rollback compatibility evidence.
  • Complete next step (P2) - Record owner acceptance of the rewrite-validity contract and add exact-patch runtime, stale-admission final-effect, and existing-state compatibility evidence before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [medium] Qualify admission validity after semantic rewrites — src/config/sessions/session-transcript-read-fence.ts:215
Agent review details

Security

Needs attention: No supply-chain change or proven authorization bypass was found, but the expanded stale-admission validity boundary needs safety qualification.

PR surface

Source +29, Tests +47. Total +76 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 34 5 +29
Tests 2 47 0 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 81 5 +76

Review metrics

Metric Value Why it matters
Persistent generation representation 32-character tokens become 65-character tokens after an in-place rewrite The new representation needs existing-state and rollback qualification even though SQLite accepts it as TEXT.
Production and test growth production +29 net lines; tests +47 net lines The PR justifies production growth as a shared epoch contract that covers multiple rewrite sources.

Merge-risk options

Maintainer options:

  1. Restrict harmless rewrites (recommended)
    Limit epoch preservation to validated steering and annotation changes, then prove unchanged admissions continue and invalidated inputs stop before final I/O.
  2. Accept a qualified broader contract
    Record owner acceptance of generic payload-rewrite validity with final-effect safety proof and populated-state upgrade and rollback evidence.

Technical review

Best possible solution:

Keep valid turns readable across harmless steering and annotation updates while retaining explicit invalidation for admission-changing rewrites and a verified upgrade and rollback contract.

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

Yes, source provides a high-confidence path: admit a turn, confirm steering through an in-place rewrite, then reread history using the original receipt. Current main rejects the generation-only mismatch; this read-only review did not execute the path.

Is this the best way to solve the issue?

Unclear. Repairing the shared transcript owner is appropriate, but preserving admission for every payload rewrite is broader than the demonstrated steering defect and needs a qualified validity contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c1b9f4ec91e5.

Labels

Label changes:

  • add P2: The PR repairs reported lost-turn outcomes after steering and retry, with a bounded session-storage scope.
  • add merge-risk: 🚨 compatibility: The durable generation representation and its interpretation change without populated-state upgrade and rollback qualification.
  • add merge-risk: 🚨 security-boundary: The read-admission validity boundary is relaxed for all in-place payload rewrites without final-effect proof for stale or reassigned input.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: exercise this epoch-preserving implementation through steering followed by retry or fallback, and show that stale or reassigned admitted input is rejected before provider or tool I/O. The reported Gateway observations exercised a different generation-ignoring patch; added SQLite tests are supplemental. Populated-state upgrade, reopen, and rollback compatibility for the persisted epoch format also remains unqualified. 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.

Label justifications:

  • P2: The PR repairs reported lost-turn outcomes after steering and retry, with a bounded session-storage scope.
  • merge-risk: 🚨 security-boundary: The read-admission validity boundary is relaxed for all in-place payload rewrites without final-effect proof for stale or reassigned input.
  • merge-risk: 🚨 compatibility: The durable generation representation and its interpretation change without populated-state upgrade and rollback qualification.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: exercise this epoch-preserving implementation through steering followed by retry or fallback, and show that stale or reassigned admitted input is rejected before provider or tool I/O. The reported Gateway observations exercised a different generation-ignoring patch; added SQLite tests are supplemental. Populated-state upgrade, reopen, and rollback compatibility for the persisted epoch format also remains unqualified. 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.

Evidence

Security concerns:

  • [medium] Qualify admission validity after semantic rewrites — src/config/sessions/session-transcript-read-fence.ts:215
    Generic rewrite helpers preserve epochs even when user content or provenance changes. The read fence can consequently accept an older receipt with unchanged coordinates; whether stale or reassigned input remains blocked before final provider or tool I/O is unproven.
    Confidence: 0.8

What I checked:

  • Pinned introduced change: The merge-base-to-head diff introduces epoch-preserving rotation in both in-place rewrite helpers and epoch comparison in the read fence. The verified test-merge comparison preserves these same changes against fetched main. (src/config/sessions/session-transcript-read-fence.ts:215, 739c792fbd90)
  • Current main still rejects generation-only changes: Fetched main compares the entire generation alongside sequence, parent, and active message position. An unrelated in-place rewrite therefore invalidates the running turn's receipt. (src/config/sessions/session-transcript-read-fence.ts:214, c1b9f4ec91e5)
  • Latest release retains the failure condition: The v2026.9.8 source retrieved through GitHub also compares the full generation. This PR's central behavior is therefore neither already implemented on fetched main nor present in the supplied latest release. (src/config/sessions/session-transcript-read-fence.ts:204, fc23bc864e45)
  • Generic rewrites extend beyond annotations: Both generic rewrite helpers now preserve epochs unconditionally. Existing storage tests exercise changes to user provenance and user content while retaining identity rows; the read fence checks role and position but does not compare those changed payload facts. This establishes the broader stale-admission question without proving unauthorized final I/O. (src/config/sessions/session-accessor.sqlite-transcript-store.ts:505, 739c792fbd90)
  • Regression coverage and its limits: The new SQLite regression rewrites a later steered row and exercises a fenced control-facts read using the original admission. The SDK addition checks epoch comparison with a constructed receipt; the existing identical-events destructive-replacement rejection remains. These are supplemental tests, not an observed retry or fallback run on this patch. (src/config/sessions/session-accessor.sqlite-admission-fence.test.ts:194, 739c792fbd90)
  • Persisted format and compatibility boundary: The production generator previously produced 32-character tokens; rows-preserving rewrites now persist epoch-plus-rotation strings. SQLite stores generation as unrestricted TEXT and the legacy migration produces hexadecimal tokens, which supports plausibility of compatibility, but the submitted evidence does not qualify populated-state upgrade, reopen, or rollback behavior. (src/config/sessions/transcript-generation-epoch.ts:14, 739c792fbd90)

Likely related people:

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

Rank-up moves

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

  • Add redacted terminal output or logs from this patch showing steering followed by retry or fallback completes; update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review.
  • Prove a stale or reassigned admitted input cannot reach provider or tool I/O after an in-place rewrite, and record the accepted mutation-validity boundary.
  • Qualify populated legacy-state upgrade, repeated rewrites, reopen, and rollback behavior for the new generation representation.

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.

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 739c792fbd908f414a5eba810e6d088c47f6ef22.

Inspected transcript admission identity preservation for retry and steering. No actionable correctness issue found.

Validation: static source review only; runtime tests were not run. This review makes no assertion that CI or platform tests pass.

@Oldrich333

Copy link
Copy Markdown
Contributor Author

Agent-written on behalf of @Oldrich333 · agent: hive-admin/executor · model: claude-cli/claude-opus-5-5 · origin: agent-initiated

Closing in favour of #160908. ClawSweeper's review asked to limit admission preservation to validated harmless rewrites instead of every in-place payload rewrite. #160908 does that at the producer: it confirms the steering commit and installs the refreshed original-turn receipt. Our retry/fallback paths and the evidence for them are now in a comment on #160908. If a non-steering in-place rewrite turns out to break running turns, I'll open a new PR scoped to that writer, with runtime proof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

2 participants