Skip to content

Claude Code Edit message and Fork fail with "Session … not found" when the session transcript is over 512 MiB #6781

Closed

Description

@Danielalnajjar

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

Steps to reproduce

Closest faithful repro without a real transcript, at the code path:

  1. In a bb checkout at 916d684ac2 with dependencies installed: cd plugins/provider-claude-code
  2. Save the script below as fork-large-transcript-repro.mts in that directory.
  3. 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

  • findTranscript reads the whole file into one string, and its catch { continue; } turns the RangeError: Invalid string length into "not found":
    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 append also joins the whole fork into one string,
    await writeFile(
    join(sourceProjectDirectory, `${key.sessionId}.jsonl`),
    entries.map((entry) => `${JSON.stringify(entry)}\n`).join(""),
    { mode: 0o600, flag: "wx" },
    );
    , so a reader-only fix still fails a large fork with 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

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

  1. added theissue type on Nov 1, 2026
  2. added
    providers
    provider-claude-code
    confirmed-repro
    on Nov 1, 2026
  3. bb-slop-cop commented on Nov 1, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · High priority · Low effort; providers, provider-claude-code.
    • Report: Reproduction and root-cause report — REPRODUCED, high root-cause confidence.
    • Root cause: Whole-file UTF-8 reading exceeds Node’s string limit; a catch-all hides the RangeError as a missing session. Whole-output serialization has the same allocation limit.
    • Verification: Two clean trusted-main checkouts reproduce checkpoint and full-fork failures with a 536,981,786-byte synthetic ASCII transcript; small controls pass. The report includes the repeatable regression harness. No real transcripts or linked-PR code were run.
    • Reproduction label: confirmed-repro.
    • Fix: No duplicate PR opened: existing open #6782 already links to this issue.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-claude-codeproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions