From fdbf0e7fe1babf52aff614d5c56af481be5c56a6 Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Thu, 29 Oct 2026 19:40:49 -0300 Subject: [PATCH 1/4] fix(server): session import no longer counts unused sessions as failures Codex rollouts that only hold session_meta and thread_settings_applied (sessions opened in an editor and never used), and Claude transcripts with only hidden or system records, have nothing to import. The parser returned the same null for them as for unusable transcripts, so recentThreads reported them as Skipped and the welcome wizard said "N threads could not be imported" on every run. They also spent a slot of the 100-transcript budget each time, so enough of them pushed real conversations out. The parser now reports "empty" when no visible message remains, and recentThreads drops those sessions and refunds their transcript slot. Transcripts with messages but no resumable session ID, or no user message, still count as skipped. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 96 +++++++++++++++++++ .../server/src/project/AgentSessionScanner.ts | 11 ++- docs/user/welcome-wizard.md | 5 +- 3 files changed, 108 insertions(+), 4 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index f9c7aaf3fd3d..3a556fe19d6c 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1535,6 +1535,102 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); + it.effect("ignores sessions without visible messages without spending the import 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-claude-home-"); + const codexHomePath = yield* makeTempDir("t3code-codex-home-"); + const workspace = yield* makeTempDir("t3code-workspace-"); + const codexRollout = (name: string) => + path.join(codexHomePath, "sessions", "2026", "08", "24", `rollout-${name}.jsonl`); + // Newer empty sessions would exhaust the 100-transcript import budget before any real one. + const emptySessions = Array.from({ length: 100 }, (_, index) => + index % 2 === 0 + ? { + filePath: codexRollout(`empty-${index}`), + records: [ + { + type: "session_meta", + payload: { id: `codex-empty-${index}`, cwd: workspace, source: "vscode" }, + }, + { + type: "event_msg", + payload: { + type: "thread_settings_applied", + thread_settings: { cwd: workspace }, + }, + }, + ], + } + : { + filePath: path.join( + claudeHomePath, + "projects", + "-slug", + `claude-empty-${index}.jsonl`, + ), + records: [ + { type: "system", subtype: "informational", content: "Status", cwd: workspace }, + { + type: "user", + isMeta: true, + message: { + role: "user", + content: "Caveat", + }, + cwd: workspace, + }, + ], + }, + ); + const transcripts = [ + ...emptySessions, + { + // Without session_meta there is no resumable session ID. + filePath: codexRollout("unusable"), + records: [ + { type: "turn_context", payload: { cwd: workspace } }, + { + type: "event_msg", + payload: { type: "user_message", message: "Import this prompt" }, + }, + ], + }, + { + filePath: codexRollout("real"), + records: [ + { type: "session_meta", payload: { id: "real-session", cwd: workspace } }, + { + type: "event_msg", + payload: { type: "user_message", message: "Import this prompt" }, + }, + ], + }, + ]; + for (const [index, { filePath, records }] of transcripts.entries()) { + yield* writeTranscript({ + filePath, + contents: records.map((record) => encodeTranscriptRecord(record)).join("\n"), + mtimeMs: nowMs - index * 60_000, + }); + } + + const outcomes = yield* runRecentThreadOutcomes({ + claudeHomePath, + codexHomePath, + workspaceRoot: workspace, + }); + + expect( + outcomes.map((outcome) => + outcome._tag === "Importable" ? outcome.thread.providerSessionId : outcome._tag, + ), + ).toEqual(["Skipped", "real-session"]); + }), + ); + it.effect("skips excessive records without blocking an older valid transcript", () => 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 dc67bd9387e0..b386c57d6204 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -416,14 +416,15 @@ export function parseAgentSessionTranscript( input.source === "claudeAgent" ? records.reduce(foldClaudeFields, emptyClaudeFields) : emptyClaudeFields; - return parseAgentSessionRecords(input, records, claudeFields); + const thread = parseAgentSessionRecords(input, records, claudeFields); + return thread === "empty" ? null : thread; } function parseAgentSessionRecords( input: AgentSessionTranscriptMetadata, records: ReadonlyArray, claudeFields: ClaudeFields, -): AgentSessionThread | null { +): AgentSessionThread | "empty" | null { const fallbackTimestamp = DateTime.formatIso(DateTime.makeUnsafe(input.lastActiveAtMs)); // Claude filenames are session IDs. Codex rollout filenames include extra // timestamp text, so only transcript metadata can provide a resumable ID. @@ -616,6 +617,7 @@ function parseAgentSessionRecords( }); } + if (messages.length === 0) return "empty"; const visibleMessages = messages.map( ({ codexResponseUser: _codexResponseUser, ...message }) => message, ); @@ -1832,6 +1834,11 @@ export const make = Effect.gen(function* () { : [...inheritedRecords, ...snapshot.records], snapshot.claudeFields, ); + if (parsedThread === "empty") { + // Never recorded as imported, so charging them would starve real sessions every run. + transcriptsRemaining += 1; + return Option.none(); + } if (parsedThread === null) { return Option.some({ _tag: "Skipped" }); } diff --git a/docs/user/welcome-wizard.md b/docs/user/welcome-wizard.md index 2d4b589d922f..6f492fe27489 100644 --- a/docs/user/welcome-wizard.md +++ b/docs/user/welcome-wizard.md @@ -89,10 +89,11 @@ same user turn. Ambiguous legacy or response-only context stays in the imported conversation so T3 Code does not remove user text. It reads one conversation at a time and skips files larger than 4 GiB. It also skips a conversation when the message text and metadata it keeps need more than 32 MiB of memory. Tool output -does not count toward that limit. It ignores malformed records and skips +does not count toward that limit. It ignores malformed records and conversations +with no messages, such as a session opened in an editor but never used. It skips unreadable or unparseable conversations. -Each import attempt reads up to 100 conversation files and 4 GiB per project, +Each import attempt reads up to 100 conversations and 4 GiB per project, with up to 100,000 input records. Run import again to continue a large batch. Completed conversations are not imported again. You can continue without the remaining history. From e94e99f94e8698210221484fe101c4b9ed364b66 Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Fri, 6 Nov 2026 15:43:36 -0300 Subject: [PATCH 2/4] fix(server): rewound Codex rollouts with unreadable history stay skipped A rewound Codex rollout can add no messages of its own and rely on the history it inherits from an earlier rollout. When that history could not be read, the rollout looked empty and was dropped silently. Report it as skipped again, as on main; ordinary unused rollouts have no history base and are still ignored. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 42 +++++++++++++++++++ .../server/src/project/AgentSessionScanner.ts | 4 ++ 2 files changed, 46 insertions(+) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 3a556fe19d6c..76864d8840db 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1631,6 +1631,48 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); + it.effect("skips a rewound Codex rollout whose inherited history is unavailable", () => + 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-claude-home-"); + const codexHomePath = yield* makeTempDir("t3code-codex-home-"); + const workspace = yield* makeTempDir("t3code-workspace-"); + const threadId = "019a0000-0000-7000-8000-000000000001"; + const rolloutId = "019a0000-0000-7000-8000-000000000002"; + // The ancestor rollout is missing, and this rollout added no messages of its own. + yield* writeTranscript({ + filePath: path.join( + codexHomePath, + "sessions", + "2026", + "08", + "24", + `rollout-2026-08-24T11-00-00-${threadId}_${rolloutId}.jsonl`, + ), + contents: encodeTranscriptRecord({ + type: "session_meta", + payload: { + id: threadId, + cwd: workspace, + history_mode: "paginated", + history_base: { thread_id: threadId, end_ordinal_exclusive: 3, end_byte_offset: 512 }, + }, + }), + mtimeMs: nowMs, + }); + + const outcomes = yield* runRecentThreadOutcomes({ + claudeHomePath, + codexHomePath, + workspaceRoot: workspace, + }); + + expect(outcomes).toEqual([{ _tag: "Skipped" }]); + }), + ); + it.effect("skips excessive records without blocking an older valid transcript", () => 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 b386c57d6204..60a8f2f9057c 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -1835,6 +1835,10 @@ export const make = Effect.gen(function* () { snapshot.claudeFields, ); if (parsedThread === "empty") { + // null means an unreadable history base, which may hold the conversation. + if (candidate.source === "codex" && inheritedRecords === null) { + return Option.some({ _tag: "Skipped" }); + } // Never recorded as imported, so charging them would starve real sessions every run. transcriptsRemaining += 1; return Option.none(); From 4354cad0fd28c602716ada962dacf309b0009a9f Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Tue, 10 Nov 2026 16:04:58 -0300 Subject: [PATCH 3/4] docs: empty conversations do not count toward the 100-conversation import limit --- docs/user/welcome-page.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/user/welcome-page.md b/docs/user/welcome-page.md index 367eb540a771..d4093b10cb5f 100644 --- a/docs/user/welcome-page.md +++ b/docs/user/welcome-page.md @@ -102,7 +102,8 @@ records every time, so opening the page again does not import it. It ignores malformed records and conversations with no messages, such as a session opened in an editor but never used. It skips unreadable or unparseable conversations. -Each import attempt reads up to 100 conversations and 4 GiB per project. To +Each import attempt reads up to 100 conversations and 4 GiB per project. +Conversations with no messages count toward the 4 GiB but not the 100. To continue a large batch, open the Welcome page again and pick the project in **Review all**. Completed conversations are not imported again. You can continue without the remaining history. From 0b82c4b6ee72e56302ef3a4963772bd408c34c97 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 04:03:35 +0000 Subject: [PATCH 4/4] fix(server): sessions with dropped history are not treated as empty Co-Authored-By: Claude Opus 5.5 --- apps/server/src/project/AgentSessionScanner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index a1758586c1f3..7a89f9c687de 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -649,7 +649,7 @@ function parseAgentSessionRecords( }); } - if (messages.length === 0) return "empty"; + if (messages.length === 0 && droppedMessageCount === 0) return "empty"; const visibleMessages = messages.map( ({ codexResponseUser: _codexResponseUser, ...message }) => message, );