Skip to content

fix(core): include matching deny patterns in permission errors - #62408

Open
rwwiv wants to merge 6 commits into
anomalyco:devfrom
rwwiv:permission-patterns
Open

rwwiv wants to merge 6 commits into
anomalyco:devfrom
rwwiv:permission-patterns

Conversation

@rwwiv

@rwwiv rwwiv commented Nov 6, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #44521

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR includes the matching deny patterns in configured permission errors. For example, echo before && awk 'BEGIN { exit 0 }' && echo after now reports Permission denied: shell. Blocked by configured rule patterns: ["awk *"] rather than just Permission denied: shell, which can lead the agent to conclude that shell access is unavailable.

It uses the last matching rule for each resource and deduplicates the denying patterns, without repeating command arguments. Custom denial reasons and interactive rejection behavior are unchanged. No feature flag is needed for this error-reporting fix.

Related to #51083, which addressed the same issue before being closed by automated cleanup. This version reports all distinct matching deny patterns rather than only the first.

How did you verify your code works?

  • Permission, shell-tool, and session-runner tests: 433 passed, 11 skipped. Coverage includes mixed allowed/denied commands, multiple patterns, last-match precedence, catch-all denies, custom reasons, and delivery to model history. The shell regression checks that no command in a denied chain executes.
  • bun run check and formatting checks passed.
  • Tested a local binary with both awk * and catch-all * denies. Both returned the expected pattern without executing the chain.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Fixes #44521

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change works. I ran the new permission and shell-tool tests against the base, where they fail with the generic Permission denied: shell. With this PR they pass: in the real shell test, a chain containing a denied subcommand reports ["printf blocked *"], and no part of the chain runs. typecheck:tsc passes too. Denial messages from plugin hooks and from the "nobody is present to approve" case are unchanged, and nothing else reads the narrowed BlockedError.resources.

Public API: unchanged. Only the text of configured-deny error messages changes.

Two small requests to keep the change minimal: revert the formatting-only edits to existing permission.test.ts cases, and drop two tests (see inline comments).

Fixes #44521

Comment thread packages/core/test/permission.test.ts Resolved
Comment thread packages/core/test/permission.test.ts Resolved

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All three earlier points are addressed: the unrelated grants reformatting is reverted, and the BlockedError.message unit test and the session-runner scenario are removed. The source is the same as what I verified before, and the permission and shell-tool tests still pass. Public API: unchanged. Nothing further.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Show only the specific permission rule responsible for a denied tool call

1 participant