Skip to content

Commit 3e567d0

Browse files
fix(server): narrow fs suppression and cover large-ID collision with a regression test
1 parent 07695d5 commit 3e567d0

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,30 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
19571957
}),
19581958
);
19591959

1960+
it("distinguishes replaced transcripts by raw file ID when the numeric inode is missing", () => {
1961+
// Equal size, mtime, and creation millisecond with a missing numeric
1962+
// inode: the Windows collision from the replaced-transcript bug. Raw IDs
1963+
// are the distinct NTFS file IDs probed in the issue report.
1964+
const base = {
1965+
filePath: "rollout-replaced.jsonl",
1966+
size: 100,
1967+
mtimeMs: 1_000,
1968+
device: 1,
1969+
inode: null,
1970+
birthtimeMs: 500,
1971+
};
1972+
const original = { ...base, inodeRaw: "5764607523043455093" };
1973+
const replaced = { ...base, inodeRaw: "5764607523044503669" };
1974+
expect(Number.isSafeInteger(Number(original.inodeRaw))).toBe(false);
1975+
expect(Number.isSafeInteger(Number(replaced.inodeRaw))).toBe(false);
1976+
expect(AgentSessionScanner.sameTranscriptIdentity(original, replaced)).toBe(false);
1977+
expect(AgentSessionScanner.sameTranscriptIdentity(original, { ...original })).toBe(true);
1978+
// Records written before the raw ID existed carry no `inodeRaw` and keep
1979+
// matching, so they are not re-imported after the upgrade.
1980+
expect(AgentSessionScanner.sameTranscriptIdentity(base, replaced)).toBe(true);
1981+
expect(AgentSessionScanner.sameTranscriptIdentity(base, { ...base })).toBe(true);
1982+
});
1983+
19601984
it.effect("imports visible history from a transcript with an oversized tool record", () =>
19611985
Effect.gen(function* () {
19621986
const path = yield* Path.Path;

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @effect-diagnostics nodeBuiltinImport:off - Effect's FileSystem drops NTFS file IDs above Number.MAX_SAFE_INTEGER; the raw bigint stat preserves them.
21
/**
32
* AgentSessionScanner - discovery of projects a user already works on.
43
*
@@ -14,6 +13,7 @@
1413
*
1514
* @module project/AgentSessionScanner
1615
*/
16+
// @effect-diagnostics-next-line nodeBuiltinImport:off - Effect's FileSystem drops NTFS file IDs above Number.MAX_SAFE_INTEGER; the raw bigint stat preserves them.
1717
import * as NodeFS from "node:fs/promises";
1818
import * as NodeOS from "node:os";
1919

@@ -589,7 +589,8 @@ function extractCwd(line: string): string | null {
589589
return null;
590590
}
591591

592-
function transcriptIdentity(
592+
/** @public Pure helper exported for regression tests; identity construction stays beside its comparison. */
593+
export function transcriptIdentity(
593594
filePath: string,
594595
stats: FileSystem.File.Info,
595596
inodeRaw: string | null,
@@ -614,9 +615,21 @@ function normalizeInodeRaw(value: unknown): string | null {
614615
return typeof value === "string" && value.length > 0 ? value : null;
615616
}
616617

617-
function sameTranscriptIdentity(
618-
left: ReturnType<typeof transcriptIdentity> | AgentSessionImportSource,
619-
right: ReturnType<typeof transcriptIdentity> | AgentSessionImportSource,
618+
/** Minimal shape compared by {@link sameTranscriptIdentity}. */
619+
interface TranscriptIdentityLike {
620+
readonly filePath: string;
621+
readonly size: number;
622+
readonly mtimeMs: number | null;
623+
readonly device: number;
624+
readonly inode: number | null;
625+
readonly inodeRaw?: unknown;
626+
readonly birthtimeMs: number | null;
627+
}
628+
629+
/** @public Pure helper exported for regression tests; the Windows collision is decided here. */
630+
export function sameTranscriptIdentity(
631+
left: TranscriptIdentityLike,
632+
right: TranscriptIdentityLike,
620633
): boolean {
621634
if (
622635
left.filePath !== right.filePath ||
@@ -631,8 +644,8 @@ function sameTranscriptIdentity(
631644
// Records written before the raw ID existed have no `inodeRaw`; fall back
632645
// to the numeric check above so they don't re-import. When both sides
633646
// carry a raw ID (the Windows case where `inode` is `null`), it must match.
634-
const leftRaw = normalizeInodeRaw((left as { readonly inodeRaw?: unknown }).inodeRaw);
635-
const rightRaw = normalizeInodeRaw((right as { readonly inodeRaw?: unknown }).inodeRaw);
647+
const leftRaw = normalizeInodeRaw(left.inodeRaw);
648+
const rightRaw = normalizeInodeRaw(right.inodeRaw);
636649
if (leftRaw !== null && rightRaw !== null && leftRaw !== rightRaw) {
637650
return false;
638651
}

0 commit comments

Comments
 (0)