Skip to content

fix(chat): preserve Claude rewind context after rollback - #31231

Merged
nwparker merged 3 commits into
mainfrom
nwparker/fix-claude-rewind-rollback
Oct 20, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/fix-claude-rewind-rollback

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​261 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​246
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​183 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​164

ELI5

Rolling Orca back after rewinding a Claude chat could bring discarded turns back into the model’s context while the chat displayed the shortened history. The rewind now saves the kept context before reporting success.

What Changed

Save a Claude fork through the SDK’s session-fork API, then commit its conversation handle and shortened journal in the same database transaction. Keep the original transcript intact, support rewinding again while the agent is stopped, and retain compatibility with older deferred-fork records. Add failure/recovery tests and a real-CLI test that resumes the saved fork using the ordinary session ID before another send.

Why

Older builds already understand the persisted conversation handle. Saving the actual fork and advancing that handle avoids depending on a new optional field that those builds ignore. The SDK handles branching and message-ID remapping; existing durable-write and journal-receipt code handles persistence.

Linked Issue

Fixes STA-11420.

Visual Proof

N/A — changes persisted provider context and crash recovery; no rendered UI or controls change. The real-CLI test proves that a normal resume remembers the kept turn and forgets the discarded turn.

Testing

Verified locally on macOS against scan base 8a4ef49a4db6, with ORCA_BACKGROUND_LAUNCH=1 on every test command:

  • 153 regression tests passed across transcript persistence, fork rewinds, failed commits and recovery, rewinds after clear, rewinds at rest, pending-rewind compatibility, account routing, journal recovery, and the real-agent-home write guard.
  • ORCA_REAL_CLAUDE_CLI_TEST=1 pnpm test src/main/claude/claude-structured-real-cli-rewind.test.ts passed. It resumes the durable fork by session ID and checks that discarded context stays absent.
  • pnpm tc:node and pnpm run check:code-quality:changed passed.
  • Manual packaged-app testing
  • Automated tests added/updated

Linux, Windows, SSH, and an actual packaged downgrade were not runtime-tested. Full build and remaining checks are for CI.

Review

Self-reviewed the commit ordering, source-account paths, empty-history rewind, failed writes, and compatibility with older records. No remote protocol opcode or dependency changes.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer source is copied or translated.

Notes

The separate stale-assertion fix is in #31229. The combined workspace passed all 16 real-Claude tests. This PR does not replace the release checklist’s packaged-update and live-network verification.

Checklist

  • This PR is small and focused
  • Explained what changed and why
  • Visual proof marked N/A with reason
  • Self-reviewed correctness, security, and performance
  • Cross-platform, SSH, and compatibility impact considered
  • Full lint, test, and build suite passes in CI

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21eca13b-9ced-459e-83be-38114e551243
📥 Commits

Reviewing files that changed from the base of the PR and between 3be5039 and 839e561.

📒 Files selected for processing: 16
  • config/scripts/vitest-real-agent-home-write-guard.test.ts
  • config/scripts/vitest-real-agent-home-write-guard.ts
  • src/main/claude/claude-rewind-fork.ts
  • src/main/claude/claude-rewind-transcript.test.ts
  • src/main/claude/claude-rewind-transcript.ts
  • src/main/claude/claude-stream-json-connection.ts
  • src/main/claude/claude-structured-real-cli-rewind.test.ts
  • src/main/native-chat/agent-session-journal/journal-epoch-controller.ts
  • src/main/native-chat/agent-session-journal/journal-epoch-replacement.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-fork-rewind.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-rewind.ts
  • src/main/native-chat/agent-session-wire/structured-rewind-recovery.ts
  • src/main/runtime/agent-session-rewind-completion.ts
  • src/shared/agent-session-rewind.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

Claude rewinds now materialize transcript forks through the selected entry and track resume state. Structured rewind completion updates provider-handle chains and journal epochs, with receipt handling and recovery for materialized forks. Tests cover transcript contents, fork persistence, failure rollback, and recovery. The real-agent home write guard permits opted-in Claude transcript writes while continuing to block Codex and Orca removals.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 839e5

The investigated rewind paths do not show a remaining issue that should block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 16 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preserving Claude rewind context after rollback.
Description check Passed The description includes all required sections, explains the user impact and implementation, links the issue, documents testing and limitations, and marks visual proof as not applicable. Some checks r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections, explains the user impact and implementation, links the issue, documents testing and limitations, and marks visual proof as not applicable. Some checks remain pending CI or were not tested locally, but the description is complete and relevant.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit e02e8f5 into main Oct 20, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant