Skip to content

fix(auth): raise password-hash contention wait budget for slow CI runners (#506) - #536

Merged
jimhoyd merged 1 commit into
mainfrom
fix/auth-hash-wait-budget-506
Sep 23, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
fix/auth-hash-wait-budget-506

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Root cause

A nightly scheduled verify run on main failed one test out of 213 in packages/auth, only on the windows-latest, node 22 matrix 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 all fulfilled rather than one being refused.

packages/auth/src/auth-core.ts's password-hash concurrency queue (acquireHashSlot) is a HASH_SLOTS = 2 semaphore backed by a HASH_QUEUE_MAX = 16 wait list. Each waiter that can't get a slot immediately waits on a single fixed HASH_WAIT_MS = 2000 timer before being rejected with 503 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-store worker startup): that PR added storeStartupBudgetMs() reading URLCODE_AUTH_STORE_STARTUP_MS to 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: added hashWaitBudgetMs(env), reading URLCODE_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 calls hashWaitBudgetMs() instead of the old fixed HASH_WAIT_MS constant. Slot count, queue-depth bound and rejection code are unchanged.
  • .github/workflows/ci.yml: sets URLCODE_AUTH_HASH_WAIT_MS: '10000' in the workspace-verify and workspace-integration jobs (the same jobs that already raise URLCODE_AUTH_STORE_STARTUP_MS for [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 for hashWaitBudgetMs's default/floor/cap/invalid-input behavior, in the style of storeStartupBudgetMs's test in auth-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-ui first — 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.
  • Windows-only flakiness can't be reproduced directly in this environment; reasoned through the timing math above (tail-waiter wait scales with queued derivations ahead of it) to size the new default CI override at 10000ms, well above the theoretical worst case at 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

…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]>
@jimhoyd
jimhoyd merged commit 713a2e1 into main Sep 23, 2026
61 checks passed
@jimhoyd
jimhoyd deleted the fix/auth-hash-wait-budget-506 branch September 23, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Windows CI flake in auth password-hashing contention test (auth-core.test.ts:489, #464)

1 participant