The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): suppress the unmask probe once /stop is pending
DavidMetcalfe65987c0800ea
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.pyindex f2ecae136f2..74980d16e2c 100644--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@ -3549,9 +3549,13 @@ class _StreamingCall(StreamingWaitMonitor):the original error. The successful delivery is bracketed by its own streamstart/end pair (the failed attempt already emitted a terminal end), and a responsethat cannot be replayed restores the saved preference before propagating ``e``.- Interrupts re-raise (the outer handler routes them). True = handled (caller must- not overwrite result); False = propagate ``e``.+ Interrupts re-raise (the outer handler routes them), and a /stop that arrived before+ this point suppresses the probe entirely — the loop's pre-retry interrupt check owns+ that decision, so a pending stop must not buy one more request.+ True = handled (caller must not overwrite result); False = propagate ``e``."""+ if getattr(self.agent, "_interrupt_requested", False):+ return Falsestatus = getattr(e, "status_code", None) or getattr(getattr(e, "response", None), "status_code", None)if not isinstance(status, int) or status < 500 or self.deltas_were_sent["yes"]:return Falsediff --git a/tests/agent/test_stream_unmask_5xx.py b/tests/agent/test_stream_unmask_5xx.pyindex 4bc0f594ed2..11b3e7fbdae 100644--- a/tests/agent/test_stream_unmask_5xx.py+++ b/tests/agent/test_stream_unmask_5xx.py@@ -292,3 +292,22 @@ def test_interrupt_during_probe_reraises(monkeypatch):with pytest.raises(InterruptedError):_run_handle_stream_error(call, _StreamErr(500))+++def test_pending_interrupt_suppresses_probe(monkeypatch):+ """A /stop seen before the failure is handled must win over the probe.++ The retry loop checks ``_interrupt_requested`` before opening another attempt;+ the probe runs inside the handler, i.e. outside that check, so without its own+ guard a stopped session still paid for one more request."""+ call = _make_call({"model": "m", "messages": []})+ _prime_probe_window(call)+ call.agent._interrupt_requested = True+ calls = _record_probe(monkeypatch, "probe must not run with a pending interrupt")++ handled = _run_handle_stream_error(call, _StreamErr(500))++ assert not handled+ assert calls == []+ assert isinstance(call.result["error"], _StreamErr) # original error still propagates+ assert call.agent._stream_5xx_probe_ts == 0.0 # a suppressed probe must not burn the window