From 5ff16c59d4fb28b0e619621ade6506161039509c Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Tue, 21 Jul 2026 19:58:41 +0000 Subject: [PATCH] fix(streaming): catch OverflowError in _terminal_turn_duration so a huge/invalid pending_started_at can't abort terminal-error settlement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex gate on #6312 found the extracted helper caught only (TypeError, ValueError) while the inline code it replaced caught Exception; float(10**400) raises OverflowError, escaping the helper and aborting terminal-error cleanup before the error message is persisted / apperror is emitted. Widen _terminal_turn_duration's float() guard to (TypeError, ValueError, OverflowError) — the exact exceptions float() can raise. Adds 10**400 to the existing invalid-origin parametrize (red-before-green verified). --- api/streaming.py | 2 +- tests/test_issue3929_error_preserves_partial.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/streaming.py b/api/streaming.py index 9c9ea54e..03b562c7 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -6508,7 +6508,7 @@ def _terminal_turn_duration(session, *, now: float | None = None) -> float | Non try: started = float(started_at) ended = float(time.time() if now is None else now) - except (TypeError, ValueError): + except (TypeError, ValueError, OverflowError): return None if not math.isfinite(started) or not math.isfinite(ended) or started <= 0: return None diff --git a/tests/test_issue3929_error_preserves_partial.py b/tests/test_issue3929_error_preserves_partial.py index cda3931d..101c15ab 100644 --- a/tests/test_issue3929_error_preserves_partial.py +++ b/tests/test_issue3929_error_preserves_partial.py @@ -15,7 +15,7 @@ import api.streaming as streaming from api.models import Session -@pytest.mark.parametrize("started_at", [None, 0, -1, "invalid", float("nan"), float("inf"), 101.0]) +@pytest.mark.parametrize("started_at", [None, 0, -1, "invalid", float("nan"), float("inf"), 101.0, 10**400]) def test_terminal_turn_duration_omits_invalid_origin(started_at): session = types.SimpleNamespace(pending_started_at=started_at)