Skip to content

TASK-172 §10 step 6: one removal sequence, a persisted mark, and a revoke that takes - #2035

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task172-removal
Sep 30, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task172-removal

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TASK-172 §10 step 6 — the removal sequence for a hosted-MCP Connection.

Removing a hosted Connection is the one sequence with a vendor step, and its
order is load-bearing: grants, row, provider, mark, material, delete. Grants
first because the granter's own revoke resolves ownership through
findConnection, so a deleted row orphans them (TASK-145); row second because
the broker refuses a row carrying revokedAt from that instant; provider third
while the material is still there; then the mark; material and delete last so a
failed vendor revoke leaves a row a retry can finish.

The mark is the fold's centre. A result code dies with the request and a retry
reads only the row, so a provider revoke that took and a step 4/5 that failed
used to strand the row: the retry found a dead reference and answered
provider_revoke_failed forever (Vera 75638, measured). The mark is written
BEFORE any material goes, is server-owned so a PATCH cannot write it, and a
retry that finds it skips the vendor. A failure after it returns
provider_revoked_removal_incomplete, which says the revoke happened so the
retry does not call the vendor again.

Only a 2xx on a token we hold counts as revoked (Wren 75660). The
invalid_grant arm is dropped: RFC 7009 answers a token already gone with 200,
while RFC 6749 §5.2 also gives invalid_grant for a token "issued to another
client" — and our CIMD client id is rebuilt from the API host at call time
(resolvedClientId), so after a host move a LIVE token answers it. Counting it
deletes the material and records a revoke that never happened.

The material read discriminates on the error's code, never its class: only
connector_secret_not_found means we hold nothing to revoke, and that case
finishes and hands the person the page. connector_secret_configuration_invalid
and connector_secret_key_missing keep the row, or one misconfigured key ring
would delete every hosted row that day while recording the vendor revoke as
done (Vera 75662). Nothing is ever sent as token: "" — the token is the
refresh reference or the access one, and a blank or absent secret means send
nothing, finish, and hand over the page.

Per #2037 the entry's revoke is now a page always and an endpoint only
when the AS advertises one, so every refusal and every success carries a
revokeAt; both URLs are checked, not just the first (the two-key shape used to
be refused outright, which is why that loop could not run before). A page-only
entry still calls no vendor.

Evidence: 21-mutant ledger, 21 killed, 0 survivors, 0 named-arm misses, no site
mismatches, all pristine copies restored (baseline 50 passed). Touched suites
55/55; neighbourhood 24 suites / 289 tests / 0 failed. eslint finding multisets
identical to the branch base on all five pre-existing files (+0/-0). tsc clean
on every touched file.


Named tests (docs/plans/tools-catalogue-room-grants.md §10.5), all present and green:

  • removing a Connection revokes every grant on it — pre-existing, still green
  • the provider revoke runs before the material is gone — the order arm
  • a failed provider revoke leaves the row and its references for a retry
  • a retry after the mark skips the provider and finishes
  • a row with no refresh token revokes its access token, and no removal sends an empty token
  • a provider answer other than 2xx is a refusal, invalid_grant included, and returns the page as revokeAt
  • a removal whose token secret is not found sends nothing, finishes, and returns the page as revokeAt — and counts the reads, so a fallback to the other reference cannot hide behind a mock that throws for both kinds
  • a removal whose token secret cannot be read for another reason keeps the row (two arms: configuration-invalid, key-missing)
  • a page entry's removal calls no provider and returns the page as revokeAt
  • an entry whose revoke names no page, a key other than endpoint and page, or a URL that is not https, is refused at load

The mark's own comment was corrected, with a measurement behind it. It said a PATCH cannot write the mark because the key is "server-owned", which is the right conclusion with the wrong mechanism named. stripServerOwnedConfig (routes/integrations.ts:65) is applied to the PATCH body at :750, and the write loop at :757 iterates Object.keys(incoming) where incoming = relay.next is that stripped copy — so a server-owned key never reaches the loop. The explicit refusals (linkedUserId, botToken) are a different mechanism covering two keys. Both comments now name the strip and the sites, and M22 (strip removed from the PATCH call site) dies on the new arm.

Still owed, and it belongs to 6b rather than here: the hosted-row PATCH refusal asserting a code that NAMES hosted. A hosted row is refused today only incidentally, by the scope: 'user' branch's linkedUserId comparison; the new suite pins the strip, not that guard.

samxu01 pushed a commit that referenced this pull request Sep 30, 2026
…own trace (TASK-172)

Rule 45 asks WHERE a mutation landed; this asks whether the arm can reach it.
A mutant that applies, passes the site check, and sits on a statement the arm's
trace never executes greens for a reason that reads as "this arm is unpinned" —
a finding filed against a correct arm. A zero-kill mutant is an INSTRUMENT
DEFECT until it is shown to be reached and semantically unchanged; "nothing died
because nothing ran" is not an equivalence.

Renumbered from 46 to 47: #2034 landed its own rule 46 (an arm's verdict is its
total against BASE) under a new heading, so this one sits below it with its own
heading. Numbers ascend in file order — a rename alone would have filed this
rule under the other one's subject.

Earned 2026-09-29, TASK-172 §10 step 6 (#2035 at a48fdfb).
samxu01 pushed a commit that referenced this pull request Sep 30, 2026
…own trace (TASK-172)

Rule 45 asks WHERE a mutation landed; this asks whether the arm can reach it.
A mutant that applies, passes the site check, and sits on a statement the arm's
trace never executes greens for a reason that reads as "this arm is unpinned" —
a finding filed against a correct arm. A zero-kill mutant is an INSTRUMENT
DEFECT until it is shown to be reached and semantically unchanged; "nothing died
because nothing ran" is not an equivalence.

Renumbered from 46 to 47: #2034 landed its own rule 46 (an arm's verdict is its
total against BASE) under a new heading, so this one sits below it with its own
heading. Numbers ascend in file order — a rename alone would have filed this
rule under the other one's subject.

Earned 2026-09-29, TASK-172 §10 step 6 (#2035 at a48fdfb).

Rhea's gate (75696) found a misclassification: a reached, non-equivalent
survivor caused by weak assertions is not an instrument defect. The rule now
keeps a survivor unclassified until it is investigated and names three outcomes
— proven equivalent, instrument defect, test gap — with n + 1 -> n + 2 under
assert(result > 1) as the test-gap counterexample: it executes, changes the
result, and passes both ways.
@samxu01
samxu01 force-pushed the kai/task172-removal branch from a48fdfb to 0bb4c88 Compare September 30, 2026 02:13
@lilyshen0722 lilyshen0722 changed the title TASK-172 §10 step 6 (removal): one sequence, and a revoke that names its kind TASK-172 §10 step 6: one removal sequence, a persisted mark, and a revoke that takes Sep 30, 2026
@samxu01
samxu01 force-pushed the kai/task172-removal branch from 0bb4c88 to 39fdbe8 Compare September 30, 2026 02:19
…voke that takes

Removing a hosted Connection is the one sequence with a vendor step, and its
order is load-bearing: grants, row, provider, mark, material, delete. Grants
first because the granter's own revoke resolves ownership through
`findConnection`, so a deleted row orphans them (TASK-145); row second because
the broker refuses a row carrying `revokedAt` from that instant; provider third
while the material is still there; then the mark; material and delete last so a
failed vendor revoke leaves a row a retry can finish.

The mark is the fold's centre. A result code dies with the request and a retry
reads only the row, so a provider revoke that took and a step 4/5 that failed
used to strand the row: the retry found a dead reference and answered
`provider_revoke_failed` forever (Vera 75638, measured). The mark is written
BEFORE any material goes, is server-owned so a PATCH cannot write it, and a
retry that finds it skips the vendor. A failure after it returns
`provider_revoked_removal_incomplete`, which says the revoke happened so the
retry does not call the vendor again.

Only a 2xx on a token we hold counts as revoked (Wren 75660). The
`invalid_grant` arm is dropped: RFC 7009 answers a token already gone with 200,
while RFC 6749 §5.2 also gives `invalid_grant` for a token "issued to another
client" — and our CIMD client id is rebuilt from the API host at call time
(`resolvedClientId`), so after a host move a LIVE token answers it. Counting it
deletes the material and records a revoke that never happened.

The material read discriminates on the error's `code`, never its class: only
`connector_secret_not_found` means we hold nothing to revoke, and that case
finishes and hands the person the page. `connector_secret_configuration_invalid`
and `connector_secret_key_missing` keep the row, or one misconfigured key ring
would delete every hosted row that day while recording the vendor revoke as
done (Vera 75662). Nothing is ever sent as `token: ""` — the token is the
refresh reference or the access one, and a blank or absent secret means send
nothing, finish, and hand over the page.

The mark's OWN comment was wrong about why a PATCH cannot write it, and the fix
is a measurement rather than a rewording. `stripServerOwnedConfig` is defined at
`routes/integrations.ts:65` and called on the PATCH body at `:750`, and the write
loop at `:757` iterates `Object.keys(incoming)`, where `incoming = relay.next` is
that stripped copy — so a server-owned key never reaches the loop at all. The
explicit refusals (`linkedUserId`, `botToken`) are a different mechanism that
covers two keys; the strip is what covers the rest, the mark included. Both
comments now name that mechanism and the sites, and
`integrations.serverOwnedConfig.test.js` pins it: a PATCH supplying the mark does
not write it, while `liveRelay` in the same body is written, which is the
acceptance control that makes the absence evidence about the strip rather than a
request that never reached a write. (`chatId` was the wrong control — it is on
the list too.)

The token is the one the ROW NAMES, and there is no fallback past a missing one
(Wren 75713): a named refresh reference is sent, otherwise the access token, and
a not-found read of the named one sends nothing and finishes with the page. A
fallback would try to revoke a grant we may still hold — RFC 7009 §2.1 makes an
access-token revoke a MAY, so the refresh token can survive it. The arm that
says so counts the reads, because its mock throws for every reference and a
fallback would otherwise look identical.

Per #2037 the entry's `revoke` is now a `page` always and an `endpoint` only
when the AS advertises one, so every refusal and every success carries a
`revokeAt`; both URLs are checked, not just the first (the two-key shape used to
be refused outright, which is why that loop could not run before). A page-only
entry still calls no vendor.

Evidence: 22-mutant ledger, 22 killed, 0 survivors, 0 named-arm misses, no site
mismatches, all pristine copies restored (baseline 52 passed). M22 removes the
strip from the PATCH call site and dies on the new arm, which is what makes "a
PATCH cannot write it" measured. Touched suites 57/57; neighbourhood 25 suites /
291 tests / 0 failed. eslint finding multisets identical to the branch base on
all five pre-existing source files and both pre-existing test files (+0/-0); the
one new .js suite adds 8 findings, all of them the `import/no-unresolved` +
`import/extensions` pair for each of its four relative `.ts` requires, which is
ambient for a new file in `backend/__tests__` (the resolver's `files: ['**/*.ts']`
override). tsc clean on every touched file.
@samxu01
samxu01 force-pushed the kai/task172-removal branch from 39fdbe8 to 1a8ed98 Compare September 30, 2026 02:23
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit 2322de6 Sep 30, 2026
19 of 23 checks passed
samxu01 pushed a commit that referenced this pull request Sep 30, 2026
…2041)

#2035 shipped step 6a, the removal sequence. The admin account-delete 409 and TASK-147's remaining per-path
witnesses (step 6b) are not on main: admin/users.ts deletes the User without the 409. The row said every
step had shipped; it now says step 6b is still open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
github-merge-queue Bot pushed a commit that referenced this pull request Sep 30, 2026
…own trace (TASK-172) (#2036)

Rule 45 asks WHERE a mutation landed; this asks whether the arm can reach it.
A mutant that applies, passes the site check, and sits on a statement the arm's
trace never executes greens for a reason that reads as "this arm is unpinned" —
a finding filed against a correct arm. A zero-kill mutant is an INSTRUMENT
DEFECT until it is shown to be reached and semantically unchanged; "nothing died
because nothing ran" is not an equivalence.

Renumbered from 46 to 47: #2034 landed its own rule 46 (an arm's verdict is its
total against BASE) under a new heading, so this one sits below it with its own
heading. Numbers ascend in file order — a rename alone would have filed this
rule under the other one's subject.

Earned 2026-09-29, TASK-172 §10 step 6 (#2035 at a48fdfb).

Rhea's gate (75696) found a misclassification: a reached, non-equivalent
survivor caused by weak assertions is not an instrument defect. The rule now
keeps a survivor unclassified until it is investigated and names three outcomes
— proven equivalent, instrument defect, test gap — with n + 1 -> n + 2 under
assert(result > 1) as the test-gap counterexample: it executes, changes the
result, and passes both ways.
samxu01 pushed a commit that referenced this pull request Sep 30, 2026
`markProviderRevoked` writes `config.providerRevokedAt` with a `$set`, and
`config` is a strict subdocument whose declaration did not list that key — so
mongod dropped every write of it in silence. Measured through the service's own
`defaultDeps()` on a real mongod and read back from the raw collection: the
stored config held `entryId` and no mark. The mark is the one record that a
provider revoke happened, and the retry-after-a-crash it exists for therefore
read a row that never carried it.

Nothing in #2035 could see this. `connectionRemoval.test.js` mocks the model and
asserts the PAYLOAD handed to it, which is green whether or not the schema keeps
the path; `hostedMcpConnectionRow.test.js` has the instrument for exactly this
class — RECORD_KEYS, one path at a time, read back through the raw collection —
and the mark was not on its list.

Both removal keys are now declared (the mark, and the `revokePage` copy below),
with a real-DB arm that runs the shipped writer, a RECORD_KEYS entry for each,
and the reason written in the schema. Removing either declaration kills two arms
(measured).

Ruling 75780 — the entry-gone finish, in the same files:

- The connect step copies the entry's `revoke.page` to `config.revokePage` on
  every connect. Server-owned: a body that could write it would repoint the
  revocation a person is sent to.
- A removal whose entry is gone sends nothing, sweeps the material, deletes the
  row, and returns the copy as `revokeAt`. A row with neither keeps today's
  `provider_revoke_failed` refusal and keeps everything.
- The entry wins while it exists: a stale copy is a fallback, not a second
  opinion.
- The endpoint is never copied, and an endpoint planted on a row is never read —
  it stays the entry's decision, taken at removal time.

Ten suites, 104 tests green, including four partially-mocked suites that had to
forward `hostedMcpRevokeTarget` once the callback started reading it (an
unforwarded accessor throws at the write, which is how those suites went red).
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…t renewed, Rewire restored, hosted-MCP through step 6a (Team-Commonly#2041)

* docs(plans): matrix rows for 2026-09-29 — Discord listed, GitHub grant renewed, Rewire relay restored, hosted-MCP live

- Discord: C0 moves from "not offered" to "listed, not offered". Team-Commonly#1826 is live, and the
  catalogue returns discord with offered:false, since commonly.me has no Discord keys. C1 stays red (TASK-104).
- GitHub (app): a new owner grant (grant_3c4d6ad5, the same scope as 09-18) runs to 2026-10-06,
  so C3, C4 and C8 are walkable again; none has been walked on the current build.
- Telegram walk notes: Rewire Live Demo relay restored by reactivating Sam's existing row.
- New row: the hosted-MCP generic type (TASK-172). Every §10 build step is live on 2322de6; the catalogue is
  empty; the first entry is open for Sam (Linear if its tools/list annotates, else Sentry).
- Decisions for Sam: item 4 (the Team-Commonly#1826 renders) is done.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

* docs(plans): the hosted-MCP row names step 6b as open (Rhea's hold on Team-Commonly#2041)

Team-Commonly#2035 shipped step 6a, the removal sequence. The admin account-delete 409 and TASK-147's remaining per-path
witnesses (step 6b) are not on main: admin/users.ts deletes the User without the 409. The row said every
step had shipped; it now says step 6b is still open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

* docs(plans): Decisions item 1 records the renewed GitHub grant (Rhea's second hold on Team-Commonly#2041)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

* docs(plans): Discord's offered:false is the roster, not missing keys (Rhea's third hold on Team-Commonly#2041)

offered comes from installableCatalogService's offeredByRoster (an active builtin Installable row exists);
commonly.me has no discord Installable row. available is manifest readiness and reads true.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…the entry-gone finish, and 6a's dropped mark (Team-Commonly#2047)

* TASK-147 witness 1/5: a hosted row is refused by its OWN kind, with a code

`PATCH /api/integrations/:id` already refused a hosted row, but only by accident
of a comparison the row can never satisfy: the `scope === 'user'` branch requires
`config.linkedUserId === requester`, and no hosted writer sets that field. The
guard is now keyed to the row's type above that branch, and it answers
`409 { code: 'hosted_mcp_managed_by_consent_flow' }` naming DELETE, so a caller
can tell "not patchable" from the identical 403 a wrong-owner PATCH gets.

The witness is the arm that plants a `linkedUserId` on the hosted row, so the
row now SATISFIES the branch it used to die on. Measured: with the guard's
condition pointed at a non-matching type the arm returns 200 and the write lands,
while the positive control — the same request on a user-scoped telegram row with
the same owner — stays 200 and applied. So the arm refuses the KIND, not the
request, and it is not a second test of the comparison.

Arm and mutation both live in `integrations.hostedMcpRefusal.test.js` (4 tests,
with the POST-time refusal by name it sits beside).

* TASK-147 witness 2/5: the pod delete cannot reach a hosted row, run as a query

podController.deletePod removes connector rows with one filter —
Integration.deleteMany({ podId }) — and a hosted-mcp row carries no podId, since
it is per-person and the schema requires podId only for scope: 'pod'.

The arm runs the real controller against a real mongod with three rows: a
pod-scoped telegram row the filter matches, a hosted row, and a linked personal
row (webhookProjector's shape). The pod-scoped row is the positive control — it
goes, which is what says the sequence ran in this request, so the two survivals
are the filter's shape rather than a step that never ran. A mocked deleteMany
could only report the selector it was handed, which is the claim and not the
evidence for it. Mutating the filter to { $or: [ {podId}, {type: 'hosted-mcp'} ] }
kills the arm.

A second arm pins the mechanism as a query: the same filter run directly returns
the pod-scoped row and not the hosted one, and countDocuments({podId: {$exists:
false}}) is 1 — a row carrying podId: null would be matched by the filter's type
bracketing, so the absence has to be a missing field, not a null one.

* TASK-147 witness 3/5: the hosted row carries neither key a removal sweep selects on

Two sweeps can remove a connection row without running the shared revoke step,
and each selects on a field this record does not have: podController.deletePod
filters Integration.deleteMany({ podId }) (:730) and installableReconciler
selects on installationId (:48, :86, :94, :127, :157, :190, :217, :240). A grant
on a hosted row is keyed by the row's own _id (grants.ts:310-316), so a sweep
that reached the row would strand that grant. The arm asserts the raw document
carries neither key.

Scope stated in the arm rather than implied by a green: it builds the row from
the record shape, so it fires on a SCHEMA change that stamps either field and
NOT on a writer that adds one to its payload. The writer payload cannot be
traced yet — the hosted connect route refuses before it writes while
HOSTED_MCP_ENTRIES is empty, which is the same first-catalogue-entry trigger
TASK-147 carries. Measured: a default: null on the schema's podId kills the arm
(E-1 in the 6b ledger), which is the mutation the arm's scope predicts.

* The 6a mark never landed: `config` is STRICT and did not declare it

`markProviderRevoked` writes `config.providerRevokedAt` with a `$set`, and
`config` is a strict subdocument whose declaration did not list that key — so
mongod dropped every write of it in silence. Measured through the service's own
`defaultDeps()` on a real mongod and read back from the raw collection: the
stored config held `entryId` and no mark. The mark is the one record that a
provider revoke happened, and the retry-after-a-crash it exists for therefore
read a row that never carried it.

Nothing in Team-Commonly#2035 could see this. `connectionRemoval.test.js` mocks the model and
asserts the PAYLOAD handed to it, which is green whether or not the schema keeps
the path; `hostedMcpConnectionRow.test.js` has the instrument for exactly this
class — RECORD_KEYS, one path at a time, read back through the raw collection —
and the mark was not on its list.

Both removal keys are now declared (the mark, and the `revokePage` copy below),
with a real-DB arm that runs the shipped writer, a RECORD_KEYS entry for each,
and the reason written in the schema. Removing either declaration kills two arms
(measured).

Ruling 75780 — the entry-gone finish, in the same files:

- The connect step copies the entry's `revoke.page` to `config.revokePage` on
  every connect. Server-owned: a body that could write it would repoint the
  revocation a person is sent to.
- A removal whose entry is gone sends nothing, sweeps the material, deletes the
  row, and returns the copy as `revokeAt`. A row with neither keeps today's
  `provider_revoke_failed` refusal and keeps everything.
- The entry wins while it exists: a stale copy is a fallback, not a second
  opinion.
- The endpoint is never copied, and an endpoint planted on a row is never read —
  it stays the entry's decision, taken at removal time.

Ten suites, 104 tests green, including four partially-mocked suites that had to
forward `hostedMcpRevokeTarget` once the callback started reading it (an
unforwarded accessor throws at the write, which is how those suites went red).

* The revokePage arm reads the row RAW as well as through the model

The generic RECORD_KEYS arm writes the path from the TEST, so it can only say
the schema keeps it. The callback's own writer is witnessed on a real mongod,
and now through the raw collection too — the read a default, a cast or a
re-declaration cannot satisfy. Measured: dropping `revokePage` from the schema
reddens this arm and the generic one; the pair is:
hostedMcpConnect.storedRow.test.js 'the page the entry names is copied onto the
row' + hostedMcpConnectionRow.test.js 'every key of the record survives a $set'.

* 6b: the admin pause/resume projection cannot reach a hosted row

`routes/admin/installables.ts` projects a pause onto the rows an
InstallableInstallation owns, selecting them by `installationId` (`:108`) and
lifting it by the same key (`:145`). A hosted-MCP row is minted `scope: 'user'`
with no `installationId`, so it is outside that projection for the reason the pod
delete and the reconciler are. Real mongod, real route handlers, real schema.

The installation-bound row is the control: it GOES, which says the sequence ran
in this request. "The hosted row survived" alone is worth nothing — a skipped or
failed projection produces the same thing.

The resume mutant survived the first version of this file, and closing it was the
useful part. Widening the RESUME selector to `{}` reddened nothing, because
`$unset` on a key a row does not carry is a no-op, so the hosted row cannot
witness it and the cross-tenant damage went unseen. What can see it is a SECOND
paused installable: resume one, and the other must stay paused. With that arm,
both selectors are killed by widening (pause → 3 failed, resume → 1 failed),
measured, restored identical.

* 6b: the legacy Discord uninstall is a witness on the paths it does not take

`routes/discord.ts:241` matches `{ installationId, type: 'discord' }` and deletes
with `findByIdAndDelete`, so it ends no grants — the one row-removing path that
does not call the shared step. It cannot reach a hosted row (the connect route
writes no `installationId`), and the second arm hands it a hosted row that DOES
carry the id it was asked to remove, so the type filter is the thing pinned
rather than the row shape being re-tested.

Real mongod, real handlers. Controls in the same call: the Discord row it
deletes (that is what says the route ran rather than 403/404-ed), and a
github-app row with a grant (the grantable shape Vera 75311 asks for on this
path). Grants are asserted by `revokedAt` absence — RoomGrant has no status
column, so "still active" is the absence of the stamp.

Mutant: dropping the type filter turns the collide arm red (404 → 200), measured,
restored identical.

* 6b: the reconciler cannot mistake a hosted row for an installation's connector

`sweepActiveInstallations` looks an active installation's own integration up by
`installationId` (`installableReconciler.ts:94`); a hosted-MCP row carries none,
so it cannot stand in for a connector the installation is missing. The branch it
would take is `continue` — the installation would stay `active` with a dead
relay and the sweep would never report it. The arm is therefore built as the
DANGEROUS direction: an active installation whose own row is gone, with a hosted
row present, must still be marked (`status: 'error'`, `errorMessageUserFacing`,
components stale). Widening that lookup to `{}` reddens it, measured, restored
identical.

Raw reads on the hosted row: `status` unchanged, material intact, and neither
`config.adminPause` nor `config.providerRevokedAt` present — the two keys this
sweep can write, both keyed on `installationId`. A raw config is not deep-equal
here because the record carries schema defaults, so the absence is asserted by
key. The unset half of the pause clear is unwitnessable by a hosted row at all:
`$unset` on a key that is not there is a no-op, so the row cannot distinguish the
selector from a widened one — recorded rather than claimed.

* 6b: the admin user delete strands a hosted row, and that is the whole handler

`DELETE /api/admin/users/:userId` (`routes/admin/users.ts:267`) references
Integration nowhere: it deletes the person and returns. So the hosted row it
leaves behind is not merely untouched, it is unmanaged — the owner is the only
caller the row's own routes accept, because PATCH refuses it by kind and
`DELETE /api/integrations/:id` wants the owner or an admin. Nothing marks it, so
the vendor revoke and the grant sweep a removal owes do not run for it either.

The control is the handler's own `deleteOne` on the target: that is what says the
route ran rather than 403-ing at the admin gate.

* 6b: admin user delete refuses while the person owns a hosted row (wren 75845)

The guard pins the refusal, not the strand. Deleting the person would leave a
hosted connection whose owner is the only caller its own routes accept — PATCH
refuses it by kind, and `DELETE /api/integrations/:id` wants the owner or an
admin — so nothing could finish the removal, not even the vendor revoke owed on
a row only they can reach.

409 `{ code: 'hosted_mcp_connection_owned', connectionIds: [...] }`. Any status
counts, because a failed revoke leaves a `disconnected` row whose material is
still present and that is precisely the one a person has to finish. The remedy
is the ordinary removal, which admits admins and runs the whole sequence grants
first; this endpoint never calls a vendor, the way pod delete does not.

Four arms, real mongod: the refusal (code + both ids + the person NOT deleted),
an acceptance control (no hosted row → 200), a stranded `disconnected` row on
its own → still refused, and a github-app row → not refused, so the filter
cannot quietly widen past hosted rows. Mutants measured: neutering the query,
dropping the type filter, and filtering on `status: 'connected'` each redden the
arm that names them, restored identical.

The unit route suite drives every handler with its models mocked and no
database, so it now answers this read with "no rows" — which is what keeps those
arms about the route's own branches.

* 6b: the user-delete guard's reason was wrong; the row IS admin-removable

My comment said nothing could finish the removal once the person was gone. Vera
75846 measured the opposite, and the sites agree: `canDeleteIntegration` answers
true on `role === 'admin'` before it ever reads `createdBy`
(`routes/integrations.ts:173`), and `GET /api/integrations/admin/all` still lists
the row — it filters on `isActive`, so the orphan comes back with `createdBy:
null`. So this was never a permanent strand, and the guard's reason is the one
wren 75847 gave instead: nothing prompts the look, and until someone takes it
the grants and the material outlive the person they act for.

The premise is now pinned rather than asserted, in the DELETE suite, on a row
whose owner has no User row at all: an admin gets 200, the row goes, the grant
on it ends, and the `revokePage` copied onto the row is the `revokeAt` the
response carries. Two mutants redden that arm and nothing else — dropping
`canDeleteIntegration`'s admin arm, and making the entry-gone finish ignore the
copied page.

* 6b: the user-delete predicate is material, not status (vera 75850)

A guard keyed on `connected` waves through the one row whose removal already
went wrong: `markDisconnected` writes `disconnected` at step 2 and the material
does not go until step 4, so a failed provider revoke leaves the row holding its
refs. The refs are the right key because the grants follow the material —
`routes/grants.ts:319` refuses to mint from a row that carries none.

Measured, and it cuts both ways. Production mints material-less rows:
`hostedMcpConnect.ts:237` inserts a `pending` row with `config.entryId` and
nothing else, and `credentialRef` is not written until the callback at :427. Such
a row can hold neither material nor a grant, so refusing the delete for it would
protect nothing — the predicate is what keeps the guard exact instead of merely
stricter.

Four arms, and four mutants each reddening the arm that names it: the predicate
dropped entirely (the abandoned attempt arm), the `credentialRef` branch dropped,
the `refreshTokenRef` branch dropped (both on the refusal arm, whose two rows
carry one key each), and the predicate ANDed with `status: 'connected'` (the
stranded row's id goes missing). Restored identical.

* Revert 6b's user-delete predicate to existence (wren 75857)

Wren took the coarser predicate, and the reason is measurable rather than
stylistic. The callback unsets `config.pendingAuth` at `hostedMcpConnect.ts:341`
and does not write `config.credentialRef` until `:427`, so for the length of its
upstream calls a connect that will land material carries neither ref — and every
failure branch in between (`issuer_unreachable`, `exchange_refused`,
`exchange_unreachable`, `exchange_incomplete`) returns a redirect with the row
left exactly so. That is not a 30s window, it is the resting state of a connect
that already failed while owing a cleanup. Material-keyed, the guard would delete
the only person who can finish it.

The abandoned-attempt arm is swapped for the mid-exchange row, which the 409 must
LIST. Four mutants, each reddening the arm that names it: the guard's query
neutered, the predicate narrowed to `config.credentialRef` (the mid-exchange row
that carries no ref), the predicate ANDed with `status: 'connected'` (the
stranded row's id), and the `type` filter dropped (the github-app narrowness
control). Restored identical; 8/8 here and 12/12 on the unit route suite.

* 6b: split the revoke-URL arms out of the collision test (vera 75720)

The both-URLs validation — every URL `revoke` names is checked, not just the
first, and a page is required even when an endpoint is present — was living
inside `test('a colliding entry id or tool name is refused')`, whose name says
nothing about it. A reader looking for the URL coverage finds a collision test
and concludes it is untested.

Moved, not rewritten: the block and its `bothURLs` declaration are now
`test('a revoke target is a page plus an optional https endpoint, and every URL
it names is checked')`. 21 tests pass here where 20 did. The name is load-bearing
and pinned: restricting the loop to `['page']` reddens it and nothing else.
eslint message multiset unchanged against HEAD.

* 6b: pin `revokePage` as server-owned, one arm per key (vera 75862)

vera deleted `'revokePage',` from `SERVER_OWNED_CONFIG_KEYS` and the route suite
stayed green — 13 suites, 116 passed — while the key one line over reddened its
arm when deleted. So the list carried a key nothing pinned.

Same instrument as the mark's arm: PATCH a row with the forged value beside a
NON-server-owned field, assert the loop ran, then assert the key is absent from
the update. Forgery here does not destroy the authorization, it MISDIRECTS it:
`revokePage` is what the entry-gone finish hands a person as `revokeAt`, so a
body that could write it sends someone to a page that revokes nothing.

Measured: deleting `'revokePage',` reddens this arm and nothing else; deleting
`'providerRevokedAt',` reddens the mark's arm and nothing else. 3/3 here,
117/117 across the 13 integrations route suites. eslint message multiset
unchanged against HEAD.

* 6b: the 409 body carries each row's entry, and the withdrawn premise leaves the comments (wren 75865)

Two items from the plan and wren's rulings, both on this PR.

1. Plan §7 (plan doc :192) says the admin-user-delete 409 lists each row's `_id`
AND entry, "which is what `DELETE /api/integrations/:id` takes". The route
listed ids only, so an admin holding the response had to look each one up to
know which app it was for. The guard now selects `config.entryId` and answers
`connections: [{ id, entryId }]` — paired, not two parallel arrays, because a
parallel array couples by index and drifts. `connectionIds` is dropped: it was
born in this PR and nothing consumes it.

2. `adminPauseLeavesHostedRow.test.js` still carried the premise wren 75847
withdrew and vera 75846 measured false — that the deleted owner is the only one
who can finish the removal. Replaced with cfb0845's reason: an admin CAN finish
such a row (`canDeleteIntegration` answers true on `role === 'admin'` before it
reads `createdBy`, `routes/integrations.ts:173`; the orphan still lists under
`/admin/all`, which filters on `isActive`), and the harm is the GAP — nothing
prompts that look — not a strand. Fixed in all three places, including the arm
whose :245 citation pointed at 75857 for a sentence 75857 retracted.

Measured: dropping `config.entryId` from the select, and reporting the entry as
a constant null, each redden both entryId assertions (2 failed / 18 passed).
27/27 across the three suites; eslint clean on the route, message multiset
unchanged on the test file.
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