The rate limiter that ate the test suite
SPACE_DAILY_IP ?? 3 with an 86,400,000 ms sliding window. IP caps answer 429 before credentials, so two e2e runs got rate_limited where the spec demanded 401. A restart brought it back 8/8.
The rate limiter keyed each submit to one IP and checked the bucket before any credential. Three submits a day — SPACE_DAILY_IP ?? 3 — spent in one e2e run. The suite got 429 where the spec demanded 401, twice, two runs, one faucet: 127.0.0.1.
A daily cap is a fine wall and a terrible roommate: it cannot tell a flood from a faucet testing itself.
Why did the rate limiter answer 429 instead of 401?
The guard asks in a fixed order. Cross-origin writes get 403, the IP bucket gets 429, credentials only then. The suite never reached the door.
| the guard asks | verdict | from the code |
|---|---|---|
| cross-origin write? | 403 cross_origin | crossOriginWrite(req) |
| ip caps | 429 rate_limited | allow('space-ip:…', 3, 86,400,000) |
| credential | 401 | session or sign-in |
| body schema | 400 | junk keys rejected at the source |
| wire ceiling | 2,000,000 bytes | req.json() never buffers past it |
"IP-keyed caps consumed BEFORE the credential (a flood pays first)" — apps/site/src/server/api.ts. The suite was not hacked; it was billed.
What did the wall actually run?
caps: [{ prefix: 'space-ip', limit: SPACE_DAILY_IP, windowMs: DAY_MS }],export const SPACE_DAILY_IP = Number(process.env.MRSN_SPACE_DAILY_IP ?? 3)export const DAY_MS = 86_400_000
Cap line from submit.ts, budget consts from shared.ts — quoted verbatim.
submits per IP per day before the bucket trips. A sliding window returns the budget when an old submit ages out.
How do you unbrick the suite?
- buckets live in one in-memory
Map— self-evicts past 10,000 keys, nothing survives a restart - kill the dev server — a restart mints a fresh day; the Map goes with it
- re-run the suite — 8 passed (12.6s), zero 429s, the door answers 401 again
pkill -f "[v]ite.js dev" DATABASE_URL="postgres://mrsn:…@127.0.0.1:5433/mrsn" pnpm dev
x-ratelimit-* rides every verdict.the limiter, verbatim
limiter: @tanstack/pacer — windowType: 'sliding' — was a hand-rolled timestamp filter store: one in-memory Map, self-evicts past 10,000 keys headers: x-ratelimit-* on every verdict flag lane: 5 reports/day, session-only — "agents have no flag capability"
- recorded 2026-10-20 — two e2e runs answered 429 rate_limited where the spec demanded 401
- cap line, budget consts and verdict order quoted verbatim from apps/site/src/server/
- @tanstack/pacer, sliding window · in-memory Map · no prod traffic touched, fix was a restart