Repository navigation
fix(app): a long poll refused a waiter slot says so, instead of looking like a quiet room - #567
Conversation
…ng like a quiet room `?wait=` degrades to an immediate empty reply when MAX_WAITERS_TOTAL or MAX_WAITERS_PER_IP is full. That degradation is right and stays — a caller that cannot get a slot gets the data it would have got anyway. What it could not get was the reason: `_await_messages` returned None both for "held your ten seconds, nothing came" and for "never waited at all", and `room_read` rendered them as the same bytes. So the correct next move (sleep, then retry) and the ruinous one (poll straight back) looked identical from outside, and a caller with no other signal does the ruinous one. It then re-polls at whatever rate it can emit requests until RATE_READ runs out and the 429 finally explains something — by which point it has burned the read budget it wanted for real reads. limit.py already said a refused caller is "exactly as well off as before long-polling existed", which was true of the data and false of the advice: before long-polling, a caller knew it was polling. `limit.waiter_note` is the missing signal, a sibling of `budget_note` on the same seam — advice appended to an otherwise ordinary reply, warning before the wall rather than at it. It names which cap was hit because the remedies differ: a caller holding its own limit must reduce its concurrency, one refused by the global cap can only wait for the instance to quieten. The `ip` is passed in rather than re-derived because `client_ip` counts proxy evidence as a side effect, and `_await_messages` now returns `(view, note)` so the reason travels with the answer instead of being inferred. The manual previously told callers to "treat a fast empty reply as no slot" — inference from latency, which a caller cannot do reliably and a model cannot do at all. It now documents the line, and says that its *absence* means the wait really was held. text/plain only, exactly like the budget footer: `?format=json` renders the view alone, and adding a field there would change the published schema. Pinned by a test so the asymmetry stays a decision rather than a surprise. Size caps raised deliberately (AGENTS.md): app.py 1017 -> 1018, limit.py 171 -> 183, core_total 2240 -> 2245. The twelve lines are `waiter_note` itself; the distinction it draws is a new primitive in the protocol — a reply that says it was refused, not merely one that is empty — and it saves a caller its entire read budget. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DW3UH854H2GYNgwRuABFmr
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa9017e35d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ed field Codex on #567: `?format=json` got no signal, so a program on the documented machine lane still could not tell an immediate refusal from a wait that timed out — the exact failure this change exists to fix, and the one the manual's new sentence claimed was gone. I had pinned that asymmetry with a test arguing consistency with `budget_note`. The precedent was real and the conclusion was wrong: `budget_note` never had a manual line promising what its absence means, and a JSON caller is likelier to poll in a tight loop than a model reading prose, so the lane that most needed the signal was the one without it. The view now carries `wait_held` when a `wait=` read returned no messages: true when the wait was held and the room stayed quiet, false when no slot was free. Positive in both directions, so nothing has to be inferred from an absence — and absent entirely when messages arrived, since a wait that produced them was held by definition. It is declared in `_ROOM_VIEW_SCHEMA`, so /openapi.json publishes it rather than a machine reader discovering it by surprise; schemathesis passes 845 cases against the live document. It also cost nothing: folding the verdict into the existing view assignment removed a line, so app.py is back at 1017 and its raised cap is handed back. Only limit.py's ratchet stands (171 -> 183, `waiter_note` itself), and core_total drops 2245 -> 2244. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DW3UH854H2GYNgwRuABFmr
Scan for related issues and PRsI went through all 90 open issues and the open PR queue looking for anything on the waiter path, empty-reply ambiguity, polling cost, or the room-view schema. Nothing open tracks this bug, so this PR closes no issue — everything below is related, not fixed by. Issues
Pull requests
Generated by Claude Code |
|
There is one remaining caller-facing documentation mismatch on current head
So a generated-client/user reading the changelog gets the opposite compatibility guidance from the actual API and from the updated manual/PR description. The changelog entry should mention the optional JSON |
c657b17 gave ?format=json its own spelling of the refusal (wait_held), but this docstring still said the signal stopped at text/plain — the claim the review thread had just shown to be the bug.
|
Correction to the last bullet above — I asserted the collision with the
The rest of the scan stands as written. Separately, re-reading Generated by Claude Code |
The entry still promised "text/plain only; ?format=json is unchanged", which c657b17 made false. Reported on the PR by @yukkie3276.
|
@yukkie3276 — correct, and thank you. Fixed in Worth recording why it happened, since it is the second instance: Gate re-run on Generated by Claude Code |
The same argument was made at length in five places. Each keeps the part its reader needs — the docstring the rationale, app.py the two placement reasons, the schema and manual what a caller does — and drops the retelling. Net -16 lines of prose; no code, and no cap, moves.
|
It is not this PR's failure: the job exempts I have not re-run the check — it is deterministic, not flaky, and will stay red until #570 lands. The rule itself still lands on this PR once the check is honest, and both hits are deliberate rather than accidental: the Generated by Claude Code |
…#570) The protected-files job exempts OWNER/MEMBER/COLLABORATOR by the webhook payload's author_association, and that value did not report MEMBER on #567, whose author the API does report as MEMBER — so the guard failed a maintainer PR it was written to exempt, and would fail every one that touches CHANGELOG.md or sz-baseline.json. Adds the fact that cannot be wrong: a head branch in this repository needs write access to push, and the fork PRs this guard exists for never have one. The association test stays first, so nothing that passed before changes.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
…pin the invariant @zkasuran picked both up while closing flop-labs#359 as a duplicate of this PR. flop-labs#567 wrote two comments stating client_ip counts proxy evidence as a side effect — app.py's `ip = client_ip(request)` in the long-poll lane and limit.py's docstring on the waiter-slot verdict. Moving the tally to take() makes both false; passing `ip` in is now an efficiency, not a correctness requirement. Also records the invariant the new placement rests on: every request makes exactly one non-create take. Walked at 019b57a — 13 `take(request` sites in app.py, twelve non-create and one per handler, the thirteenth the creation gate. A future handler taking twice outside the gate would resurrect the over-count. Comments only, no code lines.
What
When
?wait=cannot get a waiter slot, the reply says so instead of looking like a quiet room: a# wait: not heldfooter naming which cap was hit, andwait_heldin the JSON view (declared in_ROOM_VIEW_SCHEMA, so/openapi.jsonpublishes it). The degradation is unchanged — a refused caller still gets an immediate empty reply with the same data.Why
_await_messagesreturnedNoneboth for "held ten seconds, nothing came" and for "never waited at all", androom_readrendered them identically. So "sleep, then retry" and "poll straight back" looked the same from outside, and a caller with no signal picks the second — spending its read budget at wire speed against an instance already saturated enough to be refusing slots. The manual's old advice, treat a fast empty reply as "no slot", asked callers to infer that from latency.Two judgment calls: the note names which cap was hit, because the remedies differ; and
sz-baseline.jsoncarriescore/limit.py171 → 183, the twelve lines ofwaiter_note. A reply that says it was refused rather than merely empty looks like a new primitive to me, but the ratchet exists so that you make that call — the fallback is a terser note without the per-cap distinction.Caller-visible: anything parsing room reads should expect the footer beside the budget one, and the new optional JSON field.
Verified against
mainat0f69b65, and against a live server withCHAT_MAX_WAITERS_TOTAL=0; the text-lane test is negative-controlled.Checks
uv run coverage run -m pytest tests -q && uv run coverage report— 534 passed, 97.38%uv run ruff check . && uv run ruff format --check .anduv run ty check;uv run sz.py --capsclean/openapi.json— 845 cases, no issuessrc/manual.md,CHANGELOG.mdprotected-filesis red on the queue-guard defect fixed in #570, not on this change — see the comment below.