Repository navigation
fix(broker): refuse a grant that predates the connection row it resolves to (TASK-148) - #1924
Merged
Merged
Conversation
…ves to (TASK-148) A `RoomGrant` stores the installation id as `connectionId`, so it keeps resolving after the row it was minted for is deleted and the same GitHub installation is added again — the re-added row answers the installationId lookup and the old grant runs against it. #1922 closed the write half (removal revokes first); this is the consumer half: `resolveConnection` now compares the grant's `createdAt` against the resolved row's and refuses when the grant is older, with its own code (`connection_superseded`). Both timestamps are required. The population this guard exists for is the anomalous row, so an `a && b && c` test would pass exactly the rows it is meant to refuse; an absent or unreadable `createdAt` on either side is a refusal under `connection_untracked`. The fail-closed branch is also what narrows the values for the comparison. Both broker call sites inherit the check because it lives inside `resolveConnection` rather than in one caller: `callTool` and the approved-envelope path (`executeApproved`) both resolve there. Witnesses (each reddens when reverted): - the parked-write path (`executeApprovedToolCall`) refuses a re-added row with `connection_superseded`, no provider call, and the trail records it — without this the arm could be moved to the `callTool` caller and every other witness would stay green while this path silently lost the guard (Vera 74521); - a row older than its grant resolves (control) — the normal state, and a guard that refused it would take the broker offline for every seat; - a row created after the grant is refused `connection_superseded`, no provider call, and the trail records that code; - an absent or non-Date `createdAt` on either side is refused `connection_untracked`. Two sibling suites mocked both rows without the field the models always write; the fixtures now carry it, which is why they were red at the first run of the guard. No production sweep: 74472 measured an empty population.
samxu01
force-pushed
the
kai/task148-grant-predates-connection
branch
from
September 26, 2026 16:16
13ef4e8 to
6dbbf85
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 defect
A
RoomGrantstores the installation id inconnectionId(installableCatalogService.ts:79), andresolveConnectionlooks the row up by that same value. So a grant issued for a row that has since been deleted keeps resolving after the same GitHub installation is added again: the re-added row answers the lookup,createdByon it reads as the new owner (grants.ts:106), and the old grant runs against it.#1922closed the write half — every removal now revokes before the row moves. This is the consumer half: the broker refuses a grant that predates the row it resolves to.The fix
In
resolveConnection(toolBrokerService.ts), after the row is resolved and validated:connection_superseded— the grant'screatedAtis earlier than the resolved row's. The row a grant belongs to always predates the grant; a row younger than the grant is a different row.connection_untracked— an absent or unreadablecreatedAton either side. Not a pass: the population this guard exists for is the anomalous row, so ana && b && ctest would wave through exactly the rows it is meant to refuse. The fail-closed branch is also what narrows both values for the comparison.This lives inside
resolveConnection, not in one caller, so both broker entry points inherit it:callTool(:597) and the approved-envelope path (executeApproved,:748), which executes a parkedwrite-with-confirmcall.Evidence
Three witnesses, each red when reverted. Run on Node 22,
__tests__/unit/services/toolBrokerService.test.js:connection_superseded, no provider call,ToolCallrecords that codecreatedAton either sideconnection_untracked, no provider callexecuteApprovedToolCall), row re-added after proposeconnection_superseded, no provider call, trail records it — same owner/repo, so the row's age is the only divergence (Vera 74521)Placement, and why the fourth witness exists. The arm lives inside
resolveConnectionso both entry points inherit it, but that claim is only as good as the test that fails without it: moving the arm to thecallToolcaller — the placement the spec first asked for, which needs the return widened because the row'screatedAtis not in it — leaves all threecallToolwitnesses green and reddens exactly one: the approved-envelope case. Measured, not argued: 1 failed / 29 passed across the two suites under that mutation, 30 passed unmutated.Mutation ledger (guard suite,
19 passedat baseline; restored green after each):a && b && c, compare only when both present)connection_supersededrenamed to the genericconnection_mismatchRemoving the whole fail-closed branch does not compile (
TS18047: 'grantCreatedAt' is possibly 'null'): the branch is also the narrowing for the comparison.Fixture fallout, disclosed: two sibling suites (
toolBrokerApprovalService, and this one's shared fixtures) mocked the connection row withoutcreatedAt— the field both models always write (timestamps: true). With the guard in place those fixtures are refused, which is what turned 8 tests red on the first run. The fixtures now carry the field, and all nine suites that touchtoolBrokerServicepass: 9 suites / 77 tests.No production sweep: the population was measured empty (connector-ops 74472).
Scope
github-apponly, which is the only grantable type today. TASK-147 (the same ordering requirement for the other removal paths) and TASK-146 (thetools/listdisclosure) are separate rows.Gate: Vera.