#26597 fixed a Plan Mode security bypass by having deriveSubagentSessionPermission() append all parent agent deny rules into the child subagent's session permission. This broke deny-by-default multi-agent configurations where the primary/controller agent is intentionally narrow and delegates to a subagent with its own explicit allowlist.
Root cause: Permission.merge(agent.permission, session.permission) is evaluated with findLast (last-match-wins). The inherited parent denies land at the end of the merged ruleset, so they override the subagent's own allow rules. The subagent's tools disappear from its tool inventory before the LLM ever sees them.
Fix: Only inherit edit-class denies (edit, write, apply_patch) from the parent agent — these are the permissions that matter for the Plan Mode ceiling. Other parent denies describe what the parent itself cannot do and must not constrain the subagent's own explicit allowlist.
The change is one filter condition in src/agent/subagent-permissions.ts:
Added a regression test in test/agent/deny-by-default-subagent-bypass.test.ts that mirrors the controller → executor config from the issue. The test asserts that executor's read, bash, and task allows survive after deriveSubagentSessionPermission, and that edit/write are still denied (Plan Mode ceiling preserved).
Also ran the existing test/agent/plan-mode-subagent-bypass.test.ts to confirm the original #26514 fix is not broken. All 6 tests pass.
Verified end-to-end with a live bun dev session using the minimal config from the issue. Before the fix, the executor session was created with read * -> deny and bash * -> deny inherited from the controller. After the fix, only edit * -> deny and write * -> deny are inherited, and the executor successfully reads files.
Screenshots / recordings
Before fix — executor session created with all controller deny rules inherited:
After fix — executor session only inherits edit-class denies:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26700
Type of change
What does this PR do?
#26597 fixed a Plan Mode security bypass by having deriveSubagentSessionPermission() append all parent agent deny rules into the child subagent's session permission. This broke deny-by-default multi-agent configurations where the primary/controller agent is intentionally narrow and delegates to a subagent with its own explicit allowlist.
Root cause: Permission.merge(agent.permission, session.permission) is evaluated with findLast (last-match-wins). The inherited parent denies land at the end of the merged ruleset, so they override the subagent's own allow rules. The subagent's tools disappear from its tool inventory before the LLM ever sees them.
Fix: Only inherit edit-class denies (edit, write, apply_patch) from the parent agent — these are the permissions that matter for the Plan Mode ceiling. Other parent denies describe what the parent itself cannot do and must not constrain the subagent's own explicit allowlist.
The change is one filter condition in src/agent/subagent-permissions.ts:
How did you verify your code works?
Added a regression test in test/agent/deny-by-default-subagent-bypass.test.ts that mirrors the controller → executor config from the issue. The test asserts that executor's read, bash, and task allows survive after deriveSubagentSessionPermission, and that edit/write are still denied (Plan Mode ceiling preserved).
Also ran the existing test/agent/plan-mode-subagent-bypass.test.ts to confirm the original #26514 fix is not broken. All 6 tests pass.
Verified end-to-end with a live bun dev session using the minimal config from the issue. Before the fix, the executor session was created with read * -> deny and bash * -> deny inherited from the controller. After the fix, only edit * -> deny and write * -> deny are inherited, and the executor successfully reads files.
Screenshots / recordings
Before fix — executor session created with all controller deny rules inherited:
After fix — executor session only inherits edit-class denies:
Checklist