Skip to content

Subagent agent name is not persisted, so nested subagents lose inherited permission restrictions #30610

Closed

Description

@literally-dan

Description

When the task tool creates a subagent session it does not store the agent name on the new session row. If that subagent spawns its own subagent, the permission resolver reads parent.agent to inherit the parent's restrictions, finds it empty, and drops the parent agent's edit denies on the grandchild.

The practical effect: a Plan-mode subagent that spawns another subagent ends up with a grandchild that can edit files, even though Plan mode forbids edits.

This is a different root cause from #30527, which is about prompt-time setPermission replacing instead of merging the ruleset. Here the agent column is never written at session creation, so deriveSubagentSessionPermission has nothing to read. Same code area as #26597, #26700, and #26747.

I have a fix that sets the agent name when the subagent session is created.

Plugins

None

OpenCode version

1.15.13

Steps to reproduce

  1. Use an agent whose permissions deny edits (for example Plan mode).
  2. Have it spawn a subagent via the task tool, and have that subagent spawn another subagent.
  3. The deepest subagent is allowed to edit, because the deny was not inherited.

Screenshot and/or share link

No response

Operating System

Linux 6.17.0-29-generic

Terminal

foot

Activity

  1. literally-dan commented on Jun 3, 2026

    @literally-dan
    Author

    Closing this, I opened it before it was ready for review. I'll reopen once I've gone over it properly.

  2. changed the title [-]Nested subagents don't inherit the parent agent's permission restrictions[/-] [+]Subagent `agent` name is not persisted, so nested subagents lose inherited permission restrictions[/+] on Jun 3, 2026
  3. literally-dan commented on Jun 9, 2026

    @literally-dan
    Author

    Resolved on dev: tool/task.ts:151/:200 now set agent: next.name on the subagent session, so nested subagents inherit the parent agent's restrictions. Closing.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions