From cee358564990354d9c601310d1014263834dec02 Mon Sep 17 00:00:00 2001 From: Jer Miller Date: Wed, 29 Jul 2026 18:58:42 -0600 Subject: [PATCH] fix(health): report provider process uptime --- solstone/think/supervisor.py | 7 ++--- tests/test_supervisor.py | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/solstone/think/supervisor.py b/solstone/think/supervisor.py index 5acfcc36d..b66625ef0 100644 --- a/solstone/think/supervisor.py +++ b/solstone/think/supervisor.py @@ -1504,9 +1504,7 @@ def _launch_process( # NOTE: All child processes should include -v for verbose logging by default. # This ensures their output is captured in logs for debugging. """Launch process with automatic output logging and restart policy tracking.""" - policy: RestartPolicy | None = None - if restart: - policy = _get_restart_policy(name) + policy = _get_restart_policy(name) # Generate ref if not provided ref = ref if ref else str(now_ms()) @@ -1520,8 +1518,7 @@ def _launch_process( logging.error(str(exc)) raise - if policy: - policy.record_start() + policy.record_start() _SERVICE_STATE[name] = { "restart": restart, "shutdown_timeout": shutdown_timeout, diff --git a/tests/test_supervisor.py b/tests/test_supervisor.py index 4f327b7ac..e651bff17 100644 --- a/tests/test_supervisor.py +++ b/tests/test_supervisor.py @@ -205,6 +205,58 @@ def test_launch_process_records_service_state(monkeypatch): } +def test_launch_process_records_uptime_without_restart(monkeypatch): + mod = importlib.import_module("solstone.think.supervisor") + mod._SERVICE_STATE.clear() + mod._RESTART_POLICIES.clear() + monkeypatch.setattr(mod, "_supervisor_ref", None) + monkeypatch.setattr(mod, "_supervisor_start", None) + monkeypatch.setattr(mod, "_task_queue", None) + monkeypatch.setattr(mod, "_callosum_server", None) + monkeypatch.setattr(mod.scheduler, "collect_status", lambda: []) + + clock = {"now": 100.0} + monkeypatch.setattr(mod.time, "time", lambda: clock["now"]) + + process = MagicMock() + process.pid = 12345 + process.poll.return_value = None + managed = mod.RunnerManagedProcess( + process=process, + name="parakeet-server", + log_writer=MagicMock(), + cmd=["parakeet-server"], + _threads=[], + ref="ref-1", + _start_time=100.0, + _callosum=None, + ) + monkeypatch.setattr( + mod.RunnerManagedProcess, + "spawn", + lambda *_args, **_kwargs: managed, + ) + + result = mod._launch_process( + "parakeet-server", + ["parakeet-server"], + restart=False, + ref="ref-1", + ) + clock["now"] = 137.0 + + status = mod.collect_status([result]) + + assert status["services"] == [ + { + "name": "parakeet-server", + "ref": "ref-1", + "pid": 12345, + "uptime_seconds": 37, + } + ] + + def test_parse_args_remote_flag(): """Test that parse_args includes --remote flag.""" mod = importlib.reload(importlib.import_module("solstone.think.supervisor")) -- 2.51.2