The best way to control Claude Code, Codex and more from any computer or phone
fix(server): import valid conversations within each transcript record limit (#23192)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 2, 2026 at 19:05 UTC
3e1e776af3f69f95ef180535c128a0c5127ab2c3
2 files changed
+55
-24
apps/server/src/project/AgentSessionScanner.test.ts
+51
-8
@@ -1450,9 +1450,11 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1450
const claudeHomePath = yield* makeTempDir("t3code-record-budget-claude-");
1451
const codexHomePath = yield* makeTempDir("t3code-record-budget-codex-");
1452
const workspace = yield* makeTempDir("t3code-record-budget-workspace-");
1453
- for (const [sessionId, padding, mtimeMs] of [
1454
- ["excessive", "\n".repeat(100_001), nowMs],
1455
- ["older", "", nowMs - 1_000],
1453
+ const exactLimit = makeRecordLimitTranscript(workspace, false);
1454
+ // The newer transcript has 100,001 records; the older one has exactly 100,000.
1455
+ for (const [sessionId, contents, mtimeMs] of [
1456
+ ["excessive", exactLimit.replace("record-limit-session", "excessive") + "{}\n", nowMs],
1457
+ ["older", exactLimit, nowMs - 1_000],
1458
] as const) {
1459
yield* writeTranscript({
1460
filePath: path.join(
@@ -1463,18 +1465,56 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1465
"24",
1466
`rollout-${sessionId}.jsonl`,
1467
),
1468
+ contents,
1469
+ mtimeMs,
1470
+ });
1471
+ }
1472
+ const outcomes = yield* runRecentThreadOutcomes({
1473
+ claudeHomePath,
1474
+ codexHomePath,
1475
+ workspaceRoot: workspace,
1476
+ });
1477
+ expect(outcomes.map((outcome) => outcome._tag)).toEqual(["Skipped", "Importable"]);
1478
+ expect(outcomes[1]).toMatchObject({
1479
+ thread: { providerSessionId: "record-limit-session" },
1480
+ });
1481
+ }),
1482
+ );
1483
+
1484
+ it.effect("imports every transcript that fits the per-file record limit", () =>
1485
+ Effect.gen(function* () {
1486
+ const path = yield* Path.Path;
1487
+ const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1488
+ yield* TestClock.setTime(nowMs);
1489
+ const claudeHomePath = yield* makeTempDir("t3code-shared-records-claude-");
1490
+ const codexHomePath = yield* makeTempDir("t3code-shared-records-codex-");
1491
+ const workspace = yield* makeTempDir("t3code-shared-records-workspace-");
1492
+ // Together these exceed 100,000 records, but each one is individually valid.
1493
+ const recordCounts = [20_000, 20_000, 20_000, 58_000];
1494
+ for (const [index, recordCount] of recordCounts.entries()) {
1495
+ yield* writeTranscript({
1496
+ filePath: path.join(
1497
+ codexHomePath,
1498
+ "sessions",
1499
+ "2026",
1500
+ "08",
1501
+ "24",
1502
+ `rollout-${index}.jsonl`,
1503
+ ),
1504
contents:
1505
[
1506
encodeTranscriptRecord({
1507
type: "session_meta",
1470
- payload: { id: sessionId, cwd: workspace },
1508
+ payload: { id: `session-${index}`, cwd: workspace },
1509
}),
1510
encodeTranscriptRecord({
1511
type: "event_msg",
1512
payload: { type: "user_message", message: "Imported prompt" },
1513
}),
1476
- ].join("\n") + padding,
1477
- mtimeMs,
1514
+ ].join("\n") +
1515
+ "\n" +
1516
+ "{}\n".repeat(recordCount - 2),
1517
+ mtimeMs: nowMs - index * 1_000,
1518
});
1519
}
1520
const outcomes = yield* runRecentThreadOutcomes({
@@ -1482,8 +1522,11 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1522
codexHomePath,
1523
workspaceRoot: workspace,
1524
});
1485
- expect(outcomes.map((outcome) => outcome._tag)).toEqual(["Skipped", "Importable"]);
1486
- expect(outcomes[1]).toMatchObject({ thread: { providerSessionId: "older" } });
1525
+ expect(
1526
+ outcomes.map((outcome) =>
1527
+ outcome._tag === "Importable" ? outcome.thread.providerSessionId : outcome._tag,
1528
+ ),
1529
+ ).toEqual(["session-0", "session-1", "session-2", "session-3"]);
1530
}),
1531
);
1532
apps/server/src/project/AgentSessionScanner.ts
+4
-16
@@ -996,7 +996,6 @@ export const make = Effect.gen(function* () {
996
const readTranscript = Effect.fn("AgentSessionScanner.readTranscript")(function* (
997
filePath: string,
998
expected: ReturnType<typeof transcriptIdentity>,
999
- recordLimit: number,
999
source: AgentSessionSource,
1000
) {
1001
if (expected.size > MAX_IMPORTED_TRANSCRIPT_BYTES) return null;
@@ -1030,7 +1029,7 @@ export const make = Effect.gen(function* () {
1029
const finishRecord = () => {
1030
reader.write(decoder.decode());
1031
recordCount += 1;
1033
- if (recordCount > recordLimit) return false;
1032
+ if (recordCount > MAX_IMPORT_RECORDS) return false;
1033
const value = reader.finish();
1034
const decoded = decodeTranscriptValue(value);
1035
if (Option.isNone(decoded) && source === "pi") {
@@ -1090,7 +1089,7 @@ export const make = Effect.gen(function* () {
1089
1090
if (recordStarted && !(yield* Effect.try(finishRecord))) return null;
1091
return sameTranscriptIdentity(expected, transcriptIdentity(filePath, yield* file.stat))
1093
- ? { records, recordCount, cwd, claudeFields }
1092
+ ? { records, cwd, claudeFields }
1093
: null;
1094
}),
1095
),
@@ -1668,17 +1667,13 @@ export const make = Effect.gen(function* () {
1667
const codexThreadNamesByHome = new Map<string, ReadonlyMap<string, string>>();
1668
let bytesRemaining = MAX_IMPORT_BYTES;
1669
let transcriptsRemaining = MAX_IMPORT_TRANSCRIPTS;
1671
- let recordsRemaining = MAX_IMPORT_RECORDS;
1670
return Stream.fromIteratorSucceed(eligibleTranscripts.values(), 1).pipe(
1671
Stream.mapEffect(({ candidate, transcript }) =>
1672
Effect.gen(function* () {
1673
const completed = completedByFile.get(
1674
`${candidate.providerInstanceId}\0${transcript.filePath}`,
1675
);
1678
- if (
1679
- completed === undefined &&
1680
- (transcriptsRemaining === 0 || bytesRemaining === 0 || recordsRemaining === 0)
1681
- ) {
1676
+ if (completed === undefined && (transcriptsRemaining === 0 || bytesRemaining === 0)) {
1677
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
1678
}
1679
const stats = yield* statOption(transcript.filePath);
@@ -1701,7 +1696,6 @@ export const make = Effect.gen(function* () {
1696
}
1697
if (
1698
transcriptsRemaining === 0 ||
1704
- recordsRemaining === 0 ||
1699
identity.size > MAX_IMPORTED_TRANSCRIPT_BYTES ||
1700
identity.size > bytesRemaining
1701
) {
@@ -1709,16 +1703,10 @@ export const make = Effect.gen(function* () {
1703
}
1704
transcriptsRemaining -= 1;
1705
bytesRemaining -= identity.size;
1712
- const snapshot = yield* readTranscript(
1713
- transcript.filePath,
1714
- identity,
1715
- recordsRemaining,
1716
- candidate.source,
1717
- );
1706
+ const snapshot = yield* readTranscript(transcript.filePath, identity, candidate.source);
1707
if (snapshot === null) {
1708
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
1709
}
1721
- recordsRemaining -= snapshot.recordCount;
1710
1711
if (Option.isNone(snapshot.cwd)) {
1712
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });