Skip to content

Commit b420c61

Browse files
fix(server): re-import no longer marks a continued transcript imported without its new messages
When a transcript changed after its import, the existing imported thread was left as is, but the importer recorded the new transcript as imported and counted the thread. The change was then never picked up again. The importer now skips such a transcript when the thread already records a different one, so it reports the thread as not imported and leaves the transcript unrecorded. Resuming an import whose recording failed still records it. Fixes #31628 AI-assisted; verified with the tests and tools listed above.
1 parent f41b8c4 commit b420c61

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ const make = Effect.gen(function* () {
325325
if (existing.value.thread.historyOrigin !== "v1_import") {
326326
return yield* new AgentSessionThreadModifiedError({ threadId });
327327
}
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+
}
328342
yield* persistRuntime;
329343
yield* runtimes.recordImportedTranscript({ threadId, source });
330344
return true;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,10 @@ type TranscriptIdentity = Pick<
793793

794794
const fileIdKey = (inode: TranscriptIdentity["inode"]) => (inode === null ? null : String(inode));
795795

796-
function sameTranscriptIdentity(left: TranscriptIdentity, right: TranscriptIdentity): boolean {
796+
export function sameTranscriptIdentity(
797+
left: TranscriptIdentity,
798+
right: TranscriptIdentity,
799+
): boolean {
797800
// Unsafe legacy numbers may already have lost file ID precision.
798801
if (
799802
(typeof left.inode === "number" && !Number.isSafeInteger(left.inode)) ||

0 commit comments

Comments
 (0)