Skip to content

fix: keep compacted sessions usable after transcript rewrites - #123485

Merged
steipete merged 5 commits into
mainfrom
steipete/compaction-replay-invalidation
Aug 14, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/compaction-replay-invalidation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where OpenAI Responses users could lose replayed tool calls after transcript sanitizers removed or rebuilt assistant content before a server-compaction checkpoint. It also prevents a provider-rejected encrypted checkpoint from remaining in persisted history when the stripped retry later fails, which otherwise made later turns repeatedly pay the same rejection and recovery cost.

Why This Change Was Made

Content mutators now reindex unambiguous prefix-bound checkpoints and strip them when a rewrite is empty or ambiguous, covering the complete mutator neighborhood rather than compensating in the request builder. Provider rejection carries the exact ephemeral checkpoint identity to the existing runner transcript-rewrite owner, which branches and re-appends the active SQLite suffix without adding another persistence path. The in-flight suppression tombstone remains in place as a second safeguard.

No persisted replay fields, worker-protocol fields, config/default surfaces, or SQLite schema changes are introduced.

User Impact

Compacted OpenAI Responses sessions keep tool calls and results paired after transcript cleanup. If a server rejects a stale checkpoint, the rejection is removed durably before retry-stream failure, so process restart and later turns rebuild from full history instead of replaying the rejected ciphertext again.

Evidence

  • Pre-fix sanitizer regression: expected replayIndex 0 but received 1; an emptied owner also retained its checkpoint. Both intended failures passed after the owner repair.
  • Rebased full focused proof: 543 tests passed across compaction replay, prompt observation, provider/shared and ChatGPT recovery, native WebSocket fallback, image/history/tool-call mutators, SQLite transcript rewrite, runner settlement, and durable reopen coverage.
  • Final exact-head proof after the last unrelated main rebase: 249 focused tests passed.
  • pnpm tsgo passed on the exact head.
  • git diff --check origin/main...HEAD passed.
  • Codex autoreview completed clean with no accepted/actionable findings; TruffleHog was clean.
  • Production LOC: +397/-223 (net +174); tests: +369/-24 (net +345); changelog: +1/-0. The production growth is the approved owner-boundary capability covering all active mutators plus durable rejection repair; nearby replay validation, identity matching, and sanitizer branches were consolidated rather than deleting coverage to game the count.

@clawsweeper

clawsweeper Bot commented Aug 14, 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 agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 05:17
@clawsweeper clawsweeper Bot added 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 6:16 AM ET / 10:16 UTC.

ClawSweeper review

What this changes

The PR reindexes or removes server-compaction replay checkpoints after assistant transcript rewrites, and durably removes a rejected OpenAI Responses checkpoint during fallback recovery.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No blocking code defect was found in the latest head; the prior missing OpenAI tool-ID rewrite coverage is now routed through the shared checkpoint-rewrite helper. Keep this maintainer-authored, session-state-sensitive PR open for exact-head CI and the required maintainer decision on live OpenAI Responses verification.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is coherent and the previous blocker is addressed, with a remaining maintainer decision on live provider-contract proof.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the PR body reports focused after-fix terminal and durable-session evidence, while repository policy still leaves live provider verification as a merge-risk decision.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the PR body reports focused after-fix terminal and durable-session evidence, while repository policy still leaves live provider verification as a merge-risk decision.
Evidence reviewed 7 items Current main lacks the repair: Current main only recognizes and strips prefix-bound checkpoints; it has no shared owner-content replacement helper or rejected-compaction durable repair.
Canonical checkpoint rewrite: The PR centralizes content replacement: it reindexes retained prefix blocks and strips a checkpoint when content is empty or correspondence is ambiguous.
Prior review blocker addressed: Both OpenAI tool-ID rewrite paths now invoke the shared owner-content handler rather than rebuilding an assistant message directly.
Findings None None.
Security None None.

How this fits together

Assistant transcript messages retain provider replay checkpoints that let later OpenAI Responses calls replace an earlier prefix. Sanitizers, tool-ID repair, and provider recovery rewrite those messages before the session manager persists the active transcript branch.

flowchart LR
  A[Session transcript] --> B[Transcript rewrites]
  B --> C[Checkpoint reindex or removal]
  C --> D[OpenAI Responses request]
  D --> E[Rejected checkpoint recovery]
  E --> F[Durable session transcript]
Loading

Decision needed

Question Recommendation
Should this maintainer-authored replay repair require a redacted live OpenAI Responses rejection-and-recovery trace before merge, or should maintainers explicitly accept the remaining provider-contract risk on focused harness evidence alone? Require a live provider trace: Record a redacted OpenAI Responses rejection, stripped recovery, and subsequent session reopen before merge.

Why: The source repair and durable regression coverage are coherent, but the provider's encrypted-compaction rejection behavior is an external API contract that local mock tests cannot establish.

Before merge

  • Resolve merge risk (P1) - The patch changes persisted transcript replay state; its +172 net production LOC expands a safety-critical lifecycle, although the shared helper and existing transcript-rewrite owner are the narrowest identified common seams.
  • Resolve merge risk (P1) - The changed behavior depends on real OpenAI Responses rejection and recovery semantics. The PR provides focused mocked and durable-session coverage, but repository policy calls for live external-API verification before merge.
  • Complete next step (P2) - This maintainer-authored, protected session-state PR needs exact-head CI and a maintainer call on the remaining live-provider proof requirement.
Agent review details

Security

None.

PR surface

Source +172, Tests +413. Total +585 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 22 402 230 +172
Tests 11 436 23 +413
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 838 253 +585

Review metrics

Metric Value Why it matters
Production versus test LOC production +402/-230 (net +172); tests +436/-23 (net +413) The repair materially grows session-state code; the growth is concentrated in shared checkpoint handling and durable recovery tests rather than configuration or schema surface.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-stream.ts, migration/backfill/repair: src/agents/embedded-agent-runner/thinking-replay-repair.test.ts, migration/backfill/repair: src/agents/embedded-agent-runner/thinking-replay-repair.ts, serialized state: src/agents/session-transcript-repair.ts, unknown-data-model-change: src/agents/embedded-agent-runner/thinking-replay-repair.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove provider recovery before merge (recommended)
    Add a redacted live OpenAI Responses trace covering rejection, full-history fallback, and persisted-session reopen, then merge on green exact-head CI.
  2. Accept the provider-contract gap
    Merge with the focused harness coverage only if a maintainer explicitly accepts the lack of live provider verification.

Technical review

Best possible solution:

Retain the shared checkpoint-rewrite helper and existing transcript-rewrite owner, then add a redacted live OpenAI Responses rejection/recovery trace before landing; no smaller net-neutral owner boundary was identified because the repair must cover several independent transcript mutators plus durable recovery.

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

Yes, from source: rebuilding an assistant message after removing a pre-checkpoint block previously retained its old replay index; the added regression exercises that state transition and durable recovery, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, with the live-provider proof caveat: repairing checkpoint state at transcript mutation and session-rewrite owners is better than compensating in request construction, and the latest head covers the prior OpenAI ID-rewrite gap.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the PR body reports focused after-fix terminal and durable-session evidence, while repository policy still leaves live provider verification as a merge-risk decision.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded but user-visible compacted-session replay failure without evidence of a broader outage.
  • merge-risk: 🚨 session-state: The PR changes checkpoint metadata carried in persisted assistant transcript messages and the active-branch rewrite path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the PR body reports focused after-fix terminal and durable-session evidence, while repository policy still leaves live provider verification as a merge-risk decision.

Evidence

What I checked:

Likely related people:

  • steipete: Git blame attributes the existing compaction checkpoint and replay-repair foundation to Peter Steinberger, and this PR's five commits extend that same owner boundary. (role: feature owner and recent area contributor; confidence: high; commits: 1bb20fb16aa5, e1d875acff75, e928338aba40; files: packages/ai/src/transports/provider-compaction-replay.ts, src/agents/embedded-agent-runner/thinking-replay-repair.ts, src/agents/embedded-agent-helpers/openai.ts)

Rank-up moves

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

  • Add a redacted live OpenAI Responses rejection-and-recovery trace.
  • Wait for relevant exact-head CI checks to complete green.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-14T05:24:07.418Z sha 0a17927 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T06:15:53.730Z sha df8fe18 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T07:02:28.159Z sha cd1d594 :: needs changes before merge. :: [P1] Invalidate checkpoints when rekeying Responses tool calls
  • reviewed 2026-08-14T09:49:47.454Z sha 3bf9da8 :: found issues before merge. :: [P1] Apply checkpoint handling to every OpenAI ID rewrite

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@steipete steipete self-assigned this Aug 14, 2026
@steipete
steipete force-pushed the steipete/compaction-replay-invalidation branch from cd1d594 to 3bf9da8 Compare August 14, 2026 09:43
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@steipete
steipete merged commit c6fc12d into main Aug 14, 2026
174 checks passed
@steipete
steipete deleted the steipete/compaction-replay-invalidation branch August 14, 2026 10:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…aw#123485)

* fix: keep compaction checkpoints aligned through rewrites

* fix: persist rejected compaction invalidation

* chore: drop release-only changelog edit

* fix: align compaction replay with repository guards

* fix: invalidate checkpoints after OpenAI ID rewrites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant