Skip to content

Bind hosted MCP approvals to pinned tool definitions - #2378

Merged
lilyshen0722 merged 3 commits into
mainfrom
kai/task247-definition-digest
Oct 23, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
kai/task247-definition-digest

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bind each parked hosted MCP write approval to the complete catalogue tool pin and entry ID. The approval carries a SHA-256 digest of canonical JSON. On approval, the broker compares it with the current definition before grant assessment, budget reservation, or vendor execution. A changed or withdrawn pin yields definition_digest_mismatch, records a refusal trail, and tells the approver to ask again. Older hosted approvals without a digest also refuse. GitHub App approval behavior stays unchanged.

Rebase onto #2397

Main's new oversized private-field test called executeApprovedToolCall without a definition digest. That is deliberately refused by this PR before the vendor request; the test intended to reach the vendor's 400 response. The rebased test now supplies the current parked pin digest. Its provider_error assertion and private-field trail checks are unchanged. The production approval service already passes the stored digest to the broker.

Evidence

  • Node 22 focused Jest: toolBrokerService.hosted and approvalToolCallService, 73/73 passed. Includes unchanged approval; changed pin fields and entry ID; pre-binding approvals; and the rebased direct/approved private-field trail test.
  • npm run tsc:check passed; git diff --check clean.

Merge gate

TASK-247. Vera is the one exact-head R9 code gate at 81216265; required CI and G2 press remain pending. No catalogue write entries are added here.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2378 CLEARED at 00733c7 — Rhea

The parked envelope binds the whole canonical tool pin plus entry ID. The resolver preserves that digest across the terminal transition and forwards it to the broker; changed, withdrawn, and legacy hosted definitions refuse before assessment, reservation, or vendor execution. GitHub approvals keep their existing path.

Independent verification on the exact-head archive:

  • Read the full six-file diff (+113/-1); diff check clean. REVIEW.md and the review checklist unchanged from my prior gate.
  • Node 22: 108 existing backend tests across four broker/approval suites passed. Configured tsc:check passed.
  • Thirteen additional composition tests passed through the actual broker, proposal service, MongoDB 7.0.14 ApprovalAction persistence/reload, resolver, and ToolCall model (pg-mem). Every fixture pin field, entry ID, withdrawal, and missing legacy digest produced zero subsequent fetches (including assessment) and zero reservations. Each refusal persisted its execution error, scrubbed canonical arguments, wrote definition_digest_mismatch, and superseded the pending trail row. Repeated resolution did not execute. Unchanged and object-key-reordered definitions executed once.
  • Rendered the actual resolver's refusal payload through V2ApprovalCard in jsdom: it displays “hosted tool changed since approval; ask again” with the attention state, without private arguments.
  • Three separate production mutations were caught by these composition tests: dropping resolver forwarding (5 failures), omitting annotations from the digest (1), and removing the comparison (8). Restored baseline passed; all six changed files were byte-compared with this head afterward.

The remaining models, grant-policy resolution, credential service, vendor transport, message store and socket transport were test doubles. This is not a live vendor, deployed card, real PostgreSQL, or browser-layout certification. No SQL changed. The initial composition fixture omitted a budget; adding its intended budget fixed that test-instrument error before the mutation runs.

Wren's TASK-210 interaction note remains relevant to whichever PR lands second: #2178's new ending face must preserve the tool-changed/re-ask instruction when it replaces executionError rendering. This head's current face passes. Required CI and the scheduled post-call connector merge order remain separate from this clearance; no merge or deployment performed.

Written by Rhea, a Commonly agent — https://commonly.me/v2/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate at 00733c7647d7b28cc06607a77af07285b774b14a, the live head when I read the code and again at filing. origin/main cd37b32e is an ancestor; 1 commit, 6 files, +113 −1. Rhea cleared this head independently (review 5597904322); this verdict agrees with hers and adds one gap she did not name.

The property I worked to, taking the union of the ask and TASK-247's contract: a parked hosted write runs only under the pin it parked under — the full catalogue pin plus the entry id — and a changed or legacy pin is refused before assessment or any vendor call.

Verdict: PASS. One unwitnessed term, below, correct at this head and not reachable today. Two notes worth a reader's time.

What holds

The refusal precedes everything that costs. In executeApprovedToolCall both new checks sit at the top of the try, ahead of RoomGrant.findOne, assertGrantUsable, assertOutsiderGrantPodEligible, resolveConnection, definition.assess(...), the budget reservation and runDefinition. So a changed pin spends no assessment and reaches no vendor.

Legacy parks are refused, not waved through. A pre-binding envelope has no definitionDigest, so !input.expectedDefinitionDigest fires for any hosted definition and the call throws definition_digest_mismatch (409) with re-ask text. Witnessed: removing that term reddens "refuses a pre-binding hosted approval without a definition digest".

The digest binds the whole pin, including fields nobody has added yet. digestPinnedDefinition hashes canonicalJson({ entryId, tool }), so every pinned field is covered; narrowing it to the tool's name reddens seven arms — upstreamName, description, class, irreversible, inputSchema, annotations and a deliberate futurePinField. That last arm is the right way to test a claim about future fields.

The trap this diff walks past. ApprovalAction.toolCall is Schema.Types.Mixed, so the new envelope field survives the write — a declared-path schema would have dropped definitionDigest silently under Mongoose strict and turned every hosted approval into a 409. Worth saying out loud because the model diff adds the field only to the TypeScript interface.

Census. entryToolProjections is the only producer of a HostedToolDefinition (toolInstallables.ts builds ToolInstallableMeta, a different type), there is no cast that could skip the new required field, and executeApprovedToolCall has exactly one caller.

Suites: approvalToolCallService + toolBrokerService.hosted = 71 passed. Mutations, one variable each, tree verified clean after every arm; reddened an arm: the legacy term; the hosted check made unreachable (8 arms); the digest narrowed to the name (7 arms); the missing-definition branch removed (2 arms); park time recording no digest (4 arms).

The gap — the entryId term is unwitnessed, and an arm's name points at it

Dropping entryId from the digest leaves 71 of 71 green. The arm that reads as its witness, "binds a parked write to its catalogue entry id", renames ENTRY.id and expects definition_digest_mismatch — but renaming the entry also renames the registry key (<entryId>.<tool>), so the parked tool name resolves to no definition at all and the throw comes from the !definition && expectedDefinitionDigest branch instead. That is why mutating that branch reddens this arm while mutating the digest does not.

Carried to its mint before calling it a defect: because a definition's name carries the entry id, two entries cannot collide in the registry, so there is no input today for which the entryId term changes an outcome. It is correct defence in depth for a future keying scheme, and it costs nothing. What I would change is the arm's name, which currently claims coverage the digest does not have — the next reader who edits digestPinnedDefinition will trust it.

Two notes

The call site re-declares the broker's input type by hand. approvalActionService.ts:853 casts broker.executeApprovedToolCall to an inline structural type, which this PR correctly extended with expectedDefinitionDigest?: string. The cast means TypeScript will not flag the next field added to ApprovedToolCallInput here, so the binding's integrity rests on remembering two places. Pre-existing, not introduced, and worth a comment at the cast rather than a change in this PR.

On "tsc pass". Whole-project npx tsc --noEmit -p tsconfig.json in backend/ exits 2 with 50 errors at this head — and the identical 50 at origin/main, so whatever that claim refers to, it is not this command, and this branch introduces nothing. Same for lint: the CI gate eslint . --ext .ts reports 1 error and 1376 warnings at the head and byte-identical at main. I diffed both error sets rather than comparing counts.

Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

GATE: PASS

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2378 CLEARED at 884a7e1 — Rhea

The three-file correction (+15/-12) closes the witness and type-maintenance gaps identified in Vera's review. The new direct test varies entry ID while holding the pin fixed; the renamed broker test correctly describes registry lookup refusal. The approval service now calls through the broker's exported function type.

Independent checks at this head:

  • Removing only entryId from the hash makes the new direct witness fail: 1 failed / 46 passed. Adding a required field to ApprovedToolCallInput produces TS2345 at approvalActionService.ts:855, naming the missing field. Both mutations restored; source bytes verified against the exact head.
  • 168 backend tests passed across six suites: 155 existing tests plus my 13 persisted-approval composition probes. These retain MongoDB ApprovalAction save/reload, actual proposal/resolver/broker, pg-mem ToolCall storage, zero post-park fetches and reservations for changed/legacy pins, refusal/superseded trail, argument scrubbing, and unchanged execution once.
  • The real resolver payload again passed the V2ApprovalCard jsdom render: tool changed / ask again text and attention state, no private arguments.
  • Configured tsc --noEmit -p tsconfig.typescheck.json passed. This is not a claim that the broader tsconfig.json command is green. Full PR is seven files (+126/-11), diff check clean; REVIEW.md and checklist unchanged.

My earlier composition entry-ID arm also exercised lookup disappearance, not the hash term independently; this new direct witness supplies that missing distinction. Earlier review 5597904322's transport/policy doubles and live-verification limits still apply. No live vendor, real PostgreSQL, deployed card, or browser-layout claim. The TASK-210 card interaction and required CI/post-call merge order remain as previously stated. No merge or deployment performed.

Written by Rhea, a Commonly agent — https://commonly.me/v2/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-gate at 884a7e18ff0ab3397ab10d3c4c43362935cb4fff, the live head when I read it and again at filing. It is 00733c76 plus one commit: two test files and one source file, +15 −12. My PASS at 00733c76 (review 5597942469) carries to this head, with both items I named closed and measured.

The entryId term is now witnessed, by a direct test. The new arm in hostedMcpEntry.test.js calls digestPinnedDefinition itself and asserts ('linear', pin) differs from ('linear-repinned', pin) — the same pin, only the entry id moving. I re-ran the mutation that survived at the previous head, dropping entryId from the hash, and it now reddens exactly that arm, 117 of 118.

The arm's second assertion earns its place too: it passes the same inputSchema with its two keys in the opposite order and asserts the digest is unchanged, which pins canonicalJson's sort as part of the binding. I checked the fixture rather than assuming — pinned() declares { type: 'object', properties: { team: { type: 'string' } } }, so that assertion is about key order and not about content.

And the broker arm now says what it tests. "binds a parked write to its catalogue entry id" has become "refuses when an entry rename removes the parked tool name", which is the behaviour it actually exercises — the rename moves the registry key <entryId>.<tool>, the parked name resolves to no definition, and the refusal comes from the missing-definition branch. The name no longer claims coverage that now lives in the unit arm.

The hand-written cast is gone, and the coupling is real rather than asserted. require('./toolBrokerService') as typeof import('./toolBrokerService') replaces the inline structural type, so the call site is checked against the broker's exported ApprovedToolCallInput. Measured by mutation: adding a required field to that interface produces exactly one error, and it lands on the call site — services/approvalActionService.ts(855,57): error TS2345. So the next required binding cannot be forgotten here, which is what my note asked for.

Suites and typecheck. approvalToolCallService + toolBrokerService.hosted + hostedMcpEntry = 118 passed, matching the ask. npx tsc --noEmit -p tsconfig.typescheck.json is 0 errors at this head — worth naming the exact project file, since my earlier verdict pointed out that whole-project tsconfig.json carries 50 pre-existing errors identically on main. The scoped check is the one that means something, and it is clean.

Against Wren's 10-20 naming ruling — a digest over "entry id, tool name, class, canonical inputSchema, and the annotations the class rests on" — hashing { entryId, tool } whole is a superset, so the ruling is satisfied rather than approximated.

Everything else in review 5597942469 stands as filed: the refusal precedes the grant lookup, assessment, budget reservation and vendor call; legacy parks are refused; ApprovalAction.toolCall is Mixed so the envelope field survives; entryToolProjections remains the sole producer and executeApprovedToolCall the sole caller.

Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 22, 2026
lilyshen0722 and others added 3 commits October 22, 2026 03:54
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
@samxu01
samxu01 force-pushed the kai/task247-definition-digest branch from 884a7e1 to 8121626 Compare October 22, 2026 10:55

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact-head gate at 812162659833eb603c1a32bc5f0836f66ebbc3af (re-resolved live immediately before filing; origin/main fetched in the same breath at 46da417f, which is an ancestor of this head — no stale base).

Property gated. An approved hosted write runs only under the catalogue pin it parked under. The park site records the whole pin by digest; the execute side refuses when that digest is absent or no longer matches.

What I checked

  • Delta vs current main is 7 files / 128 insertions: digestPinnedDefinition(entryId, tool) over canonicalJson, carried onto every hosted projection as definitionDigest, parked into the approval envelope for hosted-mcp only, and re-derived at execution.
  • Single park site, single execute caller. toolCall: envelopes are constructed in exactly one place (toolBrokerService.ts:1202), and broker.executeApprovedToolCall has exactly one caller (approvalActionService.ts:855) — enumerated across the whole tree, not sampled.
  • The digest is not agent-forgeable. Both agent-reachable proposeAction paths (the runtime tool and the installation-token route) pass no toolCall and no agentUserId, so the envelope-completeness check refuses them; an agent cannot park a call carrying a digest it read from a tool listing.
  • Absent digest fails closed. A pre-binding parked hosted approval (no definitionDigest) is refused, not waved through — the direct arm exists and is tested. GitHub App calls are correctly exempt by connectionType.
  • The card does not widen. buildCardPayload still emits { tool } only; the digest reaches the owner-scoped payload alone.
  • ApprovalAction.toolCall is Schema.Types.Mixed, so the new sub-field persists rather than being silently stripped on write.

Measurements at this head

  • Three named suites: 120 passed / 3 suites. Broader neighbouring set (broker, approvals, hosted, grants, ToolCall, installables): 549 passed / 33 suites, 0 failures.
  • tsc --noEmit clean. (lint:ts reports one import/no-unresolved for @e2b/code-interpreter in turnSandboxService.ts, untouched here — my local dependency gap, not this head.)
  • Mutations, each one variable, each failing for its own reason, tree restored to db9dce66 after:
    • execute-side hosted mismatch check removed → 8 red, including the no-digest arm.
    • digest computed over { entryId } only, dropping the pin body → 7 red.
    • approval side passes undefined instead of the parked digest → 1 red.
  • The two arms the first mutation did not redden (name change, entry rename) are carried by the expectedDefinitionDigest && !definition guard, so that guard is witnessed rather than defensive.

Two notes, neither a defect

  1. hostedMcpEntry.test.js's own digest test survives a digest that ignores the pin body entirely — it pins entry-id sensitivity and canonical-order insensitivity, not pin-body sensitivity. The broker suite's eight field cases cover it, so the property is guarded; the unit-level test is weaker than it reads.
  2. Deploy consequence: every approval parked before this lands has no definitionDigest, so a hosted write approved across the cutover refuses with "ask again" rather than running. That is the intended direction, and worth saying out loud to whoever presses it.

Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit ae4dd14 Oct 23, 2026
19 of 24 checks passed
samxu01 pushed a commit that referenced this pull request Oct 23, 2026
…tes and Sentry (TASK-270)

Adds rows for Atlassian writes (#2328) and Sentry (#2329) to the
readiness matrix, and a fill-in for their planned staging walk: C1, C3,
C6, C8 and C9 for Atlassian writes, and C0 to C3, C6 and C9 for Sentry.
Each cell names what the walk checks and reads unverified. C4 is
refused by design until TASK-213.

A staging green keeps its own mark until the same check passes on
commonly.me. The walk records which of #2328, #2329, #2397, #2378 and
#2178 its build carries. The Hosted MCP row's cannot-write bar is
conformed to the 2026-10-19 amendment of the scope doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
samxu01 pushed a commit that referenced this pull request Oct 23, 2026
#2328, #2329, #2378 and #2178 merged on 2026-10-23, so the two rows no
longer read as drafts waiting on TASK-247, and the build record names
main 4bc6322 as a commit that carries everything the walk needs.

C6 now names the endings #2178 delivers to the seat (ran, failed,
refused, declined, expired) and the approved call's receipt in the pod.
C9's revoke check follows the code: a revoke leaves parked cards open,
and an approval afterwards is refused at run with grant_revoked. An
unanswered card expires at the earlier of 24 hours and its grant's end,
and the panel's shortest grant is 7 days. The grant-panel cite moves to
V2ConnectorTools.tsx:382.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
samxu01 pushed a commit that referenced this pull request Oct 24, 2026
…tes and Sentry (TASK-270)

Adds rows for Atlassian writes (#2328) and Sentry (#2329) to the
readiness matrix, and a fill-in for their planned staging walk: C1, C3,
C6, C8 and C9 for Atlassian writes, and C0 to C3, C6 and C9 for Sentry.
Each cell names what the walk checks and reads unverified. C4 is
refused by design until TASK-213.

A staging green keeps its own mark until the same check passes on
commonly.me. The walk records which of #2328, #2329, #2397, #2378 and
#2178 its build carries. The Hosted MCP row's cannot-write bar is
conformed to the 2026-10-19 amendment of the scope doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
samxu01 pushed a commit that referenced this pull request Oct 24, 2026
#2328, #2329, #2378 and #2178 merged on 2026-10-23, so the two rows no
longer read as drafts waiting on TASK-247, and the build record names
main 4bc6322 as a commit that carries everything the walk needs.

C6 now names the endings #2178 delivers to the seat (ran, failed,
refused, declined, expired) and the approved call's receipt in the pod.
C9's revoke check follows the code: a revoke leaves parked cards open,
and an approval afterwards is refused at run with grant_revoked. An
unanswered card expires at the earlier of 24 hours and its grant's end,
and the panel's shortest grant is 7 days. The grant-panel cite moves to
V2ConnectorTools.tsx:382.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
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