Skip to content

fix: preserve complete messages in sub-agent stream traces - #1041

Draft
u7-u7 wants to merge 1 commit into
modelscope:mainfrom
u7-u7:fix/subagent-stream-complete-messages-20261031
Draft

u7-u7 wants to merge 1 commit into
modelscope:mainfrom
u7-u7:fix/subagent-stream-complete-messages-20261031

Conversation

@u7-u7

@u7-u7 u7-u7 commented Oct 31, 2026

Copy link
Copy Markdown

Summary

With agent_stream_file: true, LLMAgent.step() yields cumulative histories while the final assistant message is still growing. SubAgentStreamWriter previously marked that message written after the first chunk, so the trace advertised to the parent agent permanently retained only the first token (and incomplete tool-call arguments), even when the sub-agent completed successfully.

  • Keep the growing tail pending until a subsequent message or terminal event, retaining the existing one-message-record-per-index JSONL format.
  • Flush the last observed partial message and close the trace on inline execution failure/cancellation, regardless of statistics being enabled.
  • Add regressions for in-place/replaced cumulative messages, completed tool arguments, AgentTool success/error/cancellation with stats on/off, and a real LLMAgent step consuming a multi-chunk OpenAI-compatible SSE response through MockTransport.

The trace remains append-only and message-granular: a growing final message is now emitted when completed rather than emitting its first token as if complete.

Validation

  • New focused regressions: 10 passed. The original six regressions failed on the unmodified source; the real LLMAgent SSE regression separately failed on the unmodified source (H instead of Hello).
  • Adjacent suite (test_stream_writer.py, test_task_manager_smoke.py, test_partial_round.py, test_llm_io.py): 64 passed, 15 skipped, 1 pre-existing failure. TestAgentToolTranscript::test_save_transcript_writes_message_objects_and_dicts still expects subagents/worker-1.jsonl instead of the current .ms_agent/subagents/worker-1.jsonl; reproduced unchanged on the base commit.
  • Flake8 for both changed production files, YAPF for changed sections, and git diff --check: passed.
  • No live model service or subprocess spawning tested; optional Anthropic tests skipped because its dependency is not installed. These are local checks, not upstream CI.

AI assistance

Implementation and automated verification were performed with OpenAI Codex. No claim of human review is made.

This branch has not been deployed

No deployments
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