The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(photon): don't read a signal-raced sidecar exit as a fatal crash
unsupportedpastels99b24916ce1e
diff --git a/plugins/platforms/photon/adapter.py b/plugins/platforms/photon/adapter.pyindex 9b56ae152a9..eceb7bd5d6e 100644--- a/plugins/platforms/photon/adapter.py+++ b/plugins/platforms/photon/adapter.py@@ -1056,7 +1056,11 @@ class PhotonAdapter(BasePlatformAdapter):logger.info("[photon-sidecar] %s", line.decode("utf-8", "replace").rstrip())except Exception as e: # pragma: no cover - defensivelogger.warning("[photon-sidecar] supervisor exited: %s", e)- if self._inbound_running:+ # A container/supervisor stop signals the whole process tree, so the sidecar (its own+ # session) can die before the gateway's stop flow reaches disconnect(). The runner flips+ # ``_stop_requested_by_signal`` in its signal handler, ahead of any stop work (#127047).+ runner_stop = getattr(getattr(self, "gateway_runner", None), "_stop_requested_by_signal", False)+ if self._inbound_running and not runner_stop:exit_code = proc.poll()logger.error("[photon] sidecar exited unexpectedly (code %s) — triggering reconnect", exit_code)self._set_fatal_error(diff --git a/tests/plugins/platforms/photon/test_overflow_recovery.py b/tests/plugins/platforms/photon/test_overflow_recovery.pyindex ab72732dba1..fff93b433fe 100644--- a/tests/plugins/platforms/photon/test_overflow_recovery.py+++ b/tests/plugins/platforms/photon/test_overflow_recovery.py@@ -238,6 +238,34 @@ async def test_clean_shutdown_does_not_raise_fatal(assert notified == [][email protected]("runner_stopping", [True, False], ids=["gateway-stopping", "gateway-running"])+async def test_sidecar_sigterm_is_fatal_only_while_gateway_keeps_running(+ monkeypatch: pytest.MonkeyPatch, runner_stopping: bool+) -> None:+ """#127047: a supervisor stop SIGTERMs the sidecar before disconnect() clears+ ``_inbound_running``. The runner's signal flag marks that window as intentional; the+ same -15 while the gateway keeps running must still queue the reconnect."""+ from types import SimpleNamespace++ adapter = _make_adapter(monkeypatch)+ adapter._inbound_running = True # disconnect() has NOT run yet+ adapter.gateway_runner = SimpleNamespace(_stop_requested_by_signal=runner_stopping) # type: ignore[assignment]++ notified: list[bool] = []++ async def _fake_notify() -> None:+ notified.append(True)++ monkeypatch.setattr(adapter, "_notify_fatal_error", _fake_notify)++ await adapter._supervise_sidecar(_DeadProc(exit_code=-15)) # type: ignore[arg-type]+ await _drain_pending_tasks()++ assert adapter.has_fatal_error is (not runner_stopping)+ assert notified == ([] if runner_stopping else [True])++@pytest.mark.asyncioasync def test_degraded_stream_health_raises_retryable_fatal(monkeypatch: pytest.MonkeyPatch,