Skip to content

V2 subagent tool does not enforce per-target subagent permissions #35238

Closed

Description

@rekram1-node

Summary

In V2, the subagent tool only has coarse whole-tool visibility filtering. Per-target rules such as allowing only one subagent are not reflected in the model-facing tool definition and are not enforced when the tool executes.

Current behavior

  • ToolRegistry.materialize(...) can hide the entire subagent tool when the active agent has a whole-tool deny such as subagent:*.
  • packages/core/src/tool/subagent.ts checks that the requested target agent exists and is not mode: "primary".
  • It does not call PermissionV2.assert({ action: "subagent", resources: [input.agent], ... }) before spawning the child session.
  • The subagent tool schema/description does not expose a filtered list of subagents allowed by the active agent.

Expected behavior

If an agent is configured to only invoke a subset of subagents, for example only explore, V2 should either:

  • expose only those allowed target subagents to the model, and
  • reject execution for disallowed targets with a clear permission error,

or otherwise document a different explicit policy. The current behavior makes per-target subagent permission rules ineffective as a runtime boundary.

Why this matters

An agent configured with narrow subagent permissions can still call another configured non-primary agent if it knows or guesses the name. This is different from the intended permission model and makes V2 subagent delegation harder to reason about.

Related V1 issues

Code pointers

  • packages/core/src/tool/subagent.ts
  • packages/core/src/tool/registry.ts
  • packages/core/src/permission.ts

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    bugSomething isn't working
    on Jul 5, 2026
  2. tlysanhuo commented on Jul 11, 2026

    @tlysanhuo

    I’m working on a focused V2 fix. Current v2 already has runtime PermissionV2.assert enforcement from #35794, but the per-agent model-facing subagent list was removed with the session request hook in 761f373. I’m restoring the filtered list through the current instruction-guidance path (without reintroducing the removed public hook), and adding coverage for target-specific deny/allow behavior.

  3. martin-braun commented on Aug 6, 2026

    @martin-braun

    yes, I can confirm this issue, I deny all task permissions but for one specific agent in one of my agents. When I accidentally instructed it to update something that can only be done by an agent that is not whitelisted, it still went through and instructed such agent to do the changes for me.

  4. 686f6c61 commented on Aug 7, 2026

    @686f6c61

    I'll take this: enforce per-target subagent permissions in the V2 subagent tool (assert + filtered target list for the model).

  5. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    The V2 subagent tool enforces per-target permissions. The list of subagents shown to the model leaves out any target the agent's permissions deny, and each call checks subagent permission for that specific target.

    The current implementation is in tool/plugin/subagent.ts (#35794).

    Closing as completed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.0bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions