Repository navigation
fix(sessions): settle native dedupe ties deterministically - #1385
Conversation
Byte-identical copies share the content-derived updatedAt, so the "keep the newest write" order in list() tied for exactly the manual-copy case the dedup was added for. The tie fell through to walkJsonl order, which follows directory enumeration and flips per platform: on NTFS a backup/ copy won while ext4 kept the original, so the copy took the session over, the original's id was dropped from records, and the new regression test failed on Windows. Break ties deterministically: an id with an open runtime keeps the file it is already writing, and the last tie is settled by path order, which every platform computes the same way. fixes vastsa#1383
The vastsa#1359 regression test only scanned its "control" after the copy existed, so it compared the winner with itself: it passed on every platform even while the byte-identical copy won the dedup on NTFS and APFS. Scan the control before writing the copy so the assertion pins which file stays canonical for the native id, and let it fail if the winner ever follows enumeration order again. Also lift the inline faux model runtime that two tests duplicated into one `fauxModelRuntime()` helper and document the rankTie comparator, including the id fallback that only keeps it total. Verified locally: the strengthened assertion fails on main (the copy wins on APFS) and passes with the deterministic tie-break; the package suite is 1240/1240 and `tsc --noEmit` is clean.
Maintainer follow-up (a2eb0a5, included in this PR)
The tie-break logic itself is unchanged (open runtime → smallest record path) and was re-verified as order-independent under forced reversed |
|
感谢审阅、强化与合并! 补一个事后核对,两处更正:
感谢修正,学到了:control 必须发生在被测变更之前,否则断言恒真。 |
Problem
#1383:
NativePiSessionService.list()dedupes copied session files by keeping the newest write per native id, butupdatedAtis derived from file content. A byte-identical copy always ties with the original, so "keep the newest write" never resolves the exact case the dedup (#1359 / #1374) was added for. The tie fell through towalkJsonlorder, which follows directory enumeration and differs per platform:backup/copy is walked first and wins, the original's record is deleted fromrecords, and the new regression test from fix(sessions): specify native duplicate identity handling #1374 fails on Windows.Consequences on Windows: a kept
.jsonlbackup takes the session over — reopening from the sidebar appends to the copy while the original freezes, persisted references to the original id getNOT_FOUND, and a live runtime's record can be deleted mid-session.Fix
Order dedupe ties deterministically instead of trusting enumeration order:
Tests
breaks copy ties by path order instead of directory enumeration (#1383)— a copy in a directory sorting before the original's group still yields exactly one entry, and the winner is deterministic across platforms.keeps the open runtime's file when a copy ties on recency (#1383)— after a faux-model turn, a byte-identical copy sorting before the original loses to the open runtime.#1359test (copy inbackup/, original wins) now passes deterministically on all platforms; it failed on NTFS before this change.Local validation (Windows 11 / NTFS):
vitest run src/native-pi-session.test.ts— 39/39 pass (37 before + 2 new)tsc -b packages/agent-runtime— cleanpackages/agent-runtimeis outside the repo's biome.json include list (checked, no findings possible)fixes #1383