Skip to content

fix(app): a long poll refused a waiter slot says so, instead of looking like a quiet room - #567

Merged
sv merged 7 commits into
mainfrom
claude/long-poll-refusal-says-so
Aug 30, 2026
Merged

sv merged 7 commits into
mainfrom
claude/long-poll-refusal-says-so

Conversation

@sv

@sv sv commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What

When ?wait= cannot get a waiter slot, the reply says so instead of looking like a quiet room: a # wait: not held footer naming which cap was hit, and wait_held in the JSON view (declared in _ROOM_VIEW_SCHEMA, so /openapi.json publishes it). The degradation is unchanged — a refused caller still gets an immediate empty reply with the same data.

Why

_await_messages returned None both for "held ten seconds, nothing came" and for "never waited at all", and room_read rendered 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.json carries core/limit.py 171 → 183, the twelve lines of waiter_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 main at 0f69b65, and against a live server with CHAT_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 . and uv run ty check; uv run sz.py --caps clean
  • The contract job run locally against the live /openapi.json — 845 cases, no issues
  • Docs that would now be wrong are updated: src/manual.md, CHANGELOG.md
  • New surface on a world-writable service: nothing new — no new route, parameter or capability. It tells a caller to make fewer requests.

protected-files is red on the queue-guard defect fixed in #570, not on this change — see the comment below.

…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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-30T13:41:42.227223Z aa9017e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/app.py Resolved
…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

sv commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Scan for related issues and PRs

I 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

Copy link
Copy Markdown

There is one remaining caller-facing documentation mismatch on current head c657b17:

CHANGELOG.md still says the new refusal signal is "text/plain only" and that ?format=json is "unchanged". But this head now adds wait_held to the JSON view (false when no waiter slot was acquired, true when the wait was held and returned empty), and publishes that field in _ROOM_VIEW_SCHEMA.

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 wait_held field alongside the text footer rather than saying JSON is unchanged.

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.

sv commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the last bullet above — I asserted the collision with the limit.py concurrency queue without reading those diffs, and it is wrong in both directions:

The rest of the scan stands as written.

Separately, re-reading waiter_note after that scan turned up a stale claim of my own: its docstring still said the signal reaches text/plain only and that ?format=json renders the view alone, which stopped being true when c657b17 added wait_held — the exact gap the review thread was about, left behind in the prose. Fixed in fd30061 (docstring only; no cap movement, full gate re-run green).


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.

sv commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

@yukkie3276 — correct, and thank you. Fixed in 6fe789e: the entry now says the fact is not text/plain only, and names wait_held with its three states and the fact that /openapi.json publishes it; the caller note asks readers to expect both spellings.

Worth recording why it happened, since it is the second instance: c657b17 changed the JSON lane in response to review, and the prose written when the signal really was text-only survived in two places — waiter_note's docstring (fixed in fd30061, caught while reading the module) and this changelog entry, which you caught. The compatibility guidance is the worse of the two to get wrong, because it is the one a client author reads instead of the code.

Gate re-run on 6fe789e: 534 passed, ruff check / ruff format --check / ty check clean, sz.py --caps unchanged (both fixes are prose).


Generated by Claude Code

claude and others added 2 commits August 30, 2026 14:49
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.

sv commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

protected-files is red here on CHANGELOG.md, sz-baseline.json (run), from the queue-guard merged in #569 while this PR was open.

It is not this PR's failure: the job exempts OWNER/MEMBER/COLLABORATOR, and the API reports this PR's author as MEMBER, so the payload's author_association carried something else. Nor can it be fixed from here — pull_request_target runs the workflow from the base branch, so a change on this branch has no effect on the check. Fix opened as #570, which adds the fact that cannot be wrong: a head branch in this repository needs write access to push, and the fork PRs the guard exists for never have one. It will red #539 the same way on its next push.

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 CHANGELOG.md entry is here because the change is caller-visible, and sz-baseline.json carries core/limit.py 171 → 183 because waiter_note is twelve core lines and core has one line of headroom left. Say the word and the release note moves into the body; the cap is the call the ratchet exists to make you make, and #570 does not change who makes it.


Generated by Claude Code

sv added a commit that referenced this pull request Aug 30, 2026
…#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.
@sv
sv merged commit 5b6b8f8 into main Aug 30, 2026
5 checks passed
@sv
sv deleted the claude/long-poll-refusal-says-so branch August 30, 2026 15:33
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Aug 31, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 1, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 2, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 3, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 3, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 6, 2026
…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.
Magicianhax pushed a commit to Magicianhax/technocore-chat that referenced this pull request Sep 8, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants