Repository navigation
Stream Claude fork transcripts so long threads can edit and fork - #6782
Merged
ymichael merged 2 commits intoNov 2, 2026
Merged
Conversation
The fork session store read the whole transcript into one string and wrote the fork as one joined string. Both fail above Node's 512 MiB string limit, and the read error surfaced as "Session <id> not found". Read the transcript line by line and write the fork one entry at a time, keeping the store, its config-dir lookup and its exclusive create. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The test mocked only readFile, so restoring the joined-string writer still passed. Also reject writeFile, and fork both through a checkpoint and the whole session. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 2, 2026
…her threads (#6855) ## Human comments ## What was wrong Editing a message or forking a Claude Code thread loads the session transcript into memory inside the Claude provider bridge (`forkClaudeSession` in `plugins/provider-claude-code/src/bridge/session-fork.ts`). bb runs one bridge process per environment, shared by every Claude thread in that environment. #6782 (issue #6781) removed Node's 512 MiB string limit, so the fork now reads transcripts of any size. That turned the clean "Session not found" failure above 512 MiB into a heap exhaustion for the largest transcripts: the bridge aborts with `SIGABRT` and every Claude thread in that environment dies mid-turn. Measured on real-shaped transcripts at the default heap (about 4.3 GB on a 48 GB Mac): 2.0–3.2 GB forked, 4.0 GB crashed. Machines with less RAM get a smaller default heap and hit this sooner, for example the 2.3 GB heap on an 8 GB Windows VM. ## What changed - `plugins/provider-claude-code/src/bridge/session-fork.ts`: `forkClaudeSession` runs the existing fork in a `worker_threads` worker that loads the plugin's own bundle (`new URL(import.meta.url)`) and runs the fork when its `workerData` asks for one. - The worker posts back the new session ID. Errors keep their message, for example the SDK's `Session <id> not found`. - `ERR_WORKER_OUT_OF_MEMORY` becomes `Claude session <id> is too large to fork: forking it ran out of memory`. Only the worker stops; the bridge and its other sessions keep running. - Worker stdout goes to the bridge's stderr, so it cannot corrupt the bridge's JSON-RPC stdout. - The fork store is unchanged and uses only the SDK's documented `SessionStore` interface. The size that forks successfully is unchanged; only the failure mode changes. Starting the worker costs about 0.1 s per fork. - Tests: the bridge tests mocked the SDK's `forkSession`, which a worker cannot see. `bridge.conformance.test.ts` now mocks bb's `forkClaudeSession`, and the unused `forkSession` mocks in `bridge.test.ts` and `bridge.calibration.test.ts` are removed. The mock-based test from #6782 is replaced, because `vi.mock` doesn't reach the worker. - No wire or protocol change, so no `HOST_DAEMON_PROTOCOL_VERSION` bump. ## How you verified New tests in `session-fork.test.ts`: | Test | On main | Here | |---|---|---| | A child process with a 32 MB heap forks a 128 MB transcript; it must receive "too large to fork" and keep running | ❌ The process dies: `FATAL ERROR: Reached heap limit … JavaScript heap out of memory` | ✅ | | A missing source session rejects with the SDK's `Session <id> not found` | n/a | ✅ | `pnpm exec turbo run typecheck lint test --filter='...[origin/main]'` (scope: `bb-plugin-provider-claude-code`, `@bb/bundled-plugins`): 10/10 tasks, 416 tests passed. The existing #6325 bridge test now runs a real checkpoint fork through the worker. Manual checks on a `pnpm start:worktree` server with the `bb` CLI and the UI. The oversized transcript was padded to 4 GB with copies of a real transcript. The bystander was a second Claude thread in the same environment, running a 90 s command. | Scenario | main | This branch | |---|---|---| | Edit a message in the 4 GB thread | Toast: `Provider "claude-code" exited unexpectedly (signal SIGABRT)` plus a V8 stack trace | Toast: `Claude session … is too large to fork: forking it ran out of memory` after about 13 s | | Fork into new thread from the 4 GB thread | The new thread shows `thread.start failed` with the SIGABRT stack trace | The new thread shows `thread.start failed` with "too large to fork" | | Bystander in the same environment | Killed mid-command (`1 interrupted`, SIGABRT) | Finishes and replies `done` | | Normal-size fork and edit (CLI) | ALPHA, BRAVO / ALPHA, DELTA | Same, with calls taking about 1 s | Runtime and platform checks: | Runtime | Result | |---|---| | macOS: system Node 22.23 and bb's Electron Node 24.15 | A worker out of memory gives `ERR_WORKER_OUT_OF_MEMORY`; the main thread stays alive with its data intact | | Windows 11 ARM64 VM, Node 24.22 | Checkpoint fork, full fork and the missing-session error work. A 160 MB transcript under a small heap is rejected cleanly here; with main's code the process exits with code 134 (`FATAL ERROR: Reached heap limit`) | Refs #6781 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Human comments
What was wrong
Edit message and Fork into new thread fail with
Session <id> not foundin Claude Code threads whose transcript is over 512 MiB (#6781). Since #6358,forkClaudeSessionpasses the SDK a session store bound to the session's config dir, which keeps #6325 fixed. That store reads the transcript withreadFile(path, "utf8")and writes the fork by joining every entry into one string. Both build a transcript-sized string, which Node cannot do above 536,870,888 characters. The read'sRangeErrorwas then caught by the directory scan and reported as "not found".What changed
plugins/provider-claude-code/src/bridge/session-fork.ts: the store reads the transcript one line at a time (FileHandle.readLines, 1 MiB chunks) and writes the fork one line per entry throughstream/promisespipeline, still withflags: "wx"and mode0o600. The store design, the config-dir lookup and the fork placement are unchanged, so Claude Code fork fails with "Session … not found" when CLAUDE_CONFIG_DIR comes from project environment variables #6325 stays fixed.HOST_DAEMON_PROTOCOL_VERSIONbump.CLAUDE_CONFIG_DIR, which is the machinery the store already avoids.How you verified
src/bridge/session-fork.test.ts:readFileandwriteFilereject withRangeError: Invalid string length, which is what Node throws above the limit, so the test fails if the store reads the transcript or writes the fork as one string. It runs a checkpoint fork and a full fork through the real SDKforkSession. On main it fails withSession <id> not found, and with only the old joined-string writer restored it fails withRangeError: Invalid string length; here it passes. V8's limit cannot be lowered in a test, so the real-size check is the manual run below.__tests__/bridge.test.ts("forks a Claude session from the session config directory through the requested checkpoint") still passes.pnpm exec turbo run typecheck lint test --filter=bb-plugin-provider-claude-code: 10 of 10 tasks successful; 29 test files, 415 tests passed.oxfmt --checkon both files,git diff --check,scripts/check-source-nul.mjsandscripts/check-provider-literal-ratchet.mjspass.ELECTRON_RUN_AS_NODE=1, Electron 44.9.3, Node 24.22.0) and the script from the issue:/usr/bin/time -lfor the whole script, single runs on a loaded machine.Fixes #6781