Skip to content

fix(shell): record an answered stat, lstat, or access as a response - #144

Merged
priyasingh2111 merged 2 commits into
mainfrom
feature/shell-record-answered-probes
Oct 29, 2026
Merged

priyasingh2111 merged 2 commits into
mainfrom
feature/shell-record-answered-probes

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Problem: An operator can cap how many files the agent may check. When the agent checked a file that does not exist, the Shell recorded the check as an error, and a cap keyed on fs:read::response does not count errors. So the agent could check any number of missing files.

Fix: The Shell now records an answered test -e, test -L, or test -r as a response, whether the answer is "yes" or "no". A check that Box itself refuses stays an error.

Description

What the history records. After an admitted check, the box records fs:read::response when the check happened and the agent got an answer, or fs:read::error when it did not happen. A check that policy denies records only fs:read::request.

Case Example main This PR
File does not exist test -e missing.txt error response
Parent folder does not exist test -e nodir/f.txt error response
Host says "no access" test -r ~/locked error response
Reach floor refuses a metadata read of <box_dir>/private/secret.txt error error
Admission-window guard refuses test -e present.txt while the namespace changes error error
Policy denies a forbid on the path request only request only
Run a non-executable program by path, or a glob with no match ./notes.txt, ls *.zzz error error (unchanged)

How.

  • Kernel gains stat_answer, lstat_answer, and access_answer. They return an admission-window refusal as an error, so the Shell can tell a missing file from its own refusal. They have no default, so each kernel must forward them.
  • Mediated records Completed for an answer and Failed for a refusal, for stat, lstat, and access only. is_executable, find_in_path, and glob do not change.
  • The policy engine does not convert outcomes. A reach-floor refusal stays fs:read::error.

Interface change, approved by the operator. This changes what when temporal observes. A rule keyed on fs:read::error{read_metadata} no longer matches an answered test -e, test -L, or test -r of a missing path. A cap on attempts should count fs:read::request, which also counts denied attempts. docs/user/policy/actions.md, docs/design/policy.md, crates/policy/README.md, and docs/design/decisions.md describe the new behaviour.

Commits. The first commit fixed this broadly, and it also recorded refusals as responses. The second commit narrows it to the above, after review.

Not in this PR. Python (os.stat(), Path.exists() and the other predicates) keeps its behaviour on main. It needs its own change, because its swap guard and a real "not a directory" answer return the same error code.

Related Issues

None

Type of Change

Bug fix

Testing

  • A cap of 3 trips after 3 checks of missing files (a_read_metadata_budget_counts_probes_of_absent_paths).
  • an_answered_probe_reports_a_completed_effect: test -e, test -r, and test -L of a missing path record Completed.
  • a_probe_the_admission_window_refuses_reports_a_failure: under namespace churn, only checks that answered record Completed, for test -e, test -L, and test -r.
  • a_metadata_read_the_floor_refuses_meets_no_response_precondition: a reach-floor refusal does not satisfy a ::response precondition, and an answered check does.
  • Each test fails when its part of the change is removed.
  • I ran the relevant suites: cargo test --workspace --all-features (4,324 passed, 0 failed), and test-integ/run.sh on macOS (GREEN, 8 Linux-only skips).
  • If I touched Rust, I ran cargo fmt --all --check and the CI clippy gate. No new warnings.

Not run locally: Linux. CI covers it.

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.

Comment thread crates/policy/src/dogwood.rs Resolved
@github-actions

Copy link
Copy Markdown

Issue (governance): This change alters what when temporal { … } observes — a frozen surface per AGENTS.md, which requires the user's explicit approval before code and notes an agent "may not grant it to itself." The PR body says "The operator approved this change," but the PR carries only the strands-running label (no api/needs-review/approval label) and the approval isn't linked to a traceable record. Please attach the approval (or the internal Robosec ticket reference) and apply the appropriate review label so the frozen-surface change is auditable.

Issue (docs): docs/user/policy/actions.md (the ::error row) states that ::error means "The operation did not happen." After this change, a metadata probe answered "no" (e.g. stat of a missing path) records as ::response, not ::error — directly contradicting that row for read_metadata. The PR checklist marks docs as updated, but the diff touches no user-facing docs (only UPSTREAM.md, a vendoring record).

Suggestion: Update actions.md to note that an answered metadata probe counts as a ::response regardless of the answer, so operators keying rules on fs:read::error{read_metadata} understand it will no longer fire.

@github-actions

Copy link
Copy Markdown

Assessment: Comment

The fix is well-targeted and the engine-level backstop in outcome_event is the right place to close the defect across every PEP. I traced the load-bearing claims and they hold: the swap-guard Stat still reports Failed (it fails at HeldPath::of, before the new Completed arm), outcome_event is the single outcome chokepoint, and report_probe only runs post-admission so a denied probe still records nothing. My feedback is about governance and documentation of an observable change, not correctness.

Review themes
  • Frozen-surface governance: The change narrows what when temporal observes (fs:read::error{read_metadata} becomes unreachable). This needs a traceable record of the operator approval and the right review label — the PR body asserts approval but nothing is linked.
  • Documentation: An operator-observable behavior change (a negative metadata probe becomes a ::response) contradicts docs/user/policy/actions.md, yet no user-facing doc was updated. The engine rationale also lives only in the PR body; a decisions.md entry would keep it after the squash.
  • Test quality (minor): metadata_at_least/at_least are near-duplicate rule templates worth parameterizing. Assertions themselves are good — full-value Option<bool> and exact-stdout checks, no per-field gaps.

Nicely scoped change with tests that each pin a distinct part of the fix — thank you for the clear decision notes in the description.

@priyasingh2111

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All points are addressed in 4f3e94c:

  • Docs: docs/user/policy/actions.md, docs/design/policy.md, and crates/policy/README.md now say that an answered metadata check is a ::response, even when the answer is "no".
  • Decision record: the existing temporal-rules-are-enforced-against-recorded-history entry records the change and its cost.
  • Approval: the operator approved the change to what when temporal observes. The tracking ticket is internal. I added the Area - policy-engine and Area - Shell/Monty labels. The repository has no api/needs-review label.
  • Tests: the two budget helpers are now one.

@priyasingh2111
priyasingh2111 marked this pull request as ready for review October 22, 2026 20:01
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Thanks for the thorough follow-up — I re-reviewed at 4f3e94c (isolating the PR's own diff against the current merge base, since the branch was rebased onto a newer main). All five items are resolved:

The new a_read_metadata_budget_counts_probes_of_absent_paths is a nicely discriminating test — three absent-path probes spend a budget of three but not four, which only holds once an answered "no" counts as a response. Nothing further from me.

@ferdingler ferdingler 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.

I think there’s a real accounting defect here, but I’d like us to separate that from the severity assessment and the proposed fix.

The reproduction shows that negative metadata answers don’t consume a response-based budget. It doesn’t demonstrate a containment escape, access beyond the authored grants, or credential disclosure. Positive probes still consume the budget. The broader reconnaissance scenario is explicitly untested, so “the operator gets no protection” is overstating what was demonstrated.

Also, the quoted guidance says to key a precondition on ::response. That makes sense when a later operation requires evidence that an earlier operation happened. A cap on attempted probes has a different requirement. Why isn’t counting ::request the right policy for that? A request-based cap passed targeted tests against

I’m particularly concerned about the suggested defense in depth. Converting every failed metadata operation into a completed response also converts reach-floor refusals into completions. That can satisfy a later permission rule. We reproduced that regression with this PR, so this part of the fix can weaken policy enforcement.

Can we reassess the ticket classification against the demonstrated impact and mitigation? I’d support a focused correction to how answered probes are recorded,
with real refusals preserved. I don’t think this ticket justifies the blanket conversion in the policy engine or the additional changes to executable checks and glob enumeration.

@priyasingh2111

Copy link
Copy Markdown
Contributor Author

@ferdingler, thank you for the review. I agree with each point.

Severity. The reproduction shows an accounting defect: a "no" answer to a metadata check does not charge a ::response budget. It does not show a containment escape, access beyond the authored grants, or credential disclosure, and the reconnaissance scenario is not tested. The internal classification now reflects that.

::request for a cap. Agreed. A cap on attempted probes should count fs:read::request, which also counts denied attempts. ::response is for a precondition that needs evidence that an earlier operation happened. The defect that remains is narrower: an answered "no" is recorded as ::error, which states that the effect did not happen. That affects only rules keyed on ::response or ::error.

Defense in depth. Agreed, and thank you for reproducing it. The conversion in outcome_event cannot see why a metadata read failed, so it also records a reach-floor refusal as a completion, and a later permission rule can then accept it. That weakens enforcement, so I will remove it.

Proposed scope for this PR:

  • stat, lstat, and access record an answered "no" as completed. is_executable and glob keep their current behaviour.
  • Python os.stat() records completed only for NotFound or NotADirectory. Every other failure stays Failed.
  • No conversion in the policy engine.
  • A new test shows that a reach-floor refusal of a metadata read still records fs:read::error and does not satisfy a ::response precondition.
  • The docs change only for answered stat, lstat, and access, and docs/user/policy/actions.md says to count fs:read::request for a cap on attempts.

Does this scope match what you would support? I will push it when you confirm.

@priyasingh2111
priyasingh2111 force-pushed the feature/shell-record-answered-probes branch from 79f6dab to fce43b1 Compare October 28, 2026 00:41
@github-actions

Copy link
Copy Markdown

Assessment update: Request Changes (superseding my earlier Approve)

The head commit moved to fce43b1, but that is a pure rebase onto newer main — the PR's own patch is byte-for-byte identical to the revision I last reviewed (only an UPSTREAM.md hunk-header/context offset shifted). So no code has changed yet.

The reason I'm withdrawing the approval is the defense-in-depth point in the discussion above, which I agree is valid in the current code:

  • dogwood.rs::answered() rewrites any failed ReadMetadata to Completed inside the policy engine. At that layer the engine can't see why the read failed, so a reach-floor refusal (permission denied) is recorded identically to an answered "no" (NotFound). A refusal surfacing as fs:read::response can then satisfy a later ::response temporal precondition — that weakens enforcement rather than just fixing the accounting defect.
  • The effects.rs Stat arm has the same over-breadth: it maps every Err(_) to Completed, not only NotFound/NotADirectory.

Your proposed scope resolves both cleanly:

  • Dropping the policy-engine conversion and classifying at the broker/mediate layer (where NotFound/NotADirectory is distinguishable from a refusal) puts the decision at the only layer that has the information.
  • Narrowing the Python arm to NotFound/NotADirectory and keeping every other failure as Failed matches that.
  • The new test pinning that a reach-floor refusal still records fs:read::error (and does not satisfy a ::response precondition) is exactly the regression guard this needs.
  • Counting fs:read::request for an attempt cap, with ::response reserved for evidence that an earlier operation occurred, is the right distinction.

That scope has my support. I'll re-review once it's pushed.

@ferdingler ferdingler 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.

So this is the current status:

File not found checks should count as completed:
Correctly fixed by this PR.

Actual refusals must not count as completed checks:
Broken by this PR. It converts those too.

Basically, we still need to make Shell distinguish “missing file” from an internal safety refusal.

@priyasingh2111
priyasingh2111 force-pushed the feature/shell-record-answered-probes branch from fce43b1 to acba0de Compare October 28, 2026 19:11
@priyasingh2111 priyasingh2111 changed the title fix(policy): record an answered metadata probe as a response fix(shell): record an answered stat, lstat, or access as a response Oct 28, 2026
@priyasingh2111

Copy link
Copy Markdown
Contributor Author

@ferdingler, thank you. 93fa441 makes the Shell distinguish a missing file from its own refusal, and keeps every refusal as an error.

Case Example Before 93fa441 After 93fa441
File does not exist test -e missing.txt response response
Reach floor refuses a metadata read of <box_dir>/private/secret.txt response error
Admission-window guard refuses test -e present.txt while the namespace changes response error
Run a non-executable program by path, or a glob with no match ./notes.txt, ls *.zzz response error, as on main

What changed:

  • Kernel gains stat_answer, lstat_answer, and access_answer. They return the admission-window refusal as an error, so Mediated records Completed only for an answer. They have no default, so a kernel that delegates must forward them.
  • The conversion in outcome_event is removed, so a reach-floor refusal stays fs:read::error.
  • is_executable, find_in_path, and glob are back to main.
  • docs/user/policy/actions.md says to count fs:read::request for a cap on attempts.

One change from my earlier proposal: I took Python out of this PR completely, instead of narrowing it. The ticket names only the Shell. In Python, the swap guard and a real "not a directory" answer return the same error code, so a correct fix needs more work. Python keeps its behaviour on main, and I will track it as a separate change.

Tests, each of which fails without its part of the change:

  • a_metadata_read_the_floor_refuses_meets_no_response_precondition: a reach-floor refusal does not satisfy a ::response precondition, and an answered check does.
  • a_probe_the_admission_window_refuses_reports_a_failure: under namespace churn, only checks that answered record Completed, for test -e, test -L, and test -r.
  • an_answered_probe_reports_a_completed_effect: test -e, test -r, and test -L of a missing path record Completed.

The workspace suite passes (4,324 tests), and test-integ is green on macOS.

## Problem

A metadata probe that the workload asks and that gets the answer "no" was
recorded as a failed effect. In the hosted Shell, `stat`, `lstat`, `access`,
`is_executable`, and `glob` reported a "no" answer as
`EffectResult::Failed(NotFound)`. In Monty, `os.stat` of a missing path
recorded `FsResult::Failed`. The policy engine wrote each one to history as
`fs:read::error`.

The workload still received the answer, so the effect occurred. A temporal
budget keyed on `fs:read::response{read_metadata}`, which `crates/policy/AGENTS.md`
recommends, counted only the "yes" answers. A workload could therefore test
any number of absent or inaccessible paths under a policy that limits
enumeration.

## Solution

- `crates/shell`: `Mediated::report_probe` records `EffectResult::Completed`
  for each answered probe. A denied probe still records no outcome. The
  divergence is in `crates/shell/UPSTREAM.md`.
- `crates/box`: the Monty `Stat` effect records `FsResult::Completed` when the
  path is missing. The script still gets the exception.
- `crates/policy`: `outcome_event` records a failed `ReadMetadata` outcome as
  a completed one, for every PEP. A regression in one PEP cannot remove a
  probe from a `::response` budget again.

- Docs: `docs/user/policy/actions.md`, `docs/design/policy.md`, and
  `crates/policy/README.md` state that an answered `read_metadata` records
  a `::response`. The `docs/design/decisions.md` entry
  `temporal-rules-are-enforced-against-recorded-history` records the
  decision and its cost, and `answered` cites it.

Observable change: a negative metadata probe now records
`fs:read::response` with `output.result = completed`, not `fs:read::error`.
Also a negative `is_executable` probe and a `glob` with no match record a
response. A rule keyed on `fs:read::error{read_metadata}` no longer matches a
probe. Each change adds events to `::response`, so a budget or a forbid
counts more, not less. The action names and the fields do not change.

## Tests

- `crates/shell/tests/kernel_effect_interception.rs::an_answered_probe_reports_a_completed_effect`
  pins that `test -e` and `test -r` of an absent path report `Completed`.
- `crates/policy/src/adapters/shell.rs::a_failed_metadata_read_records_a_response`
  pins the engine backstop: a `Failed` metadata outcome charges a
  `::response` rule, and a `Failed` content read does not.
- `crates/policy/tests/temporal_shell_record_kinds_e2e.rs`:
  `a_metadata_probe_answered_no_records_a_response` and
  `a_read_metadata_budget_counts_probes_of_absent_paths` pin the box-level
  result through the hosted Shell. `a_metadata_probe_that_finds_the_path_records_a_response`
  keeps the positive case.
- `crates/box/src/run/broker/python/effects.rs::a_stat_of_a_missing_path_records_completed`
  pins the Monty side.

Each new test failed before its fix. With the Shell fix alone or the engine
backstop alone, the e2e tests pass.

Ran on macOS, on `main` at `0b31256`: `cargo test --workspace --all-features`
(4,291 passed, 0 failed), `cargo fmt --all --check`, the CI clippy gate, and
`test-integ/run.sh` (121 passed, 0 failed, 8 skipped Linux-only cases; two
harness timing tests failed under load and passed when run again).

`crates/box/src/run/broker/python/effects.rs::an_ancestor_swapped_for_a_link_after_approval_is_never_followed`
still holds: a Monty `Stat` that the swap guard refuses reports `Failed`.
The engine still records it as a response, which a budget counts.

Not run: the Linux runtime. `list_dir` of a missing directory still records
`fs:read::error{enumerate}`, and this change does not touch it.
…revert the other probe changes

The first commit recorded every answered metadata probe as a response. It
also recorded refusals as responses: the policy engine converted every failed
metadata read, and the Shell kernel turned an admission-window refusal into a
"no" answer. A refused check could then satisfy a later `::response` rule.

This commit keeps the answered "no" as a response for `stat`, `lstat`, and
`access`, and records each refusal as an error:

- `crates/shell`: `Kernel` gains `stat_answer`, `lstat_answer`, and
  `access_answer`, which return an admission-window refusal as an error.
  They have no default, so each kernel must forward them. `VfsKernel`
  implements them, `CallKernel` and the test kernel forward them, and
  `Mediated::report_answer` records `Completed` for an answer and `Failed`
  for a refusal.
- `crates/policy`: the conversion in `outcome_event` is removed, so a
  reach-floor refusal stays `fs:read::error`.
- `is_executable`, `find_in_path`, and `glob` go back to `main`.
- Python (Monty) goes back to `main`. The ticket names only the Shell.
- Docs describe the Shell checks only, and say to count `fs:read::request`
  for a cap on attempts.

What each case records in the policy history. After an admitted check,
the box records one outcome event:

- `fs:read::response`: the check happened and the workload got an answer,
  yes or no. A rule keyed on `::response` counts it, for example a cap of
  5 checks per hour, or "allow X only after a file check".
- `fs:read::error`: the check did not happen. Box refused it, or it failed
  before it gave an answer. A rule keyed on `::response` does not count it.
- No outcome: policy denied the check, so only `fs:read::request` is
  recorded.

In the table, `response` is `fs:read::response`, `error` is `fs:read::error`,
and `request only` means policy denied the check. A mark shows whether the
record is right for that case.

| Case | Example | main | Commit 1 | Commit 2 |
|---|---|---|---|---|
| File does not exist | `test -e missing.txt` | error ✗ | response ✓ | response ✓ |
| Parent folder does not exist | `test -e nodir/f.txt` | error ✗ | response ✓ | response ✓ |
| Parent is a regular file | `test -e notes.txt/child` | error ✗ | response ✓ | response ✓ |
| Host says "no access" | `test -r ~/locked` | error ✗ | response ✓ | response ✓ |
| Link check of a missing path | `test -L missing-link` | error ✗ | response ✓ | response ✓ |
| Policy denies the check | a `forbid` on the path | request only ✓ | request only ✓ | request only ✓ |
| Reach floor refuses | a metadata read of `<box_dir>/private/secret.txt` with `fs:read` permitted | error ✓ | response ✗ (engine conversion) | error ✓ |
| Admission-window guard refuses | `test -e present.txt` while the workload creates and deletes a folder | error ✓ | response ✗ (`report_probe`) | error ✓ (`stat_answer`) |
| Run a program by path that is not executable | `./notes.txt` | error | response | error, as on main |
| Glob with no match | `ls *.zzz` | error | response | error, as on main |
| Python stat of a missing path | `os.stat("missing.txt")` | error | response | error, as on main |
| Python stat refused | `os.stat("locked.txt")` raises `PermissionError` | error ✓ | response ✗ | error ✓ |

Tests:

- `an_answered_probe_reports_a_completed_effect` now also runs `test -L`
  of a missing path, and fails with the `lstat` of `main`.
- `a_probe_the_admission_window_refuses_reports_a_failure` runs
  `test -e`, `test -L`, and `test -r` while the namespace changes. It fails
  when a refusal records `Completed`, for each of the three.
- `a_metadata_read_the_floor_refuses_meets_no_response_precondition` fails
  with the conversion in `outcome_event`.
- `a_failed_metadata_read_records_an_error` replaces the test that relied on
  that conversion.
- The Monty test `a_stat_of_a_missing_path_records_completed` is removed
  with the Monty change.

Ran on macOS, on `main` at `78d822b`: `cargo test --workspace
--all-features` (4,324 passed, 0 failed), `cargo fmt --all --check`, the CI
clippy gate, and `test-integ/run.sh` (121 passed, 0 failed, 8 skipped
Linux-only cases).

Not run: the Linux runtime.
@priyasingh2111
priyasingh2111 force-pushed the feature/shell-record-answered-probes branch from 93fa441 to 6992dee Compare October 28, 2026 23:48
@github-actions

Copy link
Copy Markdown

Assessment: Approve (replaces my Request Changes on fce43b1)

I re-reviewed at 6992dee against the current merge base. Both over-broad conversions are gone: outcome_event no longer rewrites failed metadata reads, and effects.rs matches main. Only the Shell decides whether a check got an answer or was refused, and only it can tell the two apart. Taking Python out of this PR, rather than narrowing it, is the safer choice, since the swap guard and ENOTDIR share an error code there.

Cases traced through Mediated::report_answer (all correct)
  • Missing path on a direct bind → Ok(default) → Completed → ::response (an_answered_probe_reports_a_completed_effect, e2e budget test)
  • Admission-window guard refuses → Err from *_answer → Failed → ::error (a_probe_the_admission_window_refuses_reports_a_failure)
  • Reach floor or policy refuses → refused at admission, so no outcome is recorded and no ::response precondition is met (a_metadata_read_the_floor_refuses_meets_no_response_precondition)
  • A host error other than ENOENT, such as EACCES or ELOOP → still Completed. This is consistent with the docs: the Shell runs in the trusted process outside every sandbox, so this is the host's answer, not a Box refusal
  • A failed metadata outcome in the policy engine → ::error (a_failed_metadata_read_records_an_error)

Rules checked that held:

  • crates/shell/AGENTS.md: admission stays in mediate.rs and the new trait methods take Resolved.
  • The vendored-crate divergence is recorded in UPSTREAM.md.
  • The Kernel methods have no default, so a forwarding kernel can't silently drop a refusal.
  • The docs match the Shell-only scope and the ::request guidance for caps.

I ran the targeted tests locally and they pass: shell kernel_effect_interception (50), the policy e2e file with --features shell-adapter (10), the policy adapter test, and the broker floor test.

@priyasingh2111
priyasingh2111 merged commit a916050 into main Oct 29, 2026
21 checks passed
@priyasingh2111
priyasingh2111 deleted the feature/shell-record-answered-probes branch October 29, 2026 23:34
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