Skip to content

feat(agent-core): stream background subagent progress into /tasks#293

Open
persovt2 wants to merge 1 commit into
MoonshotAI:mainfrom
persovt2:feat/stream-subagent-progress
Open

feat(agent-core): stream background subagent progress into /tasks#293
persovt2 wants to merge 1 commit into
MoonshotAI:mainfrom
persovt2:feat/stream-subagent-progress

Conversation

@persovt2
Copy link
Copy Markdown

@persovt2 persovt2 commented Jun 1, 2026

Related Issue

Resolve #292

Problem

Background subagents launched with Agent(run_in_background=true) appear in /tasks, but their output pane stays empty until completion — only the final summary lands at the end. Background bash tasks stream live in the same UI, so there is no way to watch what a long-running background subagent is doing while it runs.

Cause: agent tasks are Promise-based, so BackgroundProcessManager has no live proc.stdout to capture — registerAgentTask uses a dummy process whose stdout handlers are no-ops, and only the final result is appended on completion.

What changed

  • Agent.onEvent — a lightweight in-process event tap, fanned out alongside the existing RPC sink (size-guarded so it stays free on the no-tap hot path).
  • SubagentProgress + formatSubagentEvent (new session/subagent-progress.ts) — buffer the child agent's events (assistant deltas, tool-call boundaries) as compact log text. Tool results are reduced to a one-line status so the log stays small; the buffer replays anything captured before the manager subscribes, so no early output is lost.
  • SessionSubagentHost taps the child only for background runs (foreground already streams inline via RPC) and coalesces deltas to keep output.log appends coarse.
  • registerAgentTask gains an optional outputSource; the manager streams chunks into the same ring buffer + output.log that bash tasks use, and releases the subscription on every terminal path (completed/failed/killed/timeout) via finalizeTerminal.
  • The final result is not re-appended when it already streamed (no duplication) — only written as a fallback when nothing streamed.

Result: /tasks shows live subagent progress, consistent with background bash tasks. Foreground subagents are unaffected.

Checklist

Background subagents are Promise-based, so BackgroundProcessManager had no
live proc.stdout to capture and their /tasks output pane stayed empty until
completion. Tap the child agent's event stream via a new in-process
Agent.onEvent, format assistant deltas and tool-call boundaries into log
text, and feed it through registerAgentTask's outputSource into the task's
ring buffer + output.log — matching background bash tasks.

Output subscription is released on every terminal path (completed, failed,
killed, timeout) via finalizeTerminal. Foreground subagents are unaffected.

Closes MoonshotAI#292
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 1, 2026

🦋 Changeset detected

Latest commit: 34e1b34

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

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/migration-legacy Patch

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

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.

Stream background subagent progress into /tasks (output is empty until completion)

1 participant