Skip to content

fix(im): drop subagent stream text from main IM card - #513

Merged
xfgong merged 1 commit into
mainfrom
fix/2026-08-20-im-subagent-card
Aug 21, 2026
Merged

fix(im): drop subagent stream text from main IM card#513
xfgong merged 1 commit into
mainfrom
fix/2026-08-20-im-subagent-card

Conversation

@xfgong

@xfgong xfgong commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #508 — when subagents run in parallel, their streamed text leaked into the main run's IM card, interleaving N+1 streams into garbled output.

Root cause: in backend/cubeplex/im/outbound.py, fold_event routes subagent events into the shared run-event stream that feeds the IM card state machine. tool_call/tool_result already guard on agent_id, but text_delta never did, so subagent text deltas were appended to the card's streaming_content alongside the main agent's.

Changes

  • text_delta → return None when event["agent_id"] is set (mirrors the existing tool_result no-op). Subagent activity is already surfaced via SubAgentRow tool counts.
  • done / error → same guard, so a subagent's terminal event cannot prematurely finalize or fail the parent card.
  • Left intentionally unguarded: artifact (legitimate run output), citation (no-op index), ask_user_request / sandbox_confirm_* (not initiated by subagents in this design).

Test plan

  • Added regression tests: test_subagent_text_delta_does_not_pollute_main_card, test_subagent_done_does_not_finalize_main_card, test_subagent_error_does_not_finalize_main_card.
  • ruff format --check + ruff check clean on changed files.
  • tests/im/test_fold_event_text.py + tests/im/test_fold_event_terminal.py → 22 passed; broader IM + subagent-event suites → 32 passed.

Subagent events are tagged with agent_id and routed into the shared run
event stream that feeds the IM card state machine. The text_delta handler
never checked agent_id, so when subagents ran in parallel their text
deltas interleaved with the main agent's stream and garbled the card
(#508).

- text_delta: skip when event.agent_id is set (mirrors the tool_result
  no-op). Subagent activity is already surfaced via SubAgentRow tool counts.
- done / error: also guard on agent_id so a subagent's terminal event
  cannot prematurely finalize or fail the parent card.

Adds regression tests for subagent text_delta/done/error in fold_event.
@github-actions github-actions Bot added bug Something isn't working backend Backend code labels Aug 20, 2026
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@xfgong
xfgong merged commit 3faedc6 into main Aug 21, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend code bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(im): subagent stream text leaks into main IM card; parallel subagents interleave content

1 participant