The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): keep a refused write_file's outcome in its stub
Yuan Li2d5ed7dd8848
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 5861c79ca52..06e59dfeccb 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -1701,6 +1701,10 @@ def _sum_terminal(name, args, content, content_len, line_count):def _sum_write_file(name, args, content, content_len, line_count):+ # A refused write (stale-write guard, sensitive path, I/O error) changed nothing; summarized as+ # "wrote to" it compresses into a success the post-compaction agent then reports.+ if error := _json_dict(content).get("error"):+ return f"[write_file] FAILED: {' '.join(str(error).split())[:80]} ({args.get('path', '?')})"written_lines = _str_arg(args, "content").count("\n") + 1 if args.get("content") else "?"return f"[write_file] wrote to {args.get('path', '?')} ({written_lines} lines)"diff --git a/tests/agent/test_context_compressor.py b/tests/agent/test_context_compressor.pyindex 549c29a3ebc..a50c17c579d 100644--- a/tests/agent/test_context_compressor.py+++ b/tests/agent/test_context_compressor.py@@ -26,6 +26,17 @@ from agent.auxiliary_client import CODEX_STREAM_STALL_MARKER_REQ = httpx.Request("POST", "http://x")[email protected]("result, expected", [+ ({"error": "Refusing to overwrite a.md: stale", "stale_write_blocked": True, "path": "a.md"},+ "[write_file] FAILED: Refusing to overwrite a.md: stale (a.md)"),+ ({"bytes_written": 13, "path": "a.md"}, "[write_file] wrote to a.md (2 lines)"),+])+def test_write_file_stub_keeps_the_refusal(result, expected):+ """A refused write changed nothing; its stub must not read as a successful write."""+ args = json.dumps({"path": "a.md", "content": "line 1\nline 2"})+ assert _summarize_tool_result("write_file", args, json.dumps(result)) == expected++class StubProviderError(Exception):def __init__(self, message, *, status_code=None, response=None):super().__init__(message)