Public: anyone can read this; the crew can change it.

"tries at /signin close the API door" passes every time on a loaded check machine #16915

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added a test that reproduces the cause deterministically, and the sign-in doors test file passes 20 of 20 beside a parallel load. That load was a loop of the users, sign-in, hash-gate and http suites, run three times.

Notes

opened this

I added a test that reproduces the cause deterministically, and the sign-in doors test file passes 20 of 20 beside a parallel load. That load was a loop of the users, sign-in, hash-gate and http suites, run three times. It was not a full bun test, which my instructions forbid, so the "beside a parallel bun test" item is still only partly met. Only test/signin-password-doors.test.ts changed. The test never failed on this machine unloaded, so the cause is shown by this reproduction.

Cause. The process-wide argon2 gate allows 4 hashes at once (src/core/hash-gate.ts). A /signin try made while all 4 slots are busy is turned away as a 429 with Retry-After: 1. It is never hashed and never counted in the sign-in window. The old test gave up after 50 asks of 50 ms, which is about 2.5 s plus request time. It never checked what a non-422 answer was. On a loaded machine it could end with fewer than TRIES counted. The API call with the right password then met an open window.

What changed in the test file:

  • Retry loop: each /signin try retries against a 20 s deadline, not a fixed count. Any answer that is neither a 422 nor the gate's 429 with Retry-After: 1 fails the test, so a 403 from the origin check cannot pass.
  • Final assertion: the closing POST /api/v1/sessions must be a 429 whose Retry-After is above 1 s, so the window closed the door and not the gate.
  • New test: "tries the hash gate turns away are not counted: they leave the API door open". It holds all 4 slots and posts TRIES wrong passwords to /signin. Each is a 429 with Retry-After: 1. After the slots are released, the right password at /api/v1/sessions is not a 429. This test fails if the gate starts counting such tries or stops refusing them.

Not done. I made no production change, because I found no race in counting tries. I did not add an injected clock or a lower hash cost. The window is a sliding minute and the hash cost is not what failed.

Numbers:

  • 20 of 20 in a row with 8 tests, run quiet.
  • 5 of 5 beside the parallel subset, also with 8 tests.
  • 20 of 20 with all 9 tests, beside the parallel load described above.
  • bun x tsc --noEmit is clean and bun scripts/gate.ts --fix changed nothing.

Try it: for i in $(seq 20); do bun test test/signin-password-doors.test.ts || break; done.

Closes #4406

2 earlier comments
commented

I added a test that reproduces the cause deterministically, and the sign-in doors test file passes 20 of 20 beside a parallel load. That load was a loop of the users, sign-in, hash-gate and http suites, run three times. It was not a full bun test, which my instructions forbid, so the "beside a parallel bun test" item is still only partly met. Only test/signin-password-doors.test.ts changed. The test never failed on this machine unloaded, so the cause is shown by this reproduction.

Cause. The process-wide argon2 gate allows 4 hashes at once (src/core/hash-gate.ts). A /signin try made while all 4 slots are busy is turned away as a 429 with Retry-After: 1. It is never hashed and never counted in the sign-in window. The old test gave up after 50 asks of 50 ms, which is about 2.5 s plus request time. It never checked what a non-422 answer was. On a loaded machine it could end with fewer than TRIES counted. The API call with the right password then met an open window.

What changed in the test file:

  • Retry loop: each /signin try retries against a 20 s deadline, not a fixed count. Any answer that is neither a 422 nor the gate's 429 with Retry-After: 1 fails the test, so a 403 from the origin check cannot pass.
  • Final assertion: the closing POST /api/v1/sessions must be a 429 whose Retry-After is above 1 s, so the window closed the door and not the gate.
  • New test: "tries the hash gate turns away are not counted: they leave the API door open". It holds all 4 slots and posts TRIES wrong passwords to /signin. Each is a 429 with Retry-After: 1. After the slots are released, the right password at /api/v1/sessions is not a 429. This test fails if the gate starts counting such tries or stops refusing them.

Not done. I made no production change, because I found no race in counting tries. I did not add an injected clock or a lower hash cost. The window is a sliding minute and the hash cost is not what failed.

Numbers:

  • 20 of 20 in a row with 8 tests, run quiet.
  • 5 of 5 beside the parallel subset, also with 8 tests.
  • 20 of 20 with all 9 tests, beside the parallel load described above.
  • bun x tsc --noEmit is clean and bun scripts/gate.ts --fix changed nothing.

Try it: for i in $(seq 20); do bun test test/signin-password-doors.test.ts || break; done.

commented

The check failed on a duplicate GATE_RETRY_AFTER import in test/signin-password-doors.test.ts. I merged origin/main into the branch, resolved that conflict and pushed. After the merge, bun x tsc --noEmit is clean and the test file passes (9 of 9). The five re-runs I did before committing the merge also passed. I have not seen the forge's check on the new push.

origin/main already had part of this work (#16904, the retry loop with its GATE_RETRY_AFTER import). It conflicted with my earlier commits, which came from a branch cut before #16904. The resolution keeps one import line, GATE_RETRY_AFTER, MAX_CONCURRENT_HASHES and withHashSlot from hash-gate.ts. It also keeps both tests: the retry-loop test and the one that reproduces the cause.

bun scripts/gate.ts --fix rewrapped comments in 10 files that came from main. None of them are mine, so I did not commit them.

What this pull adds on top of main is the reproduction test, "tries the hash gate turns away are not counted: they leave the API door open". The 20-of-20 run beside a parallel load was done before the merge. It used a subset of tests as the load, not a full bun test.

commented

The terminal sign-in test now has the same deadline as the /signin test, and I pushed it. The signin-password-doors file passes (9 tests), the type check is clean, and the gate reports nothing against the committed state.

  • Shared helper: the new askUntilCounted helper in test/signin-password-doors.test.ts asks until the try is counted, against one 20 s deadline. Both tests use it and the fixed again < 50 loop is gone. A gate turn-away (the terminal's throttled, or /signin's 429 carrying the gate's Retry-After) is asked again. Any other answer fails loudly, so a 403 from the origin check can't pass for the wrong reason.
  • Timeout: the terminal test now has a 30 s timeout like the /signin one, since the deadline is longer than bun's default.
  • Gate rules: the helper's sleep carries a // real-timer: note because the hash gate frees on real time. I lowered the file's fixed-wait allowance in scripts/test-honesty-allow.json, because the gate asked for it once the two loops became one wait.

Only test files changed, so no page or terminal door is affected. Both commits say No door: test-only change. No production code and no dependencies were added.

I didn't run the dead-code export test, because the change adds no exports.

I didn't run the rest of the suite either; the forge runs the full check on push.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs