The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): mark a dead cron run and a non-zero exit in their stubs
Konstantin Khlopkov7de2fbb98fe0
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 5a566fb5e03..d203e6881f3 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -1886,6 +1886,12 @@ def _sum_skills_list(name, args, content, content_len, line_count):return f"[skills_list]{scope}{listed}{_skill_result_failure_suffix(content)} ({content_len:,} chars)"+def _failure_suffix(reason: Any) -> str:+ """`` FAILED: <reason>`` on one line, or `` FAILED`` when the payload carries no message."""+ preview = " ".join(str(reason).split())[:80] if reason else ""+ return f" FAILED: {preview}" if preview else " FAILED"++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@@ -1895,8 +1901,42 @@ def _skill_result_failure_suffix(content: str) -> str:error = payload.get("error")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"+ return _failure_suffix(error)+++def _sum_cronjob_manage(name, args, content, content_len, line_count):+ """``[cronjob] <action>``, plus the outcome of the run it triggered.++ A manual run reports a dead or skipped job inside the job view while the tool call itself+ succeeded, so the payload is a clean ``{"success": true, "job": {...}}`` and a top-level probe+ finds nothing to mark. Only this call's own fields decide: ``job`` also carries the job's stored+ state, including an ``error`` left behind by an earlier run.+ """+ stub = f"[cronjob] {args.get('action', '?')}"+ suffix = _skill_result_failure_suffix(content)+ if not suffix:+ job = _json_dict(content).get("job")+ job = job if isinstance(job, dict) else {}+ reason = job.get("execution_error") or job.get("execution_skipped")+ if reason is not None or job.get("execution_success") is False:+ suffix = _failure_suffix(reason)+ return stub + suffix+++def _sum_process_manage(name, args, content, content_len, line_count):+ """``[process] <action> session=<id>``, plus how the process itself ended.++ A poll of a finished process reports ``exit_code`` and ``completion_reason`` instead of an+ ``error``, so a non-zero exit is invisible to a top-level probe. A process still running+ reports no exit code at all, and that is not a failure.+ """+ stub = f"[process] {args.get('action', '?')} session={args.get('session_id', '?')}"+ suffix = _skill_result_failure_suffix(content)+ if not suffix:+ exit_code = _json_dict(content).get("exit_code")+ if isinstance(exit_code, int) and not isinstance(exit_code, bool) and exit_code != 0:+ suffix = f" FAILED: exit code {exit_code}"+ return stub + suffixdef _sum_template(template: str, **defaults):@@ -1940,8 +1980,8 @@ _TOOL_RESULT_SUMMARIZERS = {"todo_list": lambda *a: "[todo] updated task list","clarify": _sum_clarify,"text_to_speech": _sum_template("[text_to_speech] generated audio ({content_len:,} chars)"),- "cronjob_manage": _sum_template("[cronjob] {action}", action="?"),- "process_manage": _sum_template("[process] {action} session={session_id}", action="?", session_id="?"),+ "cronjob_manage": _sum_cronjob_manage,+ "process_manage": _sum_process_manage,}diff --git a/tests/agent/test_templated_tool_result_outcome.py b/tests/agent/test_templated_tool_result_outcome.pyindex be22751e803..17b3bf73e1b 100644--- a/tests/agent/test_templated_tool_result_outcome.py+++ b/tests/agent/test_templated_tool_result_outcome.py@@ -104,3 +104,65 @@ def test_summarizer_never_raises_on_a_hostile_payload():for tool_name, args, _reason in FAILING_CALLS:for hostile in ("", "null", "[1, 2, 3]", '{"error": {"nested": true}}', "not json at all"):assert isinstance(_stub(tool_name, args, hostile), str)+++class TestFailuresTheTopLevelProbeCannotSee:+ """Two real shapes carry their outcome where a top-level ``error`` / ``success is False`` cannot.++ A ``cronjob_manage(action="run")`` whose job died returns ``{"success": True, "job": {...+ "execution_error": ...}}`` — the tool call itself worked, the job did not. A+ ``process_manage(action="poll")`` on a process that exited non-zero reports ``exit_code`` and+ ``completion_reason`` and nothing else. Both compressed into the byte-identical success stub.+ """++ def test_a_failed_cron_run_is_marked(self):+ payload = json.dumps({"success": True, "job": {"name": "nightly", "execution_success": False,+ "execution_error": "Traceback: agent exited with code 1"}})++ stub = _stub("cronjob_manage", {"action": "run"}, payload)++ assert "FAILED: Traceback: agent exited with code 1" in stub, stub+ assert stub.startswith("[cronjob] run"), stub++ def test_a_cron_run_lost_to_the_scheduler_is_marked(self):+ payload = json.dumps({"success": True, "job": {"execution_skipped":+ "Already being fired by the scheduler; not run again."}})++ stub = _stub("cronjob_manage", {"action": "run"}, payload)++ assert "FAILED: Already being fired by the scheduler" in stub, stub++ def test_a_failed_run_without_a_message_is_still_marked(self):+ payload = json.dumps({"success": True, "job": {"execution_success": False}})++ assert "FAILED" in _stub("cronjob_manage", {"action": "run"}, payload)++ def test_a_stored_error_from_an_earlier_run_is_not_marked(self):+ """``job`` carries the job's own state, so only this call's outcome may mark the stub."""+ payload = json.dumps({"success": True, "job": {"name": "nightly", "error": "last run failed",+ "execution_success": True}})++ stub = _stub("cronjob_manage", {"action": "poll"}, payload)++ assert stub == "[cronjob] poll", stub++ def test_a_non_zero_exit_is_marked(self):+ payload = json.dumps({"session_id": "proc_1", "status": "exited", "exit_code": 1,+ "completion_reason": "nonzero_exit", "termination_source": "child"})++ stub = _stub("process_manage", {"action": "poll", "session_id": "proc_1"}, payload)++ assert "FAILED" in stub and "exit code 1" in stub, stub+ assert stub.startswith("[process] poll session=proc_1"), stub++ def test_a_clean_exit_is_not_marked(self):+ payload = json.dumps({"session_id": "proc_1", "status": "exited", "exit_code": 0})++ assert _stub("process_manage", {"action": "poll", "session_id": "proc_1"}, payload) == \+ "[process] poll session=proc_1"++ def test_a_still_running_poll_is_not_marked(self):+ payload = json.dumps({"session_id": "proc_1", "status": "running", "pid": 4242})++ assert _stub("process_manage", {"action": "poll", "session_id": "proc_1"}, payload) == \+ "[process] poll session=proc_1"