Skip to content

fix(task): respect subagent explicit edit:allow over inherited parent edit:deny#29235

Open
public-static-void wants to merge 1 commit into
anomalyco:devfrom
public-static-void:fix/subagent-edit-allow
Open

fix(task): respect subagent explicit edit:allow over inherited parent edit:deny#29235
public-static-void wants to merge 1 commit into
anomalyco:devfrom
public-static-void:fix/subagent-edit-allow

Conversation

@public-static-void
Copy link
Copy Markdown

@public-static-void public-static-void commented May 25, 2026

Issue for this PR

Closes #26514
Closes #26700

Type of change

  • Bug fix

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 (or edit: allow) configuration can now actually use edit-class tools, even when their parent agent has edit: deny (Plan Mode). Generic subagents without an explicit edit-class allow still inherit the parent's denies. Plan Mode security is preserved.
Three changes:

  1. fromConfig() aliases write/apply_patch to the edit permission key (packages/opencode/src/permission/index.ts). The runtime already treats write, apply_patch, and edit as the same tool class via EDIT_TOOLS, but the config layer stored write: allow as permission: "write" which is invisible to the "edit" lookup. Aliasing makes config consistent with runtime.
  2. deriveSubagentSessionPermission() skips parent edit: deny when the subagent has explicit edit: 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.
  3. prompt() merges tool-level denies instead of overwriting session permission (packages/opencode/src/session/prompt.ts). The task tool calls ops.prompt() with tool-level denies for todowrite/task/primary_tools. prompt() was overwriting session.permission, destroying inherited rules including the Plan Mode edit: deny that deriveSubagentSessionPermission() just set up. This fix uses [...session.permission, ...permissions] instead of session.permission = permissions.

This is more complete than the similar PR #27654 which only covers fix 2.
The fromConfig() aliasing and prompt.ts merge 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:

  • Plan Mode + generic subagent: edit: deny inherited, tools blocked
  • Plan Mode + subagent with write: allow: edit: allow overrides, tools available
  • Deny-by-default parent + capable subagent: subagent explicit allows work
  • Controller/executor delegation (PR fix(task): preserve subagent self permissions #27201 test): passes

Screenshots / recordings

N/A, no UI changes.

Checklist

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

… 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).
@github-actions
Copy link
Copy Markdown
Contributor

ghost commented May 25, 2026

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 edit:allow configuration takes precedence over a parent agent's edit:deny. It's likely either a prior attempt at the same fix, a related issue that was separately worked on, or potentially a duplicate effort.

I also found:

The first match (#27654) is the most concerning as a potential duplicate since it has an almost identical title and purpose.

@github-actions
Copy link
Copy Markdown
Contributor

ghost commented May 25, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Subagent parent deny inheritance over-constrains delegated agents with explicit permissions Subagents Bypass Plan Mode READ-ONLY Restrictions

1 participant