test(shared-budget): deflake the concurrent-spend assertion#6
Merged
Conversation
The "total is exact" test asserted exact $0.60 across two concurrent workers, but cross-process budget is documented as NOT penny-exact (gotcha #2), and exact-equality flaked CI under lock contention (one lost $0.03 tick; passes 65/65 locally). A /code-review pass correctly noted the relaxed band I first tried ($0.54 floor) was too loose to catch a broken lock — record() is file-relative read-modify-write, so a broken lock loses a few updates and clusters just under $0.60, not down at $0.30. No single aggregate floor cleanly separates "rare 1-tick loss on correct code" from "broken lock". So assert only the scheduling-independent invariants: - record() can NEVER over-count (adds its delta to a lock-fresh read) — the hard invariant; over-counting would be a real double-apply bug. - both workers' spend accumulates cross-process (total > one worker's run) — a coarse collapse smoke check, immune to documented soft-budget slop. Renamed the test off "is exact". Test-only; budget.js untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deflakes
shared-budget.test.js(the intermittent ubuntu/Node-20 failure seen on PR #5).Problem: the test asserted exact
$0.60across two concurrent workers, but cross-process budget is documented as NOT penny-exact (gotcha #2: "don't rely on hard cents-precision enforcement"). Under heavy lock contention one$0.03update was lost ($0.57) → CI flake. Passes 65/65 locally.A
/code-reviewpass correctly flagged my first attempt (a$0.54lower-bound band) as too loose:record()is file-relative read-modify-write, so a broken lock loses a few updates and clusters just under$0.60— it does not collapse to$0.30. No single aggregate floor separates "rare 1-tick loss on correct code" from "broken lock".Fix: assert only the scheduling-independent invariants —
record()can never over-count (it adds its delta to a lock-fresh read) — the hard invariant; over-counting would be a real double-apply bug;Renamed off "is exact". Test-only —
budget.jsuntouched, no version bump, no publish.🤖 Generated with Claude Code