Skip to content

feat(agent-core): align coder subagent tools with v2 and drain background tasks - #1776

Merged
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:feat/coder-subagent-tools-align
Jul 16, 2026
Merged

feat(agent-core): align coder subagent tools with v2 and drain background tasks#1776
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:feat/coder-subagent-tools-align

Conversation

@sailist

@sailist sailist commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue; the problem is explained below.

Problem

The bundled coder sub-agent profile in packages/agent-core had drifted from the equivalent profile in packages/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:

  1. Tool capabilities baked at construction (the Bash/Agent allowBackground gate, 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.
  2. A sub-agent reported completion as soon as its turn ended, leaving its background shell commands running. When such a task later finished, its terminal notification steered a fresh, unobserved turn on the finished sub-agent whose output never reached the parent.

What changed

  • Aligned the bundled coder sub-agent profile tools with agent-core-v2. Cron tools remain declared but intentionally not delivered to sub-agents, matching v2; the agent/explore/plan profiles already matched.
  • Rebuilding builtin tools on setActiveTools so profile-gated capabilities (e.g. allowBackground) reflect the profile actually applied.
  • Sub-agent completion now waits for the child agent's background tasks to settle (print-mode drain semantics) and suppresses their terminal notifications so no orphan turn runs on a finished sub-agent; the existing per-run timeout/cancel signal bounds the wait.
  • Added a real-Session e2e covering tool execution inside a coder sub-agent (skills, todo lists, background Bash + Task* trio, plan mode enter/write/exit, nested Agent and AgentSwarm), drain blocking, and cancel-during-drain; updated profile and sub-agent-host tests. Full agent-core suite (3842 tests) and typecheck pass.
  • Updated the sub-agents doc page in both locales (dropped the stale "no nested sub-agents" claim; documented the completion drain).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…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-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 07c5dfb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@07c5dfb
npx https://pkg.pr.new/@moonshot-ai/kimi-code@07c5dfb

commit: 07c5dfb

sailist added 2 commits July 16, 2026 16:54
- 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
@sailist
sailist force-pushed the feat/coder-subagent-tools-align branch from ff444a6 to 0a7541f Compare July 16, 2026 08:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +433 to +434
for (const task of child.background.list(true)) {
await child.background.suppressTerminalNotification(task.taskId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@sailist
sailist merged commit ffaf0b9 into MoonshotAI:main Jul 16, 2026
14 checks passed
This was referenced Jul 16, 2026
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 19, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant