Repository navigation
feat(core): let subagents launch nested subagents - #39
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The implementation, regression coverage, and documentation are consistent, with no unresolved blocking findings.
No open issues 🎉
What changed in this PR
Enables nested subagents while preserving bounded execution and reliable result delivery to parent sessions.
Changes:
- Raises default nesting depth to five and allows
generalto launch subagents. - Forces nested launches into foreground execution and links mcpx parent leases.
- Updates regression tests, documentation, and generated OpenAPI data.
| File | Description |
|---|---|
| services/www/src/docs/content/tools.mdx | Documents nested foreground execution. |
| services/www/src/docs/content/permissions.mdx | Updates general permissions. |
| services/www/src/docs/content/agents.mdx | Explains nesting limits and agent capabilities. |
| packages/web/src/content/docs/config.mdx | Corrects configuration placement and default. |
| packages/schema/src/config/experimental.ts | Updates depth configuration description. |
| packages/protocol/openapi.json | Adds missing shell_timeout schema. |
| packages/core/test/tool-subagent.test.ts | Covers nesting, foreground execution, and limits. |
| packages/core/test/tool-mcpx-features.test.ts | Tests nested lease lineage. |
| packages/core/test/agent.test.ts | Checks built-in subagent permissions. |
| packages/core/src/tool/plugin/subagent.ts | Implements depth and foreground behavior. |
| packages/core/src/tool/plugin/mcpx-subagent.ts | Links leases through parent lease IDs. |
| packages/core/src/plugin/agent.ts | Allows general to launch subagents. |
Review effort: Balanced
This was referenced Oct 18, 2026
Merged
This was referenced Oct 28, 2026
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
No issue. This was requested directly: subsessions should be able to create subsessions.
Type of change
What does this PR do?
A subagent could not start a subagent of its own. Two things blocked it.
experimental.subagent_depthdefaulted to 1, so thesubagenttool refused any call made from a child session. The built-ingeneralagent also denied thesubagentaction, so it never saw the tool at all.Now:
experimental.subagent_depthstill sets the limit, and1restores the old behavior. The limit was added upstream to stop runaway self-dispatch (Subagents can still recursively self-dispatch with global task permission (v1.17.20) anomalyco/opencode#36878), so a bound stays.general. It can launch subagents.explorekeeps its read-only allow list and still cannot.background: true. A child's job completes when its own run ends, so a backgrounded grandchild would report back to the child after the child had already answered its parent. The root got the interim text and the real answer reached nobody. Running nested launches in the foreground keeps every ancestor busy until its descendants finish, so each answer includes their results. Parallel nested calls in one step still run concurrently, and top-level sessions keep background mode. The tool description says this.mcpx-sub-…) instead of the parent's raw session ID, so the daemon can link the chain past depth 1.main:shell_timeoutwas missing, and theservices/wwwcopies lagged the protocol document, which madecheck:generatedfail.Left alone:
data.test.tsx"syncs direct child session info with a navigated root" pins this.None of these blocks nesting; they are follow-ups if they matter.
How did you verify your code works?
bun run script/test.ts test/tool-subagent.test.ts test/agent.test.tsfrompackages/core: 22 pass.test/tool-mcpx-features.test.ts: 13 pass. The new nested-foreground and mcpx-lineage regressions failed before their fixes.main:execute supports callable namespace tools(pretty JSON expectation) and the VCS untracked-file spawn count.bun typecheckinpackages/coreandbun run checkat the root: pass (36/36 tasks).services/www:bun typecheck,bun run check:generatedandbun run buildpass, including link validation.general("Level one"). That subagent was offeredsubagent, and its owngeneral("Level two") ran a shell command that waited for permission. All three sessions stayed running. After the reply, each level finished with its answer.Screenshots / recordings
The same live run drove OpenChamber: evidence.
Checklist
Summary by CodeRabbit
experimental.subagent_depth:0prevents subagent launches, and1prevents further nesting.generalagent can launch subagents;explorecannot.