Skip to content

fix(claude): fork a Claude reply when transcript rows lack apiBlockIndex - #48155

Closed
AdityaxDeore wants to merge 1 commit into
stablyai:mainfrom
AdityaxDeore:fix/48148-claude-fork-no-apiblockindex
Closed

AdityaxDeore wants to merge 1 commit into
stablyai:mainfrom
AdityaxDeore:fix/48148-claude-fork-no-apiblockindex

Conversation

@AdityaxDeore

Copy link
Copy Markdown
Contributor

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 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.

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

  • 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.

Fixes stablyai#48148
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: 2088a86e-babf-44cc-96fb-6a3a864fc685
Commits

Reviewing files that changed from the base of the PR and between 851d477 and 4a729d6.

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; 9 remain after this review.

Comment on lines +127 to +129
: chain
.slice(0, index)
.filter((earlier) => claudeRecord(earlier.message)?.id === message.id).length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

@nwparker

Copy link
Copy Markdown
Contributor

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.

@nwparker nwparker closed this Nov 24, 2026
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