Skip to content

Commit 3e1e776

Browse files
fix(server): import valid conversations within each transcript record limit (pingdotgg#23192)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 53e168f commit 3e1e776

2 files changed

Lines changed: 55 additions & 24 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,11 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
14501450
const claudeHomePath = yield* makeTempDir("t3code-record-budget-claude-");
14511451
const codexHomePath = yield* makeTempDir("t3code-record-budget-codex-");
14521452
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],
14561458
] as const) {
14571459
yield* writeTranscript({
14581460
filePath: path.join(
@@ -1463,27 +1465,68 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
14631465
"24",
14641466
`rollout-${sessionId}.jsonl`,
14651467
),
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+
),
14661504
contents:
14671505
[
14681506
encodeTranscriptRecord({
14691507
type: "session_meta",
1470-
payload: { id: sessionId, cwd: workspace },
1508+
payload: { id: `session-${index}`, cwd: workspace },
14711509
}),
14721510
encodeTranscriptRecord({
14731511
type: "event_msg",
14741512
payload: { type: "user_message", message: "Imported prompt" },
14751513
}),
1476-
].join("\n") + padding,
1477-
mtimeMs,
1514+
].join("\n") +
1515+
"\n" +
1516+
"{}\n".repeat(recordCount - 2),
1517+
mtimeMs: nowMs - index * 1_000,
14781518
});
14791519
}
14801520
const outcomes = yield* runRecentThreadOutcomes({
14811521
claudeHomePath,
14821522
codexHomePath,
14831523
workspaceRoot: workspace,
14841524
});
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"]);
14871530
}),
14881531
);
14891532

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,6 @@ export const make = Effect.gen(function* () {
996996
const readTranscript = Effect.fn("AgentSessionScanner.readTranscript")(function* (
997997
filePath: string,
998998
expected: ReturnType<typeof transcriptIdentity>,
999-
recordLimit: number,
1000999
source: AgentSessionSource,
10011000
) {
10021001
if (expected.size > MAX_IMPORTED_TRANSCRIPT_BYTES) return null;
@@ -1030,7 +1029,7 @@ export const make = Effect.gen(function* () {
10301029
const finishRecord = () => {
10311030
reader.write(decoder.decode());
10321031
recordCount += 1;
1033-
if (recordCount > recordLimit) return false;
1032+
if (recordCount > MAX_IMPORT_RECORDS) return false;
10341033
const value = reader.finish();
10351034
const decoded = decodeTranscriptValue(value);
10361035
if (Option.isNone(decoded) && source === "pi") {
@@ -1090,7 +1089,7 @@ export const make = Effect.gen(function* () {
10901089

10911090
if (recordStarted && !(yield* Effect.try(finishRecord))) return null;
10921091
return sameTranscriptIdentity(expected, transcriptIdentity(filePath, yield* file.stat))
1093-
? { records, recordCount, cwd, claudeFields }
1092+
? { records, cwd, claudeFields }
10941093
: null;
10951094
}),
10961095
),
@@ -1668,17 +1667,13 @@ export const make = Effect.gen(function* () {
16681667
const codexThreadNamesByHome = new Map<string, ReadonlyMap<string, string>>();
16691668
let bytesRemaining = MAX_IMPORT_BYTES;
16701669
let transcriptsRemaining = MAX_IMPORT_TRANSCRIPTS;
1671-
let recordsRemaining = MAX_IMPORT_RECORDS;
16721670
return Stream.fromIteratorSucceed(eligibleTranscripts.values(), 1).pipe(
16731671
Stream.mapEffect(({ candidate, transcript }) =>
16741672
Effect.gen(function* () {
16751673
const completed = completedByFile.get(
16761674
`${candidate.providerInstanceId}\0${transcript.filePath}`,
16771675
);
1678-
if (
1679-
completed === undefined &&
1680-
(transcriptsRemaining === 0 || bytesRemaining === 0 || recordsRemaining === 0)
1681-
) {
1676+
if (completed === undefined && (transcriptsRemaining === 0 || bytesRemaining === 0)) {
16821677
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
16831678
}
16841679
const stats = yield* statOption(transcript.filePath);
@@ -1701,24 +1696,17 @@ export const make = Effect.gen(function* () {
17011696
}
17021697
if (
17031698
transcriptsRemaining === 0 ||
1704-
recordsRemaining === 0 ||
17051699
identity.size > MAX_IMPORTED_TRANSCRIPT_BYTES ||
17061700
identity.size > bytesRemaining
17071701
) {
17081702
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
17091703
}
17101704
transcriptsRemaining -= 1;
17111705
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);
17181707
if (snapshot === null) {
17191708
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
17201709
}
1721-
recordsRemaining -= snapshot.recordCount;
17221710

17231711
if (Option.isNone(snapshot.cwd)) {
17241712
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });

0 commit comments

Comments
 (0)