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
refactor(show-runtime): define admission outcome contract (#1634)
Call Whited7e3b6d8ef8c
diff --git a/core/show_runtime.py b/core/show_runtime.pyindex 881df0296..6324aa4e7 100644--- a/core/show_runtime.py+++ b/core/show_runtime.py@@ -24,7 +24,7 @@ import threadingimport timeimport urllib.parseimport urllib.request-from dataclasses import dataclass+from dataclasses import dataclass, replacefrom enum import Enumfrom pathlib import Pathfrom sysconfig import get_platform@@ -45,6 +45,7 @@ from config import pathsfrom core.dependency_network import dependency_error_details, fetch_bytes, fetch_to_path, probe_url, redact_urlfrom core.show_pages import SHOW_RUNTIME_RECOVERY_LOADING_DELAY_SECONDSfrom core.process_isolation import KILL_SIGNAL, isolated_subprocess_kwargs, signal_process_tree+from core.show_runtime_failures import ShowRuntimeFailureClass, classify_show_runtime_failurelogger = logging.getLogger(__name__)@@ -167,6 +168,23 @@ class ShowRuntimeRequestTimeoutError(TimeoutError):"""A proxied Runtime request exceeded its total request deadline."""+class ShowRuntimePolicyState(str, Enum):+ ALLOWED = "allowed"+ SKIPPED = "skipped"+++class ShowRuntimeInstallState(str, Enum):+ INSTALLED = "installed"+ ABSENT = "absent"+ FAILED = "failed"+++class ShowRuntimeServingState(str, Enum):+ SERVING = "serving"+ UNCHECKED = "unchecked"+ START_FAILED = "start_failed"++@dataclass(frozen=True)class ShowRuntimeArchive:platform: str@@ -186,6 +204,94 @@ class ShowRuntimeManifest:source: str+@dataclass(frozen=True)+class _ShowRuntimeDiskInstall:+ install_dir: Path+ command: list[str] | None+ metadata: Mapping[str, Any]+++@dataclass(frozen=True)+class ShowRuntimeAvailability:+ policy: ShowRuntimePolicyState = ShowRuntimePolicyState.ALLOWED+ install: ShowRuntimeInstallState = ShowRuntimeInstallState.ABSENT+ runtime: ShowRuntimeServingState = ShowRuntimeServingState.UNCHECKED+ command: list[str] | None = None+ base_url: str | None = None+ policy_reason: str | None = None+ install_reason: str | None = None+ install_failure_class: ShowRuntimeFailureClass | None = None+ install_runtime_version: str | None = None+ install_matches_manifest: bool | None = None+ runtime_reason: str | None = None++ @property+ def ok(self) -> bool:+ return self.install is ShowRuntimeInstallState.INSTALLED++ @property+ def available(self) -> bool:+ return self.runtime is ShowRuntimeServingState.SERVING and self.base_url is not None++ @property+ def reason(self) -> str | None:+ return self.runtime_reason or self.install_reason or self.policy_reason++ @classmethod+ def from_install(+ cls,+ *,+ command: list[str] | None = None,+ install: ShowRuntimeInstallState | None = None,+ policy_reason: str | None = None,+ install_reason: str | None = None,+ install_runtime_version: str | None = None,+ install_matches_manifest: bool | None = None,+ ) -> "ShowRuntimeAvailability":+ if install is None:+ if command:+ install = ShowRuntimeInstallState.INSTALLED+ elif install_reason:+ install = ShowRuntimeInstallState.FAILED+ else:+ install = ShowRuntimeInstallState.ABSENT+ return cls(+ policy=(ShowRuntimePolicyState.SKIPPED if policy_reason else ShowRuntimePolicyState.ALLOWED),+ install=install,+ command=command,+ policy_reason=policy_reason,+ install_reason=install_reason,+ install_failure_class=(+ classify_show_runtime_failure(install_reason) if install is ShowRuntimeInstallState.FAILED else None+ ),+ install_runtime_version=install_runtime_version,+ install_matches_manifest=install_matches_manifest,+ )++ def as_payload(self) -> dict[str, Any]:+ command = list(self.command) if self.command else None+ return {+ "policy": {"state": self.policy.value, "reason": self.policy_reason},+ "install": {+ "state": self.install.value,+ "reason": self.install_reason,+ "failure_class": self.install_failure_class.value if self.install_failure_class else None,+ "command": command,+ "runtime_version": self.install_runtime_version,+ "matches_manifest": self.install_matches_manifest,+ },+ "runtime": {+ "state": self.runtime.value,+ "reason": self.runtime_reason,+ "base_url": self.base_url,+ },+ # Compatibility fields remain projections of the three dimensions.+ "ok": self.ok,+ "command": command,+ "reason": self.reason,+ }++class ShowRuntimeManager:def __init__(self,@@ -246,6 +352,7 @@ class ShowRuntimeManager:self._install_reason: str | None = Noneself._download_error: dict[str, Any] | None = Noneself._managed_command: list[str] | None = None+ self._availability = ShowRuntimeAvailability()self._process: subprocess.Popen[str] | None = Noneself._base_url: str | None = Noneself._lock = asyncio.Lock()@@ -265,18 +372,24 @@ class ShowRuntimeManager:self._capability_retry_attempt = 0self._capability_generation = 0- async def ensure(self) -> ShowRuntimeResult:+ async def ensure(self) -> ShowRuntimeAvailability:if self._base_url and await self._healthy(self._base_url):- return ShowRuntimeResult(True, self._base_url)+ return self._publish_runtime_availability(ShowRuntimeServingState.SERVING, self._base_url)async with self._lock:if self._base_url and await self._healthy(self._base_url):- return ShowRuntimeResult(True, self._base_url)+ return self._publish_runtime_availability(ShowRuntimeServingState.SERVING, self._base_url)self.stop()- command = _resolve_command(self.command) if self._command_explicit else None- if not command:- command = await self._resolve_managed_command()+ if self._command_explicit:+ command = _resolve_command(self.command)+ availability = self._publish_install_availability(+ command=command,+ install_reason=None if command else "runtime_command_missing",+ )+ else:+ availability = await self._resolve_managed_availability()+ command = availability.commandif not command:- return ShowRuntimeResult(False, reason=self._install_reason or "runtime_command_missing")+ return availabilityself.runtime_dir.mkdir(parents=True, exist_ok=True)self.workspace_root.mkdir(parents=True, exist_ok=True)self.cache_root.mkdir(parents=True, exist_ok=True)@@ -311,9 +424,12 @@ class ShowRuntimeManager:base_url = await self._read_startup_url()if not base_url:self.stop()- return ShowRuntimeResult(False, reason="runtime_start_failed")+ return self._publish_runtime_availability(+ ShowRuntimeServingState.START_FAILED,+ runtime_reason="runtime_start_failed",+ )self._base_url = base_url- return ShowRuntimeResult(True, base_url)+ return self._publish_runtime_availability(ShowRuntimeServingState.SERVING, base_url)async def request(self,@@ -605,72 +721,208 @@ class ShowRuntimeManager:except Exception: # pragma: no cover - defensive; sweeping must never block spawnlogger.debug("Orphan show runtime sweep skipped", exc_info=True)- async def _resolve_managed_command(self) -> list[str] | None:+ async def _resolve_managed_availability(self) -> ShowRuntimeAvailability:if self._command_explicit and self.command != _RUNTIME_BIN:- self._install_reason = "runtime_command_missing"- return None+ command = _resolve_command(self.command)+ return self._publish_install_availability(+ command=command,+ install_reason=None if command else "runtime_command_missing",+ )if self.runtime_source == _RUNTIME_SOURCE_MANIFEST:- command = None if self.force_install else self._installed_manifest_runtime_command()+ if self._managed_command and not self.force_install:+ return self._publish_install_availability(command=self._managed_command)+ command = (+ None+ if self.force_install or self.manifest_url+ else self._installed_manifest_runtime_command(offline=self.offline)+ )if command:- self._managed_command = command- return command- if self.auto_install and not self._install_attempted:- self._install_attempted = True- command = await asyncio.to_thread(self._install_managed_runtime)+ return self._publish_install_availability(command=command)+ admission = await asyncio.to_thread(+ self._attempt_managed_install,+ force=self.force_install,+ offline=self.offline,+ automatic=True,+ )+ if admission.command:+ return admission+ if self.manifest_url and not self.force_install:+ command = self._installed_manifest_runtime_command(offline=self.offline)if command:- self._managed_command = command- return command- command = self._installed_manifest_runtime_command()- if command:- self._managed_command = command- return command+ return self._publish_install_availability(+ command=command,+ policy_reason=admission.policy_reason,+ )if self._managed_command:- return self._managed_command- return None+ return self._publish_install_availability(+ command=self._managed_command,+ policy_reason=admission.policy_reason,+ )+ return admissionif self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:- if self.auto_install and not self._install_attempted:- self._install_attempted = True- command = await asyncio.to_thread(self._install_managed_runtime)- if command:- self._managed_command = command- return command+ admission = await asyncio.to_thread(+ self._attempt_managed_install,+ force=self.force_install,+ offline=self.offline,+ automatic=True,+ )+ if admission.command:+ return admissioncommand = self._installed_archive_runtime_command()if command:- self._managed_command = command- return command+ return self._publish_install_availability(+ command=command,+ policy_reason=admission.policy_reason,+ )if self._managed_command:- return self._managed_command+ return self._publish_install_availability(+ command=self._managed_command,+ policy_reason=admission.policy_reason,+ )else:managed = self._managed_bin_path()resolved = _resolve_executable_path(managed)if resolved:- return [resolved]+ return self._publish_install_availability(command=[resolved])if self._managed_command:- return self._managed_command+ return self._publish_install_availability(command=self._managed_command)if self.runtime_source == _RUNTIME_SOURCE_GITHUB:command = self._installed_github_runtime_command()if command:- self._managed_command = command- return command- if not self.auto_install:- self._install_reason = "runtime_command_missing"- return None- if self._install_attempted:- return None- self._install_attempted = True- command = await asyncio.to_thread(self._install_managed_runtime)+ return self._publish_install_availability(command=command)+ admission = await asyncio.to_thread(+ self._attempt_managed_install,+ force=self.force_install,+ offline=self.offline,+ automatic=True,+ )+ return admission++ async def _resolve_managed_command(self) -> list[str] | None:+ availability = await self._resolve_managed_availability()+ return availability.command++ def _attempt_managed_install(+ self,+ *,+ force: bool,+ offline: bool,+ automatic: bool = False,+ ) -> ShowRuntimeAvailability:+ if self._command_explicit:+ command = _resolve_command(self.command)+ return self._publish_install_availability(+ command=command,+ install_reason=None if command else "runtime_command_missing",+ )+ skipped_reason = self._managed_install_opt_out_reason(automatic=automatic)+ if skipped_reason:+ return self._publish_policy_skip(skipped_reason)+ if self._managed_command and not force:+ return self._publish_install_availability(command=self._managed_command)+ if automatic and not force and self._install_attempted:+ return self._publish_install_availability(+ install_reason=self._install_reason or "runtime_install_failed"+ )++ with self._install_guard_locked() as (acquired, guard_reason):+ if not acquired:+ command = None if force else self._installed_managed_runtime_command(offline=offline)+ if command:+ return self._publish_install_availability(command=command)+ return self._publish_install_availability(install_reason=guard_reason)++ skipped_reason = self._managed_install_opt_out_reason(automatic=automatic)+ if skipped_reason:+ return self._publish_policy_skip(skipped_reason)+ if self._managed_command and not force:+ return self._publish_install_availability(command=self._managed_command)+ if automatic and not force and self._install_attempted:+ return self._publish_install_availability(+ install_reason=self._install_reason or "runtime_install_failed"+ )++ if automatic:+ self._install_attempted = True+ command = self._install_managed_runtime_locked(force=force, offline=offline)+ if command:+ return self._publish_install_availability(command=command)+ return self._publish_install_availability(+ install_reason=self._install_reason or "runtime_install_failed"+ )++ def _managed_install_opt_out_reason(self, *, automatic: bool) -> str | None:+ if automatic and _env_flag_enabled("VIBE_INSTALL_SKIP_SHOW_RUNTIME", default=False):+ return "VIBE_INSTALL_SKIP_SHOW_RUNTIME"+ if automatic and not self.auto_install:+ return "VIBE_SHOW_RUNTIME_AUTO_INSTALL"+ return None++ def _publish_policy_skip(self, reason: str) -> ShowRuntimeAvailability:+ if self._managed_command:+ return self._publish_install_availability(command=self._managed_command, policy_reason=reason)+ if self.runtime_source == _RUNTIME_SOURCE_MANIFEST:+ disk_install = self._persisted_manifest_disk_install()+ return self._publish_install_availability(+ command=disk_install.command if disk_install else None,+ install_state=(ShowRuntimeInstallState.INSTALLED if disk_install else ShowRuntimeInstallState.ABSENT),+ policy_reason=reason,+ )+ command = self._installed_managed_runtime_command(offline=True)+ return self._publish_install_availability(command=command, policy_reason=reason)++ def _publish_install_availability(+ self,+ *,+ command: list[str] | None = None,+ install_state: ShowRuntimeInstallState | None = None,+ policy_reason: str | None = None,+ install_reason: str | None = None,+ ) -> ShowRuntimeAvailability:if command:self._managed_command = command- return command+ self._install_reason = None+ else:+ self._install_reason = install_reason+ availability = ShowRuntimeAvailability.from_install(+ command=command,+ install=install_state,+ policy_reason=policy_reason,+ install_reason=install_reason,+ )+ self._availability = availability+ return availability- def _install_managed_runtime(self) -> list[str] | None:+ def _publish_runtime_availability(+ self,+ runtime: ShowRuntimeServingState,+ base_url: str | None = None,+ *,+ runtime_reason: str | None = None,+ ) -> ShowRuntimeAvailability:+ command = self._availability.command or self._managed_command+ install = self._availability.install+ if command:+ install = ShowRuntimeInstallState.INSTALLED+ availability = replace(+ self._availability,+ install=install,+ command=command,+ runtime=runtime,+ base_url=base_url,+ runtime_reason=runtime_reason,+ )+ self._availability = availability+ return availability++ def _install_managed_runtime_locked(self, *, force: bool, offline: bool) -> list[str] | None:command: list[str] | Noneif self.runtime_source == _RUNTIME_SOURCE_MANIFEST:- command = self._install_manifest_runtime()+ command = self._install_manifest_runtime_locked(force=force, offline=offline)elif self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:- command = self._install_archive_runtime()+ command = self._install_archive_runtime(offline=offline)elif self.runtime_source == _RUNTIME_SOURCE_GITHUB:- command = self._install_github_runtime()+ command = self._install_github_runtime(force=force)elif self.runtime_source == _RUNTIME_SOURCE_NPM:command = self._install_npm_runtime()else:@@ -681,6 +933,18 @@ class ShowRuntimeManager:self._clean_after_managed_install(command)return command+ def _installed_managed_runtime_command(self, *, offline: bool) -> list[str] | None:+ if self.runtime_source == _RUNTIME_SOURCE_MANIFEST:+ return self._installed_manifest_runtime_command(offline=offline)+ if self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:+ return self._installed_archive_runtime_command()+ if self.runtime_source == _RUNTIME_SOURCE_GITHUB:+ return self._installed_github_runtime_command()+ if self.runtime_source == _RUNTIME_SOURCE_NPM:+ resolved = _resolve_executable_path(self._managed_bin_path())+ return [resolved] if resolved else None+ return None+def _clean_after_managed_install(self, command: list[str]) -> None:try:if self.runtime_source == _RUNTIME_SOURCE_MANIFEST:@@ -706,9 +970,18 @@ class ShowRuntimeManager:# Cache cleanup must never turn a usable runtime install into a failed prepare.logger.warning("Failed to clean stale managed Show Runtime installs", exc_info=True)- def status(self) -> dict[str, Any]:+ def status(self, *, offline: bool | None = None) -> dict[str, Any]:configured_command = _resolve_command(self.command) if self._command_explicit else None- manifest = self._load_runtime_manifest() if self.runtime_source == _RUNTIME_SOURCE_MANIFEST else None+ disk_install = (+ self._persisted_manifest_disk_install()+ if not configured_command and self.runtime_source == _RUNTIME_SOURCE_MANIFEST+ else None+ )+ manifest = (+ self._load_runtime_manifest(offline=offline)+ if self.runtime_source == _RUNTIME_SOURCE_MANIFEST+ else None+ )platform_tag = _runtime_platform_tag()node = _resolve_node_command()node_version = _node_version(node) if node else None@@ -717,15 +990,28 @@ class ShowRuntimeManager:installed_dir: Path | None = Nonearchive: ShowRuntimeArchive | None = Nonearchive_status: dict[str, Any] | None = None- installed_matches = False- if not configured_command and manifest:- archive = manifest.archives.get(platform_tag)+ installed_runtime_version: str | None = None+ installed_matches: bool | None = None+ installed = configured_command is not None+ manifest_status = _manifest_status_payload(manifest)+ if not configured_command and self.runtime_source == _RUNTIME_SOURCE_MANIFEST:+ if disk_install:+ installed = True+ installed_dir = disk_install.install_dir+ installed_command = disk_install.command+ installed_runtime_version = _persisted_manifest_runtime_version(disk_install.metadata)+ if manifest_status is None:+ manifest_status = _persisted_manifest_status_payload(disk_install.metadata)+ archive_status = _persisted_archive_status_payload(disk_install.metadata)+ if manifest:+ archive = manifest.archives.get(platform_tag)if archive:- installed_dir = self._manifest_install_dir(manifest, archive)for candidate in self._manifest_install_candidates(manifest, archive):if not self._manifest_install_matches(candidate, manifest, archive):continue+ installed = Trueinstalled_dir = candidate+ installed_runtime_version = manifest.runtime_versioninstalled_matches = Trueif node and node_supported is not False:installed_command = self._manifest_runtime_command(candidate, node)@@ -734,6 +1020,7 @@ class ShowRuntimeManager:elif not configured_command and self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:installed_dir = self._archive_install_dir()installed_command = self._archive_runtime_command(installed_dir, node or ["node"])+ installed = installed_command is not Nonearchive_status = {"platform": platform_tag,"name": _runtime_archive_name(),@@ -745,9 +1032,19 @@ class ShowRuntimeManager:elif not configured_command and self.runtime_source == _RUNTIME_SOURCE_GITHUB:installed_dir = self._github_source_dir()installed_command = self._github_runtime_command(installed_dir, node or ["node"])+ installed = installed_command is not Noneelif not configured_command and self.runtime_source == _RUNTIME_SOURCE_NPM:managed = _resolve_executable_path(self._managed_bin_path())installed_command = [managed] if managed else None+ installed = installed_command is not None+ if installed and manifest is not None and archive is not None and installed_matches is not True:+ installed_matches = False+ install_payload = ShowRuntimeAvailability.from_install(+ command=installed_command,+ install=(ShowRuntimeInstallState.INSTALLED if installed else ShowRuntimeInstallState.ABSENT),+ install_runtime_version=installed_runtime_version,+ install_matches_manifest=installed_matches,+ ).as_payload()["install"]return {"provider": self.runtime_source,"platform": platform_tag,@@ -755,10 +1052,16 @@ class ShowRuntimeManager:"node_available": node is not None,"node_version": _format_semver(node_version),"node_supported": node_supported,- "manifest": _manifest_status_payload(manifest),+ "manifest": manifest_status,"archive": archive_status or _archive_status_payload(archive),- "installed": installed_command is not None,- "installed_matches_manifest": installed_matches,+ "install": install_payload,+ "runtime": {+ "state": ShowRuntimeServingState.UNCHECKED.value,+ "reason": None,+ "base_url": None,+ },+ "installed": installed,+ "installed_matches_manifest": install_payload["matches_manifest"],"install_dir": str(installed_dir) if installed_dir else None,"command": installed_command,"reason": self._install_reason,@@ -1628,38 +1931,141 @@ class ShowRuntimeManager:if path.is_dir() and not any(path.iterdir()):path.rmdir()- def prepare(self, *, force: bool | None = None, offline: bool | None = None) -> dict[str, Any]:- previous_force = self.force_install- previous_offline = self.offline- if force is not None:- self.force_install = force- if offline is not None:- self.offline = offline- try:- if self._command_explicit:- command = _resolve_command(self.command)- self._install_reason = None if command else "runtime_command_missing"- else:- command = self._install_managed_runtime()- return {- "ok": command is not None,+ def prepare(+ self,+ *,+ force: bool | None = None,+ offline: bool | None = None,+ automatic: bool = False,+ ) -> dict[str, Any]:+ effective_force = self.force_install if force is None else force+ effective_offline = self.offline if offline is None else offline+ admission = self._attempt_managed_install(+ force=effective_force,+ offline=effective_offline,+ automatic=automatic,+ )+ payload = admission.as_payload()+ status_offline = True if admission.policy is ShowRuntimePolicyState.SKIPPED else effective_offline+ payload.update(+ {"provider": self.runtime_source,"platform": _runtime_platform_tag(),- "command": command,- "reason": None if command else self._install_reason,- "status": self.status(),+ "status": self.status(offline=status_offline),}- finally:- self.force_install = previous_force- self.offline = previous_offline+ )+ return payload++ def _configured_manifest_source(self) -> str:+ if self.manifest_path is not None:+ return str(self.manifest_path)+ if self.manifest_url is not None:+ return self.manifest_url+ return _PACKAGED_RUNTIME_MANIFEST_SOURCE++ def _persisted_manifest_disk_install(self) -> _ShowRuntimeDiskInstall | None:+ """Resolve the current manifest install without consulting the manifest source."""+ try:+ pointer = json.loads((self.runtime_dir / "current.json").read_text(encoding="utf-8"))+ if not isinstance(pointer, dict) or pointer.get("provider") != _RUNTIME_SOURCE_MANIFEST:+ return None++ versions_dir = self.runtime_dir / "versions"+ versions_stat = versions_dir.lstat()+ if _is_reparse_point(versions_stat) or not stat.S_ISDIR(versions_stat.st_mode):+ return None+ versions_resolved = versions_dir.resolve(strict=True)++ pointer_install_dir = pointer.get("install_dir")+ if not isinstance(pointer_install_dir, str) or not pointer_install_dir:+ return None+ install_dir = Path(pointer_install_dir).resolve(strict=True)+ if versions_resolved not in install_dir.parents:+ return None+ install_stat = install_dir.lstat()+ if _is_reparse_point(install_stat) or not stat.S_ISDIR(install_stat.st_mode):+ return None++ metadata_path = self._manifest_metadata_path(install_dir)+ metadata_stat = metadata_path.lstat()+ if _is_reparse_point(metadata_stat) or not stat.S_ISREG(metadata_stat.st_mode):+ return None+ metadata = json.loads(metadata_path.read_text(encoding="utf-8"))+ if not isinstance(metadata, dict) or metadata.get("provider") != _RUNTIME_SOURCE_MANIFEST:+ return None++ runtime_version = metadata.get("runtime_version")+ platform_tag = metadata.get("platform")+ manifest_sha256 = metadata.get("manifest_sha256")+ archive_sha256 = metadata.get("archive_sha256")+ archive_name = metadata.get("archive_name")+ if not all(+ isinstance(value, str) and value+ for value in (runtime_version, platform_tag, manifest_sha256, archive_sha256, archive_name)+ ):+ return None+ if platform_tag != _runtime_platform_tag():+ return None+ if metadata.get("manifest_source") != self._configured_manifest_source():+ return None+ if not _CONTENT_ADDRESSED_ARCHIVE_RE.fullmatch(f"{manifest_sha256}.tgz"):+ return None+ if not _CONTENT_ADDRESSED_ARCHIVE_RE.fullmatch(f"{archive_sha256}.tgz"):+ return None+ pointer_manifest_sha256 = pointer.get("manifest_sha256")+ if not isinstance(pointer_manifest_sha256, str) or not _CONTENT_ADDRESSED_ARCHIVE_RE.fullmatch(+ f"{pointer_manifest_sha256}.tgz"+ ):+ return None+ # The pointer may name a newer manifest that adopted an old-layout+ # install after only another platform changed. The serving identity+ # deliberately excludes the whole-manifest digest, so agreement is+ # required only for the fields that identify this platform's bytes.+ for field in ("runtime_version", "platform", "archive_sha256"):+ if pointer.get(field) != metadata.get(field):+ return None++ relative_parts = install_dir.relative_to(versions_resolved).parts+ expected_prefix = (_safe_path_part(runtime_version), _safe_path_part(platform_tag))+ if relative_parts[:2] != expected_prefix:+ return None+ if len(relative_parts) == 2:+ pass+ elif len(relative_parts) == 3:+ current_fingerprint = hashlib.sha256(+ f"{runtime_version}:{platform_tag}:{archive_sha256}".encode("utf-8")+ ).hexdigest()[:16]+ previous_fingerprint = hashlib.sha256(+ f"{manifest_sha256}:{archive_sha256}".encode("utf-8")+ ).hexdigest()[:16]+ if relative_parts[2] not in {current_fingerprint, previous_fingerprint}:+ return None+ else:+ return None++ cli_path = install_dir / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"+ cli_stat = cli_path.lstat()+ if _is_reparse_point(cli_stat) or not stat.S_ISREG(cli_stat.st_mode):+ return None+ cli_resolved = cli_path.resolve(strict=True)+ if install_dir not in cli_resolved.parents:+ return None+ node = _resolve_node_command()+ command = [*node, str(cli_resolved)] if node else None+ status_metadata = dict(metadata)+ status_metadata["manifest_sha256"] = pointer_manifest_sha256+ return _ShowRuntimeDiskInstall(install_dir=install_dir, command=command, metadata=status_metadata)+ except (OSError, RuntimeError, TypeError, ValueError):+ return None- def _installed_manifest_runtime_command(self) -> list[str] | None:+ def _installed_manifest_runtime_command(self, *, offline: bool | None = None) -> list[str] | None:node = _resolve_node_command()if not node:return None- manifest = self._load_runtime_manifest()+ disk_install = self._persisted_manifest_disk_install()+ manifest = self._load_runtime_manifest(offline=offline)if not manifest:- return None+ return disk_install.command if disk_install else Noneif not self._manifest_node_supported(node, manifest):return Nonearchive = self._manifest_archive_for_platform(manifest)@@ -1796,24 +2202,11 @@ class ShowRuntimeManager:except Exception:logger.warning("Failed to release Show Runtime install guard", exc_info=True)- def _install_manifest_runtime(self) -> list[str] | None:- with self._install_guard_locked() as (acquired, reason):- if not acquired:- self._install_reason = reason- # An untakeable lock (busy or unavailable) must not break a- # non-forced prepare that already has a verified install to- # reuse. A forced reinstall that cannot run is a failure —- # reporting success would hide that the repair never happened.- if self.force_install:- return None- return self._reuse_verified_manifest_command()- return self._install_manifest_runtime_locked()-- def _reuse_verified_manifest_command(self) -> list[str] | None:+ def _reuse_verified_manifest_command(self, *, offline: bool | None = None) -> list[str] | None:"""Best-effort read-only fallback: reuse a verified installed runtime."""try:node = _resolve_node_command()- manifest = self._load_runtime_manifest()+ manifest = self._load_runtime_manifest(offline=offline)if not node or not manifest:return None# Mirror the normal install path: an unsupported Node version must@@ -1828,12 +2221,12 @@ class ShowRuntimeManager:except Exception:return None- def _install_manifest_runtime_locked(self) -> list[str] | None:+ def _install_manifest_runtime_locked(self, *, force: bool, offline: bool) -> list[str] | None:node = _resolve_node_command()if not node:self._install_reason = "runtime_node_missing"return None- manifest = self._load_runtime_manifest()+ manifest = self._load_runtime_manifest(offline=offline)if not manifest:return Noneif not self._manifest_node_supported(node, manifest):@@ -1847,18 +2240,18 @@ class ShowRuntimeManager:archive,node,)- if verified_existing_command and not self.force_install:- verified_install_dir = next(- iter(self._manifest_install_dirs_for_command(verified_existing_command)),- None,- )+ if verified_existing_command and not force:+ install_dirs = self._manifest_install_dirs_for_command(verified_existing_command)+ verified_install_dir = min(install_dirs, key=lambda path: str(path)) if install_dirs else Noneif verified_install_dir is None:- self._install_reason = "runtime_install_failed"- return None- self._write_current_manifest_pointer(manifest, archive, verified_install_dir)+ logger.warning(+ "Verified Show Runtime command has no discoverable install directory; skipping current pointer update"+ )+ else:+ self._write_current_manifest_pointer(manifest, archive, verified_install_dir)self._install_reason = Nonereturn verified_existing_command- archive_path = self._resolve_manifest_archive(archive)+ archive_path = self._resolve_manifest_archive(archive, offline=offline)if not archive_path:return self._reuse_existing_archive_runtime(verified_existing_command)self.runtime_dir.mkdir(parents=True, exist_ok=True)@@ -1886,7 +2279,7 @@ class ShowRuntimeManager:if tmp_dir.exists():shutil.rmtree(tmp_dir, ignore_errors=True)- def _load_runtime_manifest(self) -> ShowRuntimeManifest | None:+ def _load_runtime_manifest(self, *, offline: bool | None = None) -> ShowRuntimeManifest | None:payload: bytes | None = Nonesource = ""if self.manifest_path:@@ -1896,7 +2289,7 @@ class ShowRuntimeManager:payload = self.manifest_path.read_bytes()source = str(self.manifest_path)elif self.manifest_url:- if self.offline:+ if self.offline if offline is None else offline:self._install_reason = "runtime_manifest_unavailable_offline"return Nonetry:@@ -1968,12 +2361,12 @@ class ShowRuntimeManager:return Nonereturn archive- def _resolve_manifest_archive(self, archive: ShowRuntimeArchive) -> Path | None:+ def _resolve_manifest_archive(self, archive: ShowRuntimeArchive, *, offline: bool | None = None) -> Path | None:cached = self.runtime_dir / "downloads" / f"{archive.sha256}.tgz"if cached.exists() and self._downloaded_archive_matches(cached, archive):self._download_error = Nonereturn cached- if self.offline:+ if self.offline if offline is None else offline:self._install_reason = "runtime_archive_unavailable_offline"return Noneparsed = urllib.parse.urlparse(archive.url)@@ -2145,7 +2538,7 @@ class ShowRuntimeManager:return Nonereturn self._archive_runtime_command(self._archive_install_dir(), node)- def _install_archive_runtime(self) -> list[str] | None:+ def _install_archive_runtime(self, *, offline: bool | None = None) -> list[str] | None:node = _resolve_node_command()if not node:self._install_reason = "runtime_node_missing"@@ -2153,7 +2546,7 @@ class ShowRuntimeManager:self.runtime_dir.mkdir(parents=True, exist_ok=True)install_dir = self._archive_install_dir()existing_command = self._archive_runtime_command(install_dir, node)- archive = self._resolve_prebuilt_archive()+ archive = self._resolve_prebuilt_archive(offline=offline)if not archive:return self._reuse_existing_archive_runtime(existing_command)archive_digest = _file_sha256(archive)@@ -2183,7 +2576,7 @@ class ShowRuntimeManager:if tmp_dir.exists():shutil.rmtree(tmp_dir, ignore_errors=True)- def _resolve_prebuilt_archive(self) -> Path | None:+ def _resolve_prebuilt_archive(self, *, offline: bool | None = None) -> Path | None:if self.archive_path:if self.archive_path.exists():return self.archive_path@@ -2195,7 +2588,7 @@ class ShowRuntimeManager:if not self.archive_url:self._install_reason = "runtime_archive_missing"return None- if self.offline:+ if self.offline if offline is None else offline:self._install_reason = "runtime_archive_unavailable_offline"return Nonereturn self._download_runtime_archive(self.archive_url)@@ -2275,7 +2668,7 @@ class ShowRuntimeManager:return Nonereturn self._github_runtime_command(self._github_source_dir(), node)- def _install_github_runtime(self) -> list[str] | None:+ def _install_github_runtime(self, *, force: bool | None = None) -> list[str] | None:node = _resolve_node_command()if not node:self._install_reason = "runtime_node_missing"@@ -2306,7 +2699,7 @@ class ShowRuntimeManager:return self._reuse_existing_github_runtime(existing_command)fetched = self._git_revision(git, source_dir, "FETCH_HEAD")if (- not self.force_install+ not (self.force_install if force is None else force)and existing_commandand fetchedand self._read_github_build_marker(source_dir) == fetched@@ -2556,7 +2949,7 @@ def sweep_orphan_show_runtime_servers(return swept-async def prewarm_show_runtime() -> ShowRuntimeResult:+async def prewarm_show_runtime() -> ShowRuntimeAvailability:return await get_show_runtime_manager().ensure()@@ -2729,6 +3122,32 @@ def _manifest_status_payload(manifest: ShowRuntimeManifest | None) -> dict[str,}+def _persisted_manifest_status_payload(metadata: Mapping[str, Any]) -> dict[str, Any]:+ return {+ "schema_version": None,+ "runtime_version": metadata.get("runtime_version"),+ "minimum_node": None,+ "sha256": metadata.get("manifest_sha256"),+ "source": metadata.get("manifest_source"),+ "platforms": [metadata.get("platform")],+ }+++def _persisted_manifest_runtime_version(metadata: Mapping[str, Any]) -> str | None:+ runtime_version = metadata.get("runtime_version")+ return runtime_version if isinstance(runtime_version, str) and runtime_version else None+++def _persisted_archive_status_payload(metadata: Mapping[str, Any]) -> dict[str, Any]:+ return {+ "platform": metadata.get("platform"),+ "name": metadata.get("archive_name"),+ "url": None,+ "sha256": metadata.get("archive_sha256"),+ "size": None,+ }++def _redact_download_url(url: str) -> str:return redact_url(url)diff --git a/core/show_runtime_failures.py b/core/show_runtime_failures.pynew file mode 100644index 000000000..e3a544a92--- /dev/null+++ b/core/show_runtime_failures.py@@ -0,0 +1,31 @@+from __future__ import annotations++from enum import Enum+++class ShowRuntimeFailureClass(str, Enum):+ TRANSIENT = "transient"+ PERMANENT = "permanent"+ CONFIGURED = "configured"+ CHECKSUM = "checksum"+++_TRANSIENT_FAILURES = frozenset(+ {+ "runtime_archive_download_failed",+ "runtime_install_already_running",+ "runtime_install_failed",+ "runtime_manifest_download_failed",+ }+)+++def classify_show_runtime_failure(reason: str | None) -> ShowRuntimeFailureClass:+ """Classify an install outcome without deciding its retry policy."""+ if reason == "runtime_archive_checksum_mismatch":+ return ShowRuntimeFailureClass.CHECKSUM+ if reason and reason.endswith("_unavailable_offline"):+ return ShowRuntimeFailureClass.CONFIGURED+ if reason in _TRANSIENT_FAILURES:+ return ShowRuntimeFailureClass.TRANSIENT+ return ShowRuntimeFailureClass.PERMANENTdiff --git a/tests/test_local_deps.py b/tests/test_local_deps.pyindex 6b5e24d14..837ab1448 100644--- a/tests/test_local_deps.py+++ b/tests/test_local_deps.py@@ -1172,7 +1172,13 @@ def test_dependencies_status_shape(monkeypatch):class _Mgr:def status(self):- return {"installed": True, "manifest": {"runtime_version": "1.4.0"}, "node_available": True, "node_version": "20.11"}+ return {+ "installed": True,+ "install": {"runtime_version": "1.4.0", "matches_manifest": True},+ "manifest": {"runtime_version": "1.4.0"},+ "node_available": True,+ "node_version": "20.11",+ }monkeypatch.setattr(srt_mod, "get_show_runtime_manager", lambda: _Mgr())import core.memory.artifact as memory_artifact@@ -1197,6 +1203,8 @@ def test_dependencies_status_shape(monkeypatch):assert by["avault"]["status"] == "ready" and by["avault"]["version"] == "0.0.1" and by["avault"]["required"]assert by["avault"]["latest_version"] is None and by["avault"]["has_update"] is Falseassert by["show-runtime"]["installed"] and by["show-runtime"]["version"] == "1.4.0"+ assert by["show-runtime"]["latest_version"] == "1.4.0"+ assert by["show-runtime"]["has_update"] is Falseassert by["memory-runtime"] == {"id": "memory-runtime","kind": "runtime",@@ -1211,6 +1219,73 @@ def test_dependencies_status_shape(monkeypatch):assert by["node"]["installed"] and by["node"]["version"] == "20.11"+ ("runtime_status", "expected"),+ (+ pytest.param(+ {+ "provider": "manifest-cache",+ "installed": True,+ "install": {"runtime_version": "runtime-installed", "matches_manifest": False},+ "manifest": {"runtime_version": "runtime-selected"},+ "node_available": True,+ "node_supported": True,+ "node_version": "22.12.0",+ },+ {"version": "runtime-installed", "latest_version": "runtime-selected", "has_update": True},+ id="stale-manifest-install",+ ),+ pytest.param(+ {+ "provider": "github-source",+ "installed": True,+ "install": {"runtime_version": None, "matches_manifest": None},+ "manifest": None,+ "node_available": True,+ "node_supported": True,+ "node_version": "22.12.0",+ },+ {"version": None, "latest_version": None, "has_update": False},+ id="github-source-not-comparable",+ ),+ ),+)+def test_dependencies_status_projects_show_runtime_identity_without_pairing(monkeypatch, runtime_status, expected):+ monkeypatch.setattr(+ api,+ "askill_update_status",+ lambda **_: {"installed": True, "version": "0.1.14", "latest_version": None, "has_update": False, "status": "ready"},+ )+ monkeypatch.setattr(+ api,+ "avault_status",+ lambda: {"installed": True, "version": "0.0.1", "status": "ready"},+ )+ monkeypatch.setattr(+ api.V2Config,+ "load",+ classmethod(lambda _cls: SimpleNamespace(memory=SimpleNamespace(enabled=False))),+ )++ import core.memory.artifact as memory_artifact+ import core.show_runtime as show_runtime+ import core.tmux_runtime as tmux_runtime++ manager = Mock()+ manager.status.return_value = runtime_status+ memory_manager = Mock()+ memory_manager.status.return_value = {"installed": False, "status": "missing", "manifest": None}+ monkeypatch.setattr(show_runtime, "get_show_runtime_manager", lambda: manager)+ monkeypatch.setattr(memory_artifact, "get_memory_artifact_manager", lambda: memory_manager)+ monkeypatch.setattr(tmux_runtime, "tmux_status", lambda: {"installed": False, "version": None, "status": "missing"})++ entry = next(item for item in api.dependencies_status()["deps"] if item["id"] == "show-runtime")++ assert entry["installed"] is True+ assert entry["status"] == "ready"+ assert {key: entry[key] for key in expected} == expected++@pytest.mark.parametrize(("runtime", "expected"),[@@ -1289,7 +1364,7 @@ def test_dependencies_status_node_unsupported_not_ready(monkeypatch):assert by["node"]["installed"] is False and by["node"]["status"] == "missing"-def test_reconcile_startup_dependencies_installs_askill_and_defers_runtime_prepare(monkeypatch):+def test_reconcile_startup_dependencies_uses_automatic_runtime_admission(monkeypatch):askill_calls = []avault_calls = []@@ -1311,18 +1386,26 @@ def test_reconcile_startup_dependencies_installs_askill_and_defers_runtime_prepadef __init__(self):self.prepared = []- def status(self):+ def status(self, *, offline=False):+ assert offline is Truereturn {- "installed": False,- "manifest": {"runtime_version": "1.4.0"},"node_available": True,"node_supported": True,"node_version": "22.12.0",}- def prepare(self, *, force=False):- self.prepared.append(force)- return {"ok": True, "reason": None}+ def prepare(self, *, force=False, automatic=False):+ self.prepared.append((force, automatic))+ return {+ "policy": {"state": "allowed", "reason": None},+ "install": {"state": "installed", "reason": None},+ "runtime": {"state": "unchecked", "reason": None},+ "status": {+ "node_available": True,+ "node_supported": True,+ "node_version": "22.12.0",+ },+ }manager = _Mgr()monkeypatch.setattr(srt_mod, "get_show_runtime_manager", lambda: manager)@@ -1332,31 +1415,49 @@ def test_reconcile_startup_dependencies_installs_askill_and_defers_runtime_prepaassert out["ok"] is Trueassert askill_calls == [False]assert avault_calls == [False]- assert manager.prepared == []+ assert manager.prepared == [(False, True)]assert out["node"]["status"] == "ready"- assert out["show_runtime"] == {"ok": True, "status": "pending_prewarm", "reason": None}+ assert out["show_runtime"]["ok"] is True+ assert out["show_runtime"]["status"] == "pending_prewarm"+ assert out["show_runtime"]["policy"]["state"] == "allowed"+ assert out["show_runtime"]["install"]["state"] == "installed"+ assert out["show_runtime"]["runtime"]["state"] == "unchecked"-def test_reconcile_startup_dependencies_does_not_prepare_runtime_without_node(monkeypatch):+def test_reconcile_startup_dependencies_reports_runtime_install_failure_without_node(monkeypatch):monkeypatch.setattr(api, "ensure_askill_installed", lambda force=False: {"ok": True, "installed": True})monkeypatch.setattr(api, "ensure_avault_installed", lambda force=False: {"ok": True, "installed": True})import core.show_runtime as srt_modclass _Mgr:- def status(self):- return {"installed": False, "node_available": False, "node_version": None}+ def __init__(self):+ self.prepared = []++ def status(self, *, offline=False):+ assert offline is True+ return {+ "node_available": False,+ "node_supported": None,+ "node_version": None,+ }- def prepare(self, *, force=False):- raise AssertionError("runtime must not prepare without Node")+ def prepare(self, *, force=False, automatic=False):+ self.prepared.append((force, automatic))+ pytest.fail("a missing prerequisite must not enter install admission")- monkeypatch.setattr(srt_mod, "get_show_runtime_manager", lambda: _Mgr())+ manager = _Mgr()+ monkeypatch.setattr(srt_mod, "get_show_runtime_manager", lambda: manager)out = api.reconcile_startup_dependencies()assert out["ok"] is False+ assert manager.prepared == []assert out["node"]["status"] == "missing"- assert out["show_runtime"] == {"ok": False, "status": "skipped", "reason": "runtime_node_missing"}+ assert out["show_runtime"]["ok"] is False+ assert out["show_runtime"]["status"] == "failed"+ assert out["show_runtime"]["install"]["state"] == "failed"+ assert out["show_runtime"]["install"]["reason"] == "runtime_node_missing"def test_reconcile_startup_dependencies_can_be_disabled(monkeypatch):@@ -1428,6 +1529,11 @@ def test_prepare_show_runtime_job_surfaces_retry_diagnostics(monkeypatch):manager.prepare.return_value = {"ok": False,"reason": "runtime_archive_download_failed",+ "install": {+ "state": "failed",+ "reason": "runtime_archive_download_failed",+ "failure_class": "transient",+ },"status": {"download_error": {"kind": "timeout",diff --git a/tests/test_show_pages.py b/tests/test_show_pages.pyindex b5ac6ce5d..aea1c828e 100644--- a/tests/test_show_pages.py+++ b/tests/test_show_pages.py@@ -71,6 +71,20 @@ def _stub_runtime_prepare_dependencies(return calls+def _show_runtime_prepare_payload(*, installed: bool = True, reason: str | None = None):+ return {+ "policy": {"state": "allowed", "reason": None},+ "install": {+ "state": "installed" if installed else "failed",+ "reason": reason,+ },+ "runtime": {"state": "unchecked", "reason": None},+ "ok": installed,+ "reason": reason,+ "status": {},+ }++def test_public_show_write_token_is_share_scoped_and_distinct(monkeypatch, tmp_path):monkeypatch.setenv("AVIBE_HOME", str(tmp_path))@@ -119,7 +133,7 @@ def test_runtime_prepare_cli_reports_warning_only_failure(monkeypatch, capsys):def prepare(self, *, force=False, offline=None):assert force is Falseassert offline is None- return {"ok": False, "reason": "runtime_node_missing"}+ return _show_runtime_prepare_payload(installed=False, reason="runtime_node_missing")monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())calls = _stub_runtime_prepare_dependencies(monkeypatch)@@ -144,7 +158,7 @@ def test_runtime_prepare_cli_preserves_offline_environment(monkeypatch):def prepare(self, *, force=False, offline=None):assert force is Falseassert offline is None- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())calls = _stub_runtime_prepare_dependencies(monkeypatch)@@ -225,7 +239,10 @@ def test_runtime_prepare_cli_strict_fails_when_prepare_fails(monkeypatch, capsysclass FakeRuntimeManager:def prepare(self, *, force=False, offline=None):- return {"ok": False, "reason": "runtime_archive_download_failed"}+ return _show_runtime_prepare_payload(+ installed=False,+ reason="runtime_archive_download_failed",+ )monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())calls = _stub_runtime_prepare_dependencies(monkeypatch)@@ -241,7 +258,7 @@ def test_runtime_prepare_cli_strict_fails_when_git_prepare_fails(monkeypatch, caclass FakeRuntimeManager:def prepare(self, *, force=False, offline=None):- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())_stub_runtime_prepare_dependencies(@@ -259,7 +276,7 @@ def test_runtime_prepare_cli_strict_allows_pending_git_publication(monkeypatch,class FakeRuntimeManager:def prepare(self, *, force=False, offline=None):- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())_stub_runtime_prepare_dependencies(@@ -277,7 +294,7 @@ def test_runtime_prepare_cli_strict_allows_unsupported_git_platform(monkeypatch,class FakeRuntimeManager:def prepare(self, *, force=False, offline=None):- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())_stub_runtime_prepare_dependencies(@@ -296,7 +313,7 @@ def test_runtime_prepare_cli_skips_avault_offline(monkeypatch, capsys):class FakeRuntimeManager:def prepare(self, *, force=False, offline=None):assert offline is True- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())offline_result = {"ok": True, "skipped": True, "reason": "offline"}@@ -324,7 +341,7 @@ def test_runtime_prepare_cli_prints_status_skipped_tmux_as_skipped(monkeypatch,class FakeRuntimeManager:def prepare(self, *, force=False, offline=None):- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())_stub_runtime_prepare_dependencies(@@ -453,7 +470,7 @@ def test_runtime_prepare_force_reaches_every_managed_dependency(monkeypatch):class FakeRuntimeManager:def prepare(self, *, force=False, offline=None):assert force is True- return {"ok": True}+ return _show_runtime_prepare_payload()monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda parsed: FakeRuntimeManager())calls = _stub_runtime_prepare_dependencies(monkeypatch)diff --git a/tests/test_show_runtime_archive_cleanup.py b/tests/test_show_runtime_archive_cleanup.pyindex 930e70857..4166ae129 100644--- a/tests/test_show_runtime_archive_cleanup.py+++ b/tests/test_show_runtime_archive_cleanup.py@@ -535,7 +535,7 @@ def test_install_guard_unavailable_falls_back_to_verified_install(tmp_path: Pathreal_open = os.openmonkeypatch.setattr(os, "open", _unwritable_open)- command = manager._install_manifest_runtime()+ command = manager._attempt_managed_install(force=False, offline=True).commandassert command is not None and command[-1].endswith("cli.js")@@ -670,7 +670,7 @@ def test_forced_prepare_fails_structured_when_guard_unavailable(tmp_path: Path,monkeypatch.setattr("os.open", _unwritable_open)- command = manager._install_manifest_runtime()+ command = manager._attempt_managed_install(force=True, offline=True).commandassert command is Noneassert manager._install_reason == "runtime_install_guard_unavailable"diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.pyindex 5d67fc0e2..033e4028b 100644--- a/tests/test_ui_show_pages.py+++ b/tests/test_ui_show_pages.py@@ -350,6 +350,7 @@ def _write_runtime_manifest(sha256: str | None = None,size: int | None = None,url: str | None = None,+ runtime_version: str = "runtime-test-ref",) -> Path:manifest_path = tmp_path / "show_runtime_manifest.json"manifest_path.parent.mkdir(parents=True, exist_ok=True)@@ -357,7 +358,7 @@ def _write_runtime_manifest(json.dumps({"schema_version": 1,- "runtime_version": "runtime-test-ref",+ "runtime_version": runtime_version,"minimum_node": "^20.19.0 || >=22.12.0","archives": {_runtime_platform_tag(): {@@ -374,6 +375,33 @@ def _write_runtime_manifest(return manifest_path+def _install_remote_manifest_runtime(monkeypatch, tmp_path: Path):+ archive_path = _write_runtime_archive(tmp_path)+ manifest_path = _write_runtime_manifest(tmp_path, archive_path)+ manifest_url = "https://example.test/show-runtime-manifest.json"+ runtime_dir = tmp_path / "runtime"+ monkeypatch.setattr(+ "core.show_runtime._resolve_command",+ lambda command: ["test-node"] if command == "node" else None,+ )+ monkeypatch.setattr("core.show_runtime._node_version", lambda _node: (22, 12, 0))+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda url, **_kwargs: manifest_path.read_bytes()+ if url == manifest_url+ else pytest.fail(f"unexpected fetch: {url}"),+ )+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_url=manifest_url,+ )+ result = manager.prepare()+ assert result["install"]["state"] == "installed"+ install_dir = Path(result["command"][1]).parents[4]+ return runtime_dir, manifest_url, install_dir, result["command"]++def _write_cached_runtime_install(runtime_dir: Path,name: str,@@ -6363,7 +6391,7 @@ def test_show_runtime_manager_installs_from_prebuilt_archive(monkeypatch, tmp_pa)monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- assert manager._install_managed_runtime() == [+ assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node",str(tmp_path / "runtime" / "prebuilt" / "current" / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"),]@@ -6395,7 +6423,7 @@ def test_show_runtime_manager_installs_prebuilt_archive_with_internal_symlinks(m)monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- command = manager._install_managed_runtime()+ command = manager._install_managed_runtime_locked(force=False, offline=False)assert command == ["/bin/node",@@ -6448,7 +6476,7 @@ def test_show_runtime_manager_reuses_installed_prebuilt_runtime_without_archive()monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)- assert manager._install_managed_runtime() == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]assert manager._install_reason is None@@ -6858,6 +6886,18 @@ def test_show_runtime_manager_adopts_previous_fingerprint_and_preserves_gc_proteassert stale_install_dir.exists() is Falseassert stale_archive.exists() is False+ restarted_manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_path=manifest_path,+ auto_install=False,+ )+ restarted = restarted_manager.prepare(automatic=True)++ assert restarted["policy"]["state"] == "skipped"+ assert restarted["install"]["state"] == "installed"+ assert restarted["command"] == ["/bin/node", str(previous_cli)]+def test_show_runtime_clean_prunes_stale_manifest_fingerprints(monkeypatch, tmp_path):old_archive_path = _write_runtime_archive(tmp_path / "old", text="old runtime\n")@@ -6914,8 +6954,12 @@ def test_show_runtime_prepare_prunes_old_packaged_installs_and_keeps_rollback(moruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: ["/bin/node", str(current_cli)])- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(+ manager,+ "_install_manifest_runtime_locked",+ lambda *, force, offline: ["/bin/node", str(current_cli)],+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -6955,8 +6999,12 @@ def test_show_runtime_prepare_preserves_nested_retained_rollback(monkeypatch, tmruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: ["/bin/node", str(current_cli)])- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(+ manager,+ "_install_manifest_runtime_locked",+ lambda *, force, offline: ["/bin/node", str(current_cli)],+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -6992,8 +7040,12 @@ def test_show_runtime_prepare_prunes_siblings_under_current_legacy_parent(monkeyruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: ["/bin/node", str(current_cli)])- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(+ manager,+ "_install_manifest_runtime_locked",+ lambda *, force, offline: ["/bin/node", str(current_cli)],+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -7024,8 +7076,12 @@ def test_show_runtime_prepare_preserves_descendants_of_current_legacy_parent(monruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: ["/bin/node", str(parent_cli)])- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(+ manager,+ "_install_manifest_runtime_locked",+ lambda *, force, offline: ["/bin/node", str(parent_cli)],+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -7062,8 +7118,12 @@ def test_show_runtime_prepare_preserves_custom_child_under_stale_packaged_parentruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: ["/bin/node", str(current_cli)])- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(+ manager,+ "_install_manifest_runtime_locked",+ lambda *, force, offline: ["/bin/node", str(current_cli)],+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -7112,8 +7172,8 @@ def test_show_runtime_failed_prepare_does_not_clean_managed_installs(monkeypatchruntime_dir=runtime_dir,runtime_source="manifest-cache",)- monkeypatch.setattr(manager, "_install_manifest_runtime", lambda: None)- monkeypatch.setattr(manager, "status", lambda: {})+ monkeypatch.setattr(manager, "_install_manifest_runtime_locked", lambda *, force, offline: None)+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})result = manager.prepare()@@ -7282,8 +7342,342 @@ def test_show_runtime_manager_can_disable_auto_install(tmp_path):auto_install=False,)- assert asyncio.run(manager._resolve_managed_command()) is None- assert manager._install_reason == "runtime_command_missing"+ availability = asyncio.run(manager._resolve_managed_availability())++ assert availability.policy.value == "skipped"+ assert availability.policy_reason == "VIBE_SHOW_RUNTIME_AUTO_INSTALL"+ assert availability.install.value == "absent"+++ ("install_skip", "auto_install", "skip_reason"),+ (+ pytest.param(True, True, "VIBE_INSTALL_SKIP_SHOW_RUNTIME", id="install-skip"),+ pytest.param(False, False, "VIBE_SHOW_RUNTIME_AUTO_INSTALL", id="auto-install-off"),+ pytest.param(False, True, None, id="allowed"),+ ),+)[email protected]("automatic", (True, False), ids=("automatic", "explicit"))[email protected]("force", (False, True), ids=("reuse", "force"))+def test_show_runtime_prepare_policy_truth_table(+ monkeypatch,+ tmp_path,+ install_skip,+ auto_install,+ skip_reason,+ automatic,+ force,+):+ monkeypatch.delenv("VIBE_INSTALL_SKIP_SHOW_RUNTIME", raising=False)+ if install_skip:+ monkeypatch.setenv("VIBE_INSTALL_SKIP_SHOW_RUNTIME", "1")+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="npm",+ auto_install=auto_install,+ )+ command = [str(tmp_path / "runtime" / "avibe-show-runtime")]+ calls = []+ monkeypatch.setattr(+ manager,+ "_install_managed_runtime_locked",+ lambda *, force, offline: calls.append((force, offline)) or command,+ )+ monkeypatch.setattr(manager, "status", lambda **_kwargs: {})++ result = manager.prepare(force=force, automatic=automatic)++ expected_skip = automatic and skip_reason is not None+ assert result["policy"] == {+ "state": "skipped" if expected_skip else "allowed",+ "reason": skip_reason if expected_skip else None,+ }+ assert result["install"]["state"] == ("absent" if expected_skip else "installed")+ assert result["runtime"]["state"] == "unchecked"+ assert result["ok"] is (not expected_skip)+ assert calls == ([] if expected_skip else [(force, False)])+++def test_show_runtime_automatic_opt_out_does_not_fetch_remote_manifest(monkeypatch, tmp_path):+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="manifest-cache",+ manifest_url="https://example.invalid/show-runtime-manifest.json",+ auto_install=False,+ )+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda *_args, **_kwargs: pytest.fail("automatic opt-out must not access the network"),+ )++ result = manager.prepare(automatic=True)++ assert result["policy"]["state"] == "skipped"+ assert result["install"]["state"] == "absent"+++def test_show_runtime_remote_manifest_install_remains_installed_when_source_is_unavailable(monkeypatch, tmp_path):+ runtime_dir, manifest_url, install_dir, command = _install_remote_manifest_runtime(monkeypatch, tmp_path)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_url=manifest_url,+ auto_install=False,+ )+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda *_args, **_kwargs: pytest.fail("policy skip must derive install state from disk"),+ )++ skipped = manager.prepare(automatic=True)++ assert skipped["policy"] == {+ "state": "skipped",+ "reason": "VIBE_SHOW_RUNTIME_AUTO_INSTALL",+ }+ assert skipped["install"]["state"] == "installed"+ assert skipped["runtime"]["state"] == "unchecked"+ assert skipped["command"] == command+ assert skipped["status"]["installed"] is True+ assert skipped["status"]["install_dir"] == str(install_dir)++ def fail_manifest_fetch(*_args, **_kwargs):+ raise OSError("manifest host unavailable")++ monkeypatch.setattr("core.show_runtime.fetch_bytes", fail_manifest_fetch)+ status = manager.status()++ assert status["installed"] is True+ assert status["install"]["state"] == "installed"+ assert status["runtime"]["state"] == "unchecked"+ assert status["install"]["runtime_version"] == "runtime-test-ref"+ assert status["install"]["matches_manifest"] is None+ assert status["installed_matches_manifest"] is None+ assert status["command"] == command+ assert status["manifest"]["source"] == manifest_url+ assert status["reason"] == "runtime_manifest_download_failed"+++def test_show_runtime_status_keeps_installed_identity_separate_from_selected_manifest(monkeypatch, tmp_path):+ runtime_dir, manifest_url, install_dir, command = _install_remote_manifest_runtime(monkeypatch, tmp_path)+ selected_archive = _write_runtime_archive(tmp_path, text="#!/usr/bin/env node\n// selected runtime\n")+ selected_manifest = _write_runtime_manifest(+ tmp_path,+ selected_archive,+ url="https://example.test/selected-runtime.tgz",+ runtime_version="runtime-selected-ref",+ )+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_url=manifest_url,+ auto_install=False,+ )+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda url, **_kwargs: selected_manifest.read_bytes()+ if url == manifest_url+ else pytest.fail(f"unexpected fetch: {url}"),+ )++ status = manager.status()++ assert status["installed"] is True+ assert status["install"] == {+ "state": "installed",+ "reason": None,+ "failure_class": None,+ "command": command,+ "runtime_version": "runtime-test-ref",+ "matches_manifest": False,+ }+ assert status["installed_matches_manifest"] is False+ assert status["manifest"]["runtime_version"] == "runtime-selected-ref"+ assert status["install_dir"] == str(install_dir)+++def test_show_runtime_disk_install_fact_does_not_require_node(monkeypatch, tmp_path):+ runtime_dir, manifest_url, _install_dir, _command = _install_remote_manifest_runtime(monkeypatch, tmp_path)+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda _command: None)+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_url=manifest_url,+ auto_install=False,+ )+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda *_args, **_kwargs: pytest.fail("policy skip must not fetch the manifest"),+ )++ result = manager.prepare(automatic=True)++ assert result["policy"]["state"] == "skipped"+ assert result["install"]["state"] == "installed"+ assert result["install"]["command"] is None+ assert result["runtime"]["state"] == "unchecked"+ assert result["ok"] is True+++ "corruption",+ ("outside-versions", "source-lineage", "pointer-metadata", "invalid-json"),+)+def test_show_runtime_disk_install_pointer_fails_closed(monkeypatch, tmp_path, corruption):+ runtime_dir, manifest_url, install_dir, _command = _install_remote_manifest_runtime(monkeypatch, tmp_path)+ pointer_path = runtime_dir / "current.json"+ metadata_path = install_dir / ".vibe-show-runtime.json"+ if corruption == "outside-versions":+ pointer = json.loads(pointer_path.read_text(encoding="utf-8"))+ pointer["install_dir"] = str(tmp_path)+ pointer_path.write_text(json.dumps(pointer), encoding="utf-8")+ elif corruption == "source-lineage":+ metadata = json.loads(metadata_path.read_text(encoding="utf-8"))+ metadata["manifest_source"] = "https://other.example/show-runtime-manifest.json"+ metadata_path.write_text(json.dumps(metadata), encoding="utf-8")+ elif corruption == "pointer-metadata":+ pointer = json.loads(pointer_path.read_text(encoding="utf-8"))+ pointer["archive_sha256"] = "f" * 64+ pointer_path.write_text(json.dumps(pointer), encoding="utf-8")+ else:+ pointer_path.write_text("not-json", encoding="utf-8")++ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=runtime_dir,+ manifest_url=manifest_url,+ auto_install=False,+ )+ monkeypatch.setattr(+ "core.show_runtime.fetch_bytes",+ lambda *_args, **_kwargs: pytest.fail("policy skip must not fetch the manifest"),+ )++ result = manager.prepare(automatic=True)++ assert result["policy"]["state"] == "skipped"+ assert result["install"]["state"] == "absent"+ assert result["command"] is None+++def test_show_runtime_policy_skip_preserves_independent_installed_state(tmp_path):+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="npm",+ auto_install=False,+ )+ manager._managed_command = [str(tmp_path / "runtime" / "avibe-show-runtime")]++ result = manager.prepare(automatic=True)++ assert result["policy"]["state"] == "skipped"+ assert result["install"]["state"] == "installed"+ assert result["runtime"]["state"] == "unchecked"+++ ("reason", "expected_class"),+ (+ ("runtime_archive_download_failed", "transient"),+ ("runtime_platform_unsupported", "permanent"),+ ("runtime_archive_unavailable_offline", "configured"),+ ("runtime_archive_checksum_mismatch", "checksum"),+ ),+)+def test_show_runtime_availability_classifies_install_failure(+ monkeypatch,+ tmp_path,+ reason,+ expected_class,+):+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="npm",+ )++ def fail_install(*, force, offline):+ manager._install_reason = reason+ return None++ monkeypatch.setattr(manager, "_install_managed_runtime_locked", fail_install)++ result = manager.prepare()++ assert result["policy"]["state"] == "allowed"+ assert result["install"] == {+ "state": "failed",+ "reason": reason,+ "failure_class": expected_class,+ "command": None,+ "runtime_version": None,+ "matches_manifest": None,+ }+ assert result["runtime"]["state"] == "unchecked"+++def test_show_runtime_prepare_options_do_not_mutate_shared_manager_state(monkeypatch, tmp_path):+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="npm",+ force_install=False,+ offline=False,+ )+ calls = []+ monkeypatch.setattr(+ manager,+ "_install_managed_runtime_locked",+ lambda *, force, offline: calls.append((force, offline)) or ["/tmp/runtime"],+ )++ result = manager.prepare(force=True, offline=True)++ assert result["install"]["state"] == "installed"+ assert calls == [(True, True)]+ assert manager.force_install is False+ assert manager.offline is False+++def test_show_runtime_prepare_and_request_share_one_install_admission(monkeypatch, tmp_path):+ manager = ShowRuntimeManager(+ workspace_root=tmp_path / "show",+ runtime_dir=tmp_path / "runtime",+ runtime_source="npm",+ )+ entered = threading.Event()+ release = threading.Event()+ command = [str(tmp_path / "runtime" / "avibe-show-runtime")]+ calls = []++ def install(*, force, offline):+ calls.append((force, offline))+ entered.set()+ assert release.wait(timeout=5)+ return command++ monkeypatch.setattr(manager, "_install_managed_runtime_locked", install)+ prepared = []+ prepare_thread = threading.Thread(target=lambda: prepared.append(manager.prepare()))+ prepare_thread.start()+ assert entered.wait(timeout=5)++ async def resolve_during_prepare():+ resolving = asyncio.create_task(manager._resolve_managed_availability())+ await asyncio.sleep(0.05)+ release.set()+ return await resolving++ resolved = asyncio.run(resolve_during_prepare())+ prepare_thread.join(timeout=5)++ assert calls == [(False, False)]+ assert prepared[0]["install"]["state"] == "installed"+ assert resolved.install.value == "installed"+ assert resolved.command == commanddef test_show_runtime_manager_installs_without_blocking_event_loop(monkeypatch, tmp_path):@@ -7299,17 +7693,17 @@ def test_show_runtime_manager_installs_without_blocking_event_loop(monkeypatch,bin_path.chmod(0o755)return [str(bin_path)]- monkeypatch.setattr(manager, "_install_managed_runtime", fake_install)+ monkeypatch.setattr(manager, "_install_managed_runtime_locked", lambda *, force, offline: fake_install())calls = []- async def fake_to_thread(func):+ async def fake_to_thread(func, *args, **kwargs):calls.append(func)- return func()+ return func(*args, **kwargs)monkeypatch.setattr("core.show_runtime.asyncio.to_thread", fake_to_thread)assert asyncio.run(manager._resolve_managed_command()) == [str(manager._managed_bin_path())]- assert calls == [fake_install]+ assert [call.__name__ for call in calls] == ["_attempt_managed_install"]def test_show_runtime_manager_fails_closed_when_manifest_is_absent(tmp_path):@@ -7373,7 +7767,10 @@ def test_show_runtime_manager_installs_from_github_source(monkeypatch, tmp_path)monkeypatch.setattr(manager, "_run_install_command", fake_run)- assert manager._install_managed_runtime() == ["/bin/node", str(source_dir / "packages" / "runtime" / "dist" / "cli.js")]+ assert manager._install_managed_runtime_locked(force=False, offline=False) == [+ "/bin/node",+ str(source_dir / "packages" / "runtime" / "dist" / "cli.js"),+ ]assert commands == [([@@ -7420,7 +7817,7 @@ def test_show_runtime_manager_reuses_installed_github_runtime_when_update_fails(monkeypatch.setattr(manager, "_run_install_command", fake_run)- assert manager._install_managed_runtime() == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]assert manager._install_reason is Noneassert commands == [(@@ -7450,7 +7847,7 @@ def test_show_runtime_manager_reuses_installed_github_runtime_without_git(monkeylambda command: ["/bin/node"] if command == "node" else None,)- assert manager._install_managed_runtime() == ["/bin/node", str(cli_path)]+ assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/bin/node", str(cli_path)]assert manager._install_reason is None@@ -7501,7 +7898,7 @@ def test_show_runtime_manager_can_use_npm_source(monkeypatch, tmp_path):called = []monkeypatch.setattr(manager, "_install_npm_runtime", lambda: called.append("npm") or ["/tmp/avibe-show-runtime"])- assert manager._install_managed_runtime() == ["/tmp/avibe-show-runtime"]+ assert manager._install_managed_runtime_locked(force=False, offline=False) == ["/tmp/avibe-show-runtime"]assert called == ["npm"]@@ -7533,7 +7930,16 @@ def test_startup_dependency_reconcile_prewarms_runtime_after_prepare(monkeypatchdef fake_reconcile():called["reconcile"] += 1- return {"ok": True, "show_runtime": {"ok": True}, "askill": {"ok": True}}+ return {+ "ok": True,+ "show_runtime": {+ "ok": True,+ "policy": {"state": "allowed", "reason": None},+ "install": {"state": "installed", "reason": None},+ "runtime": {"state": "unchecked", "reason": None},+ },+ "askill": {"ok": True},+ }async def fake_runtime_prewarm():called["runtime"] += 1@@ -7570,6 +7976,33 @@ def test_startup_dependency_reconcile_prewarms_runtime_after_prepare(monkeypatch}+def test_startup_dependency_reconcile_does_not_prewarm_policy_skip(monkeypatch):+ from vibe.ui_server import _reconcile_startup_dependencies_task++ monkeypatch.setattr(+ "vibe.api.reconcile_startup_dependencies",+ lambda: {+ "ok": True,+ "show_runtime": {+ "ok": True,+ "status": "skipped",+ "policy": {+ "state": "skipped",+ "reason": "VIBE_SHOW_RUNTIME_AUTO_INSTALL",+ },+ "install": {"state": "absent", "reason": None},+ "runtime": {"state": "unchecked", "reason": None},+ },+ },+ )+ monkeypatch.setattr(+ "core.show_runtime.prewarm_show_runtime",+ lambda: pytest.fail("a policy skip must not enter prewarm"),+ )++ asyncio.run(_reconcile_startup_dependencies_task())++def test_show_runtime_proxy_logs_entry_timing(monkeypatch, tmp_path, caplog):caplog.set_level("INFO")monkeypatch.setenv("AVIBE_HOME", str(tmp_path))diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex 1bd8bb199..a0e73a602 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -2273,6 +2273,40 @@ def test_repair_show_runtime_prepares_missing_runtime(monkeypatch, tmp_path):assert result["install_dir"] == str(tmp_path / "runtime")+def test_runtime_prepare_strict_does_not_report_policy_skip_as_ready(monkeypatch, capsys):+ manager = SimpleNamespace(+ prepare=lambda **_kwargs: {+ "policy": {+ "state": "skipped",+ "reason": "VIBE_INSTALL_SKIP_SHOW_RUNTIME",+ },+ "install": {"state": "absent", "reason": None},+ "runtime": {"state": "unchecked", "reason": None},+ "status": {},+ }+ )+ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: manager)+ monkeypatch.setattr(cli, "_ensure_askill_during_prepare", lambda **_kwargs: {"ok": True})+ monkeypatch.setattr(cli, "_ensure_tmux_during_prepare", lambda **_kwargs: {"ok": True})+ monkeypatch.setattr(cli, "_ensure_git_during_prepare", lambda **_kwargs: {"ok": True, "mode": "system"})+ monkeypatch.setattr(cli, "_ensure_avault_during_prepare", lambda **_kwargs: {"ok": True})++ exit_code = cli.cmd_runtime(+ SimpleNamespace(+ runtime_command="prepare",+ offline=False,+ force=False,+ json=False,+ strict=True,+ )+ )++ captured = capsys.readouterr()+ assert exit_code == 1+ assert "Show Runtime ready" not in captured.out+ assert "VIBE_INSTALL_SKIP_SHOW_RUNTIME" in captured.err++def test_doctor_repair_refreshes_diagnostics_after_repair(monkeypatch):paths.ensure_data_dirs()restart_path = runtime.get_restart_status_path()diff --git a/vibe/api.py b/vibe/api.pyindex 920268472..01c248ee3 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -8440,14 +8440,18 @@ def dependencies_status(*, offline: bool = False) -> dict:except Exception as exc: # noqa: BLE001srt = {"installed": False, "node_available": None, "node_version": None, "reason": str(exc)}manifest = srt.get("manifest") if isinstance(srt.get("manifest"), dict) else {}+ install = srt.get("install") if isinstance(srt.get("install"), dict) else {}srt_installed = bool(srt.get("installed"))+ installed_matches_manifest = install.get("matches_manifest")deps.append({"id": "show-runtime","kind": "runtime","required": True,"installed": srt_installed,- "version": manifest.get("runtime_version"),+ "version": install.get("runtime_version"),+ "latest_version": manifest.get("runtime_version"),+ "has_update": bool(srt_installed and installed_matches_manifest is False),"status": "ready" if srt_installed else "missing","reason": srt.get("reason"),"download_error": srt.get("download_error"),@@ -8548,18 +8552,25 @@ def _memory_runtime_dependency_status(memory_runtime: dict) -> str:def _prepare_show_runtime_job() -> dict:try:from core.show_runtime import get_show_runtime_manager+ from vibe.i18n import t as i18n_tpayload = get_show_runtime_manager().prepare(force=True)- ok = bool(payload.get("ok"))+ install = payload.get("install") if isinstance(payload.get("install"), dict) else {}+ ok = install.get("state") == "installed"+ reason = install.get("reason") or payload.get("reason")result = {"ok": ok,- "message": "Show Runtime ready." if ok else (payload.get("reason") or "Show Runtime prepare failed"),+ "message": (+ i18n_t("runtime.prepare.prepared")+ if ok+ else i18n_t("runtime.prepare.failed", reason=reason or "unknown")+ ),"output": None,}if not ok:status = payload.get("status") if isinstance(payload.get("status"), dict) else {}download_error = status.get("download_error") if isinstance(status.get("download_error"), dict) else None- result["reason"] = payload.get("reason")+ result["reason"] = reasonresult["download_error"] = download_errorif download_error:result["message"] = dependency_error_message(download_error, label="Show Runtime download")@@ -8725,10 +8736,10 @@ def reconcile_startup_dependencies() -> dict:result["avault"] = avaulttry:- from core.show_runtime import get_show_runtime_manager+ from core.show_runtime import ShowRuntimeAvailability, get_show_runtime_managermanager = get_show_runtime_manager()- status = manager.status()+ status = manager.status(offline=True)node_available = bool(status.get("node_available"))node_supported = status.get("node_supported") is not Falsenode_ok = node_available and node_supported@@ -8740,19 +8751,26 @@ def reconcile_startup_dependencies() -> dict:"status": node_status,"version": status.get("node_version"),}-if node_ok:- result["show_runtime"] = {- "ok": True,- "status": "pending_prewarm",- "reason": None,- }+ prepared = manager.prepare(force=False, automatic=True)+ status = prepared.get("status") if isinstance(prepared.get("status"), dict) else statuselse:- result["show_runtime"] = {- "ok": False,- "status": "skipped",- "reason": "runtime_node_unsupported" if node_available else "runtime_node_missing",- }+ reason = "runtime_node_unsupported" if node_available else "runtime_node_missing"+ prepared = ShowRuntimeAvailability.from_install(install_reason=reason).as_payload()+ prepared["status"] = status++ policy = prepared.get("policy") if isinstance(prepared.get("policy"), dict) else {}+ install = prepared.get("install") if isinstance(prepared.get("install"), dict) else {}+ policy_state = policy.get("state")+ install_state = install.get("state")+ dependency_ok = install_state == "installed" or policy_state == "skipped"+ prepared["ok"] = dependency_ok+ prepared["status"] = (+ "pending_prewarm"+ if policy_state == "allowed" and install_state == "installed"+ else ("skipped" if policy_state == "skipped" else "failed")+ )+ result["show_runtime"] = preparedexcept Exception as exc: # noqa: BLE001logger.warning("Startup dependency reconcile failed to prepare Show Runtime: %s", exc, exc_info=True)result["show_runtime"] = {"ok": False, "status": "failed", "reason": str(exc)}diff --git a/vibe/cli.py b/vibe/cli.pyindex 9c2788ceb..a6a348a61 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -14337,17 +14337,36 @@ def cmd_runtime(args) -> int:payload["avault"] = avaultpayload["tmux"] = tmuxpayload["git"] = git+ install = payload.get("install") if isinstance(payload.get("install"), dict) else {}+ policy = payload.get("policy") if isinstance(payload.get("policy"), dict) else {}+ runtime_prepared = install.get("state") == "installed"if getattr(args, "json", False):print(json.dumps(payload, indent=2))else:- if payload.get("ok"):- print("Show Runtime ready.")+ language = _configured_cli_language()+ if runtime_prepared:+ print(i18n_t("runtime.prepare.prepared", language))status = payload.get("status") or {}if status.get("install_dir"):print(f"Install dir: {status['install_dir']}")+ elif policy.get("state") == "skipped":+ print(+ i18n_t(+ "runtime.prepare.skipped",+ language,+ reason=policy.get("reason") or "unknown",+ ),+ file=sys.stderr,+ )else:- reason = payload.get("reason") or "unknown"- print(f"Show Runtime prepare failed: {reason}", file=sys.stderr)+ print(+ i18n_t(+ "runtime.prepare.failed",+ language,+ reason=install.get("reason") or "unknown",+ ),+ file=sys.stderr,+ )if askill.get("skipped"):print(f"askill: skipped ({askill.get('reason') or 'skipped'}).")elif askill.get("ok"):@@ -14375,7 +14394,7 @@ def cmd_runtime(args) -> int:f"git runtime not ready: {git.get('message') or git.get('reason') or 'install failed'}",file=sys.stderr,)- strict_ok = bool(payload.get("ok")) and _git_prepare_satisfies_strict(git)+ strict_ok = runtime_prepared and _git_prepare_satisfies_strict(git)return 1 if getattr(args, "strict", False) and not strict_ok else 0if command == "clean":dry_run = bool(getattr(args, "dry_run", False))diff --git a/vibe/i18n/en.json b/vibe/i18n/en.jsonindex 22c30a167..9c56b23cf 100644--- a/vibe/i18n/en.json+++ b/vibe/i18n/en.json@@ -901,6 +901,11 @@}},"runtime": {+ "prepare": {+ "prepared": "Show Runtime prepared.",+ "skipped": "Show Runtime preparation skipped: {reason}",+ "failed": "Show Runtime preparation failed: {reason}"+ },"clean": {"dryRunHelp": "Report stale archives and cache entries without removing anything.","wouldRemoveItems": "Would remove {count} Show Runtime cache item(s).",diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.jsonindex 656bb74f9..a95455838 100644--- a/vibe/i18n/zh.json+++ b/vibe/i18n/zh.json@@ -901,6 +901,11 @@}},"runtime": {+ "prepare": {+ "prepared": "Show Runtime 已准备完成。",+ "skipped": "Show Runtime 准备已跳过:{reason}",+ "failed": "Show Runtime 准备失败:{reason}"+ },"clean": {"dryRunHelp": "\u4ec5\u62a5\u544a\u53ef\u6e05\u7406\u7684\u5f52\u6863\u4e0e\u7f13\u5b58\u6761\u76ee\uff0c\u4e0d\u5220\u9664\u4efb\u4f55\u5185\u5bb9\u3002","wouldRemoveItems": "\u5c06\u6e05\u7406 {count} \u9879 Show Runtime \u7f13\u5b58\u3002",diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex a8bea3c74..eb274406a 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -15631,7 +15631,9 @@ async def _reconcile_startup_dependencies_task() -> None:result = await asyncio.to_thread(api.reconcile_startup_dependencies)show_runtime = result.get("show_runtime") if isinstance(result.get("show_runtime"), dict) else {}- if show_runtime.get("ok"):+ policy = show_runtime.get("policy") if isinstance(show_runtime.get("policy"), dict) else {}+ install = show_runtime.get("install") if isinstance(show_runtime.get("install"), dict) else {}+ if policy.get("state") == "allowed" and install.get("state") == "installed":from core.show_runtime import (ShowRuntimeContext,prewarm_show_page_session,