Repository navigation
fix(broker): bound every vendor call, and build the metadata URL RFC 8414 names (TASK-172) - #2006
Merged
Merged
Conversation
…8414 names (TASK-172) The three items left over from slice 3a's review, all hardening: - Every outbound hosted-MCP call now carries a deadline (`upstreamFetch`, `UPSTREAM_TIMEOUT_MS = 15s`). Discovery, the code exchange and the refresh all went through bare `fetch`, so a vendor that accepted the connection and then went quiet held its caller — a browser sitting on the callback, or a seat's tool call — until the OS gave up. All three already map a transport failure onto a named state, so the deadline arrives as `issuer_unreachable` / `exchange_unreachable` / `refresh_unreachable` with no new error surface. - Discovery inserts the well-known segment BETWEEN the host and the issuer's path (RFC 8414 §3.1). The old shape appended it, which agrees for a bare origin and is wrong for every issuer mounted under one; an issuer that is not a URL, or that carries a query or fragment (§2 forbids both), is refused rather than interpolated into a URL that reaches a host the entry never named. - `buildAuthorizeUrl` joins the endpoint's own query: `&` when one is already there, and nothing at all when it ends in `?` or `&`. Appending `?` blind turns a vendor's own parameter into an empty one and moves `client_id` into a query it does not parse. Evidence: baseline (4, 76); tsc:check clean; eslint clean on the four sources; ledger 15 mutants — 14 killed, 1 recorded EQUIVALENT and measured rather than argued (the ledger applied it and the suite passed 76/76, because the arm asserts WHICH failure arrives and an ignored timeout parameter still produces it, fifteen seconds later instead of in twenty milliseconds), no survivors, no named-arm misses, no not-applied. The call-site arms are the point: each of the three fetches asserts the signal it was handed, so a deadline that reaches discovery and stops there is a red rather than a half-fix, and the refresh arm asserts a timed-out vendor arrives as a retryable failure with the lease still held.
This was referenced Sep 29, 2026
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…cument claims (TASK-172) (Team-Commonly#2007) * fix(broker): compose the caller's signal, and check the issuer the document claims (TASK-172) Two guards the vendor path was missing, both recorded by the Team-Commonly#2006 review rather than blocking on it: - `upstreamFetch` composed nothing: `{ ...init, signal: AbortSignal.timeout(…) }` reads as though `init` were honoured and silently drops the one field in it that cancels. A caller's signal is now composed with the deadline instead of replaced, and the arms cover both directions — a caller who aborts stops the call, and a caller whose signal never aborts still hits the deadline. No caller passes one today (all three take the default), so this is the difference between a wrapper that is bounded and one that is bounded AND cancellable. - Discovery read endpoints out of the metadata without ever comparing the document's `issuer` to the issuer the URL was built from. RFC 8414 §3.3 requires them identical, and what the check defends is the next line of the flow: `authorization_endpoint` is where the person's browser is sent, so a document written for another issuer hands that consent to whoever wrote it. A missing `issuer` is `issuer_metadata_incomplete` (§2 makes it REQUIRED); a different one is the new `issuer_mismatch`, which the start route maps to a 502 with the other vendor-side states. Evidence: baseline (3, 50); tsc:check clean; eslint clean on the three sources; ledger 10 mutants — 9 killed, 1 recorded equivalent, no survivors, no named-arm misses, no not-applied. The equivalent is measured rather than argued: applying it leaves the suite 50/50, because the arm asserts WHICH failure arrives and an ignored timeout parameter still produces it, fifteen seconds later rather than in twenty milliseconds. * test(hosted-mcp): give every metadata fixture the issuer §3.3 requires The credential suite's METADATA was the only one that failed, because it is the only one whose discovery is real rather than mocked: with no `issuer`, the new check refuses the document and the refresh arm dies on `authorization server metadata names no issuer` — a red that says nothing about the deadline it is testing. The two mocked stubs (connect's AS_METADATA, callback's discovery return) are corrected in the same pass: they stand in for a conformant vendor today and would have been a live trap the moment either was wired to real discovery. * test(broker): the mid-flight fence arm waits at the winner's commit seam, not on a budget The arm failed in 4 of 8 isolated runs BEFORE this change, always the same way: the loser's `WINNER_WAIT_MS` budget elapsed while the winner was still writing the row, so the loser refused `credential_refreshing` and the arm read as the fence having broken. The clock is the reason, and it is the same defect Team-Commonly#2004 removed elsewhere. This suite injects `sleep`, which advances a VIRTUAL clock, while the winner's progress — its vendor call, its `commit` — is real. A poll loop therefore spends 1500 virtual milliseconds in microseconds of real time: the budget expires faster than the work it is waiting for, and which side wins is decided by mongod's scheduling. A budget that expires faster than the work it waits for is not a budget. So the loser's first poll still wakes the winner and then WAITS for the winner's commit at its seam, which the suite now wraps alongside the bump. The arm turns on the store's state — a fresh row means the winner wrote — instead of on which task the event loop ran first, and the deadline keeps its deterministic witness in `a live lease is not takeable`, where nothing else can move the row. Witnessed by instrument rather than by a quiet re-run: - 10/10 isolated runs green, against 4/8 red before - mutant S1 (the fence takes no lease at all — the defect this arm exists for) still turns it RED, along with two sibling arms, so the seam did not hollow it out - mutant S2 (`preImageWasStale &&` dropped from the loser's freshness check) SURVIVED: that clause is not a tautology, so this is an UNWITNESSED BRANCH, not an equivalence — the corner it covers (no `credentialRef` while `expiresAt` is fresh) has no arm, and whether refusing `credential_refreshing` there is right is a behaviour question for the board, not something to pin inside a test-only diff * test(broker): the incomplete-document arm names the issuer, so the endpoint guard is witnessed again Vera's catch, and it is the good kind: my §3.3 check landed ABOVE the endpoint guard, and this arm sent a document with no issuer. It went on refusing, with the SAME error code as a missing endpoint, so deleting the endpoint guard outright changed no test in the neighbourhood (she measured 102/102 green; I reproduce it). The refusal was never in doubt — its ATTRIBUTION was. Two defects, one code, and the arm was pinning whichever ran first. So the document carries an issuer on purpose, and the arm pins its MESSAGE as well as its code — the message is the only thing that tells the two apart, which is why the no-issuer arm pins its own message too. Witnessed by mutant: delete `if (!body.authorization_endpoint || !body.token_endpoint)` and this arm is the one that goes red, by name, alone. 13 suites / 155 tests green otherwise.
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.
The three items left over from slice 3a's review (recorded non-blocking in
#1995), now that the rest of the stack has landed: a deadline on every vendor call, the RFC 8414 metadata URL, and the authorization request's separator. Hardening rather than capability — no new state, no new error code.1. Every outbound call is bounded
upstreamFetchsetsAbortSignal.timeout(UPSTREAM_TIMEOUT_MS)— 15s — on all three calls: discovery, the code exchange, and the refresh. All three previously used barefetch, so a vendor that accepted the connection and then went quiet held its caller — a browser sitting on the callback, or a seat's tool call — until the OS's own socket timeout, which is minutes.No new error surface was needed: each site already maps a transport failure onto a named state, so a deadline arrives as
issuer_unreachable,exchange_unreachable, orrefresh_unreachable. The third is the interesting one — a timed-out refresh is a retryable failure, and the lease stays held, so a vendor having a bad moment is damped by the backoff rather than retried by every caller queued behind it.timeoutMsis a parameter with the shipped constant as its default. That is a test seam: an arm cannot wait fifteen seconds, and the mechanism (a stalled fetch refuses at the deadline) is asserted once, inupstreamFetch.test.js, with a 20ms deadline.2. Discovery builds the URL RFC 8414 §3.1 names
The well-known segment goes between the host and the issuer's path —
/tenantresolves at/.well-known/oauth-authorization-server/tenant. The old shape appended it, which is identical for a bare origin and wrong for every issuer mounted under a path. The bare-origin arm that already existed cannot witness the rule, so the new arm uses a path-bearing issuer, with the appended shape asserted not to be what was sent.Two refusals came with it: an issuer that is not a URL, and one carrying a query or fragment (§2 forbids both), are refused as
issuer_unreachablerather than interpolated — interpolating builds a URL that reaches a host or path the entry never named and then reports the result as that entry's metadata. The arm has a positive control: the same stub is called for a well-formed issuer, so "the network was not reached" is a refusal rather than a stub that never ran.3. The authorization request joins the endpoint's own query
buildAuthorizeUrlused to append?unconditionally. It now uses&when the endpoint already carries a query, and no separator at all when it ends in?or&(a vendor inviting parameters) — appending?blind turns that into an empty parameter and movesclient_idinto a second query the vendor does not parse.Evidence
(4, 76)— the four suites whose arms name these claims; the widerhostedMcpset is 11 suites / 126 tests green, so no existing arm regressedtsc:checkexit 0; eslint 0 on the four changed sourcesThe one equivalent is worth naming because it is a measurement rather than a judgement: M04 ignores
timeoutMsand uses the shipped constant. The ledger applied it and the suite passed 76/76 — the arm asserts which failure arrives, and an ignored parameter still produces it, fifteen seconds later instead of in twenty milliseconds. The parameter is a seam for the arm's own duration; nothing outside the suite reads it. Recorded rather than papered over with an elapsed-time assertion, which would be a wall-clock budget in a suite — the exact thing the previous review round removed one of.The arms that make the deadlines load-bearing
Each of the three call sites asserts the signal it was handed (discovery, the route's exchange, and the shipped refresh path with only the socket stubbed), so a deadline that reaches discovery and stops there is a red, not a half-fix. The refresh arm additionally asserts the timed-out vendor arrives as retryable with the lease still held.