Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: stream_router 终态报告不再被 1MB 过程限制掐死

wade_wolzzi4f2fe13b5dcd
diff --git a/jiuwenswarm/agents/harness/common/tools/deepresearch/stream_router.py b/jiuwenswarm/agents/harness/common/tools/deepresearch/stream_router.py
index a1498fd758..866dc21143 100644
--- a/jiuwenswarm/agents/harness/common/tools/deepresearch/stream_router.py
+++ b/jiuwenswarm/agents/harness/common/tools/deepresearch/stream_router.py
@@ -918,16 +918,22 @@ def route_chunk(chunk: dict, state: RouterState) -> list[dict]:
agent = _validate_identifier(chunk.get("agent", ""))
event = str(chunk.get("event", "")).strip()
section_idx = _validate_identifier(chunk.get("section_idx", "0")) or "0"
- # The successful EndNode embeds the complete final result in ``content``.
+ # The EndNode embeds the complete final result in ``content`` (1+ MiB).
# It is a workflow boundary, not process text for the frontend, so keep it
# under the terminal 16 MiB protocol bound without applying the 1 MiB
- # process-display accumulator limit.
+ # process-display accumulator limit — even when the result carries
+ # non-fatal exception_info (the SDK then emits event=error). Delivery is
+ # still gated by _is_successful_workflow_end below.
+ is_end_node = (
+ agent == "end"
+ and section_idx in {"", "0"}
+ )
successful_workflow_end = _is_successful_workflow_end(chunk, agent, event)
_validate_router_input(
chunk,
state,
- terminal_result_content=successful_workflow_end,
+ terminal_result_content=is_end_node,
)
frames: list[dict] = []
if "__deepsearch_status__" in chunk:
diff --git a/tests/unit_tests/agentserver/test_deepresearch_stream_router.py b/tests/unit_tests/agentserver/test_deepresearch_stream_router.py
index 1b35120b3e..86e66e43be 100644
--- a/tests/unit_tests/agentserver/test_deepresearch_stream_router.py
+++ b/tests/unit_tests/agentserver/test_deepresearch_stream_router.py
@@ -1241,6 +1241,84 @@ def test_successful_end_result_keeps_json_shape_limit(monkeypatch):
)
+def test_end_result_with_error_event_does_not_crash():
+ """EndNode event=error (exception_info present) must not crash, but delivery is gated."""
+ state = RouterState()
+ content = json.dumps({
+ "response_content": "# Final report",
+ "exception_info": "[212000]Error when generate sub report",
+ })
+
+ route_chunk(
+ {
+ "agent": "end",
+ "event": "error",
+ "section_idx": "0",
+ "content": content,
+ },
+ state,
+ )
+
+ assert state.final_report_started is False
+
+
+def test_end_result_with_error_event_bypasses_process_display_text_limit():
+ """The 12:18 crash: report > 1 MiB with exception_info must use the 16 MiB terminal bound, not crash."""
+ state = RouterState()
+ content = json.dumps({
+ "response_content": "x" * (MAX_CHUNK_TEXT_CHARS + 100),
+ "exception_info": "[212000]Error when generate sub report",
+ })
+
+ route_chunk(
+ {
+ "agent": "end",
+ "event": "error",
+ "section_idx": "0",
+ "content": content,
+ },
+ state,
+ )
+
+ assert len(content) > MAX_CHUNK_TEXT_CHARS
+ assert state.final_report_started is False
+
+
+def test_end_result_without_response_content_falls_through():
+ """EndNode with event=error but no response_content is not a terminal result."""
+ state = RouterState()
+ content = json.dumps({"exception_info": "fatal error"})
+
+ route_chunk(
+ {
+ "agent": "end",
+ "event": "error",
+ "section_idx": "0",
+ "content": content,
+ },
+ state,
+ )
+
+ assert state.final_report_started is False
+
+
+def test_all_end_marker_is_not_terminal():
+ """The trailing 'ALL END' marker has agent=end but content is not valid JSON."""
+ state = RouterState()
+
+ route_chunk(
+ {
+ "agent": "end",
+ "event": "summary_response",
+ "section_idx": "0",
+ "content": "ALL END",
+ },
+ state,
+ )
+
+ assert state.final_report_started is False
+
+
def test_unknown_node_no_frame():
state = RouterState()
assert route_chunk({"agent": "mystery_node", "content": "x"}, state) == []