Skip to content

Loosen the rate-limit notice tests to the burst's own duration - #3469

Merged
Birfy merged 1 commit into
mainfrom
dev/3468-rate-limit-drift-window
Nov 30, 2026
Merged

Birfy merged 1 commit into
mainfrom
dev/3468-rate-limit-drift-window

Conversation

@Birfy

@Birfy Birfy commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

The two rate-limit notice tests pinned the refusal's retry_after to [599, 600]. That number is ceil(600 - elapsed), where elapsed runs from the burst's first attempt (src/auth-limit.ts:87, ten-minute window at :23), so the bound left under two seconds for a burst of six round trips (account test) or eleven (address test), each of them hashing a password. Run alone the burst fits; run with the rest of the suite loading the machine it does not, and the tests failed with retry_after 598 and 596 while the product was correct.

What changes

services/bot-social/test/console_rate_limit_notice.test.ts (+11/-3, no product code):

  • a small assertWaitLeft(retryAfter, elapsedMs) helper derives the lower bound from the burst's own duration (600 - ceil(elapsed/1000) - 1) and keeps the upper bound at 600;
  • each test stamps Date.now() immediately before its first login attempt and passes the difference in;
  • the two >= 599 && <= 600 assertions and the "a slow runner may already be a second into it" comment are gone; the rendered-sentence assertions are untouched.

The bound still fails on a wrong value: the wait is pinned from above at exactly 600 s, and from below at one second's slack under the burst's own duration.

Provenance

That test file is imported from Bot Social and pinned by sha256 in docs/upstream/bot-social-files.json, so editing it also edits the census: the entry leaves bot-social-files.json (437 -> 436 entries, components['bot-social'].file_count follows) and a modified_files entry appears in docs/upstream/migration-manifest.json with the original sha256 and git blob, the new sha256, the byte count and a reason. Those two files are the only other changes in the diff.

Locally python3 scripts/verify-upstream-migration.py reports ok (flybot 46 files, bot-social 436 files) and python3 -m unittest tests.test_upstream_migration passes 7/7. Without this record both the provenance job and Management API fail on the manifest hash check, which is what the previous head showed.

Evidence (local readings, not CI)

Taken at the test-file-only head; the test bytes are byte-identical at the current head, the added commit only carries the manifest records.

  • node --import tsx --test test/console_rate_limit_notice.test.ts on the patched tree: 3/3 pass, twice.
  • Six copies of that file in parallel (--test-concurrency=1 each, appended only because this host saturates on the default): 18/18 pass, 0 fail.
  • Drift tolerance, deterministic: a scratch copy of the patched test with a 3 s stall inserted after the first failed attempt passes — retry_after 597, elapsed 3367 ms, lowest 595 (account) and retry_after 599, elapsed 1307 ms, lowest 597 (address).
  • Negative control, not vacuous: BOTSOCIAL_AUTH_RATE_LIMIT_WINDOW_SECONDS=300 gives retry_after 300 and both tests fail on the new bound (error: 'retry_after 300 after 494 ms' / 'retry_after 300 after 634 ms'), while the third test stays green.
  • Patch self-check: git apply on the base blob produces exactly c955c76b, byte-identical to the tree that was tested.

Out of scope

src/auth-limit.ts is unchanged: it reports the true remaining wait. Shortening the window through the env override instead was rejected, because the same two tests assert the rendered sentence "Try again in about 10 minutes.".

Related #3468

@github-actions github-actions Bot added the risk:T2 Risk tier T2 (host/plugin code or an unnamed path), set by the controller from the diff label Nov 30, 2026
The refusal reports the wait left in a ten-minute window that starts at the
burst's first attempt, so its retry_after is ceil(600 - elapsed). The two
notice tests pinned that to [599, 600], which leaves under two seconds for a
burst of six (account) or eleven (address) round trips that each hash a
password: alone the burst fits, with the rest of the suite loading the machine
it does not. The whole suite then failed on retry_after 598 and 596 while the
product itself was correct.

Measure the burst inside the test and derive the lower bound from it, keeping
the upper bound at 600. A window that is actually wrong still fails: forcing
BOTSOCIAL_AUTH_RATE_LIMIT_WINDOW_SECONDS=300 yields retry_after 300 and both
tests stay red.

Changing an imported file also has to be recorded in the upstream migration
manifest: the verifier pins the census by sha256, so the test leaves
docs/upstream/bot-social-files.json and gains a modified_files entry with its
original and new digest.

Related #3468
@Birfy
Birfy force-pushed the dev/3468-rate-limit-drift-window branch from 95ce6ad to ed888b1 Compare November 30, 2026 07:08
@Birfy

Birfy commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Lead review — head ed888b1f99e7bfa4923495523f508dc2061c4e0c

Reviewed at that exact head; base 89e163ef, one commit, 3 files +22/-10, mergeable clean. Any new commit voids this record and the evidence below.

What changes. The two rate-limit notice tests pinned the refusal's retry_after to [599, 600] while the product reports ceil(600 - elapsed) from the burst's first attempt, so the bound left under two seconds for a burst that hashes a password six (account) or eleven (address) times. The slice derives the lower bound from the burst's own duration and keeps the upper bound at 600. One test file, no product code: the window arithmetic and the rendered sentence are untouched.

Object graph, rebuilt from both ends (independent readings). Root trees reconstructed by unpacking each side and re-hashing: base aa1877aa, head 8d620c66 (matches the commit's recorded tree), 2285 files each, exactly 3 paths differing, no added or removed path. Blobs: test c955c76b (3982 B), docs/upstream/bot-social-files.json e54e65e7 (103718 B, census 437 -> 436), docs/upstream/migration-manifest.json 5b0dbf82 (115726 B, file_count follows plus one modified_files entry whose original_sha256, original_git_blob_sha, new_sha256 and bytes match independently measured values). Commit message 21 lines, last line Related #3468, zero closing keywords.

Evidence, local (not CI). Test file alone: 3/3 pass, repeated. Six parallel copies: 18/18 pass, 0 fail. Negative control BOTSOCIAL_AUTH_RATE_LIMIT_WINDOW_SECONDS=300: 2 fail on the new bound, third stays green, so the assertion was not widened into a no-op. Provenance: scripts/verify-upstream-migration.py -> ok (flybot 46 files, bot-social 436 files), and python3 -m unittest tests.test_upstream_migration 7/7 OK. Both were red at the previous head, which is why this commit exists.

Evidence, CI (read from check runs on this head). 18 of 18 completed success, including Management API · Python 3.11, Management API · Python 3.13, provenance / provenance, FlyBot required checks. No cancelled or failing run at this head.

Scope. Test-side reliability only. A very fast machine gives a lower bound of 598, so a product that really were 1-2 seconds short could in principle slip past on a slow host; that is the price of tolerating burst drift, not a defect, and the upper bound plus the rendered-sentence assertions still constrain the value. No claim of parity or acceptance.

Related #3468

@Birfy
Birfy added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit d57d6da Nov 30, 2026
18 checks passed
@Birfy
Birfy deleted the dev/3468-rate-limit-drift-window branch November 30, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:T2 Risk tier T2 (host/plugin code or an unnamed path), set by the controller from the diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant