fix(im): drop subagent stream text from main IM card - #513
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
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_eventroutes subagent events into the shared run-event stream that feeds the IM card state machine.tool_call/tool_resultalready guard onagent_id, buttext_deltanever did, so subagent text deltas were appended to the card'sstreaming_contentalongside the main agent's.Changes
text_delta→ returnNonewhenevent["agent_id"]is set (mirrors the existingtool_resultno-op). Subagent activity is already surfaced viaSubAgentRowtool counts.done/error→ same guard, so a subagent's terminal event cannot prematurely finalize or fail the parent card.artifact(legitimate run output),citation(no-op index),ask_user_request/sandbox_confirm_*(not initiated by subagents in this design).Test plan
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 checkclean 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.