Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(show-runtime): prove readiness before reporting available (#1639)
Call Whitee45e4bd2944b
diff --git a/core/show_runtime.py b/core/show_runtime.pyindex 6324aa4e7..b2efad0d0 100644--- a/core/show_runtime.py+++ b/core/show_runtime.py@@ -117,6 +117,11 @@ SHOW_RUNTIME_REQUEST_TIMEOUT_SECONDS = 30.0_CAPABILITY_RETRY_BASE_SECONDS = 0.25_CAPABILITY_RETRY_MAX_SECONDS = 5.0_CAPABILITY_RETRYABLE_STATUS_CODES = {408, 429}+_STARTUP_READY_TIMEOUT_SECONDS = 10.0+_STARTUP_POLL_INTERVAL_SECONDS = 0.05+_STARTUP_URL_TIMEOUT_REASON = "runtime_start_url_timeout"+_STARTUP_PROCESS_UNAVAILABLE_REASON = "runtime_start_process_unavailable"+_STARTUP_HEALTH_TIMEOUT_REASON = "runtime_start_health_timeout"_MISSING = object()@@ -402,6 +407,7 @@ class ShowRuntimeManager:with self.stdout_path.open("w", encoding="utf-8") as stdout, self.stderr_path.open("w", encoding="utf-8") as stderr:+ startup_deadline = asyncio.get_running_loop().time() + _STARTUP_READY_TIMEOUT_SECONDSself._process = subprocess.Popen([*command,@@ -421,12 +427,25 @@ class ShowRuntimeManager:text=True,**isolated_subprocess_kwargs(),)- base_url = await self._read_startup_url()+ base_url = await self._read_startup_url(deadline=startup_deadline)+ process = self._process+ if process is None or process.poll() is not None:+ self.stop()+ return self._publish_runtime_availability(+ ShowRuntimeServingState.START_FAILED,+ runtime_reason=_STARTUP_PROCESS_UNAVAILABLE_REASON,+ )if not base_url:self.stop()return self._publish_runtime_availability(ShowRuntimeServingState.START_FAILED,- runtime_reason="runtime_start_failed",+ runtime_reason=_STARTUP_URL_TIMEOUT_REASON,+ )+ if reason := await self._wait_for_startup_health(base_url, process, deadline=startup_deadline):+ self.stop()+ return self._publish_runtime_availability(+ ShowRuntimeServingState.START_FAILED,+ runtime_reason=reason,)self._base_url = base_urlreturn self._publish_runtime_availability(ShowRuntimeServingState.SERVING, base_url)@@ -684,10 +703,11 @@ class ShowRuntimeManager:except Exception:return False- async def _read_startup_url(self) -> str | None:- deadline = asyncio.get_running_loop().time() + 10- while asyncio.get_running_loop().time() < deadline:- if self._process and self._process.poll() is not None:+ async def _read_startup_url(self, *, deadline: float) -> str | None:+ loop = asyncio.get_running_loop()+ while loop.time() < deadline:+ process = self._process+ if process is None or process.poll() is not None:return Nonetry:text = self.stdout_path.read_text(encoding="utf-8")@@ -697,9 +717,36 @@ class ShowRuntimeManager:marker = "Vibe Show Runtime listening at "if marker in line:return line.split(marker, 1)[1].strip()- await asyncio.sleep(0.05)+ await asyncio.sleep(min(_STARTUP_POLL_INTERVAL_SECONDS, max(0.0, deadline - loop.time())))return None+ async def _wait_for_startup_health(+ self,+ base_url: str,+ process: subprocess.Popen[str],+ *,+ deadline: float,+ ) -> str | None:+ loop = asyncio.get_running_loop()+ while True:+ if process.poll() is not None:+ return _STARTUP_PROCESS_UNAVAILABLE_REASON+ remaining = deadline - loop.time()+ if remaining <= 0:+ return _STARTUP_HEALTH_TIMEOUT_REASON+ try:+ healthy = await asyncio.wait_for(self._healthy(base_url), timeout=remaining)+ except asyncio.TimeoutError:+ return _STARTUP_HEALTH_TIMEOUT_REASON+ if process.poll() is not None:+ return _STARTUP_PROCESS_UNAVAILABLE_REASON+ if healthy:+ return None+ remaining = deadline - loop.time()+ if remaining <= 0:+ return _STARTUP_HEALTH_TIMEOUT_REASON+ await asyncio.sleep(min(_STARTUP_POLL_INTERVAL_SECONDS, remaining))+def stop(self) -> None:process = self._processself._process = Nonediff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.pyindex 033e4028b..069023ab3 100644--- a/tests/test_ui_show_pages.py+++ b/tests/test_ui_show_pages.py@@ -6211,7 +6211,8 @@ def test_show_runtime_manager_passes_runtime_options(monkeypatch, tmp_path):captured["command"] = commandreturn FakeProcess()- async def fake_startup_url():+ async def fake_startup_url(*, deadline):+ captured["startup_deadline"] = deadlinereturn "http://127.0.0.1:12345"manager = ShowRuntimeManager(@@ -6222,6 +6223,7 @@ def test_show_runtime_manager_passes_runtime_options(monkeypatch, tmp_path):monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])monkeypatch.setattr("core.show_runtime.subprocess.Popen", fake_popen)monkeypatch.setattr(manager, "_read_startup_url", fake_startup_url)+ monkeypatch.setattr(manager, "_healthy", lambda _base_url: asyncio.sleep(0, result=True))result = asyncio.run(manager.ensure())@@ -6230,6 +6232,245 @@ def test_show_runtime_manager_passes_runtime_options(monkeypatch, tmp_path):assert captured["command"][cache_index + 1] == str(tmp_path / "runtime" / "vite-cache")index = captured["command"].index("--fallback-delay-seconds")assert captured["command"][index + 1] == str(SHOW_RUNTIME_RECOVERY_LOADING_DELAY_SECONDS)+ assert captured["startup_deadline"] > 0+++def test_show_runtime_manager_retries_health_until_ready(monkeypatch, tmp_path):+ class FakeProcess:+ def poll(self):+ return None++ health_results = iter([False, True])+ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )++ monkeypatch.setattr("core.show_runtime._STARTUP_READY_TIMEOUT_SECONDS", 0.1)+ monkeypatch.setattr("core.show_runtime._STARTUP_POLL_INTERVAL_SECONDS", 0.001)+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: FakeProcess())+ monkeypatch.setattr(+ manager,+ "_read_startup_url",+ lambda *, deadline: asyncio.sleep(0, result="http://127.0.0.1:12345"),+ )+ monkeypatch.setattr(+ manager,+ "_healthy",+ lambda _base_url: asyncio.sleep(0, result=next(health_results)),+ )++ result = asyncio.run(manager.ensure())++ assert result.available is True+ assert result.base_url == "http://127.0.0.1:12345"+++def test_show_runtime_manager_accepts_slow_health_within_shared_startup_budget(monkeypatch, tmp_path):+ class FakeProcess:+ def poll(self):+ return None++ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )+ stopped_live_processes = []+ health_attempts = []++ def fake_stop():+ stopped_live_processes.append(manager._process is not None)+ manager._process = None+ manager._base_url = None++ async def slow_startup_url(*, deadline):+ await asyncio.sleep(0.02)+ return "http://127.0.0.1:12345"++ async def slow_health(_base_url):+ health_attempts.append(True)+ await asyncio.sleep(0.02)+ return len(health_attempts) > 1++ monkeypatch.setattr("core.show_runtime._STARTUP_READY_TIMEOUT_SECONDS", 0.1)+ monkeypatch.setattr("core.show_runtime._STARTUP_POLL_INTERVAL_SECONDS", 0.001)+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: FakeProcess())+ monkeypatch.setattr(manager, "_read_startup_url", slow_startup_url)+ monkeypatch.setattr(manager, "_healthy", slow_health)+ monkeypatch.setattr(manager, "stop", fake_stop)++ result = asyncio.run(manager.ensure())++ assert result.available is True+ assert len(health_attempts) == 2+ assert stopped_live_processes == [False]+++def test_show_runtime_manager_reports_health_timeout_after_retrying(monkeypatch, tmp_path):+ class FakeProcess:+ def poll(self):+ return None++ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )+ health_attempts = []+ stopped_live_processes = []++ def fake_stop():+ stopped_live_processes.append(manager._process is not None)+ manager._process = None+ manager._base_url = None++ monkeypatch.setattr("core.show_runtime._STARTUP_READY_TIMEOUT_SECONDS", 0.03)+ monkeypatch.setattr("core.show_runtime._STARTUP_POLL_INTERVAL_SECONDS", 0.001)+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: FakeProcess())+ monkeypatch.setattr(+ manager,+ "_read_startup_url",+ lambda *, deadline: asyncio.sleep(0, result="http://127.0.0.1:12345"),+ )+ monkeypatch.setattr(+ manager,+ "_healthy",+ lambda _base_url: health_attempts.append(True) or asyncio.sleep(0, result=False),+ )+ monkeypatch.setattr(manager, "stop", fake_stop)++ result = asyncio.run(manager.ensure())++ assert result.available is False+ assert result.reason == "runtime_start_health_timeout"+ assert len(health_attempts) > 1+ assert stopped_live_processes == [False, True]+++def test_show_runtime_manager_bounds_in_flight_health_probe_by_shared_deadline(monkeypatch, tmp_path):+ class FakeProcess:+ def poll(self):+ return None++ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )++ monkeypatch.setattr("core.show_runtime._STARTUP_READY_TIMEOUT_SECONDS", 0.01)+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: FakeProcess())+ monkeypatch.setattr(+ manager,+ "_read_startup_url",+ lambda *, deadline: asyncio.sleep(0, result="http://127.0.0.1:12345"),+ )+ monkeypatch.setattr(manager, "_healthy", lambda _base_url: asyncio.sleep(1, result=True))+ monkeypatch.setattr(manager, "stop", lambda: setattr(manager, "_process", None))++ result = asyncio.run(manager.ensure())++ assert result.available is False+ assert result.reason == "runtime_start_health_timeout"+++def test_show_runtime_manager_reports_url_timeout_separately(monkeypatch, tmp_path):+ class FakeProcess:+ def poll(self):+ return None++ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )++ def fake_stop():+ manager._process = None+ manager._base_url = None++ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: FakeProcess())+ monkeypatch.setattr(manager, "_read_startup_url", lambda *, deadline: asyncio.sleep(0, result=None))+ monkeypatch.setattr(manager, "stop", fake_stop)++ result = asyncio.run(manager.ensure())++ assert result.available is False+ assert result.reason == "runtime_start_url_timeout"+++def test_show_runtime_manager_rejects_process_that_exits_before_health(monkeypatch, tmp_path):+ health_checks = []++ class ExitedProcess:+ def poll(self):+ return 1++ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: ExitedProcess())+ monkeypatch.setattr(+ manager,+ "_read_startup_url",+ lambda *, deadline: asyncio.sleep(0, result="http://127.0.0.1:12345"),+ )+ monkeypatch.setattr(+ manager,+ "_healthy",+ lambda base_url: health_checks.append(base_url) or asyncio.sleep(0, result=True),+ )++ result = asyncio.run(manager.ensure())++ assert result.available is False+ assert result.reason == "runtime_start_process_unavailable"+ assert health_checks == []+ assert manager._process is None+++def test_show_runtime_manager_rejects_process_that_exits_after_health(monkeypatch, tmp_path):+ class ExitsAfterHealthProcess:+ health_completed = False++ def poll(self):+ return 1 if self.health_completed else None++ process = ExitsAfterHealthProcess()+ manager = ShowRuntimeManager(+ command="/bin/runtime-cli",+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ )++ async def healthy_then_exit(_base_url):+ process.health_completed = True+ return True++ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: [command])+ monkeypatch.setattr("core.show_runtime.subprocess.Popen", lambda *_args, **_kwargs: process)+ monkeypatch.setattr(+ manager,+ "_read_startup_url",+ lambda *, deadline: asyncio.sleep(0, result="http://127.0.0.1:12345"),+ )+ monkeypatch.setattr(manager, "_healthy", healthy_then_exit)++ result = asyncio.run(manager.ensure())++ assert result.available is False+ assert result.reason == "runtime_start_process_unavailable"+ assert manager._process is Nonedef test_show_runtime_manager_prewarm_loads_entry_module(monkeypatch, tmp_path):diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex a0e73a602..adb87f9d3 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -1,3 +1,4 @@+import asyncioimport jsonimport osimport pytest@@ -2240,7 +2241,7 @@ def test_repair_show_runtime_returns_structured_download_failure(monkeypatch):},},)- monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", lambda: manager)+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", lambda **_kwargs: manager)result = cli._repair_show_runtime()@@ -2251,6 +2252,22 @@ def test_repair_show_runtime_returns_structured_download_failure(monkeypatch):def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):+ prepared = []+ stopped = []++ async def ensure():+ return SimpleNamespace(available=True, reason=None)++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": True,+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "command": [str(tmp_path / "runtime-cli")],+ "status": {"install_dir": str(tmp_path / "runtime")},+ }+manager = SimpleNamespace(status=lambda: {"provider": "manifest-cache",@@ -2258,19 +2275,275 @@ def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):"archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},"installed": False,},- prepare=lambda force=False: {+ prepare=prepare,+ ensure=ensure,+ stop=lambda: stopped.append(True),+ )+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", lambda **_kwargs: manager)++ result = cli._repair_show_runtime()++ assert result["status"] == "repaired"+ assert result["install_dir"] == str(tmp_path / "runtime")+ assert prepared == [False]+ assert stopped == [True]+++def test_repair_show_runtime_does_not_reinstall_startable_runtime(monkeypatch, tmp_path):+ constructor_calls = []+ verifier_stops = []++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "install_dir": str(tmp_path / "installed"),+ "archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},+ "installed": True,+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ prepare=lambda force=False: pytest.fail("startable runtime must not be reinstalled"),+ )+ verifier = SimpleNamespace(+ ensure=lambda: asyncio.sleep(0, result=SimpleNamespace(available=True, reason=None)),+ stop=lambda: verifier_stops.append(True),+ )++ def manager_factory(**kwargs):+ constructor_calls.append(kwargs)+ return verifier if kwargs else manager++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "skipped"+ assert result["install_dir"] == str(tmp_path / "installed")+ assert "no repair is needed" in result["message"]+ assert verifier_stops == [True]+ assert len(constructor_calls) == 2+ verification_call = constructor_calls[1]+ assert verification_call["auto_install"] is False+ assert verification_call["workspace_root"].name == "show"+ assert verification_call["runtime_dir"].name == "runtime"+ assert verification_call["workspace_root"].parent == verification_call["runtime_dir"].parent+++ ("language", "message_fragment"),+ [("en", "Fix or remove the override"), ("zh", "\u4fee\u590d\u6216\u79fb\u9664\u8be5\u8986\u76d6")],+)+def test_repair_show_runtime_refuses_explicit_command_before_hypothetical_recovery(+ monkeypatch, tmp_path, language, message_fragment+):+ prepared = []+ verification_calls = []+ verification_results = [+ SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ SimpleNamespace(available=True, reason=None),+ ]+ explicit_command = str(tmp_path / "explicit-runtime")++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "command",+ "platform": "linux-x64",+ "install_dir": None,+ "installed": True,+ "command": [explicit_command],+ "explicit_command": explicit_command,+ },+ prepare=lambda force=False: prepared.append(force),+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager++ async def ensure():+ index = len(verification_calls)+ verification_calls.append(index)+ return verification_results[index]++ return SimpleNamespace(ensure=ensure, stop=lambda: None)++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)+ monkeypatch.setattr(cli, "_configured_cli_language", lambda: language)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_start_health_timeout"+ assert result["explicit_command"] == explicit_command+ assert "VIBE_SHOW_RUNTIME_BIN" in result["message"]+ assert message_fragment in result["message"]+ assert prepared == []+ assert verification_calls == [0]+++def test_repair_show_runtime_reinstalls_unstartable_runtime_and_verifies_recovery(monkeypatch, tmp_path):+ prepared = []+ verifier_results = iter(+ [+ SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ SimpleNamespace(available=True, reason=None),+ ]+ )++ def prepare(force=False):+ prepared.append(force)+ return {"ok": True,"provider": "manifest-cache","platform": "linux-x64",- "status": {"install_dir": str(tmp_path / "runtime")},+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ "status": {"install_dir": str(tmp_path / "installed")},+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "install_dir": str(tmp_path / "installed"),+ "archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},+ "installed": True,+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],},+ prepare=prepare,)- monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", lambda: manager)++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(0, result=next(verifier_results)),+ stop=lambda: None,+ )++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)result = cli._repair_show_runtime()assert result["status"] == "repaired"- assert result["install_dir"] == str(tmp_path / "runtime")+ assert prepared == [True]+++def test_repair_show_runtime_reports_runtime_that_still_cannot_start(monkeypatch, tmp_path):+ prepared = []+ verifier_stops = []++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": True,+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ "status": {"install_dir": str(tmp_path / "installed")},+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "install_dir": str(tmp_path / "installed"),+ "archive": {"url": "https://github.com/avibe-bot/avibe/releases/download/v-test/runtime.tgz"},+ "installed": True,+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ prepare=prepare,+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(+ 0,+ result=SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ ),+ stop=lambda: verifier_stops.append(True),+ )++ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_start_health_timeout"+ assert "could not start" in result["message"]+ assert prepared == [True]+ assert verifier_stops == [True, True]+++def test_repair_show_runtime_preserves_undetermined_post_repair_verification(monkeypatch, tmp_path):+ prepared = []+ verification_index = 0+ verifier_results = iter(+ [+ SimpleNamespace(available=False, reason="runtime_start_health_timeout"),+ SimpleNamespace(available=True, reason=None),+ ]+ )++ class VerificationDirectory:+ def __init__(self, *args, **kwargs):+ nonlocal verification_index+ del args, kwargs+ verification_index += 1+ self.index = verification_index++ def __enter__(self):+ root = tmp_path / f"verification-{self.index}"+ root.mkdir()+ return str(root)++ def __exit__(self, exc_type, exc, traceback):+ del exc_type, exc, traceback+ if self.index == 2:+ raise OSError("post-repair verification cleanup failed")+ return False++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": True,+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ "status": {"install_dir": str(tmp_path / "installed")},+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "manifest-cache",+ "platform": "linux-x64",+ "install_dir": str(tmp_path / "installed"),+ "archive": {"url": str(tmp_path / "runtime.tgz")},+ "installed": True,+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ prepare=prepare,+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(0, result=next(verifier_results)),+ stop=lambda: None,+ )++ monkeypatch.setattr(cli.tempfile, "TemporaryDirectory", VerificationDirectory)+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_start_verification_failed"+ assert result["start_error"] == "post-repair verification cleanup failed"+ assert "preparation completed" in result["message"]+ assert prepared == [True]def test_runtime_prepare_strict_does_not_report_policy_skip_as_ready(monkeypatch, capsys):@@ -2307,6 +2580,69 @@ def test_runtime_prepare_strict_does_not_report_policy_skip_as_ready(monkeypatchassert "VIBE_INSTALL_SKIP_SHOW_RUNTIME" in captured.err[email protected]("failure_phase", ["temporary_directory", "verifier", "cleanup"])+def test_repair_show_runtime_reports_verification_workspace_failures(monkeypatch, tmp_path, failure_phase):+ prepared = []++ class VerificationDirectory:+ def __init__(self, *args, **kwargs):+ if failure_phase == "temporary_directory":+ raise OSError("verification workspace failed")++ def __enter__(self):+ root = tmp_path / "verification"+ root.mkdir(exist_ok=True)+ return str(root)++ def __exit__(self, exc_type, exc, traceback):+ if failure_phase == "cleanup":+ raise OSError("verification workspace failed")+ return False++ def prepare(force=False):+ prepared.append(force)+ return {+ "ok": True,+ "provider": "archive",+ "platform": "linux-x64",+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ "status": {"install_dir": str(tmp_path / "installed")},+ }++ manager = SimpleNamespace(+ status=lambda: {+ "provider": "archive",+ "platform": "linux-x64",+ "install_dir": str(tmp_path / "installed"),+ "archive": {"url": str(tmp_path / "runtime.tgz")},+ "installed": True,+ "command": [str(tmp_path / "node"), str(tmp_path / "runtime-cli.js")],+ },+ prepare=prepare,+ )++ def manager_factory(**kwargs):+ if not kwargs:+ return manager+ if failure_phase == "verifier":+ raise OSError("verification workspace failed")+ return SimpleNamespace(+ ensure=lambda: asyncio.sleep(0, result=SimpleNamespace(available=True, reason=None)),+ stop=lambda: None,+ )++ monkeypatch.setattr(cli.tempfile, "TemporaryDirectory", VerificationDirectory)+ monkeypatch.setattr("core.show_runtime.ShowRuntimeManager", manager_factory)++ result = cli._repair_show_runtime()++ assert result["status"] == "failed"+ assert result["reason"] == "runtime_start_verification_failed"+ assert result["start_error"] == "verification workspace failed"+ assert "no reinstall was attempted" in result["message"]+ assert prepared == []++def test_doctor_repair_refreshes_diagnostics_after_repair(monkeypatch):paths.ensure_data_dirs()restart_path = runtime.get_restart_status_path()diff --git a/vibe/cli.py b/vibe/cli.pyindex a6a348a61..211e4af09 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -21,7 +21,9 @@ import timeimport urllib.errorimport urllib.parseimport urllib.request+from dataclasses import dataclassfrom datetime import datetime, timedelta, timezone+from enum import Enumfrom pathlib import Pathfrom textwrap import dedentfrom typing import Any, Callable, Mapping, NamedTuple, Optional@@ -11998,6 +12000,39 @@ def _doctor_repair_result(target: str, status: str, message: str, **details) ->return payload+class _ShowRuntimeStartabilityState(str, Enum):+ STARTABLE = "startable"+ NOT_STARTABLE = "not_startable"+ UNDETERMINED = "undetermined"+++@dataclass(frozen=True)+class _ShowRuntimeStartability:+ state: _ShowRuntimeStartabilityState+ reason: str | None = None+ detail: str | None = None++ def __post_init__(self) -> None:+ if self.state is _ShowRuntimeStartabilityState.STARTABLE and (self.reason or self.detail):+ raise ValueError("startable outcome cannot carry failure evidence")+ if self.state is _ShowRuntimeStartabilityState.NOT_STARTABLE and (not self.reason or self.detail):+ raise ValueError("not-startable outcome requires only a reason")+ if self.state is _ShowRuntimeStartabilityState.UNDETERMINED and (self.reason or not self.detail):+ raise ValueError("undetermined outcome requires only a detail")++ @classmethod+ def startable(cls) -> "_ShowRuntimeStartability":+ return cls(_ShowRuntimeStartabilityState.STARTABLE)++ @classmethod+ def not_startable(cls, reason: str) -> "_ShowRuntimeStartability":+ return cls(_ShowRuntimeStartabilityState.NOT_STARTABLE, reason=reason)++ @classmethod+ def undetermined(cls, detail: str) -> "_ShowRuntimeStartability":+ return cls(_ShowRuntimeStartabilityState.UNDETERMINED, detail=detail)++def _write_refreshed_runtime_status() -> None:# Asked, not re-derived. A repair that wrote its own idea of the state word# would be the second place deciding one fact -- and the one that persists@@ -12303,8 +12338,70 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:manager = ShowRuntimeManager()before = manager.status()++ def verify_startability(command_value: Any) -> _ShowRuntimeStartability:+ command = command_value if isinstance(command_value, list) else []+ if not command:+ return _ShowRuntimeStartability.not_startable("runtime_command_missing")+ try:+ with tempfile.TemporaryDirectory(prefix="avibe-show-runtime-doctor-") as verification_root_value:+ verification_root = Path(verification_root_value)+ verifier = ShowRuntimeManager(+ command=shlex.join(str(part) for part in command),+ workspace_root=verification_root / "show",+ runtime_dir=verification_root / "runtime",+ auto_install=False,+ )+ try:+ result = asyncio.run(verifier.ensure())+ finally:+ verifier.stop()+ except Exception as exc: # noqa: BLE001+ detail = str(exc).strip() or type(exc).__name__+ return _ShowRuntimeStartability.undetermined(detail)+ if result.available:+ return _ShowRuntimeStartability.startable()+ return _ShowRuntimeStartability.not_startable(result.reason or "runtime_start_failed")++ language = _configured_cli_language()if before.get("installed"):- return _doctor_repair_result(target, "skipped", "Show Runtime is already ready.")+ startability = verify_startability(before.get("command"))+ if startability.state is _ShowRuntimeStartabilityState.UNDETERMINED:+ return _doctor_repair_result(+ target,+ "failed",+ i18n_t("runtime.doctor.repairVerificationFailed", language, detail=startability.detail),+ provider=before.get("provider"),+ platform=before.get("platform"),+ install_dir=before.get("install_dir"),+ installed=True,+ reason="runtime_start_verification_failed",+ start_error=startability.detail,+ )+ if startability.state is _ShowRuntimeStartabilityState.STARTABLE:+ return _doctor_repair_result(+ target,+ "skipped",+ i18n_t("runtime.doctor.repairHealthy", language),+ provider=before.get("provider"),+ platform=before.get("platform"),+ install_dir=before.get("install_dir"),+ )+ if startability.state is not _ShowRuntimeStartabilityState.NOT_STARTABLE:+ raise AssertionError(f"Unhandled Show Runtime startability: {startability.state}")+ if before.get("explicit_command"):+ reason = startability.reason or "runtime_start_failed"+ return _doctor_repair_result(+ target,+ "failed",+ i18n_t("runtime.doctor.repairExplicitCommandFailed", language, reason=reason),+ provider=before.get("provider"),+ platform=before.get("platform"),+ install_dir=before.get("install_dir"),+ installed=True,+ reason=reason,+ explicit_command=before.get("explicit_command"),+ )archive = before.get("archive") if isinstance(before.get("archive"), dict) else {}archive_url = str(archive.get("url") or "")@@ -12315,23 +12412,47 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:return _doctor_repair_result(target,"failed",- "The packaged Show Runtime manifest is unavailable and the legacy upstream archive URL has no release asset. "- "Upgrade or reinstall the official Avibe package, or remove stale runtime source overrides.",+ i18n_t("runtime.doctor.repairLegacyArchiveUnavailable", language),provider=before.get("provider"),archive_url=archive_url,)- result = manager.prepare(force=False)+ result = manager.prepare(force=bool(before.get("installed")))status = result.get("status") if isinstance(result.get("status"), dict) else {}if result.get("ok"):- return _doctor_repair_result(- target,- "repaired",- "Prepared the manifest-selected Show Runtime.",- provider=result.get("provider"),- platform=result.get("platform"),- install_dir=status.get("install_dir"),- )+ startability = verify_startability(result.get("command"))+ if startability.state is _ShowRuntimeStartabilityState.STARTABLE:+ return _doctor_repair_result(+ target,+ "repaired",+ i18n_t("runtime.doctor.repairStarted", language),+ provider=result.get("provider"),+ platform=result.get("platform"),+ install_dir=status.get("install_dir"),+ )+ if startability.state is _ShowRuntimeStartabilityState.NOT_STARTABLE:+ reason = startability.reason or "runtime_start_failed"+ return _doctor_repair_result(+ target,+ "failed",+ i18n_t("runtime.doctor.repairStartFailed", language, reason=reason),+ provider=result.get("provider"),+ platform=result.get("platform"),+ install_dir=status.get("install_dir"),+ reason=reason,+ )+ if startability.state is _ShowRuntimeStartabilityState.UNDETERMINED:+ return _doctor_repair_result(+ target,+ "failed",+ i18n_t("runtime.doctor.repairPostVerificationFailed", language, detail=startability.detail),+ provider=result.get("provider"),+ platform=result.get("platform"),+ install_dir=status.get("install_dir"),+ reason="runtime_start_verification_failed",+ start_error=startability.detail,+ )+ raise AssertionError(f"Unhandled Show Runtime startability: {startability.state}")reason = str(result.get("reason") or "runtime_prepare_failed")download_error = status.get("download_error") if isinstance(status.get("download_error"), dict) else None@@ -12344,7 +12465,7 @@ def _repair_show_runtime(*, dry_run: bool = False) -> dict:return _doctor_repair_result(target,"failed",- f"Show Runtime preparation failed: {detail}",+ i18n_t("runtime.doctor.repairPrepareFailed", language, detail=detail),provider=result.get("provider"),platform=result.get("platform"),reason=reason,diff --git a/vibe/i18n/en.json b/vibe/i18n/en.jsonindex 9c56b23cf..5015f6dc3 100644--- a/vibe/i18n/en.json+++ b/vibe/i18n/en.json@@ -927,7 +927,15 @@"archiveCacheClean": "Show Runtime archive cache has no reclaimable archives","archiveCacheSkipped": "Show Runtime archive cache was not inspected ({reason}); it may still hold reclaimable archives.","archiveCacheSkippedAction": "Wait for the running install or clean to finish, then rerun Doctor.",- "archiveCacheSkippedInspectionAction": "Check runtime directory permissions and the Avibe log; retry Doctor once fixed."+ "archiveCacheSkippedInspectionAction": "Check runtime directory permissions and the Avibe log; retry Doctor once fixed.",+ "repairHealthy": "Show Runtime starts successfully; no repair is needed.",+ "repairStarted": "Reinstalled and started the manifest-selected Show Runtime.",+ "repairStartFailed": "Show Runtime was reinstalled but could not start: {reason}",+ "repairVerificationFailed": "Show Runtime startability could not be verified, so no reinstall was attempted: {detail}",+ "repairPostVerificationFailed": "Show Runtime preparation completed, but startability could not be verified: {detail}",+ "repairExplicitCommandFailed": "The Show Runtime command from VIBE_SHOW_RUNTIME_BIN could not start: {reason}. Fix or remove the override, then rerun Doctor.",+ "repairPrepareFailed": "Show Runtime preparation failed: {detail}",+ "repairLegacyArchiveUnavailable": "The packaged Show Runtime manifest is unavailable and the legacy upstream archive URL has no release asset. Upgrade or reinstall the official Avibe package, or remove stale runtime source overrides."}},"data": {diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.jsonindex a95455838..150418b52 100644--- a/vibe/i18n/zh.json+++ b/vibe/i18n/zh.json@@ -927,7 +927,15 @@"archiveCacheClean": "Show Runtime \u5f52\u6863\u7f13\u5b58\u6ca1\u6709\u53ef\u56de\u6536\u5f52\u6863","archiveCacheSkipped": "未能检查 Show Runtime 归档缓存({reason});其中可能仍有可回收归档。","archiveCacheSkippedAction": "等待正在进行的安装或清理结束后,重新运行 Doctor。",- "archiveCacheSkippedInspectionAction": "\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u548c Avibe \u65e5\u5fd7\uff0c\u4fee\u590d\u540e\u91cd\u8bd5 Doctor\u3002"+ "archiveCacheSkippedInspectionAction": "\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u548c Avibe \u65e5\u5fd7\uff0c\u4fee\u590d\u540e\u91cd\u8bd5 Doctor\u3002",+ "repairHealthy": "Show Runtime \u53ef\u4ee5\u6b63\u5e38\u542f\u52a8\uff0c\u65e0\u9700\u4fee\u590d\u3002",+ "repairStarted": "\u5df2\u91cd\u65b0\u5b89\u88c5\u5e76\u6210\u529f\u542f\u52a8\u6e05\u5355\u9009\u5b9a\u7684 Show Runtime\u3002",+ "repairStartFailed": "Show Runtime \u5df2\u91cd\u65b0\u5b89\u88c5\uff0c\u4f46\u4ecd\u65e0\u6cd5\u542f\u52a8\uff1a{reason}",+ "repairVerificationFailed": "\u65e0\u6cd5\u9a8c\u8bc1 Show Runtime \u662f\u5426\u53ef\u4ee5\u542f\u52a8\uff0c\u56e0\u6b64\u672a\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5\uff1a{detail}",+ "repairPostVerificationFailed": "Show Runtime \u51c6\u5907\u5df2\u5b8c\u6210\uff0c\u4f46\u65e0\u6cd5\u9a8c\u8bc1\u5b83\u662f\u5426\u53ef\u4ee5\u542f\u52a8\uff1a{detail}",+ "repairExplicitCommandFailed": "VIBE_SHOW_RUNTIME_BIN \u6307\u5b9a\u7684 Show Runtime \u547d\u4ee4\u65e0\u6cd5\u542f\u52a8\uff1a{reason}\u3002\u8bf7\u4fee\u590d\u6216\u79fb\u9664\u8be5\u8986\u76d6\u540e\u91cd\u65b0\u8fd0\u884c Doctor\u3002",+ "repairPrepareFailed": "Show Runtime \u51c6\u5907\u5931\u8d25\uff1a{detail}",+ "repairLegacyArchiveUnavailable": "\u6253\u5305\u7684 Show Runtime \u6e05\u5355\u4e0d\u53ef\u7528\uff0c\u65e7\u7248\u4e0a\u6e38\u5f52\u6863\u5730\u5740\u4e5f\u6ca1\u6709\u53d1\u5e03\u8d44\u4ea7\u3002\u8bf7\u5347\u7ea7\u6216\u91cd\u65b0\u5b89\u88c5\u5b98\u65b9 Avibe \u8f6f\u4ef6\u5305\uff0c\u6216\u79fb\u9664\u8fc7\u671f\u7684 runtime \u6765\u6e90\u8986\u76d6\u914d\u7f6e\u3002"}},"data": {