Repository navigation
feat(mcp)!: pin MCP tool sets in config and plan identity; enforce at dispatch; add qq mcp inspect - #194
Conversation
… 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>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
… 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>
There was a problem hiding this comment.
💡 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".
| .expect("the validated concurrency bound fits usize"); | ||
| settings.pin = server | ||
| .pin() | ||
| .map(|pin| pin.parse().expect("the validated pin is a tool-set digest")); |
There was a problem hiding this comment.
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 👍 / 👎.
…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
…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
…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
…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
…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
Closes ENG-939. Supersedes #163, #165, and #171 (contributed by @rmondello2629 / Devin; attribution kept as
Co-Authored-Byon 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.qq mcp inspect NAMEconnects 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:McpServerDescriptor, so pinned and unpinned plans shared a plan digest.Intactafter 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.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
Listing { tools, digest, client, generation }before acquiring a permit; after the permit it re-checks the generation and thelist_changedflag (drift → release permit, re-resolve), requires the tool to be present in that listing (UnknownTool), and sends exactly onetools/callwhose enqueue poll runs under a synchronousdispatch_gatethaton_tool_list_changed/bump_generation/shutdownalso hold while flipping flags. The gate covers only that non-blocking poll, never a wait. Non-CallToolResultresponses →InvalidResult.qq-mcp-tool-set-v2, length-prefixed fields (the contributed\0-separated v1 was ambiguous; any v1 pin fails loudly, which is intended).list_changedduring a fetch discards it.McpServerDescriptor.pin,DESCRIPTOR_VERSION9 → 10.McpManager::inspect,ClientSnapshot::mcp_servers,qq mcp inspect(blocking config load, only that server's credential resolved, ctrl-c + 45 s bound).Compatibility / performance
DESCRIPTOR_VERSION9 → 10 invalidates cached plan digests (recompiled on next load). NoPROTOCOL_VERSIONor store-schema change. Only new dependency:sha2inqq-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=4run; 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).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.mdplan identity;protocol.mddescriptor note; guidemcp.md§ Pinning a server's tools andcli.mdqq mcp inspect; ledgerdocs/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 astd::sync::Mutexheld only across a non-blocking poll and flag flips, never across an.await.Not in this PR (deferred with reasons)
start_tool_call: separate design.qq doctorreporting quarantine like unresolved bearers.