Repository navigation
fix(auth): raise password-hash contention wait budget for slow CI runners (#506) - #536
Merged
Merged
Conversation
…ners (#506) A nightly windows-latest/node22 `verify` run flaked at auth-core.test.ts:489 (#464's contention regression test): the bounded password-hash wait queue's fixed 2000ms per-waiter timeout let one of 6 concurrent callers time out instead of getting a slot. The queue is a HASH_SLOTS=2 semaphore with a HASH_QUEUE_MAX=16 wait list; each waiter's wait is capped by a single fixed HASH_WAIT_MS. A tail waiter under 6-way contention can sit behind multiple scrypt derivations finishing ahead of it, so its wait scales with how many derivations must complete first, not just one. 2000ms is comfortable headroom locally but leaves no margin on a slower shared CI runner. Mirrors #424's fix for the analogous auth-store startup flake (#339): add hashWaitBudgetMs(), reading URLCODE_AUTH_HASH_WAIT_MS to raise (never lower) the per-waiter budget, default and floor 2000ms, capped at 30000ms. Sets it to 10000ms in the workspace-verify and workspace-integration CI jobs. The queue's depth/slot bounds and the test's "all 6 must fulfill" guarantee are unchanged — this raises the timing headroom rather than weakening the assertion #464 introduced. Adds a focused regression test for the new budget function alongside the existing #464 contention test, following the style of storeStartupBudgetMs's test in auth-store.test.ts. Closes #506 Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
Root cause
A nightly scheduled
verifyrun onmainfailed one test out of 213 inpackages/auth, only on thewindows-latest, node 22matrix cell:auth-core.test.ts:489, the #464 regression test asserting that 6 concurrent logins racing a process-wide 2-slot password-hash-derivation limit allfulfilledrather than one being refused.packages/auth/src/auth-core.ts's password-hash concurrency queue (acquireHashSlot) is aHASH_SLOTS = 2semaphore backed by aHASH_QUEUE_MAX = 16wait list. Each waiter that can't get a slot immediately waits on a single fixedHASH_WAIT_MS = 2000timer before being rejected with503 password_hash_busy. Under 6-way contention, a tail waiter sits behind however many scrypt derivations must finish ahead of it before a slot frees — its effective wait scales with the number of derivations queued in front of it, not a single derivation. 2000ms is comfortable headroom on a normal dev machine or fast CI runner, but leaves no margin on a slower shared runner (matching the "Windows CI runner is measurably slower" pattern behind #339).This is a timing-budget gap, not a logic bug in the queue itself (slot accounting, queue-depth bound and FIFO wake order all look correct), and not something to paper over by weakening the test's "all 6 must fulfill" guarantee — that guarantee is the point of #464's original regression test.
Precedent
Mirrors #424's fix for the analogous #339 flake (Windows-slow
auth-storeworker startup): that PR addedstoreStartupBudgetMs()readingURLCODE_AUTH_STORE_STARTUP_MSto raise (never lower) a fixed startup budget, with a floor/cap and a CI-only env override, plus a focused unit test for the budget function.What changed
packages/auth/src/auth-core.ts: addedhashWaitBudgetMs(env), readingURLCODE_AUTH_HASH_WAIT_MS. Default and floor 2000ms (unchanged production behavior), cap 30000ms; non-numeric or below-default values are ignored, so the env var can only raise the budget, never lower it below the reviewed default.acquireHashSlot's per-waiter timer now callshashWaitBudgetMs()instead of the old fixedHASH_WAIT_MSconstant. Slot count, queue-depth bound and rejection code are unchanged..github/workflows/ci.yml: setsURLCODE_AUTH_HASH_WAIT_MS: '10000'in theworkspace-verifyandworkspace-integrationjobs (the same jobs that already raiseURLCODE_AUTH_STORE_STARTUP_MSfor [Bug]: Windows admin pagination test is flaky (auth store worker startup timeout) #339), alongside the existing startup-budget override.packages/auth/test/auth-core.test.ts: added a focused regression test forhashWaitBudgetMs's default/floor/cap/invalid-input behavior, in the style ofstoreStartupBudgetMs's test inauth-store.test.ts. The existing [Bug]: auth password hashing returns 503 to every caller when two global slots are busy #464 contention test is unchanged.Testing
npm run typecheck(root): green.packages/auth:npm run typecheck: green (required rebuilding@jimhoyd/urlcode-uifirst — stale workspace dist, unrelated to this change).packages/auth:npm test: 214/214 passing, including the new budget test and the existing [Bug]: auth password hashing returns 503 to every caller when two global slots are busy #464 contention test.HASH_SLOTS=2/6 concurrent callers even on a slow runner, while keeping the non-CI default at the original 2000ms.Limitations
This raises timing headroom based on reasoning about the queue's mechanics, not a reproduced Windows failure (n=1 occurrence so far per the issue) — if it recurs at the new budget, that would point at (b) an actual queue bug rather than (a) runner slowness, and should be reopened against this issue.
Closes #506
🤖 Generated with Claude Code