Skip to content

fix: enforce tool grammar checks when a local server starts - #386

Merged
kevin-orellana merged 5 commits into
mainfrom
feature/missing-server-grammar-start
Nov 11, 2026
Merged

kevin-orellana merged 5 commits into
mainfrom
feature/missing-server-grammar-start

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Strands Box uses tool grammars to translate command arguments into policy actions. If a local Model Context Protocol (MCP) server's executable was missing or unreadable at Box startup, Box did not record that file for its grammar. An executable created later could then receive general permission to start, without the required grammar check. It could run with the server's filesystem grants.

Solution. Before the workload starts, Box records available executable files and their command names for each grammar. These records are grammar bindings.

When the agent requests a server, Box checks whether an installed grammar covers the executable's filename. If so, the file and name must match a startup record. If no record matches, Box refuses that server start. Box remains usable. General permission to start a process cannot substitute for this record.

Trade-off. Servers still start on demand, and an unused missing executable does not prevent Box startup. A later request can succeed if its path reaches an executable that Box already recorded under the same command name. Existing replacement checks still apply. If the executable is new to this run, restart Box before this server can use it.

Figure 1: Local server starts keep their grammar check. Box first checks whether a recorded path now points to a different file under the same command name. It refuses that start even if another startup record identifies the replacement file. The diagram assumes these replacement checks pass.

This diagram covers a local server whose executable filename matches the program name in an installed grammar. Box records available executable files and their command names at startup, but starts servers only on request. Box refuses the start if a recorded path names a different file under that command name, even if another record identifies it. After replacement checks pass, a matching file and name let grammar policy permit or deny the start. Box refuses a start with no matching record and remains usable after either refusal. A later request can use a previously recorded file under the same name, but a new executable requires a new Box run.

Editable diagram.

Description

The repair checks this requirement in GrammarBindings::coverage_for. It also checks before the policy engine returns early because it has no grammar bindings. Existing replacement checks retain their order. The repair adds no configuration key, policy action, public export, or protocol shape.

This is a deliberate change to server startup on Linux and macOS. The operator approved this behavior change during implementation planning. The user and design guides describe the refusal and limits on retries. Thirteen regression tests cover unavailable bindings, general and grammar permissions, ordinary process starts, replaced files, and a later successful retry.

Codex helped prepare the code, tests, diagram, and description.

Related Issues

Issue #38 tracks tool packs and their grammar support. Tool packs configure tools and can include grammars. Issue #385 discusses how Box selects executable files for tool commands.

Type of Change

Bug fix

Testing

The current head is 527bbca41554621126009945b832948ed3c82a80. Hosted continuous integration (CI) tests merge commit 194c294573b779d7f665fa6358078acbf27fbfd8. The two commits have identical file trees. Local checks use Amazon Linux 2023 Arm64 as a non-root user.

The totals count primary test results. They exclude duplicate summaries from child processes.

Check Result
Hosted workspace suites Linux: 5,353 primary passes, zero failures, 20 ignored. macOS: 4,942 primary passes, zero failures, 19 ignored. Each platform passed all 13 new regressions and all 23 native server-start tests.
Hosted integration gates Linux passed 131 cases and omitted ten under declared platform exclusions. macOS passed 129 cases and omitted 12 under declared platform exclusions. These deterministic gates contain all 141 expected records on each platform. They report no failures, integrity problems, or quarantined cases.
Formatting, Clippy, documentation-site checks, and CodeQL Passed on the current head. All 27 site-manifest tests passed locally and in CI. Workspace Clippy used the repository's exact list of lint allowances.
Local workspace suite 5,351 primary passes, two failures, 20 ignored. All 13 new regressions and all 23 native server-start tests passed. The failure details and follow-up controls appear below.
Refusal controls before the repair The bare-name native regression fails on unchanged d9346bf. The absolute-command regression fails on unchanged ec5ef77. Each control adds only the native test changes and fails at the missing-refusal assertion. Six policy/composition assertions fail before the repair, while five compatibility controls pass.
Additional policy and feature checks Both changed packages build with all features and separately without default features. The policy suite with all features passed 615 tests with eight ignored. The default-feature suite passed 427 tests with six ignored. Both policy Clippy configurations passed. These earlier runs used the same production policy code.
Strict policy documentation Documentation with default features passed with dependencies. Policy-only documentation with all features passed with --no-deps. These earlier runs used the same policy code.

The native regressions test bare program names and absolute executable paths. They verify that the refused executable never runs, Box remains usable, and an unrelated server starts. The trusted test host then creates a link to a program that Box already recorded. That host opens a new client to verify the successful retry. Box does not approve arbitrary new files.

The local workspace failures were:

  • box_telemetry::an_otlp_target_receives_the_records_with_the_secret_attached: its fixture reported an empty HTTP header. The complete target then passed 25 tests with one ignored at its usual parallelism. The same case passed in both hosted suites. The local failure's cause remains unresolved.
  • mcp_alias_fallback::an_incompatible_frame_after_readiness_fails_without_fallback: the fixture could not start its executable (Text file busy, operating-system error 26). A repeat of the target, with its usual parallelism, failed at the same fixture step in a different test. The same error occurred in three tests on unchanged upstream 8a5f9ba. Six tests passed. All nine alias tests passed in both hosted suites. The error also occurs without this repair, but its exact cause remains unresolved.

These repeats and upstream controls do not make the local full-suite result a pass. An earlier local attempt exhausted disk space while the linker combined the build outputs. It executed no tests. The counts above come from the completed retry.

The Linux assertion for alias reads and the test that needs a live credentials daemon were unavailable. An optional assertion about process groups lacked its instrumentation. Eight of the 20 ignored Linux entries are child-only entrypoints that passing parent tests call. Other ignored cases did not run.

Example packages built, but there were no example scripts. No live tutorial for the software development kit (SDK) ran. Hosted CI ran the native macOS checks. The development host did not run those checks locally. The supplemental macOS checks could not run the full suite for signed native enforcement. The required SDK and a current signed receipt were unavailable.

The development host lacks just, so local workspace lint used Cargo to run the exact justfile recipe. The recipe allows these lints: too_many_arguments, only_used_in_recursion, await_holding_refcell_ref, explicit_auto_deref, chunks_exact_to_as_chunks, dead_code, and non_snake_case.

An additional documentation build checked all features and dependencies with strict settings. It failed on existing links in strands-shell. All three affected Shell files are byte-identical to the original PR base. This failure is separate from the required documentation check with default features and the additional policy-only check. Both of those checks passed.

The current head includes upstream #394. That change fixes the initializer in a test helper that prevented the preceding CI run from compiling. The failed run executed neither platform's workspace suite. The current results above come from the repaired tree.

The pinned draw.io desktop 32.4.1 container exported the figure at scale 2 and border 20. Layout checks reported no errors or warnings. The control render of the committed diagram produced identical bytes. Visual inspection covered the full-size PNG and the image at PR width.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

The Clippy attestation includes the lint allowances above, which the repository documents.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Local agent reviews are complete. The human author still needs to confirm a review of every line of code, so that checkbox remains unchecked.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

A missing or unreadable MCP server program leaves no startup grammar binding.
A later executable can then receive general process-start permission instead
of the installed grammar check, with the server's filesystem grants.

## Solution

Require the existing program-file and called-name binding at each matching
server-start request, including when the policy engine has no bound files.
Refuse only that start if its binding is unavailable. Keep on-demand startup
and allow a retry through an already-bound program. A new program identity
requires a new Box run.

The operator explicitly approved this shared Linux/macOS request-time refusal
on November 10, 2026. The refusal is the changed observable behavior; no
configuration keys, policy actions, public exports, or protocol shapes change.
Update the operator and design guides and include the explanatory figure.

## Tests

The three a_server_requires_its_grammar regressions and eight
missing_server_checks tests all pass. Before the repair, six assertions fail;
five compatibility controls pass on both revisions.

a_late_server_is_refused_until_its_path_reaches_an_approved_program passes
natively on Linux Arm64 and fails on unchanged d9346bf at the refusal assertion.
It proves no execution on refusal, continued Box operation, an unrelated server
start, and a same-Box retry through an already-bound file. The trusted test host
supplies that retry link and client.

scripts/test-all.sh reports 5,264 passes and 18 ignored entries. Two initially
skipped script-boundary tests pass separately after helper placement. The
existing alias-read assertion and live credentials-daemon fixture remain gaps.
No scripted examples exist and no live SDK tutorial ran.

The deterministic suite passes all 131 Linux cases and records ten declared
macOS-only skips, with no quarantine or integrity problems. Both affected
packages build with all features and without default features. Formatting,
workspace Clippy with the justfile allowlist, and all 27 site-manifest tests
pass. Native macOS validation has not run locally.
@kevin-orellana kevin-orellana changed the title Enforce tool grammar checks when a local server starts fix: enforce tool grammar checks when a local server starts Nov 10, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 10, 2026 07:00
Comment thread crates/policy/src/grammar/bindings.rs Resolved
Comment thread docs/design/mcp.md Resolved
Comment thread docs/user/mcp.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The fix is correct for every case I traced: a server start whose called name matches a grammar now has to go through a binding recorded at startup. The remaining gaps are prose that the change makes wrong, one case that Box doesn't report at startup, and tests that compare substrings instead of whole values.

Review Categories
  • Design docs: The governing decision record and the AGENTS.md premise statements still list only the earlier refusal cases and server-start outcomes.
  • Operator experience: A server that requires a binding but can't be bound at startup gets no startup signal, and the documented remedy doesn't fit every cause.
  • Tests: The new refusal assertions check message fragments, not the whole CoverageRefusal value.
Assumptions and rules checked that held
  • Server program missing at startup and created later → UnboundServer refusal, with no fallback to shell:spawn (also ran the 3 new policy tests; all pass).
  • Server present and bound at startup → Parsed happens before unbound, so the grammar's permit and deny behaviour is unchanged.
  • PATH order writable:trusted, with a binary the agent plants in writable/ after startup → it has a new file identity, so the start is refused (before this PR, shell:spawn decided it).
  • Server whose name has no grammar → None, so shell:spawn decides it, as before.
  • tool-grammars turned off → no grammars installed, so requires_binding is always false.
  • Starter::Agent paths are unchanged, and the ordering of the ReplacedFile, gone_under and ServerName refusals is preserved.
  • Startup binding (resolve on spec.search_path() → granted_path) and the leaf launcher's program_identity use the same resolution, so a bound server matches at request time.
  • The empty-bindings fast path in policy.rs is defensive only: a grammar's own [tool] always binds, so this shouldn't break anything.
  • No new pub use, config key, policy action or protocol shape. The narrower server-start behaviour is stated as operator-approved.

The regression tests are thorough, especially the native refusal-and-retry test.

## Problem

The refusal tests checked message fragments, so they did not pin the reported
called name and program path. The binding decision still described three
pre-policy refusal cases and agent-copy fallback without the new server rule.
The recovery guide also did not explain files that were unreadable at startup.

## Solution

Compare complete UnboundServer values in all three policy regressions,
including the canonical path in the policy-engine case. Explain the fourth
pre-policy refusal, limit ordinary copy fallback to unbound agent commands,
and require new or previously unreadable executables to be readable and
executable before a new Box run. Preserve the same-name retry and replacement
checks. The runtime implementation remains unchanged from 0cc3633.

## Tests

The strengthened policy regressions pass with all features (3 tests) and the
default features (2 tests). Formatting, both policy Clippy configurations,
and all 27 site-manifest tests pass. The full default policy suite at 0cc3633
passed 427 tests with 6 ignored; unchanged production code is covered by that
suite and the previous all-feature and native runs.

Strict default-feature policy documentation passed including dependencies.
Strict all-feature policy-only documentation passed. The extra all-feature
dependency documentation build failed on unchanged strands-shell links; its
three affected files match the PR base byte for byte.

The first hosted run passed all 12 new regressions on Linux and macOS. Its
macOS workspace failed the unchanged five-second diagnostics replay timeout;
the new branch run must complete before a final CI success claim.
@github-actions

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 29f19f5. The new commit changes only tests and docs. The runtime code is the same as at 0cc3633, which I reviewed before. All three earlier threads are addressed, and I have no new findings.

Re-checked at this head
  • Policy tests now compare the whole UnboundServer { name, program_path } value, including the canonical path in the policy-engine test. Ran them: 3/3 pass with --all-features and 2/2 with default features.
  • decisions.md now lists four refusals before policy. The fourth, an unbound server start, matches CoverageRefusal::UnboundServer. The shell:spawn fallback for a copy is now limited to agent spawns, which matches Starter::Agent.
  • The user guides' fix for a refused start now covers a program that was unreadable at startup (make it readable and executable, then start a new run). That fixes the wrong instruction for the execute-only case.
  • I accept both reasons given for declining:
    • The startup warning: a retry through a link to an already-bound file can still succeed, so a blanket "will be refused" would be wrong.
    • The AGENTS.md wording: those sentences state conditions for a permitted start and were already incomplete for the existing replaced-file refusal.

The rules and cases from the previous summary still hold, because the runtime code is unchanged.

Problem:
Main now supports absolute MCP executable commands and conflicts with the server-start guidance. The grammar-binding repair also needs native coverage for absolute commands.

Solution:
Merge main at ec5ef77, preserve both documentation changes, and exercise the same refusal and approved-file retry scenario for bare and absolute configured commands. The repair guard is unchanged.

Tests:
Full local workspace: 5,274 primary passes, zero failures, 18 ignored. All 22 native server-start tests and 27 site checks pass. The absolute test fails at the intended refusal assertion on ec5ef77 with only the test changes. Formatting and workspace Clippy pass. Two existing runtime exclusions and example coverage limits remain documented.
@github-actions

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 4caa7c5, which merges main at ec5ef77 (#377, absolute MCP executable commands) into 29f19f5. The PR's server-start check is unchanged. It works for absolute commands, and I have no new findings.

Cases and rules checked that held
  • Absolute command, present at startup: bind_tool_grammars resolves ProcessSpec::program() (the full command[0]) and binds that file under called_name (its filename). At request time, authorize_mcp_start passes McpServer::program() (the filename) as the called name and the executable as program_path. The name and file match, so the grammar decides the start.
  • Absolute command, missing at startup and created later: refused with UnboundServer. The new a_late_absolute_server_… test covers this. The author reports that it fails on ec5ef77 without the fix.
  • Absolute command whose filename has no grammar: requires_binding is false, so shell:spawn decides, as before.
  • Bare command: unchanged from 29f19f5.
  • Merge conflicts in docs/user/mcp.md: both sides are kept. The guard paragraph now says "server executable's filename", which matches main's alias rule, and the error table keeps both rows.
  • Tests run:
    • Policy tests: 3/3 pass with --all-features.
    • The two native late-server tests skip on this host because the namespace launcher isn't usable here. I checked the absolute case by reading the code instead.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 2b1abad. Since 4caa7c5 the only change is in docs/user/mcp.md, and I have no new findings. The approved-program-file guidance moves out of the server-start error table into the prose that describes the check.

Checks that held
  • "When a command matches a declared server": this is accurate. The broker matches the harness command to an [mcp.<name>] entry before authorize_mcp_start runs, so an unmatched command still gets the no MCP server declares … errors and never reaches the grammar check.
  • Quoted message: its tool grammar requires an approved program file matches the CoverageRefusal::UnboundServer text in crates/policy/src/grammar/bindings.rs.
  • Recovery steps: the new-run step and the retry with a link to an already-bound file carry over unchanged. They match docs/user/tool-grammars.md and the decision record.
  • Links: no doc or site check pointed at the removed table row.
  • Code: unchanged since my last review, so the bare and absolute command cases from that review still hold.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 527bbca, which merges main at 8a5f9ba (#272 ingress, #357 ordinary fallback beside MCP aliases, #299, #394). The PR's own change on top of main is line-for-line identical to its change at 2b1abad on top of ec5ef77, and I have no new findings.

Cases and rules checked that held
  • Unmatched command on a server alias (new in fix(mcp)!: preserve ordinary program execution beside MCP aliases #357): admit_server returns Ok(None) and the alias runs the ordinary program inside the agent's sandbox. It never reaches authorize_mcp_start, so the grammar check rightly doesn't apply. The guide's "When a command matches a declared server" wording stays accurate.
  • Matched command whose program appeared after startup: Ok(Some(_)) leads to start_mcp_server, then UnboundServer, then an error frame. It is a policy refusal, so it doesn't fall back, matching "A policy denial … never falls back" in docs/user/mcp.md.
  • Startup binding: bind_tool_grammars is unchanged, and fix(mcp)!: preserve ordinary program execution beside MCP aliases #357's bare_names/HostPrograms don't change how contained_mcp programs resolve or bind.
  • Tests run:
    • All 8 hosted tests the PR adds pass, and 52 policy grammar tests pass with --all-features.
    • Two hosted tests that need the trampoline binary fail here: a_local_server_refuses_a_grant_replaced_after_startup_approval and a_fatal_schema_install_records_the_server_it_refused. They fail the same way on main (8a5f9ba), so this is the host environment, not the PR.
    • The native start tests skip here because the namespace launcher isn't usable.

@kevin-orellana
kevin-orellana merged commit 2914d12 into main Nov 11, 2026
27 checks passed
@kevin-orellana
kevin-orellana deleted the feature/missing-server-grammar-start branch November 11, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants