feat(agent-core): align coder subagent tools with v2 and drain background tasks - #1776
Conversation
…ound tasks - align the bundled coder subagent profile tools with agent-core-v2 CODER_TOOLS (Skill, Agent, AgentSwarm, Task* trio, plan-mode tools, TodoList); cron tools stay declared-but-undelivered on sub agents, matching v2 - rebuild builtin tools in setActiveTools: profile-gated capabilities (Bash/Agent allowBackground via the Task* trio) were baked at construction with an empty enabled set, so profiles applied later (every subagent) silently lost them - hold subagent completion until the child agent's background tasks settle (print-mode drain semantics) and suppress their terminal notifications, so no unobserved follow-up turn runs on a finished subagent; the run's timeout/cancel signal bounds the drain - cover with real-Session e2e (tool execution, nested Agent/AgentSwarm, drain blocking and cancel) and update profile/subagent-host tests
🦋 Changeset detectedLatest commit: 07c5dfb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
- coder sub-agents can now dispatch nested sub-agents and use background tasks, todo lists, Plan mode, and skills; drop the stale claim that sub-agents cannot schedule nested sub-agents - note that a sub-agent run reports completion only after its background tasks settle
ff444a6 to
0a7541f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff444a614b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| for (const task of child.background.list(true)) { | ||
| await child.background.suppressTerminalNotification(task.taskId); |
There was a problem hiding this comment.
Suppress already-settled child tasks before returning
When a child background task reaches a terminal state just before this drain starts, list(true) excludes it, so its terminal notification is never suppressed. BackgroundManager.finalizeTask() schedules the notification asynchronously before the task wait resolves, so a quick background command that finishes around the child’s final turn can still call turn.steer after this method returns and launch the same unobserved orphan turn this change is meant to prevent. Consider also suppressing detached terminal tasks that have not delivered their notification before deciding the child is drained.
Useful? React with 👍 / 👎.
A background task that terminated before the drain's suppression pass was excluded from the active-only list, so its terminal notification escaped suppression and could still steer an orphan turn onto the finished subagent. Suppress every child task (including settled ones whose notification may still be in flight) and run the pass both before and after the settle wait; notification delivery re-checks suppression after its async output snapshot, which makes the block deterministic. Cover the mid-turn delivery path with an e2e case.
…ound tasks (MoonshotAI#1776) * feat(agent-core): align coder subagent tools with v2 and drain background tasks - align the bundled coder subagent profile tools with agent-core-v2 CODER_TOOLS (Skill, Agent, AgentSwarm, Task* trio, plan-mode tools, TodoList); cron tools stay declared-but-undelivered on sub agents, matching v2 - rebuild builtin tools in setActiveTools: profile-gated capabilities (Bash/Agent allowBackground via the Task* trio) were baked at construction with an empty enabled set, so profiles applied later (every subagent) silently lost them - hold subagent completion until the child agent's background tasks settle (print-mode drain semantics) and suppress their terminal notifications, so no unobserved follow-up turn runs on a finished subagent; the run's timeout/cancel signal bounds the drain - cover with real-Session e2e (tool execution, nested Agent/AgentSwarm, drain blocking and cancel) and update profile/subagent-host tests * chore: add changeset for coder subagent tool alignment * docs(agents): sync sub-agent capabilities with expanded coder tool set - coder sub-agents can now dispatch nested sub-agents and use background tasks, todo lists, Plan mode, and skills; drop the stale claim that sub-agents cannot schedule nested sub-agents - note that a sub-agent run reports completion only after its background tasks settle * fix(agent-core): close drain race for tasks settled before completion A background task that terminated before the drain's suppression pass was excluded from the active-only list, so its terminal notification escaped suppression and could still steer an orphan turn onto the finished subagent. Suppress every child task (including settled ones whose notification may still be in flight) and run the pass both before and after the settle wait; notification delivery re-checks suppression after its async output snapshot, which makes the block deterministic. Cover the mid-turn delivery path with an e2e case.
Related Issue
No linked issue; the problem is explained below.
Problem
The bundled
codersub-agent profile inpackages/agent-corehad drifted from the equivalent profile inpackages/agent-core-v2: it lacked background tasks, todo lists, plan-mode tools, skill invocation, and nested sub-agent delegation. Adding the missing tool names then exposed two engine bugs that made them misbehave inside sub-agents:allowBackgroundgate, derived from the Task* tool trio) never picked up a profile applied later — which is how every sub-agent receives its profile — so background execution stayed disabled for sub-agents even when the profile allowed it. agent-core-v2 evaluates this gate per call and does not have the problem.What changed
codersub-agent profile tools with agent-core-v2. Cron tools remain declared but intentionally not delivered to sub-agents, matching v2; theagent/explore/planprofiles already matched.setActiveToolsso profile-gated capabilities (e.g.allowBackground) reflect the profile actually applied.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.