The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): budget the stall fallback from the moved fence deadline
ethernet5b6e75b32e58
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.pyindex d8e69542e3e..81f9ab1bcbd 100644--- a/agent/conversation_compression.py+++ b/agent/conversation_compression.py@@ -1292,7 +1292,9 @@ def run_compress_context_with_progress_timeout(recovered = _retry_compression_on_fallback_chain(worker=fallback_worker or worker, messages=messages, system_prompt_fallback=system_prompt_fallback,idle_timeout_seconds=idle, total_ceiling_seconds=ceiling,- precommit_deadline_monotonic=precommit_deadline_monotonic, on_commit_overrun=on_commit_overrun,+ # Prompt reading moves the fence deadline after the primary armed it.+ precommit_deadline_monotonic=fence.deadline_monotonic or precommit_deadline_monotonic,+ on_commit_overrun=on_commit_overrun,on_timeout_cause=on_timeout_cause, telemetry_agent=telemetry_agent, new_fence=new_fence,escalate_deterministic=escalate_deterministic,)diff --git a/tests/agent/test_compression_stall_fallback.py b/tests/agent/test_compression_stall_fallback.pyindex 65c63bc099f..d6cb8dfab25 100644--- a/tests/agent/test_compression_stall_fallback.py+++ b/tests/agent/test_compression_stall_fallback.py@@ -254,6 +254,38 @@ def test_total_ceiling_exhaustion_does_not_start_fallback():assert len(timeouts) == 1+class _ReadThenStallWorker(_StalledSummaryWorker):+ """The primary attempt's server reads the prompt (pushing the fence deadline back), then stalls."""++ def __call__(self, fence: CompressionCommitFence):+ if not self.routes:+ assert fence.extend_deadline(10.0)+ return super().__call__(fence)+++def test_stall_after_prompt_reading_still_funds_the_fallback():+ """Prompt reading moves the fence deadline; the fallback must be budgeted from the moved deadline,+ not the primary attempt's original one, or a long read followed by a stall skips the fallback."""+ original = [{"role": "user", "content": "keep-me"}]+ compressed = [{"role": "user", "content": "summary"}]+ worker = _ReadThenStallWorker(compressed)+ timeouts = []++ try:+ msgs, prompt = _run(+ # Same budget as the exhaustion test above: without the extension the idle expiry spends it.+ worker, chain=[dict(CHAIN_ENTRY, timeout=2.0)], timeouts=timeouts, messages=original,+ idle=2.0, ceiling=2.0,+ )+ finally:+ worker.release.set()++ assert worker.attempts == 2, "the extended budget must fund the fallback attempt"+ assert msgs == compressed+ assert prompt == "summarized-prompt"+ assert not timeouts++def test_same_turn_fallback_retry_is_not_gated_by_the_primary_stall_backoff(tmp_path, monkeypatch):"""The cancelled primary worker persists ``stall_interrupted`` while the fallback retry is alreadyrunning; that cooldown must not no-op the retry (#112387). Real AIAgent, real ``compress_context``