fix(task): respect subagent explicit edit:allow over inherited parent edit:deny#29235
Open
public-static-void wants to merge 1 commit into
Open
fix(task): respect subagent explicit edit:allow over inherited parent edit:deny#29235public-static-void wants to merge 1 commit into
public-static-void wants to merge 1 commit into
Conversation
… edit:deny Three changes that together allow a subagent's explicit edit-class configuration to override inherited parent restrictions: 1. fromConfig() aliases write/apply_patch to the edit permission key (packages/opencode/src/permission/index.ts) The runtime layer already treats write, apply_patch, and edit as the same tool class via EDIT_TOOLS in core/src/permission.ts, but the config layer stored write: allow as permission: write, invisible to the edit lookup. Aliasing in fromConfig makes the config layer consistent with the runtime. 2. deriveSubagentSessionPermission skips parent edit denies when subagent explicitly allows edit-class tools (packages/opencode/src/agent/subagent-permissions.ts) PR anomalyco#26597 forwarded all parent agent denies to subagents (Plan Mode security). PR anomalyco#27201 scoped this to only edit denies. This change extends the same principle: if the subagent has explicit edit:allow (or write:allow via fix anomalyco#1), the inherited edit:deny is suppressed. The subagent's explicit config represents user intent and overrides inherited restrictions. Plan Mode's edit:deny still cascades to subagents without an explicit edit:allow. 3. prompt() merges tool-level denies into session permission instead of overwriting (packages/opencode/src/session/prompt.ts) The task tool calls ops.prompt() with tool-level denies for todowrite/task/primary_tools. prompt() was overwriting the entire session.permission, destroying any inherited rules (including the Plan Mode edit:deny that deriveSubagentSessionPermission just set up). This fix merges instead of replaces, preserving session-level permission integrity. Fixes the interaction between issues anomalyco#26514 (Plan Mode bypass) and anomalyco#26700 (parent denies over-constrain subagents).
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one related PR that appears to be addressing a very similar issue: Related PR:
This PR appears to directly address the same core issue: ensuring that a subagent's explicit I also found:
The first match (#27654) is the most concerning as a potential duplicate since it has an almost identical title and purpose. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #26514
Closes #26700
Type of change
What does this PR do?
Fixes the interaction between #26514 (Plan Mode bypass) and #26700 (parent denies over-constrain subagents).
Subagents with an explicit
write: allow(oredit: allow) configuration can now actually use edit-class tools, even when their parent agent hasedit: deny(Plan Mode). Generic subagents without an explicit edit-class allow still inherit the parent's denies. Plan Mode security is preserved.Three changes:
fromConfig()aliaseswrite/apply_patchto theeditpermission key (packages/opencode/src/permission/index.ts). The runtime already treats write, apply_patch, and edit as the same tool class viaEDIT_TOOLS, but the config layer storedwrite: allowaspermission: "write"which is invisible to the"edit"lookup. Aliasing makes config consistent with runtime.deriveSubagentSessionPermission()skips parentedit: denywhen the subagent has explicitedit: allow(packages/opencode/src/agent/subagent-permissions.ts). PR fix(task): subagent inherits parent agent's deny rules (Plan Mode security bypass) #26597 forwarded all parent edit denies to subagents. PR fix(task): preserve subagent self permissions #27201 narrowed it to only edit denies. This extends the same principle: if the subagent explicitly allows edit tools, the inherited deny is suppressed. Generic subagents without explicit edit rules still inherit the parent deny so Plan Mode stays secure.prompt()merges tool-level denies instead of overwriting session permission (packages/opencode/src/session/prompt.ts). The task tool callsops.prompt()with tool-level denies for todowrite/task/primary_tools.prompt()was overwritingsession.permission, destroying inherited rules including the Plan Modeedit: denythatderiveSubagentSessionPermission()just set up. This fix uses[...session.permission, ...permissions]instead ofsession.permission = permissions.This is more complete than the similar PR #27654 which only covers fix 2.
The
fromConfig()aliasing andprompt.tsmerge are needed too.This fix is also complementary to the approach in #24293 which propagated parent session permissions to subagents (enabling inheritance), while this PR adds the explicit allow check on top of that (allowing overrides when the subagent opts in).
How did you verify your code works?
All upstream test scenarios pass:
edit: denyinherited, tools blockedwrite: allow:edit: allowoverrides, tools availableScreenshots / recordings
N/A, no UI changes.
Checklist