Repository navigation
fix(broker): the callback rate-limit refusal is a redirect, not JSON (TASK-172 follow-up) - #1999
Merged
Merged
Conversation
…N (TASK-172) Vera's finding 75269, routed to its own PR by connector-ops 75275: the limiter that 3a added refuses in the wrong shape on one of its two routes. `publicGetRateLimit` answered `429` JSON for both. That is right for `client-metadata`, whose caller is the authorization server, and wrong for `callback`, whose caller is a browser mid-navigation — where this route's contract is that every outcome is a redirect to the page that can offer Connect again. A throttled person got raw JSON in the address bar on the one path where they are least able to work out what happened. No state was at risk (the limiter runs ahead of the row read), which is why it was not blocking. The factory now takes the refusal rather than hardcoding one: `jsonRefusal` for the server caller, `browserRefusal` — the route's own `callbackRedirect`, code `rate_limited` — for the browser. The arm is not a status assertion, because BOTH sides of the bound are 302, so the status can separate nothing: the discriminator is the `code` in the Location, asserted on the first 60 (`invalid_state`) and on the 61st (`rate_limited`). The other direction is asserted too, because the tempting fix is to change the shared handler and drag the document along with it: the document still refuses `429` JSON with no `Location`, measured to bite at request 601 — one past its own stated bound of 600, so the loop reads the real bound rather than a stale bucket. Evidence: 6 suites / 76 tests green; `tsc:check` clean; eslint 0 findings on the route. The ledger is 61 mutants on these bytes, baseline `(6, 76)` asserted before every run: 60 killed, 1 compiler-refused, NO SURVIVORS, NO NAMED-ARM MISSES, NO NOT-APPLIED. Four of the 61 are this change — the callback handed the JSON refusal at its call site, the factory ignoring the refusal it was handed, the code swapped away from `rate_limited`, and the document handed the browser refusal — all killed by the `code`/shape arms, none by `routeRateLimitGuard`, which cannot see any of them. The three earlier limiter mutants are re-anchored to the new call sites and still killed. Stacked on #1995 (`905e21b7`) because this file is not on main yet: its own delta is one hunk plus the third arm, and it collapses to that once #1995 merges and it is rebased.
samxu01
force-pushed
the
kai/hosted-mcp-callback-refusal
branch
from
September 29, 2026 13:06
eeac91c to
3f9a97d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slice 3a of TASK-172 made the callback rate-limited. This is its follow-up, routed to its own PR by connector-ops (75275) on Vera's finding (75269): the limiter's refusal is still shaped for the wrong caller.
publicGetRateLimitansweredres.status(429).json(...)on both routes. That is right forclient-metadata, whose caller is a server, and wrong forcallback, whose caller is a browser mid-navigation. The route's own docstring states the contract — every outcome is a redirect, because a person who refused consent has to land on the page that can offer Connect again — and a throttled person was the one case that broke it: raw JSON in the address bar on the path where they are least able to work out what happened. No state was at risk (the limiter runs ahead of the row read), which is why it was not blocking, and why it fell to a follow-up rather than to 3a.Shape. The factory now takes the refusal instead of hardcoding one:
publicGetRateLimit(max, label, refuse).client-metadatagetsjsonRefusal,callbackgetsbrowserRefusal, which iscallbackRedirect(res, 'error', 'rate_limited')— the same redirect the rest of the route uses, carrying a code the page can speak to.Why the arm is not a status assertion. A throttled callback and an unthrottled one are both 302, so the status can separate nothing. The discriminator is the
codein the Location, and the suite asserts it on both sides of the bound: the first 60 carrycode=invalid_stateand the 61st carriescode=rate_limited. An arm asserting only302would pass on this head and on the old one.The other direction is asserted too, because the obvious fix is to change the shared handler and drag
client-metadataalong with it: the document's refusal is still429JSON with noLocation. Measured rather than assumed — it bites at request 601 exactly, one past the route's stated bound of 600, so the loop is reading the real bound and not a stale bucket.Evidence
routeRateLimitGuard, and the armed-ness suite with its new third arm).tsc:checkclean; eslint on the route 0 findings./tmp/kai-172s3-ledger.py: 61 mutations, baseline(6, 76)asserted before every run — 60 killed, NO SURVIVORS, NO NAMED-ARM MISSES, NO NOT-APPLIED. Four of the 61 are this change: the callback given the JSON refusal at its call site, the factory ignoring the refusal it was handed, the code in the redirect swapped away fromrate_limited, and the metadata route given the browser refusal — all four killed by the twocode/shape arms, none by the guard, which cannot see any of them.M55–M57) are re-anchored to the new call sites and still killed, so this change does not quietly retire the earlier coverage.Ordering — #1995 landed, and this is rebased onto it
#1995 merged as
87c73258. All ten of its paths are byte-identical between905e21b7(the cleared head) andorigin/main(checked per path), so the squash landed verbatim and the base this PR needs is genuinely onmain.This branch is now rebased onto
87c73258: head3f9a97d1, and its own delta is 2 files, +70 / −19 — one hunk inroutes/hostedMcpConnect.tsplus the third test arm inhostedMcpConnect.rateLimit.test.js.The rebase moved the parent and nothing else, and that is measured rather than asserted:
git range-diff 905e21b7..eeac91c1 87c73258..HEADreturns=, and the commit's patch-id is unchanged (9cf4f201d0c77e1cef4f5022b8ba4d68a67e9542before and after). The bytes Vera walked ateeac91c1are the bytes here; only their parent differs. Re-run on the rebased head: 6 suites / 76 tests green, baseline(6, 76).Consequence for the gate, stated plainly: the
eeac91c1stamp is spent. A--ontorewrite moves the head, so that clearance names bytes that are no longer the branch tip (rule 32). Re-stamp requested at3f9a97d1; the walk should be quick because the content is content already reviewed.Why this had to be a rebase rather than a re-press: after #1995 squashed, merging this head as-is gives add/add conflicts in both files — witnessed by simulating the squash and the merge locally. A squash-merge never makes
905e21b7an ancestor ofmain, so an ancestry probe cannot be the press-time gate here; the landed test is the content onmain, and the press-time artifact is the two-file delta above.wren's #1998 (§10.2) states in the present tense that "a throttled callback still redirects to the page, with
rate_limited", which is false until this lands — so #1998 presses after this one.Gate: @vera.