Skip to content

feat(mcp)!: pin MCP tool sets in config and plan identity; enforce at dispatch; add qq mcp inspect - #194

Merged
lg2m merged 2 commits into
mainfrom
feat/eng-939-mcp-pinning-stack
Sep 26, 2026
Merged

lg2m merged 2 commits into
mainfrom
feat/eng-939-mcp-pinning-stack

Conversation

@lg2m

@lg2m lg2m commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Closes ENG-939. Supersedes #163, #165, and #171 (contributed by @rmondello2629 / Devin; attribution kept as Co-Authored-By on the commit).

What this ships

An MCP server's tool descriptors are untrusted text the model reads as instructions, and a server may change them at any time. A server declaration may now carry pin: the SHA-256 digest of the tool set an operator reviewed. A pinned server whose live listing digests differently is quarantined: it contributes no tools, the readiness message names both digests, and every call on it is refused (McpCallFailure::Quarantined → HostCallError::Refused). Unpinned servers are unchanged.

"linear": Http(url: "https://mcp.linear.app/mcp", bearer: Env("LINEAR_TOKEN"), pin: "5a1f…e9c0"),

qq mcp inspect NAME connects to one server, calls nothing, and prints the digest plus every tool's name/description/schema/hints as JSON (with an explicit "untrusted descriptors" warning) so the digest is reviewed before it is pinned.

Why this replaces the original stack

Review of #163 → #165 → #171 (heads 4dcb062 / 448d6bd / 932f953) found, with reproducing probes:

  1. Dispatch race — a pinned call that passed the pin check, then waited for the per-server permit, executed after the server was quarantined.
  2. Identity gap — the pin was absent from McpServerDescriptor, so pinned and unpinned plans shared a plan digest.
  3. Silent reduction — malformed/duplicate tool names were skipped before hashing, so a pin could approve a listing the operator never saw.
  4. Discovery UX — the only way to learn a digest was to configure a wrong pin and copy it out of the error.
  5. Audit chain (feat(runtime): hash-link the event journal and export/verify the audit chain (SK1) #165) — verifier returned Intact after a SQL cursor rewrite and treated an unhashed row in a fresh store as a legacy prefix; pages bounded by count not bytes; no consumer, checkpoint, or retention contract; conflicts with proposed ADR-0038 event deletion.
  6. Docs (docs(adr): ADR-0042 security kernel as library code inside qq-core/qq-mcp (SK0) #163) framed an unrelated project as QQ's requirements source.

This PR ports only the #171 MCP delta and repairs 1–4; 5 and 6 are not ported. Decision recorded as ADR-0046 and decisions-needed #10.

Design

  • Dispatch-time enforcement: a pinned call resolves the cached Listing { tools, digest, client, generation } before acquiring a permit; after the permit it re-checks the generation and the list_changed flag (drift → release permit, re-resolve), requires the tool to be present in that listing (UnknownTool), and sends exactly one tools/call whose enqueue poll runs under a synchronous dispatch_gate that on_tool_list_changed / bump_generation / shutdown also hold while flipping flags. The gate covers only that non-blocking poll, never a wait. Non-CallToolResult responses → InvalidResult.
  • Injective digest: domain qq-mcp-tool-set-v2, length-prefixed fields (the contributed \0-separated v1 was ambiguous; any v1 pin fails loudly, which is intended).
  • Whole listings only: invalid/duplicate names fail the listing; bounded to 32 pages / 512 tools / 1 MiB under the 20 s deadline; a list_changed during a fetch discards it.
  • Durable identity: McpServerDescriptor.pin, DESCRIPTOR_VERSION 9 → 10.
  • Inspect: McpManager::inspect, ClientSnapshot::mcp_servers, qq mcp inspect (blocking config load, only that server's credential resolved, ctrl-c + 45 s bound).

Compatibility / performance

  • Breaking: DESCRIPTOR_VERSION 9 → 10 invalidates cached plan digests (recompiled on next load). No PROTOCOL_VERSION or store-schema change. Only new dependency: sha2 in qq-mcp (already in the lock).
  • cargo bench -p qq-core --bench plan_compile (5 repeats, shared host): compile median 24.7 µs vs 24.2 µs baseline; descriptor digest 2.48 µs vs 2.31 µs; canonical descriptor +2 bytes. Within run-to-run spread (baseline ranged 23.3–30.4 µs). Raw in the ledger.

Verification

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo build --workspace --all-targets --locked: pass.
  • cargo test --workspace --locked: all green in a --test-threads=4 run; at default parallelism one unrelated 2 s timing test (sessions::tests::delegation::child_mutation_drains_before_steering_or_a_replacement_run_can_write) flaked once on the shared host and passes --exact.
  • cargo test -p qq-provider --no-default-features --features test-support: pass (lock touched).
  • New tests (qq-mcp, red-first against the ported feat(mcp): pin MCP tool-set digests and quarantine drifted servers (SK2) #171 code): queued_pinned_call_refuses_drift_before_dispatch, pinned_call_cannot_execute_an_unlisted_tool, pinned_listing_refuses_duplicates_instead_of_hashing_a_subset, queued_pinned_call_revalidates_a_replacement_connection, pinned_call_cancellation_and_shutdown_do_not_dispatch_waiters, a_notification_during_discovery_never_certifies_the_old_listing, inspection_exposes_quarantined_descriptors_without_authorizing_them, listings_bound_pages_tool_count_and_bytes_without_partial_pins, invalid_tool_names_are_not_omitted_from_a_pin_candidate; root: mcp::tests::inspection_reports_descriptors_and_pin_status_without_calling_a_tool, CLI parse + guide-coverage guard; descriptor v10 golden.

Docs

ADR-0046; docs/design/tools.md § MCP; architecture.md plan identity; protocol.md descriptor note; guide mcp.md § Pinning a server's tools and cli.md qq mcp inspect; ledger docs/plans/progress/mcp-pinning.md; indexes.

Review ask

An independent look at the dispatch-gate design in crates/qq-mcp/src/lib.rs (ServerHandle::execute) would be valuable: the invariant is that the gate is a std::sync::Mutex held only across a non-blocking poll and flag flips, never across an .await.

Not in this PR (deferred with reasons)

… dispatch; add qq mcp inspect

An MCP server's tool descriptors are untrusted text the model reads as
instructions, and the server may change them at any time. A server
declaration may now carry `pin`: the SHA-256 tool-set digest (64 hex
digits, validated at load) of the listing an operator reviewed. A pinned
server whose listing digests differently is quarantined: it contributes no
tools, the readiness message names both digests, and every call to it is
refused (`McpCallFailure::Quarantined` -> `HostCallError::Refused`).

This takes over the contributed stack #163 / #165 / #171 and ships only
the MCP pinning delta, repaired against QQ's own contracts (ADR-0046):

- Dispatch-time enforcement. A pinned call resolves the cached listing
  before waiting for a permit, re-checks the listing generation and the
  `list_changed` flag after it, requires the tool to be in that listing,
  and sends exactly one `tools/call` whose enqueue poll runs under a
  synchronous dispatch gate shared with `on_tool_list_changed`,
  `bump_generation`, and `shutdown`. Previously a queued call that passed
  the pin check executed after the server was quarantined.
- Durable identity. `McpServerDescriptor.pin` is recorded and
  `DESCRIPTOR_VERSION` moves 9 -> 10; pinned and unpinned plans no longer
  share a digest.
- Injective digest. Domain `qq-mcp-tool-set-v2` with length-prefixed
  fields replaces the `\0`-separated v1 encoding.
- Whole listings only. Malformed or duplicate tool names fail the listing
  instead of being skipped before hashing; fetches are bounded to 32
  pages, 512 tools, and 1 MiB; a `list_changed` during a fetch discards it.
- Inspection. `McpManager::inspect` and `qq mcp inspect NAME` print the
  live digest and every descriptor as JSON without calling a tool, so the
  digest is reviewed before it is pinned rather than copied out of a
  quarantine error.

The per-event audit hash chain from #165 is not ported: it has no
consumer, checkpoint, or retention contract yet, and its verifier
accepted a cursor rewrite. Approval/argument binding is deferred.

Breaking: `DESCRIPTOR_VERSION` 9 -> 10 invalidates cached plan digests
(recompiled on next load; no store migration). No protocol change.

Verification: fmt, clippy (-D warnings), workspace build and tests, the
minimal qq-provider profile, and `plan_compile` bench within noise of the
baseline (ledger `docs/plans/progress/mcp-pinning.md`).

Closes ENG-939. Supersedes #163, #165, #171.

Co-Authored-By: romy <[email protected]>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T06:32:38.152527Z a46fde7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 789c6d9a23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-mcp/src/lib.rs Resolved
@lg2m lg2m self-assigned this Sep 26, 2026
… copy

Codex review on #194: `serde_json::to_vec(tool)` allocated the whole
encoded descriptor before the 1 MiB check, doubling the resident bytes for
a page `rmcp` had already decoded. Measure through a counting `ByteBudget`
writer instead; the write that crosses the budget is rejected and nothing
is allocated. The check now bounds only what it claims to bound; the
transport read limit remains an `rmcp` concern (SSE events are capped at
16 MiB there, stdio lines are unbounded) and is noted in the ledger.

Co-Authored-By: romy <[email protected]>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@lg2m
lg2m merged commit bd8c580 into main Sep 26, 2026
6 checks passed
@lg2m
lg2m deleted the feat/eng-939-mcp-pinning-stack branch September 26, 2026 06:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a46fde79c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp.rs
.expect("the validated concurrency bound fits usize");
settings.pin = server
.pin()
.map(|pin| pin.parse().expect("the validated pin is a tool-set digest"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate pack-provided pins before infallible parsing

When an admitted agent pack supplies an unshadowed MCP server with a malformed pin, this expect is reachable: load_pack only rejects removals and literal secrets, while finish_for_client applies the pack's McpServerPatch without calling validate_mcp_servers. Configuration loading therefore succeeds, but starting the affected profile or running qq mcp inspect panics instead of returning an actionable configuration error; validate pack MCP declarations, including the pin, before constructing McpServerConfig.

AGENTS.md reference: AGENTS.md:L96-L101

Useful? React with 👍 / 👎.

lg2m added a commit that referenced this pull request Sep 26, 2026
…an descriptor to v11 (RR8.4 review)

A role-derived effort (fast → low, balanced → medium) ignored what the child's
route accepts: `fast` onto a model without reasoning sent an effort the
provider rejects, and `balanced` onto a route advertising only `[low, high]`
failed admission as ReasoningEffortNotAdvertised. When the root builds the
roster from a catalog it knows, a derived effort is now fitted first: a model
without reasoning takes `default` (nothing sent) and a ladder lacking the level
yields the highest rung at or below it. An explicit entry effort is untouched
and validated at the child's load as before. Test:
a_derived_roster_effort_is_fitted_to_the_child_route.

`DelegationRosterEntry.effort` changed the descriptor's canonical bytes without
the version bump the module requires: DESCRIPTOR_VERSION 10 → 11 (#194 took
v10 for MCP pins), digest domain and golden re-pinned, `delegation.effort`
added to the mutation test.

Docs: `worker_model` is a balanced roster entry and runs at medium; the text
claiming it "inherits as before" was wrong. Ledger records the review round.

Linear: ENG-956
lg2m added a commit that referenced this pull request Sep 26, 2026
…an descriptor to v11 (RR8.4 review)

A role-derived effort (fast → low, balanced → medium) ignored what the child's
route accepts: `fast` onto a model without reasoning sent an effort the
provider rejects, and `balanced` onto a route advertising only `[low, high]`
failed admission as ReasoningEffortNotAdvertised. When the root builds the
roster from a catalog it knows, a derived effort is now fitted first: a model
without reasoning takes `default` (nothing sent) and a ladder lacking the level
yields the highest rung at or below it. An explicit entry effort is untouched
and validated at the child's load as before. Test:
a_derived_roster_effort_is_fitted_to_the_child_route.

`DelegationRosterEntry.effort` changed the descriptor's canonical bytes without
the version bump the module requires: DESCRIPTOR_VERSION 10 → 11 (#194 took
v10 for MCP pins), digest domain and golden re-pinned, `delegation.effort`
added to the mutation test.

Docs: `worker_model` is a balanced roster entry and runs at medium; the text
claiming it "inherits as before" was wrong. Ledger records the review round.

Linear: ENG-956
lg2m added a commit that referenced this pull request Sep 26, 2026
…an descriptor to v11 (RR8.4 review)

A role-derived effort (fast → low, balanced → medium) ignored what the child's
route accepts: `fast` onto a model without reasoning sent an effort the
provider rejects, and `balanced` onto a route advertising only `[low, high]`
failed admission as ReasoningEffortNotAdvertised. When the root builds the
roster from a catalog it knows, a derived effort is now fitted first: a model
without reasoning takes `default` (nothing sent) and a ladder lacking the level
yields the highest rung at or below it. An explicit entry effort is untouched
and validated at the child's load as before. Test:
a_derived_roster_effort_is_fitted_to_the_child_route.

`DelegationRosterEntry.effort` changed the descriptor's canonical bytes without
the version bump the module requires: DESCRIPTOR_VERSION 10 → 11 (#194 took
v10 for MCP pins), digest domain and golden re-pinned, `delegation.effort`
added to the mutation test.

Docs: `worker_model` is a balanced roster entry and runs at medium; the text
claiming it "inherits as before" was wrong. Ledger records the review round.

Linear: ENG-956
lg2m added a commit that referenced this pull request Sep 28, 2026
…an descriptor to v11 (RR8.4 review)

A role-derived effort (fast → low, balanced → medium) ignored what the child's
route accepts: `fast` onto a model without reasoning sent an effort the
provider rejects, and `balanced` onto a route advertising only `[low, high]`
failed admission as ReasoningEffortNotAdvertised. When the root builds the
roster from a catalog it knows, a derived effort is now fitted first: a model
without reasoning takes `default` (nothing sent) and a ladder lacking the level
yields the highest rung at or below it. An explicit entry effort is untouched
and validated at the child's load as before. Test:
a_derived_roster_effort_is_fitted_to_the_child_route.

`DelegationRosterEntry.effort` changed the descriptor's canonical bytes without
the version bump the module requires: DESCRIPTOR_VERSION 10 → 11 (#194 took
v10 for MCP pins), digest domain and golden re-pinned, `delegation.effort`
added to the mutation test.

Docs: `worker_model` is a balanced roster entry and runs at medium; the text
claiming it "inherits as before" was wrong. Ledger records the review round.

Linear: ENG-956
lg2m added a commit that referenced this pull request Sep 28, 2026
…er role (RR8.4) (#201)

* feat(delegation): choose a sub-agent's reasoning effort from its roster role (RR8.4)

Children inherited the parent session's effort pin verbatim, so a read-only
review worker under `max` spent ~14 k hidden reasoning tokens per read_file
turn (the audited 33-minute run). The effort is now chosen at spawn from the
roster entry the call resolved through: an explicit `effort` on the entry
wins; otherwise fast → low and balanced → medium, each capped by the parent's
own pin, and strong inherits. The chosen value is written to the child's
session row in the creation transaction so the loader, replay and clients
agree. Legacy worker-model spawns and audits inherit as before.

Config: `delegation.roster[].effort`. Protocol: `DelegationRosterEntry.effort`
(optional, additive; goldens unchanged) and `child_reasoning_effort`.

Tests: child_effort_derives_from_the_role_and_never_exceeds_the_parent,
a_balanced_child_of_a_max_effort_parent_is_admitted_at_medium,
roster effort round-trip in delegation_roster_layers_validates_….

Linear: ENG-956

* docs(plans): ledger RR8.1–RR8.4 output-cap stack (ENG-953..956)

* fix(delegation): fit a derived child effort to its route; bump the plan descriptor to v11 (RR8.4 review)

A role-derived effort (fast → low, balanced → medium) ignored what the child's
route accepts: `fast` onto a model without reasoning sent an effort the
provider rejects, and `balanced` onto a route advertising only `[low, high]`
failed admission as ReasoningEffortNotAdvertised. When the root builds the
roster from a catalog it knows, a derived effort is now fitted first: a model
without reasoning takes `default` (nothing sent) and a ladder lacking the level
yields the highest rung at or below it. An explicit entry effort is untouched
and validated at the child's load as before. Test:
a_derived_roster_effort_is_fitted_to_the_child_route.

`DelegationRosterEntry.effort` changed the descriptor's canonical bytes without
the version bump the module requires: DESCRIPTOR_VERSION 10 → 11 (#194 took
v10 for MCP pins), digest domain and golden re-pinned, `delegation.effort`
added to the mutation test.

Docs: `worker_model` is a balanced roster entry and runs at medium; the text
claiming it "inherits as before" was wrong. Ledger records the review round.

Linear: ENG-956

* docs(plans): ledger the second RR8 review round

* docs(plans): ledger the third RR8 review round

* docs(plans): ledger the third RR8 review round on the cap stack

* docs(design): the roster has been in the descriptor since version 4; ledger round four
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