Skip to content

The agent that grows with you

fix(api): drop the redundant try/except around the interrupted-run marker

teknium10b2b5e183ebe
diff --git a/gateway/platforms/api_server_runs.py b/gateway/platforms/api_server_runs.py
index d5505826712..53025b7450d 100644
--- a/gateway/platforms/api_server_runs.py
+++ b/gateway/platforms/api_server_runs.py
@@ -187,15 +187,12 @@ def _mark_shutdown_interrupted_runs(self, run_ids) -> None:
"""Publish the shutdown outcome before cooperative interruption can race teardown."""
for run_id in run_ids:
self._shutdown_interrupted_run_ids.add(run_id)
- try:
- self._set_run_status(
- run_id,
- "interrupted",
- error="Gateway shutdown interrupted the run.",
- last_event="run.interrupted",
- )
- except Exception:
- logger.exception("[api_server] failed to record shutdown for run %s", run_id)
+ self._set_run_status(
+ run_id,
+ "interrupted",
+ error="Gateway shutdown interrupted the run.",
+ last_event="run.interrupted",
+ )
def _make_run_event_callback(self, run_id: str, loop: "asyncio.AbstractEventLoop", *, _api_server):
diff --git a/tests/gateway/test_api_server_active_work_drain.py b/tests/gateway/test_api_server_active_work_drain.py
index a25798c6ab0..1878df7ff98 100644
--- a/tests/gateway/test_api_server_active_work_drain.py
+++ b/tests/gateway/test_api_server_active_work_drain.py
@@ -18,6 +18,7 @@ from aiohttp import web
from aiohttp.test_utils import TestClient, TestServer
from gateway.config import Platform, PlatformConfig
+from gateway.platforms import api_server_runs as _api_runs
from gateway.platforms.api_server import APIServerAdapter
from gateway.platforms.api_server_run_idempotency import RunIdempotencyStore
from gateway.run import _INTERRUPT_REASON_GATEWAY_SHUTDOWN
@@ -410,6 +411,15 @@ class TestInterruptActiveRuns:
assert adapter.interrupt_active_runs("gateway shutdown") == 1
healthy.interrupt.assert_called_once_with("gateway shutdown", tool_reason="gateway shutdown")
+ def test_shutdown_marker_does_not_swallow_status_failures(self):
+ """``_set_run_status`` already contains the only fallible step (store persist);
+ the shutdown marker must not hide a programming error behind a second net."""
+ adapter = APIServerAdapter(PlatformConfig(enabled=True))
+ with patch.object(adapter, "_set_run_status", side_effect=RuntimeError("boom")):
+ with pytest.raises(RuntimeError, match="boom"):
+ _api_runs._mark_shutdown_interrupted_runs(adapter, ["run-1"])
+ assert adapter._shutdown_interrupted_run_ids == {"run-1"}
+
class TestShutdownInterruptReachesEveryApiTurn:
@pytest.mark.parametrize("late_outcome", ["success", "failure"])