Skip to content

fix(agents): retain internal session writer fence - #169876

Open
ethanhawkes-gif wants to merge 2 commits into
openclaw:mainfrom
ethanhawkes-gif:fix/internal-session-writer-rebound-20261012
Open

ethanhawkes-gif wants to merge 2 commits into
openclaw:mainfrom
ethanhawkes-gif:fix/internal-session-writer-rebound-20261012

Conversation

@ethanhawkes-gif

@ethanhawkes-gif ethanhawkes-gif commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

OpenClaw internal-session and CLI-backed turns that reach settled-turn fallback can currently lose the transcript after otherwise successful tool work, forcing fallback or retry. This server-side change requires no client update and adds only scoped context propagation; it does not add a new write or retry path.

Implementation:

  • src/agents/embedded-agent-runner/run/session-prompt-state.ts: retains the admitted session writer fence during post-attempt transcript work
  • src/agents/embedded-agent-runner/run/settled-turn-finalization.ts: re-inherits that fence after fallback target resolution and preserves fail-closed rejection when the writer is genuinely replaced
  • src/agents/internal-session-effects.test.ts: adds paired persistence and genuine-replacement rejection coverage

What Problem This Solves

Internal-session admission can establish a committed writer fence (the lifecycle/run identity allowed to persist that session), but withSessionWriterContext did not keep that durable fence ambient for post-attempt work (session-prompt-state.ts:210). persistSettledToolFallbackTranscript may then resolve a fresh target without the admitted fence (settled-turn-finalization.ts:582-617) and reopen persistence as an unfenced writer. That produces a false SessionTranscriptWriterClaimReboundError even though the admitted writer was not replaced.

Evidence

After rebasing onto current upstream/main:

npx vitest run src/agents/internal-session-effects.test.ts

Test Files  1 passed (1)
Tests       11 passed (11)

The SQLite-backed pair covers successful settled-turn fallback persistence and cleanup, plus rejection after a genuine writer replacement.

pnpm exec oxlint src/agents/embedded-agent-runner/run/session-prompt-state.ts src/agents/embedded-agent-runner/run/settled-turn-finalization.ts src/agents/internal-session-effects.test.ts

Found 0 warnings and 0 errors.

Fixes #164215

@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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. agents Agent runtime and tooling size: M and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 retains the admitted session writer fence in ambient context and inherits it when persisting a settled-turn fallback.

Example: The internal-session fixture uses runId skill-workshop-review:internal-fallback-success and removes the explicit finalization fence.

  • Before: Post-attempt context does not expose the committed writer fence.
  • After: Fallback persistence inherits the fence and records skill-workshop-review:internal-fallback-success:settled-finalization-fallback.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and has no established introduced defect, but its production relevance and authority-chain behavior remain unproven.
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: Partial
User problem: A turn may complete tool work but fail to retain its final transcript or usable completion.
Reason: Preserving admitted writer custody has clear value, but this patch covers the fallback boundary without establishing the linked CLI report's complete resolution.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this PR contains distinct writer-custody work and has an unresolved same-author companion PR; no definite introduced correctness defect was found.

Priority: P2
Reviewed head: 83318928f22fa81951e094f6556143b9a4a6b171

Before merge

  • Add real behavior proof - Authority-chain proof required: exercise the retained fence through production dispatch and fallback SQLite append with normal explicit fence propagation intact, and show foreign-session, revoked-admission, and replaced-writer rejection before persistence; the body supplies only Vitest and lint output with a synthetic finalizer, and the companion PR's borrowed-manager proof covers a different path, so add redacted terminal output or logs excluding 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 - Ambient writer authority changes require final-effect validation, although source inspection found no concrete authorization bypass.
  • Resolve merge risk - Confirm that extending ambient committed-writer custody across dispatch and recovery cannot transfer write authority to another session or retain it after admission closes.

Findings

None.

Tests

  • Missing end-to-end proof: Show base-fail/head-pass production dispatch without removing its explicit fence, plus final-append rejection for foreign sessions, revoked admission, and writer replacement.
Agent review details

How this fits together

The embedded runner coordinates admitted session writers, provider attempts, and post-tool finalization; fallback text passes through the transcript accessor into SQLite.

flowchart TD
  A[Run admission] --> B[Session writer claim]
  B --> C[Session prompt state]
  C --> D[Attempt dispatch]
  D --> E[Settled turn finalization]
  C --> E
  E --> F[Transcript append owner]
  F --> G[SQLite transcript]
Loading

Technical review

Best possible solution:

Preserve the original writer through a reproduced failing production turn while retaining exact-session matching and live-admission checks.

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

No high-confidence production reproduction is established: current main explicitly propagates the fence, while the added fixture removes it before calling finalization.

Is this the best way to solve the issue?

Using the existing transcript owner is appropriately narrow, but the evidence does not establish that additional ambient propagation fixes the linked CLI failure.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Hold until scoped custody is demonstrated (recommended)
    Keep the PR open while the contributor demonstrates valid fallback persistence and rejection of foreign-session, revoked-admission, and replaced-writer writes at the final append.

Provenance checked

  • Committed writer context changes intended behavior with a stated reason (f000b48: Initial-writer lifecycle custody ends after commitment while existing run and durable writer checks remain authoritative.)
  • Settled fallback target and append keeps the original intent (04fb401: Child finalization carries its committed fence explicitly and revalidates child admission at the fallback commit edge.)

Testing

Proof path: in-process harness.

Security

Needs attention: Ambient writer authority changes require final-effect validation, although source inspection found no concrete authorization bypass.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f000b48 adds src/agents/embedded-agent-runner/run/session-prompt-state.ts:195 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f000b487300b; files: src/agents/embedded-agent-runner/run/session-prompt-state.ts)

PR surface

Source +24, Tests +265. Total +289 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 32 8 +24
Tests 1 265 0 +265
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 297 8 +289

Review metrics

Metric Value Why it matters
Production versus test growth Production net +24 lines; tests +265 lines Most growth constructs two SQLite integration fixtures; their connection to an actual failing dispatch remains unestablished.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal transcript-custody change without a verified urgent production regression attributable to the changed path.
  • merge-risk: 🚨 session-state: The change extends ambient durable writer claims across dispatch and recovery, affecting which session writes inherit that claim.
  • 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.

  • Demonstrate the failing production path while preserving its normal explicit writer fence.
  • Prove foreign-session, revoked-admission, and replaced-writer rejection before the final SQLite append.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-12T12:21:15.345Z sha 8791144215eb3316ec6aaca5db3f5e112cfe8984 :: needs real behavior proof before merge. :: none

Reviewed October 13, 2026, 2:17 PM ET / 18:17 UTC (Revision 2).

This branch has not been deployed

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M 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.

[Bug]: claude-cli turns fail transcript persistence with writer claim rebound

1 participant