fix(cli): warn when hook recovery starts the proxy but it never becomes ready

_ensure_profile_running ignored the result of the final 45s wait_ready, so a
proxy that started but never became ready left no trace. That case now logs
the same one WARNING as a failed start, with "it did not become ready within
45s" as the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tejas Chopra
2026-10-09 18:33:15 -07:00
co-authored by Claude Opus 5.5
parent c9f7a46960
commit 08386d0357
2 changed files with 42 additions and 4 deletions
+4 -3
View File
@@ -875,7 +875,7 @@ def _ensure_profile_running(profile: str) -> None:
return
if manifest is None:
return
failure: Exception | None = None
failure: str | None = None
with _suppress_hook_output():
if wait_ready(manifest, timeout_seconds=1, require_identity=True):
return
@@ -899,12 +899,13 @@ def _ensure_profile_running(profile: str) -> None:
start_supervisor(manifest)
else:
start_detached_agent(manifest.profile)
wait_ready(manifest, timeout_seconds=45, require_identity=True)
if not wait_ready(manifest, timeout_seconds=45, require_identity=True):
failure = "it did not become ready within 45s"
except (click.ClickException, RuntimeError, OSError, subprocess.SubprocessError) as exc:
# Supervisor and runtime starts raise these; anything else is a bug
# and should surface. Report outside the suppressed block so the
# one line reaches stderr while stdout stays clean for the hook.
failure = exc
failure = str(exc)
if failure is not None:
logger.warning(
"headroom: could not start persistent proxy %r: %s. "
+38 -1
View File
@@ -1797,7 +1797,9 @@ def test_ensure_profile_running_logs_a_failed_recovery(monkeypatch, caplog) -> N
monkeypatch.setattr(init_cli, "runtime_status", lambda manifest: "stopped")
monkeypatch.setattr(init_cli, "runtime_ownership", lambda manifest: "service")
monkeypatch.setattr(
init_cli, "wait_ready", lambda manifest, timeout_seconds, require_identity: False
init_cli,
"wait_ready",
lambda manifest, timeout_seconds, require_identity: timeout_seconds == 45,
)
monkeypatch.setattr(init_cli, "start_supervisor", lambda manifest: None)
@@ -1818,3 +1820,38 @@ def test_ensure_profile_running_logs_a_failed_recovery(monkeypatch, caplog) -> N
"headroom: could not start persistent proxy 'service-profile': launchctl bootstrap "
"failed. Check it with `headroom install status --profile service-profile`."
]
def test_ensure_profile_running_logs_a_recovery_that_never_becomes_ready(
monkeypatch, caplog
) -> None:
init_cli, _ = _load_init_module(monkeypatch)
manifest = SimpleNamespace(
preset=init_cli.InstallPreset.PERSISTENT_TASK.value,
supervisor_kind=init_cli.SupervisorKind.NONE.value,
profile="task-profile",
)
started: list[str] = []
@contextmanager
def fake_start_lock(profile: str):
yield True
monkeypatch.setattr(init_cli, "load_manifest", lambda profile: manifest)
monkeypatch.setattr(init_cli, "acquire_runtime_start_lock", fake_start_lock)
monkeypatch.setattr(init_cli, "runtime_status", lambda manifest: "stopped")
monkeypatch.setattr(init_cli, "runtime_ownership", lambda manifest: "task")
monkeypatch.setattr(
init_cli, "wait_ready", lambda manifest, timeout_seconds, require_identity: False
)
monkeypatch.setattr(init_cli, "start_detached_agent", started.append)
with caplog.at_level("WARNING", logger="headroom.cli.init"):
init_cli._ensure_profile_running("task-profile")
assert started == ["task-profile"]
messages = [r.getMessage() for r in caplog.records if r.name == "headroom.cli.init"]
assert messages == [
"headroom: could not start persistent proxy 'task-profile': it did not become ready "
"within 45s. Check it with `headroom install status --profile task-profile`."
]