Skip to content

fix(claude): fork from a reply on transcripts that have no apiBlockIndex - #48153

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Common-Player:fix/claude-fork-legacy-block-index
Nov 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Common-Player:fix/claude-fork-legacy-block-index

Conversation

@Common-Player

@Common-Player Common-Player commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you fork a Claude chat from a specific reply, Orca has to find that reply in Claude's saved history file. Older Claude Code builds (for example 2.0.42) save each piece of a reply on its own line, but they don't number the pieces. Orca only looked for numbered pieces, so it couldn't find the reply and showed "Claude could not find the saved context for this response." Now Orca numbers the pieces itself, in the order they appear, so it finds the right spot and the fork works.

What Changed

  • Before: on a transcript from an older Claude Code build, forking from a reply always failed with "Claude could not find the saved context for this response."
  • After: the fork copies the conversation up to the selected reply, the same as on newer builds.
  • Mechanism: claudeConversationForkBoundary (src/main/claude/transcripts/claude-conversation-fork-boundary.ts) matches the streamed block id block:<messageId>:<index> against transcript rows. It used to match only rows that had a numeric apiBlockIndex. Now, when a row has no apiBlockIndex, the index comes from the row's position among the chain rows with the same message.id. Rows that do have apiBlockIndex are handled exactly as before. Rows without a message.id (for example user tool_result rows between tool calls) are not counted.
  • claude-conversation-fork-boundary.test.ts: runs the same transcript with and without apiBlockIndex. The transcript has thinking, two tool_use blocks with a tool_result row between them, and a second reply. The test checks that each block id resolves to the right row and that out-of-range ids still throw.

Why

Claude Code writes one transcript row per content block, in block order. Newer builds add apiBlockIndex to each row, but older builds don't. Counting a row's position among the rows of the same message gives the same index those builds would have written, so we don't need a second id scheme or any change to the transcript reader.

Out of scope: claude-transcript-item-reader.ts and claude-transcript-import-plan.ts also build the block id only from apiBlockIndex. Counting positions there isn't safe, because catch-up reads a tail window that may not include a message's earlier rows. That needs a separate fix.

Linked Issue

Fixes #48148

Reported by @Common-Player. Original fix by @Common-Player in #48153; final version reworked during the bug bash. Thanks also to @2SinceJuly (#48156) and @AdityaxDeore (#48155) for their fixes. All three are co-authors on the commit.

Visual Proof

N/A. The fix changes how a main-process worker looks up a transcript row. The only visible effect is that an error toast no longer appears on older transcripts, and the before/after unit runs below show that directly.

Testing

  • Repro: on main, the new test case without apiBlockIndex fails with Claude could not find the saved context for this response. With this change, both cases pass.

  • pnpm exec vitest run src/main/claude/transcripts/: 2/2 pass.

  • oxlint, oxfmt --check, the anti-slop oxlint, native code-quality oxlint (--deny-warnings), ast-grep (warning severity) and check-changed-code-quality.mjs are clean on the touched files.

  • Platforms: macOS (unit tests). The logic is plain in-memory matching with no paths or platform APIs.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

This only runs in the fork worker thread (claude-conversation-fork-worker-entry.ts), once per fork click, after the JSONL has been read and parsed. Nothing changes on the main or renderer thread, and there is no new I/O, subprocess work or polling. The only addition is one Map get and set per chain row that has a message.id.

Mean ms per call, old vs new, on synthetic chains with 10 blocks per reply (vitest, M-series, machine in use, so the numbers are noisy):

rows case old new
330 with apiBlockIndex, early / late 0.04 / 0.03 0.03 / 0.03
330 without apiBlockIndex, early / late threw 0.04 / 0.04
22k with apiBlockIndex, early / late / missing 1.96 / 2.88 / 3.28 1.98 / 3.22 / 2.85
22k without apiBlockIndex, early / late / missing threw 1.86 / 3.05 / 2.98
99k with apiBlockIndex, early / late / missing 12.98 / 16.71 / 14.05 11.26 / 18.48 / 16.21
99k without apiBlockIndex, early / late / missing threw 11.57 / 17.92 / 15.34

The worst case adds about 2 ms at 99k rows, off the UI thread. That is small next to the JSONL read and parse that runs just before it.

Risk

Level: Low

The fallback only runs for rows that have no apiBlockIndex, and those rows always failed to match before. If a transcript somehow wrote a message's blocks out of order, the fork would cut at the wrong block of the same reply instead of showing an error. To back this out, revert the commit. No saved data or settings change.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

claudeConversationForkBoundary now infers missing assistant apiBlockIndex values from row order for rows with the same message ID. Explicit numeric indexes remain in use. Tests verify that checkpoints resolve to the expected transcript rows with missing or explicit indexes, and that out-of-range block IDs produce the saved-context error.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 3694f

Forking from Claude replies with thinking blocks should now work for older Claude Code transcripts that lack block indexes. Newer transcripts that carry explicit indexes are unaffected. The fallback assumes saved rows appear one per content block, in order. This is the documented limitation, and transcripts that break it could resolve to a different block. Nothing found blocks merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#48148] requires that "Fork from this reply" resolve the streamed block id block:<message.id>:<blockIndex> when transcript rows lack apiBlockIndex (Claude Code 2.0.42). The whole-PR diff against …
Out of Scope Changes check Passed The whole-PR diff changes one function body in claude-conversation-fork-boundary.ts and adds one test file. The code hunk changes only the block-index derivation: a per-message counter, the fallback…
Title check Passed The title names the change: a fork from a reply now works on Claude transcripts that lack apiBlockIndex. The raw summary and objectives describe the same fallback in claudeConversationForkBoundary, so…
Description check Passed The description follows the template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #48148), Visual Proof (N/A with reason), Testing, Performance (with measurements), Risk (Level: Low…
Full details: Linked Issues check

Explanation

[#48148] requires that "Fork from this reply" resolve the streamed block id block:&lt;message.id&gt;:&lt;blockIndex&gt; when transcript rows lack apiBlockIndex (Claude Code 2.0.42). The whole-PR diff against the merge base changes only claudeConversationForkBoundary in src/main/claude/transcripts/claude-conversation-fork-boundary.ts. At the reviewed head, the function keeps a per-message.id counter over chain rows. It increments the counter by 1 per row. A row with a numeric apiBlockIndex uses that value. A row without it uses its counter position. The selected row is the one whose derived block id equals checkpoint.throughMessage.uuid. A direct uuid match still selects the row immediately. For the issue shape (one content block per row, in order), the thinking row maps to block 0 and the text row maps to block 1, so block:msg_X:1 resolves to the text row. This corrects the previous review: that review described a counter that advances by message.content.length. The head code advances by 1 per row. The two agree for the one-block-per-row shape in the issue. The PR adds claude-conversation-fork-boundary.test.ts with legacy and apiBlockIndex cases. I did not read the test file. Its content rests on the PR summary and the author's report that the test fails without the fix. The issue does not require the follow-up reader changes named in the PR description.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff changes one function body in claude-conversation-fork-boundary.ts and adds one test file. The code hunk changes only the block-index derivation: a per-message counter, the fallback to counter position when apiBlockIndex is absent, and an early return for direct uuid matches. Each change supports the #48148 objective. The numeric apiBlockIndex path yields the same block id as before. The PR does not modify claude-transcript-item-reader.ts or claude-transcript-import-plan.ts, which the PR description names only as possible follow-up work. No UI, SSH, or platform change appears in the diff. The test file was not read directly, so its scope is taken from the PR summary.

Full details: Title check

Explanation

The title names the change: a fork from a reply now works on Claude transcripts that lack apiBlockIndex. The raw summary and objectives describe the same fallback in claudeConversationForkBoundary, so the title matches the main change. It uses the conventional fix(scope) prefix and is one sentence.

Full details: Description check

Explanation

The description follows the template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #48148), Visual Proof (N/A with reason), Testing, Performance (with measurements), Risk (Level: Low, with a back-out plan), the upstream boundary checkbox, and the checklist. The main gaps are minor. The AI Disclosure section is omitted, though it is only required for non-StablyAI contributors. The Review and Notes sections are not addressed. The Testing section does not state the platform explicitly beyond macOS unit tests. The Linked Issue section adds attribution text. None of these gaps are critical.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5a18a46-77c5-4431-a44d-76b6aa2cb88f
Commits

Reviewing files that changed from the base of the PR and between 2c182e3 and 3694fa0.

Files selected for processing: 2

  • src/main/claude/transcripts/claude-conversation-fork-boundary.test.ts
  • src/main/claude/transcripts/claude-conversation-fork-boundary.ts

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

@nwparker
nwparker force-pushed the fix/claude-fork-legacy-block-index branch from 2c182e3 to 3694fa0 Compare November 24, 2026 08:17
@nwparker nwparker changed the title fix(claude): fork from a reply in transcripts written without apiBlockIndex fix(claude): fork from a reply on transcripts that have no apiBlockIndex Nov 24, 2026
Claude Code writes one transcript row per content block, but only newer
builds record apiBlockIndex on each row. Fork-through-message matched the
streamed block id (block:<messageId>:<index>) only against rows that carried
apiBlockIndex, so forking from a reply failed with "could not find the saved
context" on transcripts from older Claude Code builds. Fall back to the row's
position among rows sharing the same message id when apiBlockIndex is absent.

Fixes stablyai#48148

Co-authored-by: Common-Player <[email protected]>
Co-authored-by: 2SinceJuly <[email protected]>
Co-authored-by: Aditya Chandrajit Deore <[email protected]>
@nwparker
nwparker force-pushed the fix/claude-fork-legacy-block-index branch from 3694fa0 to 35b408b Compare November 24, 2026 08:25
@nwparker
nwparker merged commit 3127405 into stablyai:main Nov 24, 2026
56 of 57 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.

[Bug]: Fork from a Claude reply fails when the transcript rows have no apiBlockIndex (Claude Code 2.0.42)

2 participants