Repository navigation
Description
Summary
In a long-running Claude Code thread, Edit message and Fork into new thread fail with Session <uuid> not found, although the transcript exists at <CLAUDE_CONFIG_DIR>/projects/<project>/<uuid>.jsonl. It happens once the current session's transcript is larger than Node's maximum string length (536,870,888 characters). Expected: the edit or fork succeeds.
Versions and environment
- bb 0.48.1 (desktop app), macOS 27.0.1, Electron 44.9.3 / Node 24.22.0 for the provider bridge
- claude-code provider, Claude Code 2.1.314, bundled
@anthropic-ai/claude-agent-sdk0.3.245 - Regression from Fork Claude sessions from the session's config dir and keep fork intent across failed starts #6358 (first released in desktop v0.48.0); 0.47.1 and earlier forked through the SDK's own file path
Steps to reproduce
Closest faithful repro without a real transcript, at the code path:
- In a bb checkout at
916d684ac2with dependencies installed:cd plugins/provider-claude-code - Save the script below as
fork-large-transcript-repro.mtsin that directory. - Run
node --experimental-strip-types --no-warnings fork-large-transcript-repro.mts ./src/bridge/session-fork.ts
The script writes a synthetic 537,025,136-character transcript under a temporary CLAUDE_CONFIG_DIR, calls forkClaudeSession with a checkpoint (the edit path) and without one (the fork path), and deletes everything afterwards. It needs about 1.1 GB of free disk while it runs. An optional second argument sets the transcript size in characters.
fork-large-transcript-repro.mts
import { randomUUID } from "node:crypto";
import { createWriteStream, mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { once } from "node:events";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { constants } from "node:buffer";
const sessionForkModule = resolve(process.argv[2] ?? "./src/bridge/session-fork.ts");
const targetChars = Number(process.argv[3] ?? constants.MAX_STRING_LENGTH);
const { forkClaudeSession } = await import(pathToFileURL(sessionForkModule).href);
const configDirectory = mkdtempSync(join(tmpdir(), "bb-fork-repro-"));
const transcriptDir = join(configDirectory, "projects", "-tmp-worktree");
mkdirSync(transcriptDir, { recursive: true });
const sourceSessionId = randomUUID();
const ids: string[] = [];
const out = createWriteStream(join(transcriptDir, `${sourceSessionId}.jsonl`));
const pad = "x".repeat(1024 * 1024);
let chars = 0;
for (let i = 0; chars <= targetChars; i++) {
const role = i % 2 === 0 ? "user" : "assistant";
ids.push(randomUUID());
const line = `${JSON.stringify({
type: role,
uuid: ids[i],
parentUuid: i === 0 ? null : ids[i - 1],
sessionId: sourceSessionId,
cwd: "/tmp/worktree",
isSidechain: false,
timestamp: new Date(Date.UTC(2026, 9, 31, 0, 0, i)).toISOString(),
message: { role, content: `${role} ${i} ${pad}` },
})}\n`;
chars += line.length;
if (!out.write(line)) await once(out, "drain");
}
out.end();
await once(out, "finish");
console.log(`transcript: ${chars} characters, MAX_STRING_LENGTH ${constants.MAX_STRING_LENGTH}`);
try {
for (const upToMessageId of [ids[Math.floor(ids.length / 2)], undefined]) {
const label = upToMessageId === undefined ? "full fork" : "checkpoint fork (edit message)";
try {
const forked = await forkClaudeSession({ configDirectory, sourceSessionId, upToMessageId });
console.log(`${label}: ok, new session ${forked}`);
rmSync(join(transcriptDir, `${forked}.jsonl`), { force: true });
} catch (error) {
console.log(`${label}: ${error instanceof Error ? `${error.name}: ${error.message}` : String(error)}`);
}
}
} finally {
rmSync(configDirectory, { recursive: true, force: true });
}In the app: in any Claude Code thread whose current transcript is over 512 MiB, choose Edit message on an earlier plain-text message, or Fork into new thread on an assistant reply.
Did not reproduce with: transcripts under 512 MiB (earlier testing on new, small threads, where edit and fork worked); Codex threads (different code path, by code reading).
Expected vs actual
Actual, at 916d684ac2, run with the bb app's own Node (ELECTRON_RUN_AS_NODE=1 /Applications/bb.app/Contents/MacOS/bb, Node 24.22.0):
transcript: 537025136 characters, MAX_STRING_LENGTH 536870888
checkpoint fork (edit message): Error: Session 2833f7e2-d681-4457-a98a-6089eb76e0f2 not found
full fork: Error: Session 2833f7e2-d681-4457-a98a-6089eb76e0f2 not found
Server log in real use: POST /api/v1/threads/<id>/edit-message 502 {"code":"command_failed","message":"Session <uuid> not found"}.
Expected: both forks succeed. If a transcript truly cannot be read, the error names the cause.
Evidence
findTranscriptreads the whole file into one string, and itscatch { continue; }turns theRangeError: Invalid string lengthinto "not found":bb/plugins/provider-claude-code/src/bridge/session-fork.ts
Lines 78 to 91 in 916d684
for (const projectDirectory of projectDirectories) { let contents: string; try { contents = await readFile( join(projectDirectory, `${sessionId}.jsonl`), "utf8", ); } catch { continue; } if (contents.length > 0) { return { projectDirectory, contents }; } } - The store's
appendalso joins the whole fork into one string,, so a reader-only fix still fails a large fork withbb/plugins/provider-claude-code/src/bridge/session-fork.ts
Lines 55 to 59 in 916d684
await writeFile( join(sourceProjectDirectory, `${key.sessionId}.jsonl`), entries.map((entry) => `${JSON.stringify(entry)}\n`).join(""), { mode: 0o600, flag: "wx" }, ); RangeError: Invalid string length(verified on a 545 MB synthetic transcript). - Real use: 9 failed edit attempts across 3 threads between Oct 27 and Oct 31, with the current transcript between 655 MB and 1.22 GB at each attempt. Each session file existed. (Thread IDs available on request.)
- Measured with synthetic transcripts only; no real transcript was opened.
What you ruled out
- Not Claude Code fork fails with "Session … not found" when CLAUDE_CONFIG_DIR comes from project environment variables #6325: the config dir is resolved correctly; the read fails on size.
- Not Forking a thread whose source has already been compacted causes the fork to immediately re-compact (claude-code) #3185: that one is a fork that succeeds and then re-compacts.
- Still happens on
mainat916d684ac2. - Updating the SDK alone does not help: the failing reads and writes are in bb's store, not the SDK.
Suggested priority and effort
High for long-running Claude threads: edit and fork fail in every thread past about 512 MiB, there is no workaround other than starting a new thread, and no data is lost. Effort low (one file).
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 1, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotproviders,provider-claude-code.RangeErroras a missing session. Whole-output serialization has the same allocation limit.confirmed-repro.Stream Claude fork transcripts so long threads can edit and fork (get…
Fork Claude sessions in a worker so an oversized fork cannot crash ot…