fix(photon): recover degraded upstream stream

This commit is contained in:
helix4u 2026-06-22 17:52:46 -06:00 committed by Teknium
parent 34bd6a0db5
commit 06cbc3bae9
6 changed files with 241 additions and 4 deletions

View file

@ -12,6 +12,8 @@ dying (issue #50185):
``retryable=True`` fatal so the gateway reconnect watcher revives the
platform instead of returning silently and leaving ``_inbound_loop``
spinning against a dead port.
4. ``_monitor_sidecar_health`` promotes degraded upstream stream health
reported by ``/healthz`` into the same retryable reconnect path.
No Node sidecar is spawned and no ports are bound.
"""
@ -195,3 +197,40 @@ async def test_clean_shutdown_does_not_raise_fatal(
assert adapter.has_fatal_error is False
assert notified == []
@pytest.mark.asyncio
async def test_degraded_stream_health_raises_retryable_fatal(
monkeypatch: pytest.MonkeyPatch,
) -> None:
adapter = _make_adapter(monkeypatch)
adapter._inbound_running = True
adapter._sidecar_health_interval = 0.0
async def _fake_call(path: str, payload: Dict[str, Any]) -> Any:
assert path == "/healthz"
return {
"ok": True,
"stream": {
"ok": False,
"state": "degraded",
"degradedForMs": 120000,
"lastIssue": "[spectrum.stream] stream interrupted; reconnecting",
},
}
notified: list[bool] = []
async def _fake_notify() -> None:
notified.append(True)
adapter._inbound_running = False
monkeypatch.setattr(adapter, "_sidecar_call", _fake_call)
monkeypatch.setattr(adapter, "_notify_fatal_error", _fake_notify)
await adapter._monitor_sidecar_health()
assert adapter.has_fatal_error is True
assert adapter.fatal_error_code == "UPSTREAM_STREAM_DEGRADED"
assert adapter.fatal_error_retryable is True
assert notified == [True]

View file

@ -17,6 +17,15 @@ def test_sidecar_applies_spectrum_patch_before_importing_sdk() -> None:
assert index.index("patchSpectrumTs();") < index.index('await import("spectrum-ts")')
def test_sidecar_healthz_reports_stream_health() -> None:
"""Local process health must include upstream stream health."""
index = Path("plugins/platforms/photon/sidecar/index.mjs").read_text(encoding="utf-8")
assert "function streamHealthSnapshot()" in index
assert 'return ok(res, { stream: streamHealthSnapshot() });' in index
assert "STREAM_INTERRUPTED_DEGRADE_COUNT" in index
assert "process.exit(75);" in index
def test_spectrum_patch_preserves_text_when_single_attachment(tmp_path: Path) -> None:
"""The sidecar dependency patch must turn text+one attachment into group content."""
dist = tmp_path / "node_modules" / "spectrum-ts" / "dist"