@devries-cameron20 / t3code Mirror · read-only / commits / 14a60e85e5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 12:15 UTC

fix(server): session import no longer counts unused sessions as failures (#32122)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Matheus Marques committed Nov 15, 2026 at 01:34 UTC 14a60e85e52121eebc542fe02393d6a4f0fbf422
3 files changed +155 -4
apps/server/src/project/AgentSessionScanner.test.ts
+138
@@ -2024,6 +2024,144 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
2024 }),
2025 );
2026
2027 + it.effect("ignores sessions without visible messages without spending the import budget", () =>
2028 + Effect.gen(function* () {
2029 + const path = yield* Path.Path;
2030 + const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
2031 + yield* TestClock.setTime(nowMs);
2032 + const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
2033 + const codexHomePath = yield* makeTempDir("t3code-codex-home-");
2034 + const workspace = yield* makeTempDir("t3code-workspace-");
2035 + const codexRollout = (name: string) =>
2036 + path.join(codexHomePath, "sessions", "2026", "08", "24", `rollout-${name}.jsonl`);
2037 + // Newer empty sessions would exhaust the 100-transcript import budget before any real one.
2038 + const emptySessions = Array.from({ length: 100 }, (_, index) =>
2039 + index % 2 === 0
2040 + ? {
2041 + filePath: codexRollout(`empty-${index}`),
2042 + records: [
2043 + {
2044 + type: "session_meta",
2045 + payload: { id: `codex-empty-${index}`, cwd: workspace, source: "vscode" },
2046 + },
2047 + {
2048 + type: "event_msg",
2049 + payload: {
2050 + type: "thread_settings_applied",
2051 + thread_settings: { cwd: workspace },
2052 + },
2053 + },
2054 + ],
2055 + }
2056 + : {
2057 + filePath: path.join(
2058 + claudeHomePath,
2059 + "projects",
2060 + "-slug",
2061 + `claude-empty-${index}.jsonl`,
2062 + ),
2063 + records: [
2064 + { type: "system", subtype: "informational", content: "Status", cwd: workspace },
2065 + {
2066 + type: "user",
2067 + isMeta: true,
2068 + message: {
2069 + role: "user",
2070 + content: "<local-command-caveat>Caveat</local-command-caveat>",
2071 + },
2072 + cwd: workspace,
2073 + },
2074 + ],
2075 + },
2076 + );
2077 + const transcripts = [
2078 + ...emptySessions,
2079 + {
2080 + // Without session_meta there is no resumable session ID.
2081 + filePath: codexRollout("unusable"),
2082 + records: [
2083 + { type: "turn_context", payload: { cwd: workspace } },
2084 + {
2085 + type: "event_msg",
2086 + payload: { type: "user_message", message: "Import this prompt" },
2087 + },
2088 + ],
2089 + },
2090 + {
2091 + filePath: codexRollout("real"),
2092 + records: [
2093 + { type: "session_meta", payload: { id: "real-session", cwd: workspace } },
2094 + {
2095 + type: "event_msg",
2096 + payload: { type: "user_message", message: "Import this prompt" },
2097 + },
2098 + ],
2099 + },
2100 + ];
2101 + for (const [index, { filePath, records }] of transcripts.entries()) {
2102 + yield* writeTranscript({
2103 + filePath,
2104 + contents: records.map((record) => encodeTranscriptRecord(record)).join("\n"),
2105 + mtimeMs: nowMs - index * 60_000,
2106 + });
2107 + }
2108 +
2109 + const outcomes = yield* runRecentThreadOutcomes({
2110 + claudeHomePath,
2111 + codexHomePath,
2112 + workspaceRoot: workspace,
2113 + });
2114 +
2115 + expect(
2116 + outcomes.map((outcome) =>
2117 + outcome._tag === "Importable" ? outcome.thread.providerSessionId : outcome._tag,
2118 + ),
2119 + ).toEqual(["Skipped", "real-session"]);
2120 + }),
2121 + );
2122 +
2123 + it.effect("skips a rewound Codex rollout whose inherited history is unavailable", () =>
2124 + Effect.gen(function* () {
2125 + const path = yield* Path.Path;
2126 + const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
2127 + yield* TestClock.setTime(nowMs);
2128 + const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
2129 + const codexHomePath = yield* makeTempDir("t3code-codex-home-");
2130 + const workspace = yield* makeTempDir("t3code-workspace-");
2131 + const threadId = "019a0000-0000-7000-8000-000000000001";
2132 + const rolloutId = "019a0000-0000-7000-8000-000000000002";
2133 + // The ancestor rollout is missing, and this rollout added no messages of its own.
2134 + yield* writeTranscript({
2135 + filePath: path.join(
2136 + codexHomePath,
2137 + "sessions",
2138 + "2026",
2139 + "08",
2140 + "24",
2141 + `rollout-2026-08-24T11-00-00-${threadId}_${rolloutId}.jsonl`,
2142 + ),
2143 + contents: encodeTranscriptRecord({
2144 + type: "session_meta",
2145 + payload: {
2146 + id: threadId,
2147 + cwd: workspace,
2148 + history_mode: "paginated",
2149 + history_base: { thread_id: threadId, end_ordinal_exclusive: 3, end_byte_offset: 512 },
2150 + },
2151 + }),
2152 + mtimeMs: nowMs,
2153 + });
2154 +
2155 + const outcomes = yield* runRecentThreadOutcomes({
2156 + claudeHomePath,
2157 + codexHomePath,
2158 + workspaceRoot: workspace,
2159 + });
2160 +
2161 + expect(outcomes).toEqual([{ _tag: "Skipped" }]);
2162 + }),
2163 + );
2164 +
2165 it.effect("skips excessive records without blocking an older valid transcript", () =>
2166 Effect.gen(function* () {
2167 const path = yield* Path.Path;
apps/server/src/project/AgentSessionScanner.ts
+13 -2
@@ -447,7 +447,8 @@ export function parseAgentSessionTranscript(
447 input.source === "claudeAgent"
448 ? records.reduce(foldClaudeFields, emptyClaudeFields)
449 : emptyClaudeFields;
450 - return parseAgentSessionRecords(input, records, claudeFields, 0);
450 + const thread = parseAgentSessionRecords(input, records, claudeFields, 0);
451 + return thread === "empty" ? null : thread;
452 }
453
454 function parseAgentSessionRecords(
@@ -455,7 +456,7 @@ function parseAgentSessionRecords(
456 records: ReadonlyArray<DecodedTranscriptRecord>,
457 claudeFields: ClaudeFields,
458 droppedMessageCount: number,
458 -): AgentSessionThread | null {
459 +): AgentSessionThread | "empty" | null {
460 const fallbackTimestamp = DateTime.formatIso(DateTime.makeUnsafe(input.lastActiveAtMs));
461 // Claude filenames are session IDs. Codex rollout filenames include extra
462 // timestamp text, so only transcript metadata can provide a resumable ID.
@@ -648,6 +649,7 @@ function parseAgentSessionRecords(
649 });
650 }
651
652 + if (messages.length === 0 && droppedMessageCount === 0) return "empty";
653 const visibleMessages = messages.map(
654 ({ codexResponseUser: _codexResponseUser, ...message }) => message,
655 );
@@ -2139,6 +2141,15 @@ export const make = Effect.gen(function* () {
2141 snapshot.claudeFields,
2142 snapshot.droppedMessageCount,
2143 );
2144 + if (parsedThread === "empty") {
2145 + // null means an unreadable history base, which may hold the conversation.
2146 + if (candidate.source === "codex" && inheritedRecords === null) {
2147 + return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
2148 + }
2149 + // Never recorded as imported, so charging them would starve real sessions every run.
2150 + transcriptsRemaining += 1;
2151 + return Option.none<AgentSessionRecentThread>();
2152 + }
2153 if (parsedThread === null) {
2154 return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
2155 }
docs/user/welcome-page.md
+4 -2
@@ -100,9 +100,11 @@ a time and skips files larger than 4 GiB. It also skips a conversation when the
100 message text and metadata it keeps need more than 32 MiB of memory. Tool output
101 does not count toward that limit. It skips a conversation with more than 100,000
102 records every time, so opening the page again does not import it. It ignores
103 -malformed records and skips unreadable or unparseable conversations.
103 +malformed records and conversations with no messages, such as a session opened
104 +in an editor but never used. It skips unreadable or unparseable conversations.
105
105 -Each import attempt reads up to 100 conversation files and 4 GiB per project. To
106 +Each import attempt reads up to 100 conversations and 4 GiB per project.
107 +Conversations with no messages count toward the 4 GiB but not the 100. To
108 continue a large batch, open the Welcome page again and pick the project in
109 **Review all**. Completed conversations are not imported again. You can continue
110 without the remaining history.