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, 21:00 UTC
fix(server): re-import no longer marks a continued transcript imported without its new messages (#34809)
Julius Marminge committed
Nov 11, 2026 at 23:20 UTC
7466707a83ee4f8c2e392c6b63e79a412299c4d1
3 files changed
+59
-1
apps/server/src/project/AgentSessionImporter.test.ts
+41
@@ -446,6 +446,47 @@ it.effect(
446
}).pipe(Effect.scoped, Effect.provide(persistence)),
447
);
448
449
+it.effect("does not record a changed transcript as imported without its new messages", () =>
450
+ Effect.gen(function* () {
451
+ const projections = yield* ProjectionStore.ProjectionStoreV2;
452
+ const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
453
+ const first = candidate(
454
+ CLAUDE_MODEL_SELECTION,
455
+ "6f1c2a7e-3b4d-4e5f-9a8b-1c2d3e4f5a6b",
456
+ "claudeAgent",
457
+ );
458
+ const threadId = importId(first);
459
+ expect(yield* (yield* makeImporter([first])).run).toEqual({
460
+ importedCount: 1,
461
+ skippedCount: 0,
462
+ });
463
+
464
+ const continued = candidate(
465
+ CLAUDE_MODEL_SELECTION,
466
+ first.source.providerSessionId,
467
+ "claudeAgent",
468
+ );
469
+ continued.source.size = 200;
470
+ continued.source.mtimeMs = 3;
471
+ continued.thread.messages.push(
472
+ { role: "user", text: "Continue", createdAt: timestamp },
473
+ { role: "assistant", text: "Continued", createdAt: timestamp },
474
+ );
475
+ yield* (yield* makeImporter([continued])).run;
476
+
477
+ const recorded = AgentSessionScanner.decodeImportedTranscriptPayload(
478
+ Option.getOrThrow(yield* runtimes.getByThreadId({ threadId })).runtimePayload,
479
+ ).pipe(Option.getOrThrow).importedTranscripts;
480
+ const texts = (yield* projections.getThreadRecords(threadId, ["messages"])).messages.map(
481
+ (message) => message.text,
482
+ );
483
+ expect({
484
+ recordsChangedTranscript: recorded?.some((source) => source.size === 200) ?? false,
485
+ showsNewMessages: texts.includes("Continued"),
486
+ }).not.toEqual({ recordsChangedTranscript: true, showsNewMessages: false });
487
+ }).pipe(Effect.scoped, Effect.provide(persistence)),
488
+);
489
+
490
it.effect(
491
"copies native session history into the imported thread once, retrying a failed read",
492
() =>
apps/server/src/project/AgentSessionImporter.ts
+14
@@ -325,6 +325,20 @@ const make = Effect.gen(function* () {
325
if (existing.value.thread.historyOrigin !== "v1_import") {
326
return yield* new AgentSessionThreadModifiedError({ threadId });
327
}
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));
333
+ if (
334
+ Option.isSome(recorded) &&
335
+ recorded.value.length > 0 &&
336
+ !recorded.value.some((imported) =>
337
+ AgentSessionScanner.sameTranscriptIdentity(imported, source),
338
+ )
339
+ ) {
340
+ return false;
341
+ }
342
yield* persistRuntime;
343
yield* runtimes.recordImportedTranscript({ threadId, source });
344
return true;
apps/server/src/project/AgentSessionScanner.ts
+4
-1
@@ -793,7 +793,10 @@ type TranscriptIdentity = Pick<
793
794
const fileIdKey = (inode: TranscriptIdentity["inode"]) => (inode === null ? null : String(inode));
795
796
-function sameTranscriptIdentity(left: TranscriptIdentity, right: TranscriptIdentity): boolean {
796
+export function sameTranscriptIdentity(
797
+ left: TranscriptIdentity,
798
+ right: TranscriptIdentity,
799
+): boolean {
800
// Unsafe legacy numbers may already have lost file ID precision.
801
if (
802
(typeof left.inode === "number" && !Number.isSafeInteger(left.inode)) ||