Skip to content

TASK-172 §10 step 6b: the removals that must not reach a hosted row, the entry-gone finish, and 6a's dropped mark - #2047

Merged
lilyshen0722 merged 16 commits into
mainfrom
kai/task172-step6b
Sep 30, 2026
Merged

lilyshen0722 merged 16 commits into
mainfrom
kai/task172-step6b

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TASK-172 §10 step 6b. Two jobs: make the removals that are not the connection-removal sequence unable to reach a hosted-mcp row, and make the removal finishable when its catalogue entry has left. One measured defect from 6a is fixed on the way.

1. 6a's mark never landed — measured, not spotted

providerRevokedAt was written with $set onto config, a strict subdocument that did not declare it, so mongoose dropped every write in silence and the retry-after-crash read a row that never carried the mark. Both gates were blind by construction: connectionRemoval.test.js asserts the payload handed to a mocked model, and hostedMcpConnectionRow.test.js (which does read raw) did not list the key.

Fix: declare both removal keys (models/Integration.ts:397-398), add both to RECORD_KEYS, and add a named arm that drives the real sequence and reads the mark back through the raw collection. A payload arm cannot see a strict-schema drop; the instrument is a read-back.

2. The entry-gone finish

The connect step copies the entry's page onto the row (hostedMcpConnect.ts:426) as a server-owned key (serverOwnedConfigKeys.ts:97), and the removal reads it when the entry is gone (connectionRemovalService.ts), so a row whose entry has left the catalogue still finishes and still hands the person a URL. Both URLs an entry names are now validated where the entry is declared, page required, endpoint optional.

3. Every other row-removing path, as a witness on the paths it does not take

path what it would have to do arm
PATCH /api/integrations/:id refuse a hosted row by its kind — 409 hosted_mcp_managed_by_consent_flow, placed above the incidental scope: 'user' branch (that branch refuses github-app rows too, so a status assertion cannot see the guard) the arm plants a matching linkedUserId so the incidental gate cannot be what refuses it, and asserts the code
DELETE /api/pods/:id deleteMany({ podId }); a hosted row is minted with no podId positive control is a pod-scoped row that goes, so the sequence is proven to have run; the miss is pinned as a query ($exists: false), not argued
legacy Discord uninstall { installationId, type: 'discord' } + findByIdAndDelete — ends no grants control is the Discord row it deletes; the collide arm hands it a hosted row that does carry the installation id → 404, which pins the type filter
installable reconciler report an active installation whose own row is gone built in the dangerous direction: a widened lookup takes continue and leaves the install active with a dead relay
DELETE /api/admin/users/:id refuse while the person owns a hosted row see §4
tripwire the row carries neither key a sweep selects on asserted as absent keys, with the disclosure that it does not trace the writer while HOSTED_MCP_ENTRIES is empty

4. Admin user delete — 409, and the predicate is the row's existence

Ruling: wren 75845, 75857. The predicate moved three times and each step is measured:

  • status: 'connected' is wrong — markDisconnected writes disconnected at step 2 and the material does not go until step 4, so it waves through the row a failed provider revoke left holding its refs (vera 75850).
  • material presence (credentialRef/refreshTokenRef) is also wrong, and this is the case that decides it: between hostedMcpConnect.ts:341 ($unset config.pendingAuth) and :427 (write credentialRef) the row 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. A material-keyed guard deletes the only person who can finish a connect that already failed while owing a cleanup.
  • existence is right. The cost is bounded and falls on a caller who can pay it: a genuinely dead attempt costs one DELETE from the ids this response lists.

The premise underneath is pinned rather than asserted: an admin can finish an orphaned row — canDeleteIntegration answers true on role === 'admin' before it reads createdBy (routes/integrations.ts:173), and GET /api/integrations/admin/all still lists it (it filters on isActive, so the orphan returns with createdBy: null). So this guard is about the gap before anyone looks, not a permanent strand.

5. Ordering: closed by measurement

Three order mutants — grants/row swapped, mark hoisted above the vendor call, mark moved after the material goes — each redden the sequence arms (connectionRemoval.test.js:84 and the page-path order arms). No new code was needed for §7's "mutate the ORDER".

Recorded rather than claimed, and then corrected: swapping the grants step with the row mark changes no behaviour in isolation — revokeConnectionGrants derives its identifiers from the in-memory connection object (roomGrantService.ts:470-478) and never reads the row. It is nevertheless detected, by the three call-log arms (the order arm plus the page-only and copied-page arms). My first write-up said "unobservable in isolation" and stopped there; vera 75863 measured the swap against those arms and found all three redden. Behaviourally free, observably pinned — the distinction is the point.

5b. revokePage had no arm (vera 75862)

Deleting 'revokePage', from SERVER_OWNED_CONFIG_KEYS left the whole route suite green (13 suites, 116 passed) while deleting the key one line over reddened its arm. So the list carried a key nothing pinned. Added the matching arm — same instrument, forged value beside a NON-server-owned field, loop-ran control, key absent from the update — and measured the pair: deleting either key reddens only its own arm (3/3 here, 117/117 across the 13 integrations route suites).

6. Rename (vera 75720)

The both-URLs validation lived inside test('a colliding entry id or tool name is refused'). Moved, not rewritten, into test('a revoke target is a page plus an optional https endpoint, and every URL it names is checked'). The name is pinned: restricting the loop to ['page'] reddens it and nothing else.

Tests

Service — adminPauseLeavesHostedRow 8/8 (4 pause/resume + 4 user-delete), podDeleteLeavesHostedRow 2/2, discordUninstallLeavesHostedRow 2/2, hostedMcpConnectionRow 11/11. Unit — connectionRemoval 29/29, hostedMcpEntry 21/21, integrations.hostedMcpRefusal 4/4, integrations.delete.revokesGrants 7/7, hostedMcpConnect.storedRow 6/6, admin.users 12/12, installableInstallationService 33/33.

Every arm above names the mutant that reddens it, and RESTORED-IDENTICAL is asserted after each mutation run. eslint and tsc --noEmit clean; the eslint message multiset is unchanged against HEAD on the one touched .js test file. Backend-only, so no version bump.

Gate: vera.

… 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).
…s 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.
…eep 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.
`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).
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'.
`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.
…t 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.
…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.
… 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.
…n 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.
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.
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.
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.
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.
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.
…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.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit e96bb8f Sep 30, 2026
15 of 16 checks passed
samxu01 pushed a commit that referenced this pull request Sep 30, 2026
#2047 landed the admin account-delete 409, TASK-147's per-path witnesses, the revoke page copied onto
the row, and the declared revoked-at-vendor mark. Verified in the live build: the 409 code in the
compiled admin/users route; revokePage and providerRevokedAt on the compiled Integration model.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…ly#2050)

* docs(plans): hosted-MCP row — step 6b is live on e96bb8f

Team-Commonly#2047 landed the admin account-delete 409, TASK-147's per-path witnesses, the revoke page copied onto
the row, and the declared revoked-at-vendor mark. Verified in the live build: the 409 code in the
compiled admin/users route; revokePage and providerRevokedAt on the compiled Integration model.

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

* docs(plans): hosted-MCP row — steps 1–6 live, step 7 (first entry) open

Rhea 75890: §10 step 7 is the first entry and its live walk, so 'every build step' overstated.

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>
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