fix: block subagents from spawning subagents - #7056
Merged
alex-alecu merged 3 commits intoMar 26, 2026
Merged
alex-alecu merged 3 commits into
alex-alecu merged 3 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Fix these issues in Kilo Cloud Other Observations (not in diff)None. Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 2,997,678 tokens |
alex-alecu
reviewed
Mar 23, 2026
alex-alecu
approved these changes
Mar 26, 2026
alex-alecu
left a comment
Contributor
There was a problem hiding this comment.
Thank you for contribution.
jliounis
pushed a commit
to jliounis/kilocode
that referenced
this pull request
May 18, 2026
…ents-spawning-subagents fix: block subagents from spawning subagents
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
…ents-spawning-subagents fix: block subagents from spawning subagents
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.
Context
Fixes #7055. Subagents were able to spawn further subagents when their merged agent permissions contained an explicit
taskrule. This created a recursion/infinite delegation risk and violated the expected boundary that only the top-level agent should delegate.Implementation
The root cause was a
hasTaskPermissioncheck inpackages/opencode/src/tool/task.tsthat conditionally skipped adding atask: denyrule to the child session's permissions — and also conditionally kepttaskin the tool list passed toSessionPrompt.prompt— whenever the child agent had any explicittaskpermission configured.The fix removes the conditional entirely. The
taskpermission is now always denied on sessions created byTaskTool, andtaskis always excluded from the tool list for subagent prompts, regardless of the child agent's configured permissions.Root cause analysis
The
hasTaskPermissionconditional was originally introduced in upstream opencode via anomalyco/opencode#8111 ("fix(task): respect agent task permission for nested sub-agents"), merged Jan 13 2026. That PR restored the ability for agents to opt in to the task tool via permission frontmatter after the permission rework in anomalyco/opencode#6319 removed it.Before that upstream PR, task was unconditionally denied for all subagent sessions:
The upstream PR made it conditional:
This check was too broad — it matched any rule mentioning
task(includingdenyorask), not just explicit allows. It was also vulnerable to user config: since user permissions are merged into every agent's permission array viaPermissionNext.merge(defaults, ..., user), a user clicking "Always allow" on a task permission prompt would persisttask: "allow"to global config, which would then causehasTaskPermissionto betruefor every agent — includinggeneralandexploresubagents.What this PR changed
c4898d78): reverted to unconditional deny — the safe baseline.4ee4d49): tightened the conditional fromrule.permission === "task"torule.permission === "task" && rule.action === "allow", renamed toallowsTask. This preserves the orchestrator agent's ability to delegate (it has explicittask: "allow") while blocking subagents that only have task rules via user config inheritance.Remaining gaps
Despite this fix, infinite recursion is still possible in specific scenarios:
User config override: If a user's global config contains
task: "allow"(from a prior "Always allow" click), it gets merged into every agent's permissions, makingallowsTasktrue for all subagents.Cross-agent mutual recursion: The self-delegation guard added later in
4f2ac44("block same-agent recursive delegation") only prevents agent A → A loops. It does not prevent A → B → A → B chains (e.g.general→explore→general→ ...).No hard depth limit: The system relies entirely on permission-based gating with no maximum nesting depth counter. A proper fix would track depth via the
parentIDchain and refuse to create sessions beyond a threshold.Screenshots
N/A — no UI changes.
How to Test
task: allowpermission rule in your config.tasktool.tasktool (previously it could; now it cannot).Get in Touch
thomas07374