@devries-cameron20 / t3code-1 / commits / 91fa913be9
Fork 0

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

fix(server): partial import retries no longer certify missing messages (#36604)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 10:36 UTC 91fa913be9c280dcf9da6ad655aa6bac7c8ce74a
3 files changed +45 -14
apps/server/src/project/AgentSessionImporter.test.ts
+33
@@ -453,6 +453,39 @@ it.effect(
453 }).pipe(Effect.scoped, Effect.provide(persistence)),
454 );
455
456 +it.effect("does not certify new native history after a partial import retry", () =>
457 + Effect.gen(function* () {
458 + const sql = yield* SqlClient.SqlClient;
459 + const projections = yield* ProjectionStore.ProjectionStoreV2;
460 + const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
461 + const original = candidate(CODEX_MODEL_SELECTION, "partial-retry");
462 + const threadId = importId(original);
463 + const importer = yield* makeImporter([original]);
464 + yield* sql`CREATE TEMP TRIGGER fail_runtime BEFORE INSERT ON provider_session_runtime BEGIN SELECT RAISE(ABORT, 'test runtime failure'); END`;
465 + expect(yield* importer.run).toEqual({ importedCount: 0, skippedCount: 1 });
466 + yield* sql`DROP TRIGGER fail_runtime`;
467 + expect(yield* runtimes.list()).toEqual([]);
468 + const continued = candidate(CODEX_MODEL_SELECTION, original.source.providerSessionId);
469 + continued.source.size = 200;
470 + continued.source.mtimeMs = 3;
471 + continued.thread.messages.push(
472 + { role: "user", text: "Continue outside T3", createdAt: timestamp },
473 + { role: "assistant", text: "Native continuation", createdAt: timestamp },
474 + );
475 + // The thread holds only the original messages, so the continued transcript stays unrecorded.
476 + expect(yield* (yield* makeImporter([continued])).run).toEqual({
477 + importedCount: 0,
478 + skippedCount: 1,
479 + });
480 + expect(yield* runtimes.list()).toEqual([]);
481 + expect(
482 + (yield* projections.getThreadRecords(threadId, ["messages"])).messages.map(
483 + (message) => message.text,
484 + ),
485 + ).toEqual(["Fix it", "Fixed"]);
486 + }).pipe(Effect.scoped, Effect.provide(persistence)),
487 +);
488 +
489 it.effect("does not record a changed transcript as imported without its new messages", () =>
490 Effect.gen(function* () {
491 const projections = yield* ProjectionStore.ProjectionStoreV2;
apps/server/src/project/AgentSessionImporter.ts
+11 -10
@@ -313,7 +313,9 @@ const make = Effect.gen(function* () {
313 },
314 { onConflict: "ignore" },
315 );
316 - const existing = yield* Effect.option(orchestrator.getThreadRecords(threadId, []));
316 + const existing = yield* Effect.option(
317 + orchestrator.getThreadRecords(threadId, ["messages"]),
318 + );
319 if (Option.isSome(existing)) {
320 if (existing.value.thread.projectId !== input.projectId) {
321 return yield* new AgentSessionThreadProjectConflictError({
@@ -325,16 +327,15 @@ const make = Effect.gen(function* () {
327 if (existing.value.thread.historyOrigin !== "v1_import") {
328 return yield* new AgentSessionThreadModifiedError({ threadId });
329 }
328 - // Other recorded transcripts mean this one changed after the import, and the
329 - // thread does not hold its new messages, so it must stay unrecorded.
330 - const recorded = Option.flatMap(yield* runtimes.getByThreadId({ threadId }), (row) =>
331 - AgentSessionScanner.decodeImportedTranscriptPayload(row.runtimePayload),
332 - ).pipe(Option.flatMapNullishOr((payload) => payload.importedTranscripts));
330 + // A transcript can change after the import, so record it only when the
331 + // thread already holds exactly its messages.
332 + const stored = existing.value.messages;
333 if (
334 - Option.isSome(recorded) &&
335 - recorded.value.length > 0 &&
336 - !recorded.value.some((imported) =>
337 - AgentSessionScanner.sameTranscriptIdentity(imported, source),
334 + stored.length !== thread.messages.length ||
335 + stored.some(
336 + (message, index) =>
337 + message.role !== thread.messages[index]?.role ||
338 + message.text !== thread.messages[index]?.text,
339 )
340 ) {
341 return false;
apps/server/src/project/AgentSessionScanner.ts
+1 -4
@@ -802,10 +802,7 @@ type TranscriptIdentity = Pick<
802
803 const fileIdKey = (inode: TranscriptIdentity["inode"]) => (inode === null ? null : String(inode));
804
805 -export function sameTranscriptIdentity(
806 - left: TranscriptIdentity,
807 - right: TranscriptIdentity,
808 -): boolean {
805 +function sameTranscriptIdentity(left: TranscriptIdentity, right: TranscriptIdentity): boolean {
806 // Unsafe legacy numbers may already have lost file ID precision.
807 if (
808 (typeof left.inode === "number" && !Number.isSafeInteger(left.inode)) ||