@devries-cameron20 / t3code Mirror · read-only / commits / db4221b74b
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, 09:45 UTC

fix(server): long sessions import when most transcript lines are bookkeeping (#31687)

Julius Marminge committed Nov 16, 2026 at 12:54 UTC db4221b74b33ba71e1c04570ff185d8078770ac7
2 files changed +34 -37
apps/server/src/project/AgentSessionScanner.test.ts
+33 -32
@@ -225,6 +225,24 @@ function makeRecordLimitTranscript(cwd: string, overflow: boolean): string {
225 : records;
226 }
227
228 +// Pi retains every entry, keeping tool results as links outside the history budget.
229 +function makePiToolResultTranscript(sessionId: string, cwd: string, recordCount: number): string {
230 + const entry = (id: number, message: { readonly role: string; readonly content: string }) =>
231 + encodeTranscriptRecord({
232 + type: "message",
233 + id: `e${id}`,
234 + parentId: id === 0 ? null : `e${id - 1}`,
235 + message,
236 + });
237 + return [
238 + encodeTranscriptRecord({ type: "session", version: 3, id: sessionId, cwd }),
239 + entry(0, { role: "user", content: "Imported prompt" }),
240 + ...Array.from({ length: recordCount - 2 }, (_, index) =>
241 + entry(index + 1, { role: "toolResult", content: "Tool output" }),
242 + ),
243 + ].join("\n");
244 +}
245 +
246 const makeFileIdentityFixture = Effect.fn("AgentSessionScanner.test.makeFileIdentityFixture")(
247 function* (originalInode = 10_000_000_000_000_001n, replacementInode = 10_000_000_000_000_000n) {
248 const path = yield* Path.Path;
@@ -2282,22 +2300,20 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
2300 const claudeHomePath = yield* makeTempDir("t3code-record-budget-claude-");
2301 const codexHomePath = yield* makeTempDir("t3code-record-budget-codex-");
2302 const workspace = yield* makeTempDir("t3code-record-budget-workspace-");
2285 - const exactLimit = makeRecordLimitTranscript(workspace, false);
2286 - // The newer transcript has 100,001 records; the older one has exactly 100,000.
2287 - for (const [sessionId, contents, mtimeMs] of [
2288 - ["excessive", exactLimit.replace("record-limit-session", "excessive") + "{}\n", nowMs],
2289 - ["older", exactLimit, nowMs - 1_000],
2303 + // The newer transcript retains 100,001 records; the older one exactly 100,000.
2304 + for (const [sessionId, recordCount, mtimeMs] of [
2305 + ["excessive", 100_001, nowMs],
2306 + ["older", 100_000, nowMs - 1_000],
2307 ] as const) {
2308 yield* writeTranscript({
2309 filePath: path.join(
2293 - codexHomePath,
2310 + claudeHomePath,
2311 + "pi-agent",
2312 "sessions",
2295 - "2026",
2296 - "08",
2297 - "24",
2298 - `rollout-${sessionId}.jsonl`,
2313 + "--workspace--",
2314 + `${sessionId}.jsonl`,
2315 ),
2300 - contents,
2316 + contents: makePiToolResultTranscript(sessionId, workspace, recordCount),
2317 mtimeMs,
2318 });
2319 }
@@ -2307,9 +2323,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
2323 workspaceRoot: workspace,
2324 });
2325 expect(outcomes.map((outcome) => outcome._tag)).toEqual(["Skipped", "Importable"]);
2310 - expect(outcomes[1]).toMatchObject({
2311 - thread: { providerSessionId: "record-limit-session" },
2312 - });
2326 + expect(outcomes[1]).toMatchObject({ thread: { providerSessionId: "older" } });
2327 }),
2328 );
2329
@@ -2326,26 +2340,13 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
2340 for (const [index, recordCount] of recordCounts.entries()) {
2341 yield* writeTranscript({
2342 filePath: path.join(
2329 - codexHomePath,
2343 + claudeHomePath,
2344 + "pi-agent",
2345 "sessions",
2331 - "2026",
2332 - "08",
2333 - "24",
2334 - `rollout-${index}.jsonl`,
2346 + "--workspace--",
2347 + `${index}.jsonl`,
2348 ),
2336 - contents:
2337 - [
2338 - encodeTranscriptRecord({
2339 - type: "session_meta",
2340 - payload: { id: `session-${index}`, cwd: workspace },
2341 - }),
2342 - encodeTranscriptRecord({
2343 - type: "event_msg",
2344 - payload: { type: "user_message", message: "Imported prompt" },
2345 - }),
2346 - ].join("\n") +
2347 - "\n" +
2348 - "{}\n".repeat(recordCount - 2),
2349 + contents: makePiToolResultTranscript(`session-${index}`, workspace, recordCount),
2350 mtimeMs: nowMs - index * 1_000,
2351 });
2352 }
apps/server/src/project/AgentSessionScanner.ts
+1 -5
@@ -1242,7 +1242,6 @@ export const make = Effect.gen(function* () {
1242 let claudeFields = emptyClaudeFields;
1243 let historyBytes = prefix?.historyBytes ?? 0;
1244 let recordBytes = 0;
1245 - let recordCount = 0;
1245 let bytesRead = 0;
1246 const reserve = (bytes: number) => {
1247 recordBytes += bytes;
@@ -1258,9 +1257,6 @@ export const make = Effect.gen(function* () {
1257
1258 const finishRecord = () => {
1259 reader.write(decoder.decode());
1261 - recordCount += 1;
1262 - // Claude keeps a bounded window, so only the byte budgets limit its length.
1263 - if (recordCount > MAX_IMPORT_RECORDS && source !== "claudeAgent") return false;
1260 const value = reader.finish();
1261 const decoded = decodeTranscriptValue(value);
1262 if (Option.isNone(decoded) && source === "pi") {
@@ -1292,7 +1288,7 @@ export const make = Effect.gen(function* () {
1288 reader = createTranscriptJsonReader(reserve, selectTranscriptPath);
1289 decoder = new TextDecoder();
1290 recordStarted = false;
1295 - return true;
1291 + return records.length <= MAX_IMPORT_RECORDS;
1292 };
1293
1294 while (bytesRead < readBytes) {