Repository navigation
fix(grants): removal ends the connection's grants before the row moves (TASK-145) - #1922
Merged
Merged
Conversation
samxu01
force-pushed
the
kai/task145-connection-grant-revocation
branch
2 times, most recently
from
September 26, 2026 13:47
9b6e256 to
6ea16e1
Compare
…s (TASK-145) Both removal paths left every grant on a removed connection `active`: `DELETE /api/integrations/:id` hard-deleted the row (integrations.ts:756) and the installable path tombstoned it (installableInstallationService.ts), while `revokeGrant` had exactly one caller — the granter's own route (grants.ts:424). After the hard delete that route could not act either: ownership resolves through `findConnection` (grants.ts:257), so each grant on the connection answered 403 `access_denied`, and nothing recorded a revoke. One shared step now runs on both paths, before the row moves: `revokeConnectionGrants` (roomGrantService.ts) addresses a connection by the row's `_id`, its top-level `installationId` and `config.installationId`, revokes each grant on it (cascading the lineage) and returns the count. The installable path calls it once per uninstall, ahead of both the projector loop and the retired-manifest tombstone. Two follow-ups from the gate, folded at this head: * The grants step was guarded by `if (revokedBy)`, which fails in the wrong direction — an empty actor skipped the revoke and still reached the delete (Vera 74462). The identity is now a floor: no id, no delete, 401. `auth` always sets one, so it is unreachable today; it is there so it cannot become reachable in silence, and the route suite witnesses it. * `DELETE /:id` was the one write sink on the router without a limiter — `js/missing-rate-limiting` #1345 (open on main, integrations.ts:746) names it, while `POST /` and `PATCH /:id` already carry `writeIntegrationsRateLimit`. Authority already ended at the call boundary — toolBrokerService.ts:464-467 refuses a missing row, `status !== 'connected'` or `revokedAt`, and grants expire — so this is the revocation record and the granter's remedy, not a live bypass (tools plan §10.5).
samxu01
force-pushed
the
kai/task145-connection-grant-revocation
branch
from
September 26, 2026 13:58
6ea16e1 to
c9fa419
Compare
samxu01
pushed a commit
that referenced
this pull request
Sep 26, 2026
…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): - 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
pushed a commit
that referenced
this pull request
Sep 26, 2026
…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
pushed a commit
that referenced
this pull request
Sep 29, 2026
…TASK-172) Sam approved the sizing on 2026-09-29, so the HOLD markers on §10 and §1's row 6 now say so. The table stays as approved. A dated note ahead of it names what moved after it was written on 2026-09-12: - 6a's grant cascade is on main as revokeConnectionGrants (TASK-145, #1922). - 6b's secret keys joined INTEGRATION_SECRET_CONFIG_KEYS with hosted-mcp. - credentialFor and the refresh fence are built first for hosted-mcp (hosted-mcp-connection-scope.md), so 6b and 6f extend them. The 12-13 d total becomes an upper bound, re-sized when TASK-172's removal step lands. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…ves to (TASK-148) (Team-Commonly#1924) 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. Team-Commonly#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.
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…ra's four constraints, the question for Sam (HOLD) (Team-Commonly#1696) * docs(plans): §10.7 sizes piece 6 — seven ordered pieces, gates mapped to Vera's four constraints, the question for Sam (HOLD) Sam 68231: §10 was "not scheduled, not sized" by its own status line and nothing in it is built until it is. This adds §10.7: seven ordered pieces with a day estimate each (12–14 d for GitHub, one builder), the gate for each with Vera's four constraints (67647) mapped to the piece that satisfies them, and the one question a build needs Sam to answer first — whether a member's first Connection may come from the paste path before OAuth exists. Status line and §1 row 6 updated; still HOLD for Sam's read. Co-Authored-By: Claude Fable 5.1 <[email protected]> * docs(plans): §10.7 — never-returns-the-credential is new in 6b, total is 12–13 d (Vera 68233) Co-Authored-By: Claude Fable 5.1 <[email protected]> * docs(plans): §10.7 records Sam's approval and what main already has (TASK-172) Sam approved the sizing on 2026-09-29, so the HOLD markers on §10 and §1's row 6 now say so. The table stays as approved. A dated note ahead of it names what moved after it was written on 2026-09-12: - 6a's grant cascade is on main as revokeConnectionGrants (TASK-145, Team-Commonly#1922). - 6b's secret keys joined INTEGRATION_SECRET_CONFIG_KEYS with hosted-mcp. - credentialFor and the refresh fence are built first for hosted-mcp (hosted-mcp-connection-scope.md), so 6b and 6f extend them. The 12-13 d total becomes an upper bound, re-sized when TASK-172's removal step lands. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(plans): 6e refuses an OAuth row's removal until 6f, and §10.5 says what the App row gets (TASK-172) - 6e: DELETE on an `intake: 'oauth'` row is refused with a typed code before 10.5's step 1, with a named test. Without 6f's provider revoke, a removal would destroy the only credential that can revoke the authorization, through 6d's paste branch or through the orphan sweep once the row is gone. 6f lifts the refusal in the same PR as the revoke, and its tests replace the refusal's (review, 75229). - §10.5: the App row holds no material (its token is minted per call from the instance's App key), so its removal is steps 1, 2 and 5. The lead now describes main's DELETE as it is (grants, then delete), and step 1 names `revokeConnectionGrants`, the function on main. - §10.5 step 2: `isActive` stays true, because the orphan sweep revokes the material of an inactive row, and a row waiting on step 3 needs it. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
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.
What
Removing a connector now ends its grants, in one shared step both removal paths call before the connection row moves (tools plan §10.5, row TASK-145).
revokeConnectionGrants(backend/services/roomGrantService.ts) — addresses a connection by the row's_id, its top-levelinstallationIdandconfig.installationId; revokes each grant on it through the existingrevokeGrant(so the lineage cascades and only moved rows count); returns the count; tolerates a grant that vanished between the read and the write.DELETE /api/integrations/:id(backend/routes/integrations.ts:753) — revokes beforefindByIdAndDelete.unprojectInstallation(backend/services/installable/installableInstallationService.ts:527) — once per uninstall, ahead of both the projector loop and the retired-manifest tombstone.Two things the first gate pass added, folded at this head:
if (revokedBy), which fails in the wrong direction — an empty actor skipped the revoke and still reached the delete, reinstating the orphan this PR exists to remove. No id now means 401 and no delete.authalways sets one (auth.ts:79/:131), so it is unreachable today; it is there so it cannot become reachable in silence, and the suite authenticates a caller then strips the id to witness it.DELETE /:idnow carrieswriteIntegrationsRateLimit— the routejs/missing-rate-limitingdocs(runbooks): provisioning a hosted agent (W2 operator runbook) #1345 names (open on main,integrations.ts:746; the sink moved with this diff).POST /andPATCH /:idon the same router already carry it, from the import at:50; this was the one write sink without it.Why
Measured at
bbab711c:revokeGranthad exactly one caller,grants.ts:424— the granter's own route — andRoomGrantappears in six non-test files. Neither removal path revoked anything, so a removed connection left every grant on itactiveuntilexpiresAt.On the hard-delete path the granter's remedy died with the row too: ownership resolves through
findConnection(grants.ts:257), so after the deletion every grant on that connection answered 403access_deniedat the revoke route, and nothing recorded a revocation.Severity, honestly: authority already ended at the call boundary —
toolBrokerService.ts:464-467refuses a missing row,status !== 'connected'orrevokedAt, and every grant carriesexpiresAt— so this is the revocation record and the granter's remedy, not a live bypass. It is C9's "revoke takes effect" for the Slack/GitHub/Telegram rows, and it is the step Linear's build was otherwise going to add a third copy of.Witness
__tests__/unit/routes/integrations.delete.revokesGrants.test.js(new)__tests__/unit/services/roomGrantService.connectionRemoval.test.js(new)__tests__/unit/services/installableInstallationService.test.js(+2 cases)The route suite's second case is the one TASK-145 names — remove, then revoke: the route still answers 403
access_denied(the row is gone, sofindConnectioncannot resolve ownership) and the grant is already revoked, which is the point — nothing is left for the granter to chase.The witness is the post-state, not the returned count (Vera 74459).
revokeCascadefilters to unrevoked rows and counts only what it moved, so a0is equally satisfied by "already revoked" and by "found none". Both new suites therefore assertcountDocuments({ <addressable>, revokedAt: null })— 0 after, with the pre-state read in the same test (3 in each), and per-grantrevokedAt+revokedBy.The lookup key is the one the broker reads.
resolveConnection(toolBrokerService.ts:446-451) resolvesgrant.connectionIdasIntegration.findOne({ type, installationId })and thenIntegration.findById, so the route fixture carries both keys — one root grant addressed by the row_id, another by the connection's top-levelinstallationId. A sweep matching only one of them would leave a grant the broker still honours.Node 22 (CI's pin) for all runs;
grantBrokerProjectionService.test.jscannot load under this host's Node 26 (buffer.SlowBuffer, pre-existing) and is 16/16 on Node 22.Mutation ledger
Each arm reddens a named test, then restores.
_iddropped from the identifier setinstallationIddroppedconfig.installationIddroppedinstallationIdmatch branch dropped from the queryconnectionIdmatch branch dropped (route path)_iddropped (route path)installationIddropped (route path)_iddropped (service path, post-state predicate)installationIddropped (service path, post-state predicate)M3–M9 redden through different fixtures, each grant addressable by only one key, so no single-key implementation survives. Two things this ledger earned:
M5 caught the first draft, which read
installationId || config.installationId(the same||the mint route uses atgrants.ts:310): the config slot was unmatchable whenever the top-level one was filled, so a grant minted against it would be skipped.M9 was a survivor at first, and not because the test was weak: the lineage cascade masked it. The missed grant was a child of a matched root, so
revokeCascadeended it anyway. The route fixture now carries a second root grant addressed by the other key — after which M7/M8/M9 each redden. An address-space witness needs a grant the cascade cannot reach.M10 reddens, and the mechanism is worth stating: with the floor gone the request does not delete either —
canDeleteIntegration('')fails, so it answers 403. The floor's value is that the refusal no longer rests on that coincidence; the assertion is on the 401 because "some other check happened to fail" is not a guard.Disclosed, untested arms (tripwires, no mutation covers them): the
grant_not_foundcatch (a grant deleted between the read and the write) in the helper.Out of scope
tools/listdisclosure — TASK-146, per connector-ops 74457; lands after this one.routes/discord.ts:246(legacy Discord remove, hard delete),controllers/podController.ts:715(pod deletion hard-deletes every Integration on the pod at once) andinstallableReconciler.ts:200(the revocation sweep tombstones outsideunprojectInstallation) still bypass the shared step. This PR fixes the two paths in the row and gives the other three the step to call; @connector-ops is filing the census as its own row, to land after this one.