Repository navigation
fix(broker): a suspended owner's connection stops authorising calls (TASK-181) - #2029
Merged
Merged
Conversation
samxu01
pushed a commit
that referenced
this pull request
Sep 29, 2026
…only hosted (§7) Rework after Vera's hold on #2029. The first cut diverged from the ratified plan on main in three ways, and the plan is specific: - The predicate now comes from `sessionAccountService` (`loadSessionAccount` + `sessionRefusal`), the one live-row read the session verifiers share. The service's own doc names the failure of recomputing it: a verifier that forgets one of the two fields in its projection reads `undefined` and refuses nothing. `select('banned')` omits `isBot`, so a bot-owned row stayed callable — for that reason alone, since `sessionRefusal` reads both fields together. A mutation that recomputes the predicate from `banned` alone is in the ledger and dies on the bot arm. - All three codes are rendered, each naming its own remedy: `connection_owner_banned` (lift the ban), `connection_owner_missing` (remove the row so its owner can be replaced), `connection_owner_bot`. A row with no `createdBy` at all is `missing` rather than a database question, so an uncastable value never reaches `findById`. - It applies to `hosted-mcp` ONLY. A `github-app` row's token belongs to the app installation, not to the admin who created the row, so suspending that admin must not disable the app connector for every pod holding a grant on it. The exclusion is pinned by an arm beside it, and the §7 inversion is a ledger mutant. One existing arm re-pointed, not deleted: the park-path arm showing that a permanent refusal keeps its own code used to reach `resolveApprovalPodId`'s `connection_mismatch` through a row with no `createdBy`. The owner check now refuses that fixture earlier and more specifically, so the arm walks the same path through `invalid_target` instead. Its subject is unchanged; only the cause moved, and the reason is in the comment. Ledger: 9 mutants, 9 killed, 0 survivors, 0 NAMED-ARM MISSES.
…TASK-181) A ban was enforced only at sign-in (`middleware/auth.ts`). An agent acting on someone's connection never signs in as them: it presents its own runtime token and the broker spends the owner's stored credential, so banning the person stopped the human and left the authority working — on both broker paths, since neither `mcpGrants`' agentRuntimeAuth nor the in-process native runtime reads `banned`. The check goes where every broker call already resolves the connection: `resolveConnection`, through one `assertOwnerNotBanned` called by both resolvers (the github-app branch and the hosted-MCP branch). Both paths — the MCP endpoint and `nativeRuntimeService` → `dispatchHostedBrokerTool` → `callTool` — reach it there, and a new connection type is a third call site the helper's doc names. Refusal is `connection_owner_banned`, 403, recorded on the trail like every other refused call, so the listing refuses too: a list is a capability disclosure and must not offer tools every call would reject. Two boundaries, both pinned by arms: a `createdBy` that cannot be an id shape is never looked up (the value is written server-side from the authenticated user's id and typed ObjectId; skipping keeps an uncastable string away from `findById`, whose CastError would otherwise have to be swallowed, and a swallowed database error would allow the call), and an owner row that no longer exists is not a ban — "no ban recorded" is not "banned". No migration and no new state: banned is already the User document's field.
…only hosted (§7) Rework after Vera's hold on #2029. The first cut diverged from the ratified plan on main in three ways, and the plan is specific: - The predicate now comes from `sessionAccountService` (`loadSessionAccount` + `sessionRefusal`), the one live-row read the session verifiers share. The service's own doc names the failure of recomputing it: a verifier that forgets one of the two fields in its projection reads `undefined` and refuses nothing. `select('banned')` omits `isBot`, so a bot-owned row stayed callable — for that reason alone, since `sessionRefusal` reads both fields together. A mutation that recomputes the predicate from `banned` alone is in the ledger and dies on the bot arm. - All three codes are rendered, each naming its own remedy: `connection_owner_banned` (lift the ban), `connection_owner_missing` (remove the row so its owner can be replaced), `connection_owner_bot`. A row with no `createdBy` at all is `missing` rather than a database question, so an uncastable value never reaches `findById`. - It applies to `hosted-mcp` ONLY. A `github-app` row's token belongs to the app installation, not to the admin who created the row, so suspending that admin must not disable the app connector for every pod holding a grant on it. The exclusion is pinned by an arm beside it, and the §7 inversion is a ledger mutant. One existing arm re-pointed, not deleted: the park-path arm showing that a permanent refusal keeps its own code used to reach `resolveApprovalPodId`'s `connection_mismatch` through a row with no `createdBy`. The owner check now refuses that fixture earlier and more specifically, so the arm walks the same path through `invalid_target` instead. Its subject is unchanged; only the cause moved, and the reason is in the comment. Ledger: 9 mutants, 9 killed, 0 survivors, 0 NAMED-ARM MISSES.
The owner check throws inside `resolveHostedConnection`, which is where `connection.ownerUserId` is resolved, so the catch's local was unset exactly on the row whose reason names the owner: a `connection_owner_banned` record could not answer "which suspended person's connection was this". The guard now carries the account id on the error's details and both catches prefer it over the local. Only an account-shaped id is carried — `VARCHAR(255)` is read as an owner id, so a malformed value would be a guess wearing a fact's clothes; the blank is more honest. Also pins Wren's rule (75546) as arms: a record names an owner only once the row is PROVEN the grant's own. `connection_mismatch`, `connection_untracked` and `connection_superseded` are that proof failing; a superseded row is the re-added one, whose `createdBy` never made the grant, so those refusals record nobody even though the row carries the owner. The docblocks now say so, and the superseded and untracked arms assert it against a fixture row that does carry an owner. No authority moves: this changes which string lands in the audit column, never whether a call is refused.
samxu01
force-pushed
the
kai/task181-broker-ban
branch
from
September 29, 2026 22:15
ff25d41 to
8476550
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.
The hole, at source
A ban is enforced at sign-in (
middleware/auth.ts:74) and on the socket handshake, and nowhere else. But the broker's caller is an agent, which never signs in as the owner: it presents its own runtime token (mcpGrants.ts:50→agentRuntimeAuth, which does not readbanned) and the broker spends the credential the owner connected. The in-process path (nativeRuntimeService.ts:1110→dispatchHostedBrokerTool→callTool) is the same shape. So banning a person stopped the person and left their authority running.Checked first, because it bounds the fix: bots cannot be banned at all —
routes/admin/users.ts:249refusesisBottargets.bannedis a human-only state, and the gap is exactly the human's hosted row outliving their ban.The fix — plan §7, as ratified
assertHostedOwnerUsable, called fromresolveHostedConnection. Both broker paths funnel throughresolveConnection, so the check sits where the credential is chosen rather than in either driver.sessionAccountService(loadSessionAccount+sessionRefusal), the one live-row read the session verifiers share. That is not style: the service's own doc names the failure of recomputing it — "a verifier that forgets one of the two fields in its projection readsundefinedand refuses nothing." A check written asselect('banned')omitsisBot, so a bot-owned row stays callable;sessionRefusalreads both fields together. The ledger carries that exact mutation (M07) and it dies on the bot arm.connection_owner_banned(lift the ban),connection_owner_missing(remove the row so its owner can be replaced),connection_owner_bot. All 403, besideconnection_superseded.createdByismissing, not a database question: an id that cannot name an account never reachesfindById, whoseCastErrorwould arrive as a 500.hosted-mcponly. Agithub-approw's token belongs to the app installation, not to the admin who created the row, so a suspension must not disable the app connector for every pod holding a grant on it. The exclusion is pinned by an arm beside the code, and inverting it is ledger mutant M02 (23 red).listToolsForGrant,callToolandexecuteApprovedToolCallall resolve through it, so one check covers the offer, the call, and a call approved after the ban. Nothing is written when the ban is set, and a lifted ban needs no reconnect. A refused list writes no row, because a list is not a call.One existing arm re-pointed rather than deleted
The park-path arm showing that a permanent refusal keeps its own code used to reach
resolveApprovalPodId'sconnection_mismatchthrough a row with nocreatedBy. The owner check now refuses that fixture earlier and more specifically, so the arm walks the same path throughinvalid_targetinstead. Its subject is unchanged — only the cause moved — and the comment says so, because a guard added above an existing one can invalidate the arms below it without changing a line of them.A refused owner refusal records the owner it names (vera 75542)
The guard throws inside
resolveHostedConnection, which is whereconnection.ownerUserIdis resolved, so the catch's local was unset on exactly the row whose reason names the owner: aconnection_owner_bannedrecord could not answer which suspended person's connection was this. Not an authority gap — an audit one.The guard now carries the account id on the error's details and both catches prefer it over the local (
refusedCredentialOwner). Only an account-shaped id is carried (/^[a-f\d]{24}$/i): the column is read as an owner id, so a malformed value would be a guess wearing a fact's clothes — the blank is more honest. The empty case stays blank either way. Two sites still deliberately record no owner, and both readundefined, not a guess: a call refused before a connection resolved, and a row with nocreatedBy.No authority moves. This changes which string lands in the audit column, never whether a call is refused.
Wren's rule (75546), pinned as arms
A record names an owner only once the row is PROVEN the grant's own.
connection_mismatch,connection_untrackedandconnection_supersededare that proof failing, and they record nobody: a superseded row is the re-added one, whosecreatedBynever made the grant. The owner check runs after the proof, so its codes carry the id as staged.Verified at source rather than taken:
resolveHostedConnectionruns type/status/revokedAt→entryIdmatch → both creation timestamps (connection_untracked) → supersession (connection_superseded), and only then readsrow.createdBy. So the rule holds by construction, and it is now pinned by fixtures that would read the row's creator — the superseded and untracked arms assert the refused row'scredentialOwnerIdisundefinedwhile their fixture row carriesOWNER. The three docblocks (recordCall's overrides,refusedCredentialOwner, and thecallToollocal) now state the rule instead of an over-broad claim.Evidence at
84765504Rebased onto main
8e3270ef(#2028 landed as1d0b82b9), so this branch is cut from current main and not stacked.toolBroker|approval|ToolCall|grants|seatGrant|roomGrant|nativeRuntime|sessionAccount|hostedMcp— 44 suites / 426 passed / 0 failed.agentsRuntime.rateLimitTiersunder full-suite load; it passes 3/3 in isolation (verified this run).eslintonservices/toolBrokerService.ts: 0 findings;tsc:checkclean and the touched files add no error to the fulltsc --noEmit(its 50 errors are all in four root scratch files). Modified test files: +0 / −1 against main by message-multiset diff (max-len, on a line this branch rewraps)./tmp/kai-181-rebase-ledger.py, occurrence-asserted anchors with explicitnth, pristine restored after every run, baseline asserted before every run): 13 mutants / 13 killed / 0 survivors / 0 compiler-refused / 0 NAMED-ARM MISSES / all files restored. Nine for the owner check (call site, the §7 inversion, each code mapping, the status, the predicate recomputed frombannedalone, a missing id sent to the database, the check reading the seat instead of the owner), three for the carried id (the refused row ignoring what the guard carried, the guard refusing without carrying it, a value that names no account recorded anyway), and one for Wren's rule (a proof-failing refusal recording the row's owner anyway).Landed: the merge-order note is resolved
#2028 pressed as
1d0b82b9; this head is rebased past it. The two assertions the note named — the parked-call arm'scredentialOwnerIdand the approval-proposal arm'scredentialOwnerId— now readOWNER, as the note said they must.'owner-1'remains correct only inside the malformed-owner arm, where naming no account is the point.Gate: Vera (code), asked at this head.