Repository navigation
fix(store): make the store's file semantics hold on Windows (+ a windows-latest CI leg) - #89
Conversation
…aces An open(lockPath, "wx") failure no longer decides the writer's fate by its label. On Windows a held lock surfaces as a sharing violation (EPERM) rather than EEXIST, and the file can also vanish between the failed create and any probe (the holder finished) — the EEXIST-only policy died writers outright on both: the multi-process store tests lost rows with children exiting on an EPERM/EEXIST stderr. Any creation failure now routes to the same wait-the-holder path EEXIST already took. Two guards keep real failures from hiding in that wait: - if creation keeps failing while stat keeps proving the lock file absent (no holder ever existed), the original error is rethrown after a short bounded strike, instead of decaying into a budget timeout that — with onTimeout defaulting to proceed — would run the write with no lock on a filesystem that cannot even create the lock; - stealIfStale answers an undeterminable age with "not stealable" so the budgeted backoff always runs; its old retry-the-create branch hot-spun whenever stat itself was what kept failing (probed: the old shape spun past its budget where the new one terminates at it).
…n value DirHandle.close() returns undefined (not a Promise) on Bun/Windows, so dh.close().catch() threw a TypeError from the finally block of walkSources — escaping the function and failing every gate run that walked the tree on Windows (GATE-1 traces in scenarios/gated-injection).
…provably untouched On Windows, renaming a destination a reader still holds fails with a sharing violation until that handle closes; readers of a small store file cycle their handle on a microsecond scale, so the failure is usually transient. The handover now retries within a ~2s window (inside the 5s lock budget) — but only where retrying cannot lose a row: read-modify-write callers pass the destination's identity from BEFORE their read (fileIdentity), and a retry proceeds only while the destination still matches it. A degraded writer (lock.ts lets a starved waiter proceed without the lock) appending during the window changes the destination, so the publish fails with the original error — what the immediate-failure path always did — instead of republishing a stale snapshot over the new row. Measured with a reader-blocked 3-rewrite + 1-degraded-append probe: the append survives and the blocked rewrites report failure, on both Bun versions. The retry is gated to Windows by design: POSIX renames swap the file out from under readers and never fail for contention; retrying there only converts permanent failures (read-only destination, sticky dir, unwritable parent — each probed at a full 2s stall) into latency. Callers without a pre-read identity publish with a single rename, as before, on every platform.
The plugin loads and its tools register on Windows, but the suite had never run there: 3 of 328 tests fail on main at 0.8.8 on Windows under both Bun 1.3.10 and 1.4.4 — the bugs the fixes in this branch address — while CI, ubuntu-only, saw nothing. A separate job, not a matrix entry: a matrix renames the check to 'test (ubuntu-latest)'/'test (windows-latest)', which would park a ruleset-required bare 'test' check forever. test-windows reports without gating merges. The smoke leg stays Linux-pinned (per-platform opencode binaries).
|
Bummer, on it. |
|
Why |
|
I'm sorry if all this CI work blows your plan/budget at Github. |
abogartz
left a comment
There was a problem hiding this comment.
Reviewed line-by-line and re-verified locally (macOS, Bun 1.4.4). The mechanism is approved: the lock.ts strikes/deadline design, the single-stat probe, stealIfStale's "undeterminable → not stealable", fileIdentity, and the identity-gated handoverRename all hold up — full suite here 352 pass / 4 skip / 0 fail, tsc clean, and lock.test.ts + concurrency.test.ts green ×3 back-to-back. POSIX neutrality is consistent with the code (retry gated on IS_WINDOWS && since). Also confirmed the 4th Windows failure is not yours: it's the pre-existing load family (repoScopeFor session-map test does 70 synchronous mkdirs; AV scanning pushed it past the 5 s default with a dangling process killed after) — the three guard deaths are #88's, now merged, so a rebase should take the leg to your stated 0–1 flaky shape.
Two pieces the PR body describes are not in the branch, so I'm requesting changes rather than nitpicking style:
-
The promised regression tests are absent.
git diff --stat origin/main...HEADoncc4b66dis ci.yml + 7src/files — notest/file. The body promises "4 new regression tests" with two "deterministically red on the pre-fix code". Right now nothing in the suite pins: the absent-strikes rethrow (ACL-denied dir), the deadline-only-with-holder rule (the 223-expiry stress result), the identity-abort of a retried publish, or the per-call temp property. Epic #68's whole premise is that each of these lands with a test that dies without the fix. -
The per-call temp naming never landed — and the retry window makes it load-bearing.
src/logfmt.ts:127is stillconst tmp = `${file}.${process.pid}.tmp`(unchanged sinceea03b91— no commit on this branch alters it). The body's commit-3 narrative is exactly right about the hazard: with a pid-stable temp, a same-process unlocked writer (the starved-waiteronTimeoutproceed path this PR explicitly preserves) canBun.writeinto the same temp path while our publish sits in the ≤2 s retry loop, and a subsequentrename(tmp, file)publishes those bytes under our success report. Pre-PR that window was microseconds (single rename); the PR's own retry window widens it to seconds on the exact platform this PR targets. Please land the per-call-unique temp (+ the 8/8-style pin test) on the branch.
Also: your comment says the leg's "3 failures" — heads-up the run on cc4b66d had a 4th (the load timeout above), so don't be surprised if the rebased leg still flakes occasionally while it's reports-only.
Everything else I claimed to check, I checked. Fix those two and this is merge-ready from my side.
The publish retry window (<=2s on Windows) makes the pid-stable temp name load-bearing: a starved-waiter unlocked writer for the same file can Bun.write into the same temp path while the anchored publish sits in the retry loop, and the next rename publishes THOSE bytes under our success report. Temp names now carry a per-call sequence. Found in the abogartz#89 review (per-call naming was promised in the body but never landed after the branch rewrite).
7e42f41 to
eb0ade0
Compare
|
Both demands addressed — and for the record, you're right that the gap was real: the branch rewrite (thank you for the cleaner commits, by the way) dropped the 1. Per-call temp naming ( 2. The four regression tests ( Verification on
Noted on the reports-only leg possibly flaking on the |
The branch rewrite dropped the test files; this restores them: - deadline-only-with-holder: an ordinary write never dies at the budget deadline on a just-released lock (40 cycle-the-lock attempts, 0 throws); - absent-strikes rethrow: an ACL-denied store directory surfaces the live EPERM in <2s and never runs the writer (icacls-gated, skips honestly where ACLs cannot be applied); - retried publish renames ITS OWN temp file (deterministically red on the pid-stable name, green on per-call uniqueness); - a degraded append during the retry window aborts the publish and the append survives. All four die without this PR's src changes; the Windows pair skips outside win32.
eb0ade0 to
a72a82b
Compare
|
SHA note: the test commit is now |
The lone member of the Windows load family that keeps dying in CI: 70 synchronous mkdirs under Defender scanning measured 5.2-5.3s on windows-latest - past the 5s default, so the runner kills the test while its dangling process is still sweeping. Not a hang; the logic is fine. Other tests in the file keep the default timeout. Pre-annotated as the 4th failure by the #89 review; this is the pin.
abogartz
left a comment
There was a problem hiding this comment.
Re-review on 4627d04 — both notes are addressed. Merging.
Note 1 — the regression tests landed
git diff --stat origin/main...HEAD now carries test/lock.test.ts (+92) and test/logfmt.test.ts (+74). The four pins and where they actually execute:
| pin | where |
|---|---|
test/lock.test.ts:172 deadline races > an ordinary write never dies at the deadline on a just-released lock |
both legs |
test/lock.test.ts:211 broken store directory (Windows ACL) > fails fast with the real error and never runs the writer |
win32 |
test/logfmt.test.ts:137 a retried publish renames its own temp file, not the degraded writer's |
win32 |
test/logfmt.test.ts:186 a degraded append during the retry window aborts the publish and survives |
win32 |
All four read (pass) on the test-windows leg of run 40231741418, and the ACL one at 140 ms — which independently confirms the strike-out is the fast path you describe, not the 5 s budget.
Note 2 — per-call temp naming
src/logfmt.ts:123 let tmpSeq = 0; and src/logfmt.ts:134 const tmp = `${file}.${process.pid}.${++tmpSeq}.tmp`. The pid-stable name is gone, and the own-temp pin guards exactly the hazard I described.
What I re-ran here (macOS, Bun 1.4.3)
- Full suite on the branch: 462 pass / 8 skip / 0 fail;
biomelint andtsc --noEmitclean. (8 skip = your 3 win32 pins + the 5 that already skipped on main.) - Your version claim, reproduced with a real Bun 1.3.10 binary: filtered
gated-injection + scenariosinside a git checkout → 3 fail with the merge-basesrc/resolver.ts, 22 pass with yours. First time I've seen the 1.3.xDirHandle.close()walk death locally; it behaves exactly as your corrected body says, including the full-suite-ordering mask on non-Windows. - Healthy-filesystem stress against your
lock.ts(5 processes × 60withStoreLockacquisitions each, budgets 30 / 100 / 5000 ms, 2 rounds = 1800 acquisitions): 0 writer errors, no strike-out on APFS. - The deadline test is green both with your
lock.tsand with main's. So on POSIX it is a property pin, not a delta-catcher — the delta it guards (the mislabelled-EPERMshape) only exists on Windows. Not a complaint, just recording what the gating legs do and don't prove, since three of the four pins run only on the reports-only leg.
Two observations, neither blocking
src/lock.ts:178—if (absentStrikes > 0) throw firstErr;sits under a comment saying "never while the lock file has been absent this whole time", butabsentStrikesis reset to 0 by any probe that finds the lock, so the condition as written reads "the last probe proved absence". The two differ in the healthy vanish race at the deadline (create fails against a live holder, the holder unlinks before our probe, the budget expires in that iteration): that writer now loses an ordinaryLOCK_WRITEwhere main would proceed. My stress never reached it on APFS, the ACL case the guard was built for is already covered ~130 ms earlier by the strike-out, andstatfailing with a non-ENOENTlabel leavesabsentStrikesat 0 and proceeds unguarded anyway — so the guard neither covers its named case nor is harmless in the healthy one. Making the comment true is cheap: seteverSawHolder = truewhen a probe finds the lock and gate the rethrow on!everSawHolder. Follow-up, your call.src/hits.ts:70is a store-locked read-modify-write that callswriteAtomicwithoutsince, so it keeps today's single-rename behavior. Out of scope here; I'll track it with (1).
CI state as of this review
test-windows is red on 4627d04 for exactly one known load flake (repoScopeFor precedence > the session map is bounded, 5250 ms — the 70-mkdir test under AV timing), the family I pre-annotated. Reports-only leg; lint / test / smoke green, branch contains main.
Merging now with --merge. Thanks for the re-verification on both Bun versions — the corrected Linux cell in the body is the part I'd have got wrong.
|
Appreciate the re-review — and the 1800-acquisition stress run is a nicer confirmation than anything we'd have scripted. Agreed on both observations: the �bsentStrikes-vs-�verSawHolder distinction and the hits.ts unanchored publish are exactly the kind of follow-ups worth their own small PRs; leaving both on your tracker rather than growing this branch. (The 5250 ms flake you cited on the reports-only leg got its own pin in #105 while this was in review.) |
Superseded by the APPROVED re-review on 0bbc545: both demands (per-call temp naming src/logfmt.ts:134, the four regression tests) are in the tree and verified locally and on the Windows leg.
|
Correction on my last paragraph — I found the actual cause, and it is neither policy nor a platform quirk.
My token's scopes are State of play: reviewed, approved (the stale request-changes is dismissed), |
The situation
This plugin works on Windows and Linux — it loads, registers tools, and passes the real-host e2e suite (9/9) — but the store's concurrency layer was written against POSIX file semantics, and CI has only ever run ubuntu-latest with the latest Bun. Measured on current
main(2123551, 0.8.9+; 342 tests):mainNote what this says about the bugs: the
DirHandle.close()failure is Bun-1.3.x-version-specific, not Windows-specific (it fails identically on Linux under 1.3.10 — invisible to CI because the workflow'ssetup-bunresolveslatest). Thelinux-latestCI leg has been riding the 1.4.x behavior all along. Re-verified on current main: FULL-SUITE Linux runs under 1.3.10 pass (full-suite ordering hides the walk), while filtered runs of the three files inside a git checkout fail identically on both OSes - the version bug is real on Linux, just ordering-masked; the Windows full suite still fails it deterministically.Instrumented 4-process race (3 writers × 50 concurrent
appendMemoryvs 300readLines): before, ~1 in 15 Windows runs silently lost a row (child writers died onEPERM/EEXISTon the.lockfile); after: 0 losses in 12 runs (Windows) and the proper cross-process concurrency tests pass on both OSes.The four commits
1.
lock.ts— mislabelled contention and vanished locks keep writers alive.The
open(lockPath, "wx")catch no longer decides by error label — both labels lie: on Windows a held lock still reports plainEEXIST, while the sharing-violationEPERMappears when the holder's releaseUNLINKis still in flight (probed: ~9 of 10EPERMs are followed microseconds later byENOENT), and the file can simply vanish between the failed create and any probe. The EEXIST-only policy died writers outright on the EPERM shape. Any creation failure now takes the wait-the-holder path. Three guards keep real failures from hiding — and one of them is a bug this review caught in an earlier draft of this PR:onTimeoutdefaulting to proceed) would run the write with no lock at all on a filesystem that can't create the lock. (ACL-denied-directory probe + test.)LOCK_WRITEwrite to contention: measured 13/35 deadline hits threw on Linux (WSL2), 7/140 on Windows pre-fix; the shipped shape: 0 of 223 deadline hits threw on Linux (vs a 46-throw control on the pre-fix branch code, same machine, same script).probeLockanswers "absent?" and "stealable?" with ONEstatper failed attempt, and an undeterminable age means "not stealable" (the old retry-the-create branch hot-spun past its budget whereverstatitself kept failing — probed).2.
resolver.ts—await dh.close?.(), never.close().catch(...).Bun 1.3.10 returns
undefinedfromDirHandle.close()(the chained.catchis a synchronousTypeErrorthat killed the directory walk — 3 deterministic test failures on any OS under that version), 1.4.x returns a Promise — and after a completedfor awaitthe handle is already closed, soclose()rejectsERR_DIR_CLOSED, which the await's catch now swallows as what it is: the walk is done.3.
logfmt.ts— the rename handover retries with a staleness check, and temps are per-call.Windows mandatory locking makes a rename-over-a-held-destination fail until the reader's handle closes; POSIX never fails this way (rename swaps under readers) — so the ~2s retry window (inside the 5s lock budget) is Windows-only by design; on POSIX the same retry measured as nothing but 2s stalls on permanent failures (read-only destination, sticky dir, unwritable parent). Read-modify-write callers pass the destination's identity from before their read; a retry proceeds only while the destination still matches it. Honest scope: this narrows the stale-publish race, it doesn't close it — an unlocked writer whose append opens, writes and closes entirely inside the check→rename-syscall window slips through (measured under forced interleavings: 41/1500 on Bun 1.3.10, 2/1500 on 1.4.4; such starved-waiter writers already raced the single-rename publish on every platform). Two Windows-only tests pin the properties that do hold: a retried publish renames its own temp file (temp names are unique per call, not per process — a shared name made two unlocked writers in one process publish each other's bytes with a success report: 2/6 and 4/4 trials pre-fix, 8/8 honest post-fix), and an append that lands during the window aborts the publish and survives.
4.
ci.yml— atest-windowsjob.Reporting what no leg ever looked at: on current main's Windows, six failures are deterministic — 3 of the resolver walk under Bun 1.3.x (invisible to CI because
setup-bunresolveslatest, which the linux leg has been riding all along) plus 3 from #86's guard bug (separately fixed by #88) — alongside 0–7/run of the pre-existing load-sensitive torn-read races (any branch state, any Bun; they pass in isolation and lose under full-suite load). Commits 1–3 fix every deterministic class and cut the race rate. Deliberately a separate job, not a matrix: a matrix renames the check (test (ubuntu-latest)) which would park any ruleset-required baretestcheck forever.test-windowsreports without gating merges; the smoke leg stays Linux-pinned (per-platform opencode binaries). Verified auto-mergeable with #62 whichever order they land (if #62 lands first, itsbun-versionpin needs the same one-line addition in the new job — trivial follow-up in either order).Linux testing (the other half of "cross-platform")
Both fixed and baseline trees were run natively on Linux (WSL2, ext4, both Bun binaries, Ubuntu 24.04): the table above is measured, not inferred. The branch's Linux-visible deltas: the resolver trio goes 3-fail to 0-fail under 1.3.10 (measured with filtered runs inside a git checkout; Linux full-suite runs already pass on main by ordering, Windows full-suite runs do not until this fix lands); the lock changes (deliberately platform-neutral) turn the deadline-starvation shape from losing writes into waiting through them — a 5-process cycle-the-lock hammer at a 50 ms writer budget: 223 deadline expiries, 0 writer errors, 12k+ appends, 0 lost rows (control on the pre-fix branch code, same machine/script: 46 writers died on stale
EEXIST). And nothing regressed: POSIX paths are unchanged by construction (the rename retry is gated off; the identity anchor is one extrastat— repo's own write-latency bench: base 35/23/27ms vs branch 25/21/27ms, within noise).Not claimed / adjacent
exportMemories({file})writes an arbitrary destination unlocked (pre-existing); pointing it at a live store file would clobber it. Separate follow-up if wanted.spawn opencode.cmd EINVALunder Bun 1.4.4). Test-infra only — follow-up sent as fix(e2e): run the opencode host off the real binary, not the cmd-shim (Windows Bun 1.4 EINVAL) #85.mainalso carries a Windows-only bug in test(scenarios): acceptance suites — ordered-event harness + cross-process red/green #86's test helper —test/helpers/temp-root.tscomparesrealpathSyncoutput againsttmpdir + "/", but Windows realpath yields backslashes, so the guard's own children exit(2) against valid temp paths and three cross-process tests die deterministically on Windows. Fixed stand-alone as test: temp-path guard cannot match on Windows - 3 deterministic cross-process test deaths #88 (one token,+ sep, with a both-directions guard test). The 0-fail Windows cells below assume test: temp-path guard cannot match on Windows - 3 deterministic cross-process test deaths #88 (or the same one-liner) is in the tree; it changes nothing on Linux.half-written file,prune racing appends, occasionally a third sibling) remain flaky-on-Windows here too — 0–2/run, load-dependent, identical family on main (measured there at 0–7/run alongside everything else). Lock-freeappendFilevs. a reader can expose a partial last line; this PR neither introduces nor touches that path, and it passes in isolation on both states. Fixing it needs its own design conversation (reader-side tail repair vs. handover-only writes), so it's called out rather than silently scoped out.Verification
tsc --noEmit+biome lintclean · 346-test suite on Windows (+ #88): 0 fails @1.3.10, 1 torn-read flake @1.4.4 vs 10 and 2 onmain; 0 fails × 2 Bun on Linux · concurrency file standalone: 0–2 torn-read flakes/run depending on machine load (main: same family plus the deterministic deaths) · 4-process healthy hammer: 972–978 appends, 0 lost, 0 errors, repeatedly · reader-blocked handover probe: degraded writer fails honestly on its own temp file, append survives, both Buns · e2e 9/9 × 2 Bun (with #85's harness fix) · 4 new regression tests; the two that encode the review-found bugs are deterministically red on the pre-fix code and green after · adversarial review pass (two rounds: fault injection, ACL-denied dirs, 9k+ spawn label surveys, forced rename/append interleavings, cycle-the-lock deadline stress) with findings fixed in-branch.Adjacent: #87 (temp-dir cleanup) touches the same two test files' hook blocks — trivial conflict in whichever order we land; mention it rather than pretend independence.
Model-assisted work: Qwen3-flash-next (analysis, implementation, and adversarial review assistance).