From d4e7e979d76978f8973c8238189d72ea743dc691 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 07:54:03 +0000 Subject: [PATCH 1/4] test(server): reproduce long Claude session import skip (#29153) These tests reproduce #29153: a Claude transcript whose conversation text exceeds the 32 MiB selected-history budget is skipped instead of imported with its first prompt, most recent messages, and an omitted-message count. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 688b974e7658..45263e004a72 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1689,6 +1689,51 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); + it.effect("imports long Claude conversation history beyond the selected-history budget", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const nowMs = Date.parse("2026-08-24T12:00:00.000Z"); + yield* TestClock.setTime(nowMs); + const claudeHomePath = yield* makeTempDir("t3code-long-conversation-claude-"); + const codexHomePath = yield* makeTempDir("t3code-long-conversation-codex-"); + const workspace = yield* makeTempDir("t3code-long-conversation-workspace-"); + const record = (fields: Record) => + encodeTranscriptRecord({ sessionId: "claude-long", ...fields }); + const longText = "x".repeat(100 * 1024); + const middleCount = 240; + yield* writeTranscript({ + filePath: path.join(claudeHomePath, "projects", "-slug", "claude-long.jsonl"), + contents: [ + record({ + type: "user", + cwd: workspace, + message: { role: "user", content: "First prompt" }, + }), + // 24 MiB of conversation text exceeds the real 32 MiB selected-history budget. + ...Array.from({ length: middleCount }, (_, index) => { + const role = index % 2 === 0 ? "assistant" : "user"; + return record({ type: role, message: { role, content: longText } }); + }), + record({ type: "user", message: { role: "user", content: "Latest prompt" } }), + ].join("\n"), + mtimeMs: nowMs - 60_000, + }); + + const outcomes = yield* runRecentThreadOutcomes({ + claudeHomePath, + codexHomePath, + workspaceRoot: workspace, + }); + + expect(outcomes.map((outcome) => outcome._tag)).toEqual(["Importable"]); + const thread = outcomes[0]?._tag === "Importable" ? outcomes[0].thread : undefined; + expect(thread?.messages[0]).toMatchObject({ role: "user", text: "First prompt" }); + expect(thread?.messages.at(-1)).toMatchObject({ role: "user", text: "Latest prompt" }); + expect(thread?.messages).toHaveLength(200); + expect(thread?.omittedMessageCount).toBe(middleCount + 2 - 200); + }), + ); + it.effect("skips growth during reading without exceeding the reserved bytes", () => Effect.gen(function* () { const path = yield* Path.Path; From 5d1592e40f096b487aa25999625f0155c3d5045c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 08:00:10 +0000 Subject: [PATCH 2/4] fix(server): import long Claude sessions past the history budget Claude session import charged every conversational record to the 32 MiB selected-history budget, so long sessions were skipped even though the import only shows the first user message and the latest 200 messages. The Claude read now holds the first user message plus a rolling window of the latest 200 conversational records, releases evicted records from the budget, and threads the dropped count into omittedMessageCount so the imported thread matches an unbounded read. Codex and Pi are unchanged. The reproduction's messages are recalibrated to 64 KiB x 400: the reader charges 2 bytes per character, so 200 messages of 100 KiB would exceed the budget on their own. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 48 +++++++++++++++++-- .../server/src/project/AgentSessionScanner.ts | 44 +++++++++++++++-- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 45263e004a72..aea5ee1357a5 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1699,8 +1699,8 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { const workspace = yield* makeTempDir("t3code-long-conversation-workspace-"); const record = (fields: Record) => encodeTranscriptRecord({ sessionId: "claude-long", ...fields }); - const longText = "x".repeat(100 * 1024); - const middleCount = 240; + const longText = "x".repeat(64 * 1024); + const middleCount = 400; yield* writeTranscript({ filePath: path.join(claudeHomePath, "projects", "-slug", "claude-long.jsonl"), contents: [ @@ -1709,7 +1709,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { cwd: workspace, message: { role: "user", content: "First prompt" }, }), - // 24 MiB of conversation text exceeds the real 32 MiB selected-history budget. + // The whole history exceeds the real 32 MiB selected-history budget; the shown window fits. ...Array.from({ length: middleCount }, (_, index) => { const role = index % 2 === 0 ? "assistant" : "user"; return record({ type: role, message: { role, content: longText } }); @@ -1734,6 +1734,48 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); + it.effect("imports a late first Claude prompt once when older replies are dropped", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const nowMs = Date.parse("2026-08-24T12:00:00.000Z"); + yield* TestClock.setTime(nowMs); + const claudeHomePath = yield* makeTempDir("t3code-late-prompt-claude-"); + const codexHomePath = yield* makeTempDir("t3code-late-prompt-codex-"); + const workspace = yield* makeTempDir("t3code-late-prompt-workspace-"); + const contents = [ + encodeTranscriptRecord({ type: "attachment", sessionId: "late-prompt", cwd: workspace }), + // The first prompt is still among the latest 200 messages after older replies drop out. + ...Array.from({ length: 250 }, (_, index) => { + const role = index < 60 || index % 2 === 1 ? "assistant" : "user"; + return encodeTranscriptRecord({ + type: role, + sessionId: "late-prompt", + message: { role, content: `${role} ${index}` }, + }); + }), + ].join("\n"); + const filePath = path.join(claudeHomePath, "projects", "-slug", "late-prompt.jsonl"); + yield* writeTranscript({ filePath, contents, mtimeMs: nowMs - 60_000 }); + + const [thread] = yield* runRecentThreads({ + claudeHomePath, + codexHomePath, + workspaceRoot: workspace, + }); + + expect(thread?.messages[0]).toMatchObject({ role: "assistant", text: "assistant 50" }); + expect(thread).toEqual( + AgentSessionScanner.parseAgentSessionTranscript({ + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "late-prompt", + lastActiveAtMs: nowMs - 60_000, + contents, + }), + ); + }), + ); + it.effect("skips growth during reading without exceeding the reserved bytes", () => Effect.gen(function* () { const path = yield* Path.Path; diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index bbd3ba5a631e..020bb668cd9f 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -368,13 +368,14 @@ export function parseAgentSessionTranscript( input.source === "claudeAgent" ? records.reduce(foldClaudeFields, emptyClaudeFields) : emptyClaudeFields; - return parseAgentSessionRecords(input, records, claudeFields); + return parseAgentSessionRecords(input, records, claudeFields, 0); } function parseAgentSessionRecords( input: AgentSessionTranscriptMetadata, records: ReadonlyArray, claudeFields: ClaudeFields, + droppedMessageCount: number, ): AgentSessionThread | null { const fallbackTimestamp = DateTime.formatIso(DateTime.makeUnsafe(input.lastActiveAtMs)); // Claude filenames are session IDs. Codex rollout filenames include extra @@ -587,7 +588,7 @@ function parseAgentSessionRecords( createdAt: retainedMessages[0]?.createdAt ?? fallbackTimestamp, updatedAt: fallbackTimestamp, messages: retainedMessages, - omittedMessageCount: conversationMessageCount - retainedMessages.length, + omittedMessageCount: conversationMessageCount + droppedMessageCount - retainedMessages.length, }; } @@ -624,6 +625,31 @@ function shouldRetainDecodedRecord( ); } +// The import shows only the first user message and the latest messages, so a +// long Claude session holds just those and counts the rest as dropped. +function createClaudeHistoryWindow() { + const recent: Array<{ readonly record: DecodedTranscriptRecord; readonly bytes: number }> = []; + let firstUser: DecodedTranscriptRecord | undefined; + let droppedMessageCount = 0; + return { + // Takes a record shouldRetainDecodedRecord kept; returns the bytes it released. + push: (record: DecodedTranscriptRecord, bytes: number): number => { + if (firstUser === undefined && record.type === "user") firstUser = record; + recent.push({ record, bytes }); + if (recent.length <= MAX_IMPORTED_MESSAGES) return 0; + const evicted = recent.shift(); + if (evicted === undefined || evicted.record === firstUser) return 0; + droppedMessageCount += 1; + return evicted.bytes; + }, + records: () => { + const held = recent.map((entry) => entry.record); + return firstUser === undefined || held.includes(firstUser) ? held : [firstUser, ...held]; + }, + droppedMessageCount: () => droppedMessageCount, + }; +} + function normalizeForWorktreeMatch(value: string, caseFold: boolean): string { const normalized = `${value.replaceAll("\\", "/")}/`; return caseFold ? normalized.toLowerCase() : normalized; @@ -916,6 +942,7 @@ export const make = Effect.gen(function* () { return null; } const records: Array = []; + const claudeHistory = createClaudeHistoryWindow(); let cwd = Option.none(); let claudeFields = emptyClaudeFields; let historyBytes = 0; @@ -949,7 +976,9 @@ export const make = Effect.gen(function* () { claudeFields = foldClaudeFields(claudeFields, decoded.value); } if (shouldRetainDecodedRecord(source, decoded.value)) { - if ( + if (source === "claudeAgent") { + historyBytes += recordBytes - claudeHistory.push(decoded.value, recordBytes); + } else if ( source === "pi" && decoded.value.type === "message" && !isPiConversationRecord(decoded.value) @@ -997,7 +1026,13 @@ export const make = Effect.gen(function* () { if (recordStarted && !(yield* Effect.try(finishRecord))) return null; return sameTranscriptIdentity(expected, transcriptIdentity(filePath, yield* file.stat)) - ? { records, recordCount, cwd, claudeFields } + ? { + records: source === "claudeAgent" ? claudeHistory.records() : records, + droppedMessageCount: claudeHistory.droppedMessageCount(), + recordCount, + cwd, + claudeFields, + } : null; }), ), @@ -1635,6 +1670,7 @@ export const make = Effect.gen(function* () { }, snapshot.records, snapshot.claudeFields, + snapshot.droppedMessageCount, ); if (parsedThread === null) { return Option.some({ _tag: "Skipped" }); From 55bc94b3e72fca59a33e22157a4d7857f4b41550 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 01:06:55 +0000 Subject: [PATCH 3/4] fix(server): long Claude sessions import past the record limit Claude imports now keep a bounded message window, so the 100,000-record cap only rejects Codex and Pi transcripts. The byte budgets still bound Claude reads. AI-assisted; verified with the tests and tools listed above. --- apps/server/src/project/AgentSessionScanner.test.ts | 4 +++- apps/server/src/project/AgentSessionScanner.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 8edd8c0f38b4..39741b78c647 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1867,7 +1867,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); - it.effect("imports long Claude conversation history beyond the selected-history budget", () => + it.effect("imports long Claude history beyond the selected-history and record limits", () => Effect.gen(function* () { const path = yield* Path.Path; const nowMs = Date.parse("2026-08-24T12:00:00.000Z"); @@ -1892,6 +1892,8 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { const role = index % 2 === 0 ? "assistant" : "user"; return record({ type: role, message: { role, content: longText } }); }), + // Tool and progress records push the file past the 100,000-record limit. + ...Array.from({ length: 100_000 }, () => "{}"), record({ type: "user", message: { role: "user", content: "Latest prompt" } }), ].join("\n"), mtimeMs: nowMs - 60_000, diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 832ce159c1d3..7261d9209e4a 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -1089,7 +1089,8 @@ export const make = Effect.gen(function* () { const finishRecord = () => { reader.write(decoder.decode()); recordCount += 1; - if (recordCount > MAX_IMPORT_RECORDS) return false; + // Claude keeps a bounded window, so only the byte budgets limit its length. + if (recordCount > MAX_IMPORT_RECORDS && source !== "claudeAgent") return false; const value = reader.finish(); const decoded = decodeTranscriptValue(value); if (Option.isNone(decoded) && source === "pi") { From aa634aafc78d98330e82934b496580294ec298e8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:09:19 +0000 Subject: [PATCH 4/4] test(server): long Claude import test exceeds the history budget AI-assisted; verified with the tests and tools listed above. --- apps/server/src/project/AgentSessionScanner.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 39741b78c647..30fec7c48228 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1878,7 +1878,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { const record = (fields: Record) => encodeTranscriptRecord({ sessionId: "claude-long", ...fields }); const longText = "x".repeat(64 * 1024); - const middleCount = 400; + const middleCount = 600; yield* writeTranscript({ filePath: path.join(claudeHomePath, "projects", "-slug", "claude-long.jsonl"), contents: [ @@ -1887,7 +1887,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { cwd: workspace, message: { role: "user", content: "First prompt" }, }), - // The whole history exceeds the real 32 MiB selected-history budget; the shown window fits. + // 600 x 64 KiB exceeds the 32 MiB selected-history budget; the shown window fits. ...Array.from({ length: middleCount }, (_, index) => { const role = index % 2 === 0 ? "assistant" : "user"; return record({ type: role, message: { role, content: longText } });