Skip to content

The agent that grows with you

fix(compression): mark failed skill-tool results and drop the duplicated stub suffix

teknium15670f846cf16
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index b231558a30c..e95d54a26f0 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -1510,26 +1510,31 @@ def _sum_skill_manage(name, args, content, content_len, line_count):
action = _str_arg(args, "action", "?")
op_name = _str_arg(args, "name", "?")
summary = f"[skill_manage] {action} {op_name}"
- payload = _json_dict(content)
- error = payload.get("error")
- if error:
- summary += f" FAILED: {str(error)[:80]}"
- return f"{summary} ({content_len:,} chars)"
+ return f"{summary}{_skill_result_failure_suffix(content)} ({content_len:,} chars)"
def _sum_skills_list(name, args, content, content_len, line_count):
- # `skills_list` takes category/query, not a top-level `name` — the count
+ # `skills_list` takes only `category`, not a top-level `name` — the count
# from the payload is what identifies the call after compression.
category = _str_arg(args, "category")
scope = f" category={category}" if category else ""
payload = _json_dict(content)
count = payload.get("count")
listed = f" {count} skills" if isinstance(count, int) else ""
- summary = f"[skills_list]{scope}{listed}"
+ return f"[skills_list]{scope}{listed}{_skill_result_failure_suffix(content)} ({content_len:,} chars)"
+
+
+def _skill_result_failure_suffix(content: str) -> str:
+ """`` FAILED: <error>`` for a skill-tool payload that reports failure, else ``""``.
+ The skill tools return ``{"success": false, "error": ...}``; without the outcome in the stub a
+ failed batch compresses into the same line as a success and the post-compaction agent chases the
+ stub text as the error (#112710). Bounded to one line so the stub stays a stub."""
+ payload = _json_dict(content)
error = payload.get("error")
- if error:
- summary += f" FAILED: {str(error)[:80]}"
- return f"{summary} ({content_len:,} chars)"
+ if not error and payload.get("success") is not False:
+ return ""
+ preview = " ".join(str(error).split())[:80] if error else ""
+ return f" FAILED: {preview}" if preview else " FAILED"
def _sum_template(template: str, **defaults):
diff --git a/tests/agent/test_compressor_skill_tool_summaries.py b/tests/agent/test_compressor_skill_tool_summaries.py
deleted file mode 100644
index 9c84d95f484..00000000000
--- a/tests/agent/test_compressor_skill_tool_summaries.py
+++ /dev/null
@@ -1,118 +0,0 @@
-"""Summaries of skill-tool results must carry the skill names and the failure
-outcome across compression — `skill_manage` names live inside ``operations``
-(or the legacy flat shape), and ``skills_list`` has no top-level ``name`` at
-all. A failed call must never compress into a success-shaped line."""
-
-import json
-
-from agent.context_compressor import _summarize_tool_result
-
-
-class TestSummarizeSkillManage:
- def test_operations_array_names_the_skills(self):
- args = json.dumps({
- "operations": [
- {
- "action": "create",
- "name": "orca-ade",
- "content": "---\nname: orca-ade\n---\nbody",
- },
- {
- "action": "patch",
- "name": "llama-server",
- "old_string": "a",
- "new_string": "b",
- },
- ]
- })
- content = json.dumps({
- "success": True,
- "operations_applied": 2,
- "results": [
- {"name": "orca-ade", "action": "create", "success": True},
- {"name": "llama-server", "action": "patch", "success": True},
- ],
- })
- summary = _summarize_tool_result("skill_manage", args, content)
- assert "create orca-ade" in summary
- assert "patch llama-server" in summary
- assert "name=?" not in summary
- assert "FAILED" not in summary
-
- def test_failed_batch_keeps_error_visible(self):
- args = json.dumps({"operations": [{"action": "create", "name": "orca-ade"}]})
- content = json.dumps({
- "success": False,
- "error": (
- "operations[0] (create on 'orca-ade') failed: content is "
- "required for 'create' — batch aborted, all touched skills "
- "rolled back."
- ),
- })
- summary = _summarize_tool_result("skill_manage", args, content)
- assert "FAILED" in summary
- assert "create orca-ade" in summary
- assert "content is required" in summary
-
- def test_legacy_flat_shape_names_the_skill(self):
- args = json.dumps({"action": "delete", "name": "stale-skill"})
- content = json.dumps({
- "success": True,
- "message": "Skill 'stale-skill' deleted.",
- })
- summary = _summarize_tool_result("skill_manage", args, content)
- assert "delete stale-skill" in summary
- assert "name=?" not in summary
- assert "FAILED" not in summary
-
- def test_malformed_ops_render_guarded_not_crash(self):
- args = json.dumps({"operations": ["not-a-dict", 42]})
- content = json.dumps({
- "success": False,
- "error": "operations[0] needs an 'action'.",
- })
- summary = _summarize_tool_result("skill_manage", args, content)
- assert summary.startswith("[skill_manage]")
- assert "FAILED" in summary
-
- def test_error_text_is_bounded_to_one_line(self):
- args = json.dumps({"operations": [{"action": "patch", "name": "s"}]})
- content = json.dumps({"success": False, "error": "x" * 500})
- summary = _summarize_tool_result("skill_manage", args, content)
- assert "\n" not in summary
- assert len(summary) < 250
-
-
-class TestSummarizeSkillsList:
- def test_success_lists_count_and_category(self):
- args = json.dumps({"category": "devops"})
- content = json.dumps({
- "success": True,
- "skills": [{"name": "a"}, {"name": "b"}],
- "categories": ["devops"],
- "count": 2,
- })
- summary = _summarize_tool_result("skills_list", args, content)
- assert "category=devops" in summary
- assert "2 skills" in summary
- assert "name=?" not in summary
- assert "FAILED" not in summary
-
- def test_failure_keeps_error_visible(self):
- args = json.dumps({})
- content = json.dumps({"success": False, "error": "skills directory unreadable"})
- summary = _summarize_tool_result("skills_list", args, content)
- assert "FAILED" in summary
- assert "skills directory unreadable" in summary
-
-
-class TestSummarizerRegistryEntries:
- def test_skill_tool_stubs_never_render_question_name(self):
- cases = [
- ("skills_list", "{}", '{"success": true, "skills": [], "count": 0}'),
- ("skill_manage", "{}", '{"success": true}'),
- ("skill_view", '{"name": "real-skill"}', "x" * 300),
- ]
- for tool, args, content in cases:
- summary = _summarize_tool_result(tool, args, content)
- assert "name=?" not in summary, (tool, summary)
diff --git a/tests/agent/test_context_compressor.py b/tests/agent/test_context_compressor.py
index 8c81452b8f0..61492421e34 100644
--- a/tests/agent/test_context_compressor.py
+++ b/tests/agent/test_context_compressor.py
@@ -64,6 +64,39 @@ class TestSummarizeToolResultWebExtract:
assert summary == "[web_extract] https://example.com/h (500 chars)"
+class TestSummarizeToolResultSkillTools:
+ """`skill_manage` names live at ``operations[i].name`` and `skills_list` has no ``name`` arg at
+ all, so the shared ``name=`` stub rendered ``name=?`` for both and dropped the outcome — a failed
+ batch compressed into the same line as a success (#112710)."""
+
+ @pytest.mark.parametrize("args", [
+ {"operations": [{"action": "create", "name": "orca-ade"}, {"action": "patch", "name": "llama-server"}]},
+ {"action": "create", "name": "orca-ade"}, # legacy flat shape, still accepted by the tool
+ ])
+ def test_skill_manage_names_ops_and_keeps_failure_visible(self, args):
+ error = "operations[0] (create on 'orca-ade') failed: content is required for 'create'\n— batch rolled back."
+ failed = _summarize_tool_result("skill_manage", json.dumps(args), json.dumps({"success": False, "error": error}))
+ ok = _summarize_tool_result("skill_manage", json.dumps(args), json.dumps({"success": True, "operations_applied": 1}))
+
+ for summary in (failed, ok):
+ assert summary.startswith("[skill_manage] create orca-ade")
+ assert "name=?" not in summary and "\n" not in summary
+ assert "FAILED: operations[0] (create on 'orca-ade') failed: content is required" in failed
+ assert "FAILED" not in ok
+ assert failed != ok
+
+ def test_skills_list_uses_category_and_count_and_marks_failure(self):
+ args = json.dumps({"category": "devops"})
+ ok_content = json.dumps({"success": True, "skills": [{}, {}], "count": 2})
+ ok = _summarize_tool_result("skills_list", args, ok_content)
+ failed = _summarize_tool_result("skills_list", "{}", json.dumps({"success": False, "error": "skills dir unreadable"}))
+
+ assert ok == f"[skills_list] category=devops 2 skills ({len(ok_content)} chars)"
+ assert failed.startswith("[skills_list] FAILED: skills dir unreadable")
+ # Control: skill_view really has a top-level ``name`` and keeps its stub.
+ assert _summarize_tool_result("skill_view", json.dumps({"name": "github"}), "x" * 100) == "[skill_view] name=github (100 chars)"
+
+
class TestSummarizeToolResultClarify:
def test_preserves_resolved_user_response_without_metadata(self):
content = json.dumps({