Repository navigation
fix(grants): the broker call refuses a seat that cannot confine it (TASK-175) - #1971
Merged
Merged
Conversation
samxu01
force-pushed
the
kai/task175-broker-refusal
branch
from
September 27, 2026 13:06
1699799 to
9886cb9
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.
TASK-175. The confinement refusal ran where the broker is offered — the server projection, the grant read, the daemon's derive — and never where it is used.
routes/mcpGrants.tshanded any caller holding a token and a grant id straight tocallTool. For a write that is bounded by the approval park; for a read it is not bounded at all (reads never park, scope note §5), so confinement was the only bound and it held only on the offering side. Grant-generic, not hosted-specific. Backend only — no version bump (the onecli/file is a test).The two halves
1. The adapter is
runtime.adapterORruntime.runtimeType.commonly agent attach piwritesconfig.runtime = {runtimeType: 'pi', host: 'byo'}with noadapterkey (cli/src/commands/agent.js:664falls back to the adapter's name for the tag,:688writes the pair), so the old rule —normalizeAdapter(runtime.adapter)— admitted exactly the seat it exists to refuse. A declaredadapterstill wins, as it does in the daemon (daemon.js:142); a row naming neither field is still not refused, because undeclared the daemon resolves only claude or codex, never pi, and failing closed there would refuse working claude seats.2. The refusal now runs at the broker call. A new
judgeSeatConfinementresolves the calling seat through the sameprojectSeatEnvironmentsthe daemon's work list is built from, andcallTool+listToolsForGrantthrowRoomGrantError('grant_broker_unconfined', <the predicate's detail>, 403, {reason, decidedBy})— the shared catch trails itrefused, and it runs before the connection is resolved, the approval parked, and the budget line reserved, so a refusal is not a spendable call.tools/listis refused too: a seat that may not use the grant must not be handed its definitions (TASK-146's rule, now for the seat's own confinement).Placement disclosed: Wren's wording was "the grants endpoint evaluates … before callTool". I put it inside the two service functions that endpoint calls, not in the route, because the
ToolCalltrail row and the budget reserve live there — a route-level refusal would have been untrailed, which the same sentence requires. It is still the endpoint's judgement, before any tool work, on both verbs.Who judges the seat.
req.agentInstallationisinstallations[0]on the bot-token path and can name a row from another pod, so the row is not the authority. The owners consulted are the installers of the seat's own installation rows, and this is complete rather than a sample:projectSeatEnvironmentsfilters{installedBy}and keys each entry by the row's identity, so a seat can appear in a projection only when that owner installed one of its rows. Every installer is consulted, so two projections that disagree fail closed — the refusing one wins, whichever order they are scanned in.The native path is out of scope (
hosted: true, set only bygrantBrokerProjectionService.dispatchHostedBrokerTool): a hosted turn has no shell, web or file tools, so there is nothing for a sandbox to confine (Wren 74882). Without the flag a hosted seat carrying a pi declaration would be refused the path the ruling excludes.Evidence
seatGrantConfinement.test.jsis new and runs on memory Mongo with realRoomGrant/User/AgentInstallationrows — the resolution and the predicate are the things under test, and a mocked model would prove a fact about the mock. The broker call is driven end to end against a real grant (assertGrantUsablereal); only the Postgres trail, the connection and the provider are mocked, as the neighbouring broker suites do. No Postgres is reached.nonerefused,{public, workspace}passing to the audience check, absent passing, a refused call not spent, and the{runtimeType:'pi'}/{runtimeType:'claude-code'}pair — plus the two he added at 12:48Z ({host:'byo'}with neither field admitted;{adapter:'claude', runtimeType:'pi'}admitted) and the webhook connect-page seat.claude-coderuns; the list resolves;grant_revokedstill wins overgrant_broker_unconfined(the new check does not preempt grant-level rules).cli/__tests__/adapter-confinement-parity.test.mjsassertslistAdapterNames()minus claude/codex/stub equals['pi'], with a comment namingCONFINEMENTLESS_ADAPTERS. The two literal pins are the guard, because neither side can import the other and the polarities are opposite (backend denylist, daemon allowlist).Ledger — 12 mutations, 11 killed, one disclosed survivor
Each run asserts the
(suites, tests)pair, so a suite that fails to compile cannot read as a kill. Killed: the runtimeType fallback dropped (predicate-level and call-level), the hosted exemption removed, the refusal moved after the budget reserve, the judge dropped from the list, the judge dropped from the call, "first projection decides both ways", the non-ObjectId guard removed, the bot-row key fallback removed, thejudgedflag collapsed tounbound. The call-level drops are killed by two suites at once (the real-Mongo one and the mocked seam), which is the point of having both.Survivor (kept as a tripwire): removing the
keys.has(...)filter in the installer scan changes no verdict. Extra owners are harmless because the projection lookup is itself keyed, so an owner with no row for this seat contributes nothing. The filter is an intentional bound on how many projections one call makes, not a rule — it is redundant by construction and no arm can make it load-bearing.A mutation that was wrong, disclosed because it nearly passed: my first "move the refusal after the reserve" duplicated the call site instead of moving it, so it survived while the code was correct. Fixing the mutation exposed the real defect in the arm: the refusal test's grant carried no budget, so
reserveBudgetLineagewas unreachable andexpect(...).not.toHaveBeenCalled()was vacuous. The grant now carries a budget on purpose.Not closed here
grantBrokerRefusalis returned by the grants read (routes/grants.ts:513) and no frontend file reads it — verified by grep overfrontend/src. The grant's page showing the refusal, which Wren 74883 asked for, is therefore still open and is not touched by this PR. Also unchanged: the server is a denylist and the daemon an allowlist, which is why the adapter-list pin exists.