Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(realtime): trust the native-binary hash even when the npm launcher cannot print a version

Ruben Lütke57bc59e75ead
diff --git a/jarvis/codex_app_server.py b/jarvis/codex_app_server.py
index 0cf517e2b9..1392c73961 100644
--- a/jarvis/codex_app_server.py
+++ b/jarvis/codex_app_server.py
@@ -882,10 +882,14 @@ def _codex_package_roots(launcher: Path) -> list[Path]:
def _trusted_native_codex_binary(resolved_binary: str, version: str | None) -> str:
- if version != _SUPPORTED_CODEX_VERSION:
- raise CodexSubscriptionUnavailable(
- f"Subscription voice requires Codex CLI {_SUPPORTED_CODEX_VERSION}."
- )
+ """Locate the SHA-256-approved native executable for the pinned release.
+
+ The hash is the authority: a candidate matching an official artifact IS
+ the pinned build, whatever the launcher's ``--version`` said. The version
+ string is advisory only — the npm ``codex`` launcher needs a working
+ ``node`` on PATH just to print it, and a service process without node used
+ to fail the whole feature here although the native binary was intact.
+ """
target = _TRUSTED_CODEX_TARGETS.get((sys.platform, _normalized_machine()))
if target is None:
raise CodexSubscriptionUnavailable(
@@ -933,11 +937,30 @@ def _trusted_native_codex_binary(resolved_binary: str, version: str | None) -> s
return str(canonical)
except OSError: # Unreadable installation candidates are skipped during discovery.
continue
+ if version is not None and version.startswith("codex-cli") and (
+ version != _SUPPORTED_CODEX_VERSION
+ ):
+ # The launcher answered with a real but different release — name the
+ # required one instead of a generic hash complaint.
+ raise CodexSubscriptionUnavailable(
+ f"Subscription voice requires Codex CLI {_SUPPORTED_CODEX_VERSION}."
+ )
raise CodexSubscriptionUnavailable(
"The installed Codex 0.146 executable does not match an official approved build."
)
+def _displayable_cli_version(raw: str | None) -> str | None:
+ """Return the probe output only when it is an actual version string.
+
+ The npm launcher prints a localized shell error instead of a version when
+ ``node`` is missing; that text must never reach the UI's version chip or
+ count as an installed version.
+ """
+ text = " ".join(str(raw or "").split())
+ return text if text.startswith("codex-cli ") else None
+
+
def _read_codex_capability(binary_path: str | None) -> CodexAppServerCapability:
"""Resolve the CLI; app-server itself authoritatively reads its auth store.
@@ -963,12 +986,16 @@ def _read_codex_capability(binary_path: str | None) -> CodexAppServerCapability:
reason="Codex CLI is not installed.",
reason_code="not_installed",
)
- version = service._probe_version(resolved)
+ version = _displayable_cli_version(service._probe_version(resolved))
try:
resolved_binary = _trusted_native_codex_binary(
resolved,
version,
)
+ # A hash match proves the pinned official build even when the npm
+ # launcher could not print its version (for example: no node on the
+ # service PATH).
+ version = _SUPPORTED_CODEX_VERSION
except CodexSubscriptionContainmentUnavailable as exc: # Expected platform gate becomes status.
return CodexAppServerCapability(
available=False,
diff --git a/tests/unit/codex_app_server/test_transport.py b/tests/unit/codex_app_server/test_transport.py
index bf1919ad89..a11045d92f 100644
--- a/tests/unit/codex_app_server/test_transport.py
+++ b/tests/unit/codex_app_server/test_transport.py
@@ -2134,18 +2134,68 @@ def test_native_codex_version_and_hash_are_both_required(
)
== str(binary.resolve())
)
- with pytest.raises(CodexSubscriptionUnavailable, match="requires Codex"):
- transport._trusted_native_codex_binary(str(binary), "codex-cli 0.147.0")
+ # The hash IS the pinned build: a launcher that cannot print its version
+ # (npm wrapper without node on PATH) must not brick a verified binary.
+ assert (
+ transport._trusted_native_codex_binary(str(binary), None)
+ == str(binary.resolve())
+ )
monkeypatch.setattr(
transport, "_sha256_file_cached", lambda _path: "wrong-hash"
)
+ # A real-but-different release names the required version...
+ with pytest.raises(CodexSubscriptionUnavailable, match="requires Codex"):
+ transport._trusted_native_codex_binary(str(binary), "codex-cli 0.147.0")
+ # ...while an unknown build with the right version fails on the hash.
with pytest.raises(CodexSubscriptionUnavailable, match="approved build"):
transport._trusted_native_codex_binary(
str(binary), transport._SUPPORTED_CODEX_VERSION
)
+def test_capability_survives_a_version_probe_that_prints_a_shell_error(
+ monkeypatch: pytest.MonkeyPatch,
+ tmp_path: Path,
+) -> None:
+ """npm's codex launcher without node prints a localized error, not a version."""
+ import jarvis.codex_auth as auth_module
+
+ class FakeAuthService:
+ def __init__(self, *_args: object, **_kwargs: object) -> None:
+ pass
+
+ def _resolve_binary(self) -> str:
+ return "codex-test"
+
+ def _probe_version(self, _binary: str) -> str:
+ return 'Der Befehl ""node"" ist entweder falsch geschrieben oder\n' # i18n-allow: verbatim Windows shell error under test
+
+ def login_status(self) -> tuple[bool, str]:
+ return True, "chatgpt"
+
+ monkeypatch.setattr(auth_module, "CodexAuthService", FakeAuthService)
+ monkeypatch.setattr(
+ transport,
+ "_trusted_native_codex_binary",
+ lambda binary, _version: binary,
+ )
+ monkeypatch.setattr(
+ transport,
+ "_validated_subscription_home",
+ lambda **_kwargs: tmp_path,
+ )
+
+ capability = transport._read_codex_capability(None)
+
+ assert capability.available is True
+ assert capability.chatgpt_authenticated is True
+ assert capability.reason_code == "ready"
+ # The shell error never becomes the version chip; the hash-proven pinned
+ # release is reported instead.
+ assert capability.version == transport._SUPPORTED_CODEX_VERSION
+
+
def test_sha256_memo_rehashes_when_the_file_identity_changes(
tmp_path: Path,
) -> None: