Skip to content

bot-social: the rate-limit notice test allows under 2 s of burst drift and fails under parallel load #3468

Done

Description

@Birfy

What happens

services/bot-social/test/console_rate_limit_notice.test.ts pins the refusal's retry_after to [599, 600] in two tests: :25 (account burst) and :43 (address burst).

The product derives that number from the oldest attempt still inside the window:

  • services/bot-social/src/auth-limit.ts:23 — windowMs: 10 * 60 * 1000
  • services/bot-social/src/auth-limit.ts:87 — retry_after: Math.max(1, Math.ceil((oldest + this.limits.windowMs - now) / 1000))

So the value is exactly ceil(600 - elapsed_s), where elapsed_s runs from the first attempt of the burst to the refused one. The >= 599 bound therefore leaves under two seconds for a burst that makes 6 HTTP round trips (account test: sign-up, five failed logins, the refused one) or 11 (address test), each of them hashing a password. Alone on a quiet machine that takes well under a second; with the suite's 411 *.test.ts files loading the machine it does not, and both tests fail while the product behaves exactly as specified.

Evidence (local readings, not CI)

On 0d18af72ce8f478be473b16533df4e807ee3222b, from a local extract of the tree:

  1. Whole suite (npm test → node --import tsx --test test/*.test.ts, plus --test-concurrency=4 because the default concurrency saturates the host): not ok 527 and not ok 528, reporting retry_after 598 and retry_after 596, at :25:12 and :43:12 with ERR_ASSERTION. Both are plain assertion failures — not crashes, not timeouts — and the other 1111 cases that had run by then were green.
  2. The same file alone, three consecutive runs: 3/3 pass, retry_after 599 or 600 every time. So it is the parallel load, not the product.
  3. Deterministic probe: replaying the account burst with a known stall between the first and the refused attempt yields elapsed 6000 ms → 594 and elapsed 3991 ms → 597, matching ceil(600 - elapsed_s) to the second.
  4. No duplicate: search/issues q=repo:ThinkFlowLab/FlyBot is:issue in:title rate limit → total_count 0.

Expected

Both tests pass whenever the product returns the specified refusal, however long the burst itself takes; only an actually wrong retry_after (wrong window, wrong rounding, wrong scope) should fail them.

Suggested fix (test-only, no product change)

Measure the burst's own elapsed time in the test and derive the lower bound from it, keeping the upper bound at 600 and leaving the console-string assertions ("Try again in about 10 minutes.") untouched:

const started = Date.now();
// ...the burst...
const elapsed = Date.now() - started;
const lowest = 600 - Math.ceil(elapsed / 1000) - 1;
assert.ok(
  blocked.body.error.retry_after >= lowest && blocked.body.error.retry_after <= 600,
  `retry_after ${blocked.body.error.retry_after} elapsed ${elapsed}`,
);

A secondary option is to shrink the window through BOTSOCIAL_AUTH_RATE_LIMIT_WINDOW_SECONDS (src/auth-limit.ts:38) and assert the exact number, but both tests also assert the rendered sentence "Try again in about 10 minutes.", which is derived from the window, so that path needs the string assertions relaxed too and is the larger change.

Scope

Test-only. src/auth-limit.ts behaves correctly here: the refusal reports the true remaining wait.

Activity

  1. Birfy commented on Nov 30, 2026

    @Birfy
    CollaboratorAuthor

    Claimed for a test-only slice. Branch dev/3468-rate-limit-drift-window, cut from main (89e163ef).

    Scope: the two retry_after bounds in services/bot-social/test/console_rate_limit_notice.test.ts (:25, :43) become derived from the burst's own elapsed time; the console-string assertions and src/auth-limit.ts stay untouched. Patch and local readings come from Services Dev; the push and PR are done by the Lead.

  2. added
    bug
    agent-ready
    area:social
    agent-working
    on Nov 30, 2026
  3. Birfy commented on Nov 30, 2026

    @Birfy
    CollaboratorAuthor

    Landed on main as d57d6da41941822b9067cc579ad4944da3715eb3 (squash of #3469, merged 07:29:49Z through the merge queue).

    Verified against the reviewed head ed888b1f99e7bfa4923495523f508dc2061c4e0c: single parent 89e163ef, tree 8d620c66 — the same tree the review recorded — with three files: services/bot-social/test/console_rate_limit_notice.test.ts +11/-3 (blob c955c76b), docs/upstream/bot-social-files.json 0/-6 (blob e54e65e7), docs/upstream/migration-manifest.json +11/-1 (blob 5b0dbf82). All three blobs are byte-identical to the reviewed ones, and the squash message carries Related #3468 with no closing keyword.

    Closing as completed: the notice tests now derive their lower bound from the burst's own duration instead of assuming the burst fits inside two seconds, and the migration manifest records the edited imported file so the provenance jobs stay green. merge_group on this tree reported success (18/18 at the reviewed head; the merge queue run on d57d6da4 also completed success).

  4. removed
    agent-working
    agent-ready
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:socialbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions