feat(run): forward child session events to NDJSON stream#33403
Open
cHIsIMun wants to merge 1 commit into
Open
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
When the `task` tool spawns a subagent, its child session events are published on the bus but filtered out of the parent NDJSON stream (`opencode run --format json`). This makes `opencode run` unusable as a headless runtime for multi-agent platforms that need real-time visibility into subagent execution. Two new event types are emitted in `--format json` mode: - `subtask_delta` — streaming token delta from a child session (`childSessionID`, `partID`, `delta`) - `subtask_event` — completed/updated part from a child session (`childSessionID`, `part`) Child sessions are discovered when a `task` tool part transitions to `running` and its metadata exposes `sessionId`. Only events from known child sessions are forwarded; the filter is additive and does not affect any existing event types. Closes anomalyco#33397
5aba126 to
bec5fdc
Compare
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
Closes #33397
Type of change
What does this PR do?
opencode run --format jsonfilters out all events from child sessions (subagents spawned by thetasktool), so there is no way to observe what a subagent is doing while it runs — only the final result arrives after it completes.The fix tracks child session IDs as task tool parts transition to
running(the ID is already inpart.state.metadata.sessionId) and forwards two new event types to the parent NDJSON stream:subtask_delta— a streaming token delta from a child sessionsubtask_event— a completed/updated part from a child sessionChange is additive: one file touched (
cli/cmd/run.ts, +28 lines), no existing event types or default output affected.How did you verify your code works?
Ran a multi-agent squad workflow (master + 3 subagents: planner → executor → reviewer) coordinated via a custom pipeline MCP. Without the patch, only the final
tool_use completedevent arrives. With the patch, each subagent's tool calls and text appear assubtask_delta/subtask_eventin real time.Screenshots / recordings
N/A — CLI-only change, no UI.
Checklist