Skip to content

feat(policy): decide and record tool pack actions in the policy engine - #247

Merged
ferdingler merged 7 commits into
mainfrom
feature/tool-packs-decide-pack-action
Nov 2, 2026
Merged

ferdingler merged 7 commits into
mainfrom
feature/tool-packs-decide-pack-action

Conversation

@ferdingler

@ferdingler ferdingler commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR adds the decide_pack_action function in the Tool Packs feature. This function is what lets Box actually make a decision (allow/deny) about a tool pack command. After this change, this is how the sequence of actions happen when an Agent runs a shell command.

sequenceDiagram
    participant A as Agent
    participant B as Shell
    participant P as Pack Parser
    participant E as Policy Engine

    A->>B: git push --force origin main
    B->>P: read this command
    P-->>B: action "push", effects [force_push]
    B->>E: decide_pack_action(action)
    E->>E: check the rules and the history
    E-->>B: allowed, here's a receipt
    B->>B: run git
    B->>E: push finished with status 0 (with the receipt)
    E->>E: save it in the history
    B-->>A: git's output
Loading

Related Issues

#38

Type of Change

New feature

Testing

The corpus test now decides every case through the real engine, which makes it slower (about 35 seconds in a debug build). I also added tests for unmodeled being denied, a push allowed only after a passing test run, and a denied action leaving nothing to record, and I broke each guard on purpose and the tests caught it.

  • 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

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

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

## Problem

The policy crate can parse a command line with a tool pack, but no code
decides the pack action that the parse gives. So the box cannot use a
pack action as a decision, and a temporal rule cannot read what a pack
action did. Also, the golden corpus test built the event with its own
private copy of the event builder, and decided it with the Dogwood
authorizer directly. Thus the test did not pin the production code.

## Solution

- Add `PolicyEngine::decide_pack_action` (crate-private). It builds the
  `context.input` record from a parsed pack action (`Parsed::Action` or
  `Parsed::Unmodeled`), with the base fields `program`, `program_path`,
  `cwd`, `args`, `effects`, and `credential_reads`. It decides the record
  through the one live authority, with the same request gate, the same
  durable history, and the same observer as every other decision.
- Add `PolicyEngine::record_pack_response` (crate-private). It records
  the `::response` of a decided pack action, with the exit status in
  `output.status`.
- Add `PackInvocation` and `PackResponse` in the `pack` module, and the
  `ActionIdentity::PackAction` variant.
- Let the complete open path take tool pack schema fragments. Only a
  test constructor, `PolicyEngine::open_with_packs`, uses it now. A
  later change adds the production load.
- The corpus test now opens an engine with the pack, and decides each
  case through `decide_pack_action`. The private event builder and the
  direct authorizer are deleted. The exact rules and the negated rules
  of a corpus load into one engine, so each case takes one decision.
- Add two entries to `docs/design/decisions.md`: a pack action names no
  enforcement point, and `unmodeled` is denied by default. The user
  asked for them in this change.

Nothing calls the new functions outside tests. The `pub use` set does
not change, and `adapters/shell.rs` does not change.

## Tests

- `pack::corpus::every_corpus_case_is_typed_and_decided_by_the_policy_engine`
  pins that the engine types and decides each golden case, that the rule
  over the exact values allows it, and that no negated rule allows it.
- `pack::corpus::a_group_permit_never_reaches_an_unmodeled_command_and_an_explicit_permit_does`
  pins that `unmodeled` is denied under only a `"*"` group permit, and
  that an explicit permit on `unmodeled` allows it.
- `pack::invocation::tests::a_temporal_rule_reads_the_exit_status_that_a_pack_response_records`
  pins that `git push` is allowed only after `cargo test` exits 0.
- `pack::invocation::tests::a_pack_decision_enters_the_one_history_and_reaches_the_observer`
  pins that a `shell:spawn` rule reads a pack decision from the same
  history, and that the observer sees the pack action and its resource.
- `pack::invocation::tests::an_input_that_its_action_schema_does_not_type_is_refused_as_a_fault`
  pins that the request gate refuses an input that the action schema
  does not type, as an internal fault.
- I broke each guard on purpose and the test failed: `unmodeled` in the
  `"*"` group, an unmodeled event with no `effects`, a wrong exit status,
  a wrong event namespace, no observer call, an inverted field value, and
  no request gate.
- I ran build, test, clippy, and fmt for `strands-box-policy` with all
  features, on Linux. Clippy shows 0 warnings in `crates/policy`. I did
  not build on macOS; CI does that.
- The corpus test now takes about 35 seconds in a debug build, because
  each corpus opens a durable engine.
@ferdingler

Copy link
Copy Markdown
Collaborator Author

GPT-Astra review feedback

Codebase design: use one internal decision path.

The shared handler removes duplicated decision handling, but the change still adds a second request contract across PolicyEngine, Authority, and DogwoodEngine. PolicyEngine::decide_input accepts the action identity, JSON input, and observer resource as independent values. PackInvocation already knows how those values belong together. Passing them separately weakens the interface and gives each layer two decision paths to maintain.

The difference is already visible in Authority: decide checks pending and degraded MCP actions, while the generic decide_input route skips those checks. Current callers pass only pack identities, so this is not a demonstrated authorization bypass. It shows why request handling should have one owner.

JSON itself is reasonable for fields defined by a pack schema. Request::McpCall already carries JSON arguments, and the new pack path validates its input against the schema. The concern is exposing a separate decision interface around that representation.

I recommend a private request type with variants for the existing Request and a pack invocation. Route both through one authority decision method and one engine decision method, and remove the parallel decide_input methods. Keep representation-specific conversion inside that boundary, keep the public Request API unchanged, and preserve the pending-response receipt. A pack convenience method can adapt into the common path. This also lets the decision flow avoid the current PolicyEngine → PackInvocation → PolicyEngine round trip.

Reviewed aad686e. All eight focused invocation, corpus, and malformed-input tests passed with --all-features. I did not run the full suite.

@ferdingler
ferdingler marked this pull request as ready for review November 1, 2026 21:19
Comment thread crates/policy/src/pack/invocation.rs Resolved
Comment thread crates/policy/src/policy/authority.rs Resolved
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Comment

I reviewed 6057dfa. The refactor answers the earlier one-decision-path feedback on aad686e: ActionRequest sends both a Request and a pack action through one Authority::decide and one DogwoodEngine::decide, and the parallel decide_input methods are gone. Two gaps remain, and both appear when a caller is wired. An allowed action can lose its ::response, and a staged authority cannot decide pack actions. Neither one can be reached today, because every entry point is dead_code or #[cfg(test)].

Checked and held
  • ActionRequest::Request gets the same identity as before through for_request, including refine_tool_call (arguments Some gives McpTool).
  • The degraded and pending MCP guards still apply only to McpTool. A pack identity cannot match them.
  • entity_json_value sees only grammar-produced Bool, String, and Set<String> values, and the pack loader refuses __-prefixed field names. A command-line word cannot become an entity.
  • Sorting and deduplicating args is safe, because the schema declares args: Set<String>.
  • unmodeled stays outside "*". a_group_permit_never_reaches_an_unmodeled_command_and_an_explicit_permit_does pins this.
  • tool_actions counts only single-component namespaces, so Tool::<pack>::Action is not treated as an MCP tool action.
  • The façade is unchanged: every new item is pub(crate), so the 52-name pub use set holds.
  • decisions.md has entries for the two new decisions.
  • cargo test -p strands-box-policy --all-features --lib pack: 28 passed.
Scope note

The description's sequence diagram shows Shell calling decide_pack_action, but no production caller exists yet (expect(dead_code, reason = "no caller decides a pack action yet")). Please say so in the description, and name the follow-up PR that wires Shell and the staged open.

@kevin-orellana kevin-orellana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The shared decision path looks sound at 6057dfa. The full policy suite passed on 64-bit Arm Linux: 487 passed, seven marked ignored, and no runtime skips. Five additional probes and formatting passed.

The new functions have no production callers yet. The two existing review findings remain prerequisites for production integration: preserve completion history when a pending response is discarded, and carry pack definitions through discovery initialization.

@ferdingler
ferdingler merged commit d112963 into main Nov 2, 2026
49 of 52 checks passed
@ferdingler
ferdingler deleted the feature/tool-packs-decide-pack-action branch November 2, 2026 17:46
@github-actions github-actions Bot mentioned this pull request Nov 2, 2026
7 of 8 tasks
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.

2 participants