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(deepresearch): 推理消息上限提至 512 对齐图表,修复多章节报告落盘失败

hy5920706165ed7227e47a8
diff --git a/jiuwenswarm/agents/harness/common/tools/deepresearch_plugin/report_bundle.py b/jiuwenswarm/agents/harness/common/tools/deepresearch_plugin/report_bundle.py
index 1bd76c4682..09af482236 100644
--- a/jiuwenswarm/agents/harness/common/tools/deepresearch_plugin/report_bundle.py
+++ b/jiuwenswarm/agents/harness/common/tools/deepresearch_plugin/report_bundle.py
@@ -23,15 +23,19 @@ CHART_PLACEHOLDER_RE = re.compile(r"\(#insertChart:([^)]+)\)")
SAFE_BUNDLE_ID_RE = re.compile(r"^[A-Za-z0-9_-]+$")
RESPONSE_CONTENT_MAX_BYTES = 10 * 1024 * 1024
-INFER_MESSAGE_MAX = 20
-# Multi-section SDK reports can contain dozens of charts. Bound their count
-# separately from the per-image and aggregate decoded-byte limits below.
+# Multi-section SDK reports can contain dozens of inference graphs and charts.
+# Bound their counts separately from the per-field base64 and aggregate
+# decoded-byte limits below; the byte limits are the real blast-containment.
+INFER_MESSAGE_MAX = 512
CHART_MESSAGE_MAX = 512
BASE64_FIELD_MAX_BYTES = 5 * 1024 * 1024
DECODED_BINARY_TOTAL_MAX_BYTES = 100 * 1024 * 1024
CITATION_COUNT_MAX = 10_000
CITATION_FIELD_MAX_BYTES = 1024 * 1024
FINAL_RESULT_MAX_BYTES = 64 * 1024 * 1024
+# Aggregate inference graphs JSON is written outside the snapshot byte budget,
+# so bound it independently as well.
+INFERENCE_GRAPH_MAX_BYTES = 64 * 1024 * 1024
MAX_NESTING_DEPTH = 64
MAX_CONTAINER_ITEMS = 100_000
MAX_TOTAL_NODES = 1_000_000
@@ -716,6 +720,8 @@ def build_report_bundle(
"graphs": graphs,
}
graph_bytes = json.dumps(graph_data, ensure_ascii=False).encode("utf-8")
+ if len(graph_bytes) > INFERENCE_GRAPH_MAX_BYTES:
+ raise ValueError("inference_graphs exceeds the UTF-8 byte limit")
graph_path = groups[0].directory / "inference_graphs.json"
graph_path.write_bytes(graph_bytes)
inference_graph_path = f"{groups[0].directory.name}/inference_graphs.json"
diff --git a/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py b/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py
index 6e61df15d5..89c613afd5 100644
--- a/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py
+++ b/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py
@@ -80,6 +80,56 @@ def test_build_report_bundle_rejects_more_than_512_charts_before_writing(tmp_pat
assert not list(tmp_path.iterdir())
[email protected]("infer_count", [32, 104, 512])
+def test_build_report_bundle_preserves_large_infer_sets(tmp_path, infer_count):
+ inferences = [_infer(str(index)) for index in range(infer_count)]
+ bundle = build_report_bundle(
+ _payload(
+ response_content="\n".join(
+ f"[detail {index}](#inference:{index})" for index in range(infer_count)
+ ),
+ infer_messages=inferences,
+ ),
+ tmp_path / "report-v1",
+ )
+
+ assert len(bundle.inference_manifest) == infer_count
+ snapshot = json.loads(serialize_final_result_snapshot(bundle.final_result_snapshot))
+ assert len(snapshot["infer_messages"]) == infer_count
+ for message in snapshot["infer_messages"]:
+ path = tmp_path / message["artifact_path"]
+ assert path.read_bytes() == b"<html>safe</html>"
+ assert message["artifact_path"] in bundle.markdown_text
+ assert "html_base64" not in message
+ assert "(#inference:" not in bundle.markdown_text
+
+
+def test_build_report_bundle_rejects_more_than_512_infer_before_writing(tmp_path):
+ with pytest.raises(ValueError, match="infer_messages exceeds the message count limit"):
+ build_report_bundle(
+ _payload(infer_messages=[_infer(str(index)) for index in range(513)]),
+ tmp_path / "report-v1",
+ )
+
+ assert not list(tmp_path.iterdir())
+
+
+def test_build_report_bundle_rejects_oversized_inference_graphs_before_writing(
+ tmp_path, monkeypatch
+):
+ monkeypatch.setattr(bundle_module, "INFERENCE_GRAPH_MAX_BYTES", 1)
+
+ with pytest.raises(
+ ValueError, match="inference_graphs exceeds the UTF-8 byte limit"
+ ):
+ build_report_bundle(
+ _payload(infer_messages=[_infer("one")]),
+ tmp_path / "report-v1",
+ )
+
+ assert not list(tmp_path.iterdir())
+
+
@pytest.mark.parametrize(
"occupied_kind",
["directory", "directory_symlink", "file_symlink", "file_hardlink"],