You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(claude): fork a Claude reply when transcript rows lack apiBlockIndex - #48155
Forking a Claude chat from a reply broke when the chat came from an older Claude Code build (2.0.42). Instead of copying the conversation up to that reply, Orca showed "Claude could not find the saved context for this response." This fixes the lookup so those older transcripts fork correctly.
What Changed
src/main/claude/transcripts/claude-conversation-fork-boundary.ts: when a transcript row has no apiBlockIndex, the fork-boundary lookup now recovers the block index from the row's position among the rows sharing the same message.id in the parent chain, instead of only matching rows that carry apiBlockIndex. Rows that do carry apiBlockIndex (Claude Code 2.1.x) keep using it, unchanged.
src/main/claude/transcripts/claude-conversation-fork-boundary.test.ts (new): regression tests for the fork boundary.
Before: forking from a reply whose transcript has a thinking row followed by a text row (2.0.42 writes one row per content block, no apiBlockIndex) threw AgentConversationCopyError and left an empty Claude Chat tab. After: the fork selects the text row (block:msg_X:1) and proceeds.
Why
Older Claude Code builds write one transcript row per content block in order, sharing message.id, with no apiBlockIndex field. The block index is recoverable from the row order, as the issue notes — no new API or format change is needed, and the 2.1.x path is untouched, so this is the smallest fix that covers both formats.
N/A — no visual or interaction change. The fix only changes which transcript row the fork boundary selects internally; the fork flow renders identically, and there is no UI surface modified.
Testing
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
Ran the new test file with vitest (repo versions: vitest 5.1.0, TypeScript 7.0.2) against the real source in an isolated harness (the repo tree is 3.4 GB, so the full pnpm test was not run locally; CI covers it):
Without the fix: 1 failed / 2 passed — the 2.0.42 test throws exactly the reported error (AgentConversationCopyError: Claude could not find the saved context for this response.).
With the fix: 3 passed / 0 failed — the 2.0.42 fixture returns the text row, the 2.1.x fixture still returns it, and a nonexistent block still throws.
Tested on Linux (this machine). macOS/Windows not tested locally — the change is platform-independent transcript logic.
Performance
None, because the fallback only runs for rows that have no apiBlockIndex, and it scans only the rows already in the parent chain (a single turn's rows). The apiBlockIndex path is unchanged.
Risk
Level: Low
The riskiest part is the fallback index derivation: if the row order among same-message.id rows ever did not match block order, a fork could start from the wrong block. Older CLIs write one row per content block in order (per the issue), and the 2.1.x path is untouched, so the blast radius is limited to forks from 2.0.42-era transcripts. Back out with a plain revert.
AI Disclosure
Disclosure: AI coding assistance was used in preparing this change. Model: Muse Spark 1.3 (Muse).
Review
AI coding agent summary: this change touches only the Claude transcript fork-boundary lookup in the main process. Cross-platform: the logic is platform-independent (pure transcript-row matching, no OS paths, no shell, no Electron APIs). SSH/remote: no effect — the transcript is read from the local session store before the fork is issued. Agent and integration compatibility: only Claude transcripts are affected; other providers do not use this path, and 2.1.x transcripts (with apiBlockIndex) take the unchanged code path. Performance: no hot-path impact (see Performance). UI quality: no UI change. Security: no new input handling, no credential or path handling; the fix only reads fields already present on transcript rows.
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.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
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) — targeted vitest run passed locally (see Testing); full lint/typecheck/test/build left to CI
Claude Code 2.0.42 writes one transcript row per content block, sharing
message.id, with no apiBlockIndex. claudeConversationForkBoundary only
matched a row when apiBlockIndex was a number, so forking from a reply
whose transcript has a thinking row followed by a text row threw
"Claude could not find the saved context for this response."
For rows without apiBlockIndex, recover the block index from the row's
position among the rows sharing the same message.id in the parent chain,
since older CLIs write one row per content block in order. Rows that
carry apiBlockIndex keep using it.
Adds claude-conversation-fork-boundary.test.ts: a 2.0.42 fixture (fails
without the fix, passes with it), a 2.1.x fixture (passes before and
after), and a no-match case that still throws.
Fixesstablyai#48148
The fork-boundary lookup now matches checkpoints to transcript rows by row UUID or source-block UUID. When a row has no numeric apiBlockIndex, the lookup infers the block index from earlier parent-chain rows with the same message ID. Tests cover matching with and without apiBlockIndex, and the error when no row matches.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to 4a729
This change makes forking from Claude Code 2.0.42 transcripts work by inferring the block index from row order. The inference rescans the preceding rows for every legacy row, so fork time grows quadratically on very long legacy sessions. Replacing it with a running count keeps the same behavior in linear time and is a small change that should be made before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and its scope: forking a Claude reply when transcript rows lack apiBlockIndex. The raw summary and objectives confirm the change adds a fallback block-index derivation in claud…
Description check
The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #48148), Visual Proof (N/A with reason), Testing with specific results, Performance, Ris…
Linked Issues check
Issue #48148 requires that forking from a Claude reply whose 2.0.42 transcript rows lack apiBlockIndex selects the streamed text block (block:msg_X:1) instead of throwing. The reviewed head changes cl…
Out of Scope Changes check
The whole-PR diff (merge base 851d477 to head 4a729d6) touches two files: the fork-boundary source file and its new test file. The source change is limited to the throughMessage selection logic that #…
Full details: Title check
Explanation
The title names the fix and its scope: forking a Claude reply when transcript rows lack apiBlockIndex. The raw summary and objectives confirm the change adds a fallback block-index derivation in claudeConversationForkBoundary for rows without apiBlockIndex. The title is concise, specific, and follows the conventional fix(scope) form.
Full details: Description check
Explanation
The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #48148), Visual Proof (N/A with reason), Testing with specific results, Performance, Risk with level and revert path, AI Disclosure, Review, and the checklist. The before and after behavior is explained. One checklist item is unchecked: full pnpm lint, typecheck, test, and build were left to CI, and this is stated openly. The Risk section names the riskiest part. The Testing section notes the full test suite was not run locally.
Full details: Linked Issues check
Explanation
Issue #48148 requires that forking from a Claude reply whose 2.0.42 transcript rows lack apiBlockIndex selects the streamed text block (block:msg_X:1) instead of throwing. The reviewed head changes claudeConversationForkBoundary in claude-conversation-fork-boundary.ts. When a row has a string message.id and no numeric apiBlockIndex, the code now derives blockIndex as the count of earlier chain rows with the same message.id. It then compares claudeSourceBlockId(message.id, blockIndex) with checkpoint.throughMessage.uuid. For the thinking-then-text sequence in the issue, the text row gets index 1 and matches. Rows with apiBlockIndex use the same value as before, and the uuid match is unchanged. The diff adds a regression test file covering the 2.0.42 and 2.1.x fixtures. The test results in the PR description are author-reported; I did not run the tests. The source logic supports the required behavior.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff (merge base 851d477 to head 4a729d6) touches two files: the fork-boundary source file and its new test file. The source change is limited to the throughMessage selection logic that #48148 requires. The new test file supports that same change. No unrelated behavior, UI, or other provider path is modified in the inspected diff.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Performance & Scalability · Quick win
Avoid rescanning the transcript for every legacy row.
For a checkpoint near the end, each legacy row copies and scans its entire chain prefix. With 10,000 legacy assistant rows, this causes approximately 50 million predecessor checks before the fork can finish.
Track a running count per message.id instead. Advance that count for every message-bearing row, including rows with apiBlockIndex. Use the count only for the fallback. This preserves the current matching rules with linear traversal.
Thanks @AdityaxDeore for this fix and its tests. Three PRs targeted #48148, so we're landing one reviewed version through #48153 (#48153), and you're credited there as a co-author. Closing this one in favor of it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Forking a Claude chat from a reply broke when the chat came from an older Claude Code build (2.0.42). Instead of copying the conversation up to that reply, Orca showed "Claude could not find the saved context for this response." This fixes the lookup so those older transcripts fork correctly.
What Changed
src/main/claude/transcripts/claude-conversation-fork-boundary.ts: when a transcript row has noapiBlockIndex, the fork-boundary lookup now recovers the block index from the row's position among the rows sharing the samemessage.idin the parent chain, instead of only matching rows that carryapiBlockIndex. Rows that do carryapiBlockIndex(Claude Code 2.1.x) keep using it, unchanged.src/main/claude/transcripts/claude-conversation-fork-boundary.test.ts(new): regression tests for the fork boundary.Before: forking from a reply whose transcript has a thinking row followed by a text row (2.0.42 writes one row per content block, no
apiBlockIndex) threwAgentConversationCopyErrorand left an empty Claude Chat tab. After: the fork selects the text row (block:msg_X:1) and proceeds.Why
Older Claude Code builds write one transcript row per content block in order, sharing
message.id, with noapiBlockIndexfield. The block index is recoverable from the row order, as the issue notes — no new API or format change is needed, and the 2.1.x path is untouched, so this is the smallest fix that covers both formats.Linked Issue
Fixes #48148
Visual Proof
N/A — no visual or interaction change. The fix only changes which transcript row the fork boundary selects internally; the fork flow renders identically, and there is no UI surface modified.
Testing
Ran the new test file with vitest (repo versions: vitest 5.1.0, TypeScript 7.0.2) against the real source in an isolated harness (the repo tree is 3.4 GB, so the full
pnpm testwas not run locally; CI covers it):AgentConversationCopyError: Claude could not find the saved context for this response.).Performance
None, because the fallback only runs for rows that have no
apiBlockIndex, and it scans only the rows already in the parent chain (a single turn's rows). TheapiBlockIndexpath is unchanged.Risk
Level: Low
The riskiest part is the fallback index derivation: if the row order among same-
message.idrows ever did not match block order, a fork could start from the wrong block. Older CLIs write one row per content block in order (per the issue), and the 2.1.x path is untouched, so the blast radius is limited to forks from 2.0.42-era transcripts. Back out with a plain revert.AI Disclosure
Disclosure: AI coding assistance was used in preparing this change. Model: Muse Spark 1.3 (Muse).
Review
AI coding agent summary: this change touches only the Claude transcript fork-boundary lookup in the main process. Cross-platform: the logic is platform-independent (pure transcript-row matching, no OS paths, no shell, no Electron APIs). SSH/remote: no effect — the transcript is read from the local session store before the fork is issued. Agent and integration compatibility: only Claude transcripts are affected; other providers do not use this path, and 2.1.x transcripts (with
apiBlockIndex) take the unchanged code path. Performance: no hot-path impact (see Performance). UI quality: no UI change. Security: no new input handling, no credential or path handling; the fix only reads fields already present on transcript rows.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred) — targeted vitest run passed locally (see Testing); full lint/typecheck/test/build left to CI