Skip to content

fix(core): hide tools whose rules deny every resource - #47337

Closed
rekram1-node wants to merge 2 commits into
v2from
tool-filter-evaluate
Closed

rekram1-node wants to merge 2 commits into
v2from
tool-filter-evaluate

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

Problem

`Tool.snapshot` decides whether a tool is advertised to the model with `whollyDisabled`, which only peeked at the last rule matching the tool's action and hid the tool iff that rule was `{ resource: "*", effect: "deny" }`. Call-time `Permission.evaluate` matches on action and resource. The two disagree whenever a narrower rule for the action trails a catch-all deny:

```
[*, *, deny], [shell, "git ", deny] -> advertised, but every call is denied
[
, , deny], [shell, "rm", ask] -> advertised, but every non-rm call is denied
```

Observed in practice with the built-in `explore` subagent: a user's global `permission.bash = { "rm*": "ask" }` is appended after explore's `{*, *, deny}`, so `shell` shows up in explore's tool list and the model burns calls on `Permission denied: shell` before falling back to grep/glob.

Fix

Define "wholly disabled" via `Permission.evaluate` so the filter cannot drift from call-time semantics: a tool is hidden iff no resource can get past `deny`. Each rule's resource pattern matches itself as a literal under `Wildcard.match`, so the resource patterns of the action's rules form a complete set of probes — a later broader rule overrides a probe exactly when it also covers every resource the probe covers.

Behavior change is limited to rulesets where narrow rules trail a catch-all deny for the same action; a trailing narrow `ask`/`allow` still keeps the tool visible (faithful to `evaluate`), while trailing narrow `deny` rules now hide it.

Note: this does not by itself remove `shell` from `explore` for the `rm*: ask` config above, since `rm foo` genuinely would prompt under those rules. That is a rule merge-order issue (global config appended after built-in agent rules) and will be addressed separately.

Testing

  • Added `hides tools whose narrower trailing rules cannot get past deny` in `packages/core/test/tool-registry.test.ts`
  • `bun test test/tool-registry.test.ts` and `bun test test/permission` pass; `bun typecheck` clean in `packages/core`

@feelxbloom

Copy link
Copy Markdown

Reproducing exactly this on 2.0.18 with a deny-all-then-narrow-allows ladder (four agents configured this way): actions with trailing narrow allows stay advertised while every call outside the allow is denied at settlement, and the model burns several calls on Permission denied before falling back to the nearest read-only tool. Confirmed in both directions on the same host: plugin tools with a name-level * deny vanish from the list entirely, so within one session some denied tools are advertised and others are silently hidden — the model gets no consistent signal. The probe-set replay of Permission.evaluate looks like the right fix for the listed-but-denied direction; noting for completeness that on our ladders the partially-allowed actions (shell narrowed to a few commands) will still be advertised by design, so we are pairing the fix with prompt-level guidance. Happy to test the branch against our config if that would help.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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