Skip to content

fix(broker): the callback rate-limit refusal is a redirect, not JSON (TASK-172 follow-up) - #1999

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/hosted-mcp-callback-refusal
Sep 29, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/hosted-mcp-callback-refusal

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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.

publicGetRateLimit answered res.status(429).json(...) on both routes. That is right for client-metadata, whose caller is a server, and wrong for callback, 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-metadata gets jsonRefusal, callback gets browserRefusal, which is callbackRedirect(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 code in the Location, and the suite asserts it on both sides of the bound: the first 60 carry code=invalid_state and the 61st carries code=rate_limited. An arm asserting only 302 would 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-metadata along with it: the document's refusal is still 429 JSON with no Location. 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

  • 6 suites / 76 tests green (the four slice suites, routeRateLimitGuard, and the armed-ness suite with its new third arm). tsc:check clean; eslint on the route 0 findings.
  • Mutation ledger /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 from rate_limited, and the metadata route given the browser refusal — all four killed by the two code/shape arms, none by the guard, which cannot see any of them.
  • The three pre-existing limiter mutants (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 between 905e21b7 (the cleared head) and origin/main (checked per path), so the squash landed verbatim and the base this PR needs is genuinely on main.

This branch is now rebased onto 87c73258: head 3f9a97d1, and its own delta is 2 files, +70 / −19 — one hunk in routes/hostedMcpConnect.ts plus the third test arm in hostedMcpConnect.rateLimit.test.js.

The rebase moved the parent and nothing else, and that is measured rather than asserted: git range-diff 905e21b7..eeac91c1 87c73258..HEAD returns =, and the commit's patch-id is unchanged (9cf4f201d0c77e1cef4f5022b8ba4d68a67e9542 before and after). The bytes Vera walked at eeac91c1 are 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 eeac91c1 stamp is spent. A --onto rewrite moves the head, so that clearance names bytes that are no longer the branch tip (rule 32). Re-stamp requested at 3f9a97d1; 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 905e21b7 an ancestor of main, so an ancestry probe cannot be the press-time gate here; the landed test is the content on main, 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.

…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
samxu01 force-pushed the kai/hosted-mcp-callback-refusal branch from eeac91c to 3f9a97d Compare September 29, 2026 13:06
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit ce0ed17 Sep 29, 2026
20 of 23 checks passed
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.

1 participant