Repository navigation
fix(store): the batch supersession + ledger rotation get the fileIdentity anchor (#106) - #112
Conversation
… with fileIdentity
abogartz
left a comment
There was a problem hiding this comment.
Verdict: APPROVED
Independently verified, not trusting the body.
Mechanism traced end to end. handoverRename (src/logfmt.ts:157-180) fails → Windows+anchored only → ≤2s retry, every pass re-checks fileIdentity(file) !== since → throw. Both sites now capture the anchor before their read inside the lock: markManySuperseded (src/memory.ts:381, before readLines) matches stampRow's established shape (memory.ts:347); rotateIfNeeded (src/hits.ts:71) runs inside withStoreLock(hitsFile(), …) (hits.ts:114-118), so the ledger anchor is taken under the lock too. Exactly what #106 prescribed.
Red-first is a construction proof, and I confirmed it by reading the pre-fix path: writeAtomic without since → handoverRename hits if (!IS_WINDOWS || since === undefined) throw err → one rename, one throw. There is no retry for the old shape to have reached; both batch tests and the ledger test could only have been red. The ledger test's cap arithmetic checks out (40 000 rows asserted > 2 000 000 bytes against MAX_HITS_BYTES = 2_000_000), and the assertions distinguish halve-vs-no-halve (lines.length < filler.length + 1) rather than just "no throw".
POSIX inertness is the right claim, and I checked the trap: on POSIX the first rename always succeeds, so the anchor never fires — the new tests are skipIf(!win32) and this platform sees no new failure mode. On macOS full suite: 480 pass / 11 skip / 0 fail, tsc --noEmit clean.
Residual (accepted, matches #106's scope): a rotation that aborts on a genuine mid-window append is still swallowed by recordHits' telemetry catch — the halving is skipped silently, though now without ever clobbering the append. That is the pre-existing "telemetry never breaks retrieval" trade, unchanged.
CI: test-windows passed on this branch (486-era leg); the three pins only execute there.
|
🎉 This PR is included in version 0.14.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #106 - both sites, both paths the issue names.
What
markManySuperseded(from #102) andhits.tsrotateIfNeeded(pre-existing) published whole-file read-modify-writes without thefileIdentity/sinceanchor #89 made the standard. On Windows, mandatory locking refuses the handover rename while any reader still holds the destination - so the batch died outright on an ordinary retirement (writeAtomic's no-anchor path is exactly one rename), and the ledger rotation died silently, swallowed byrecordHits' telemetry catch: a lost halving with no signal, the ring growing past its cap.The fix is the issue's, verbatim:
const since = await fileIdentity(file)inside the lock beforereadLines(and before the ledger read), threaded towriteAtomic. With the anchor, the healthy Windows shape - blocked rename, file unmoved - retries and lands inside the ~2s window; the dangerous shape - an unlocked append landing mid-window - aborts honestly with the destination intact, exactly asstampRowalready did.Tests (red-first on the windows leg)
Three pins reusing #89's
held()machinery (openSync(file, "r")shares reads/writes but blocks replacement):4627d04-era leg for the same reason fix(store): make the store's file semantics hold on Windows (+ a windows-latest CI leg) #89'sstampRowfix existed).trueand halves the file (pre-fix:false+ silently over-cap - red).POSIX takes neither path (rename swaps under readers, the retry is
IS_WINDOWS-gated) - the three tests areskipIf(!win32); the red leg istest-windowsCI.Verified
bun run test)tsc --noEmitclean. The zero-fail Windows number finally agrees with the store's promises because #89 is in the tree - nice time to be doing this follow-up.assisted by Qwen3-flash-next