Created
September 25, 2026 17:12
-
-
Save BlackWhiteYellow/f44e367254db24fbe20d7fe10002ab1f to your computer and use it in GitHub Desktop.
Synthetic Claude Code session transcript generator + Buffer.indexOf >2 GiB repro (for anthropics/claude-code issues)
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
| # -*- coding: utf-8 -*- | |
| """Generate a SYNTHETIC Claude Code session transcript (JSONL) for the bug report -- no real data. | |
| Shape follows real transcripts (user/assistant records chained by parentUuid; a system/compact_boundary record every | |
| --boundary-every records with parentUuid null and compactMetadata.preservedSegment + preservedMessages, as current | |
| Claude Code writes them). --no-segments writes the same file with boundaries WITHOUT the preserved fields (control). | |
| Usage: | |
| python gen_synthetic_transcript.py OUT --target-mb 30 [--no-segments] [--boundary-every 40] [--pad 4000] | |
| OUT is a file path, or an existing directory: then the file is written as <session-id>.jsonl inside it | |
| (the extension expects the file name to equal the sessionId in the records). --boundary-every 0 writes no | |
| compact boundaries at all (a never-compacted session). | |
| Keep generated files OUTSIDE ~/.claude/projects until you mean to open them: a >2 GiB file opened in the | |
| VS Code extension crashes the extension host and every Claude tab with it. | |
| """ | |
| import os | |
| import argparse | |
| import json | |
| import random | |
| import uuid | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("out") | |
| ap.add_argument("--target-mb", type=float, required=True) | |
| ap.add_argument("--no-segments", action="store_true") | |
| ap.add_argument("--boundary-every", type=int, default=40) | |
| ap.add_argument("--pad", type=int, default=4000) | |
| a = ap.parse_args() | |
| rnd = random.Random(20260925) | |
| def uid(): | |
| return str(uuid.UUID(int=rnd.getrandbits(128), version=4)) | |
| SID = uid() | |
| target = int(a.target_mb * 1048576) | |
| if os.path.isdir(a.out): | |
| a.out = os.path.join(a.out, SID + ".jsonl") | |
| # Key order and compact separators as the CLI writes them. It matters: the extension's scanner only treats a line | |
| # as a boundary when '"compact_boundary"' appears within its first 256 bytes. | |
| tail_keys = {"userType": "external", "entrypoint": "claude-vscode", "cwd": "/synthetic/project", | |
| "sessionId": SID, "version": "2.1.280", "gitBranch": "main"} | |
| written = 0 | |
| n = 0 | |
| prev = None | |
| recent = [] | |
| t = 1790000000 | |
| with open(a.out, "w", encoding="utf-8", newline="\n") as fh: | |
| def put(rec): | |
| global written | |
| rec.update(tail_keys) | |
| line = json.dumps(rec, ensure_ascii=False, separators=(",", ":")) + "\n" | |
| fh.write(line) | |
| written += len(line.encode("utf-8")) | |
| while written < target: | |
| n += 1 | |
| t += 7 | |
| ts = "2026-09-%02dT%02d:%02d:%02d.000Z" % (1 + (t // 86400) % 28, (t // 3600) % 24, (t // 60) % 60, t % 60) | |
| u = uid() | |
| if a.boundary_every > 0 and n % a.boundary_every == 0: | |
| meta = {"trigger": "auto", "preTokens": 150000, "durationMs": 20000, "preCompactDiscoveredTools": [], | |
| "postTokens": 8000, "cumulativeDroppedTokens": 0} | |
| if not a.no_segments and len(recent) >= 2: | |
| meta["preservedSegment"] = {"headUuid": recent[-2], "anchorUuid": u, "tailUuid": recent[-1]} | |
| meta["preservedMessages"] = {"anchorUuid": u, "uuids": recent[-2:], "allUuids": recent[-10:]} | |
| put({"parentUuid": None, "logicalParentUuid": prev, "isSidechain": False, "type": "system", | |
| "subtype": "compact_boundary", "content": "Conversation compacted", "isMeta": False, | |
| "timestamp": ts, "uuid": u, "level": "info", "compactMetadata": meta}) | |
| elif n % 2: | |
| put({"parentUuid": prev, "isSidechain": False, "type": "user", | |
| "message": {"role": "user", "content": "synthetic user text " + "u" * a.pad}, | |
| "uuid": u, "timestamp": ts}) | |
| else: | |
| put({"parentUuid": prev, "isSidechain": False, "type": "assistant", | |
| "message": {"role": "assistant", "content": [{"type": "text", "text": "synthetic reply " + "a" * a.pad}]}, | |
| "uuid": u, "timestamp": ts}) | |
| prev = u | |
| recent.append(u) | |
| recent = recent[-10:] | |
| print("wrote %s: session %s, %d records, %.1f MB (%d bytes), boundaries every %s, preserved segments=%s" | |
| % (a.out, SID, n, written / 1048576, written, a.boundary_every or "never", not a.no_segments)) |
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
| // Buffer.prototype.indexOf beyond 2 GiB returns an int32-wrapped (negative) position. | |
| // Run inside VS Code's runtime: ELECTRON_RUN_AS_NODE=1 "<VS Code install>/Code.exe" indexof_2gib.js | |
| // or in plain Node: node indexof_2gib.js (needs ~4.5 GB of free RAM) | |
| console.log("runtime:", JSON.stringify({ node: process.versions.node, electron: process.versions.electron, v8: process.versions.v8 })); | |
| const big = Buffer.alloc(2 ** 31 + 4096, 97); | |
| const hit = 2 ** 31 + 100, off = 2 ** 31 + 50; | |
| big[hit] = 10; | |
| const r = { number: big.indexOf(10, off), buffer: big.indexOf(Buffer.from([10]), off), string: big.indexOf("\n", off) }; | |
| for (const [k, v] of Object.entries(r)) console.log(k.padEnd(8), v, v === hit ? "ok" : "WRONG (expected " + hit + ")"); | |
| const n = 2 ** 31 - 4096, small = Buffer.alloc(n, 97), hit2 = n - 1000; | |
| small[hit2] = 10; | |
| const c = small.indexOf(10, hit2 - 500); | |
| console.log("control below 2 GiB:", c, c === hit2 ? "ok" : "WRONG (expected " + hit2 + ")"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment