Skip to content

fix(grants): removal ends the connection's grants before the row moves (TASK-145) - #1922

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task145-connection-grant-revocation
Sep 26, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task145-connection-grant-revocation

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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-level installationId and config.installationId; revokes each grant on it through the existing revokeGrant (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 before findByIdAndDelete.
  • 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:

  • The identity is a floor, not a condition (Vera 74462): 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, reinstating the orphan this PR exists to remove. No id now means 401 and no delete. auth always 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 /:id now carries writeIntegrationsRateLimit — the route js/missing-rate-limiting docs(runbooks): provisioning a hosted agent (W2 operator runbook) #1345 names (open on main, integrations.ts:746; the sink moved with this diff). POST / and PATCH /:id on the same router already carry it, from the import at :50; this was the one write sink without it.

Why

Measured at bbab711c: revokeGrant had exactly one caller, grants.ts:424 — the granter's own route — and RoomGrant appears in six non-test files. Neither removal path revoked anything, so a removed connection left every grant on it active until expiresAt.

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 403 access_denied at the revoke route, and nothing recorded a revocation.

Severity, honestly: authority already ended at the call boundary — toolBrokerService.ts:464-467 refuses a missing row, status !== 'connected' or revokedAt, and every grant carries expiresAt — 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

suite result
__tests__/unit/routes/integrations.delete.revokesGrants.test.js (new) 4 passed
__tests__/unit/services/roomGrantService.connectionRemoval.test.js (new) 5 passed
__tests__/unit/services/installableInstallationService.test.js (+2 cases) 31 passed
related suites re-run (grants read/mint, toolBroker, installable) 81 passed, 6 suites
integrations + Discord routes re-run after the limiter (12 suites) 120 passed

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, so findConnection cannot 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). revokeCascade filters to unrevoked rows and counts only what it moved, so a 0 is equally satisfied by "already revoked" and by "found none". Both new suites therefore assert countDocuments({ <addressable>, revokedAt: null }) — 0 after, with the pre-state read in the same test (3 in each), and per-grant revokedAt + revokedBy.

The lookup key is the one the broker reads. resolveConnection (toolBrokerService.ts:446-451) resolves grant.connectionId as Integration.findOne({ type, installationId }) and then Integration.findById, so the route fixture carries both keys — one root grant addressed by the row _id, another by the connection's top-level installationId. 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.js cannot 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.

arm result
M1 route call removed 2 failed / 1 passed — both grant assertions
M2 installable call removed 2 failed / 29 passed — both new cases
M3 row _id dropped from the identifier set 1 failed / 4 passed
M4 top-level installationId dropped 1 failed / 4 passed
M5 config.installationId dropped 1 failed / 4 passed
M6 installationId match branch dropped from the query 1 failed / 4 passed
M7 connectionId match branch dropped (route path) 2 failed / 1 passed
M8 row _id dropped (route path) 2 failed / 1 passed
M9 top-level installationId dropped (route path) 1 failed / 2 passed
M8b row _id dropped (service path, post-state predicate) 1 failed / 4 passed
M9b top-level installationId dropped (service path, post-state predicate) 1 failed / 4 passed
M10 identity floor removed (route path) 1 failed / 3 passed — the new case

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 at grants.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 revokeCascade ended 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_found catch (a grant deleted between the read and the write) in the helper.

Out of scope

  • The broker tools/list disclosure — TASK-146, per connector-ops 74457; lands after this one.
  • The removal-path census (Vera 74463): the row named two removal paths and a census finds five — routes/discord.ts:246 (legacy Discord remove, hard delete), controllers/podController.ts:715 (pod deletion hard-deletes every Integration on the pod at once) and installableReconciler.ts:200 (the revocation sweep tombstones outside unprojectInstallation) 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.

@samxu01
samxu01 force-pushed the kai/task145-connection-grant-revocation branch 2 times, most recently from 9b6e256 to 6ea16e1 Compare September 26, 2026 13:47
…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
samxu01 force-pushed the kai/task145-connection-grant-revocation branch from 6ea16e1 to c9fa419 Compare September 26, 2026 13:58
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 26, 2026
Merged via the queue into main with commit 13a9853 Sep 26, 2026
14 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant