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(macos): wake crash-loop on comma-decimal locales — stub sets only LC_CTYPE (BUG-068)

Joana Lütke47e30ac69520
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 80c73a0874..f6c40067ce 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -5537,3 +5537,44 @@ conform) instead of failing a completed install. Guard:
**Class rule.** A long-running installer process must never assume it can
import what it just installed — re-scan site-packages first, and never let a
post-install nicety (auto-launch) turn a completed install into a failure.
+
+---
+
+## BUG-079: wake stack crash-looped on a German macOS — the stub launcher's LC_ALL leaked a de_DE LC_NUMERIC into libvosk (HIGH, FIXED 2026-07-17)
+
+<!-- Ported from the public Mac line, where this entry was numbered BUG-068.
+ Renumbered: local BUG-068 is a realtime bug (the two registers assigned
+ 063..069 independently after the 2026-07-14 cut). The Tk-9 JarvisBar
+ entry the Mac line filed as BUG-067 already lives here as BUG-074. -->
+
+**Symptom.** On the freshly installed German-locale Mac, "Wake loop failed:
+Expecting property name enclosed in double quotes" every ~20-40 s — wake
+effectively deaf. Only reproducible with REAL speech audio; synthetic noise
+produced empty results and parsed fine.
+
+**Root cause.** The BUG-076 stub launcher (macOS non-framework launcher)
+called ``setlocale(LC_ALL, "")`` (copied from py2app's UTF-8 bootstrap). On a
+German macOS that sets ``LC_NUMERIC=de_DE`` for the whole process; libvosk
+formats its result JSON with printf-family calls, so every word confidence
+became ``"conf" : 1,000000`` — a comma decimal separator, i.e. malformed
+JSON. A plain ``python`` binary never does this (CPython only touches
+LC_CTYPE), which is why no other launch path ever showed it. Diagnosed via
+the parse-guard hardening shipped with this same fix: it logged the raw
+payload with the commas.
+
+**Fix (2026-07-17).**
+- ``macos_stub_launcher.c`` sets only ``setlocale(LC_CTYPE, "")`` — UTF-8
+ path/argv decoding is preserved, LC_NUMERIC stays "C" like a normal
+ Python process.
+- ``_BUNDLE_FORMAT_VERSION`` bumped to 2 so existing bundles rebuild with
+ the corrected stub on their next ensure pass.
+- Defense in depth: ``jarvis/plugins/wake/vosk_kws_provider.py`` parses all
+ recognizer JSON through ``_parse_recognizer_json`` — a malformed payload
+ is a logged no-hit (first occurrence carries the raw payload), never a
+ wake-loop kill. Guard: ``tests/unit/plugins/wake/test_vosk_result_parse_hardening.py``.
+
+**Class rule.** Never ``setlocale(LC_ALL, ...)`` in a launcher that embeds
+Python — mirror CPython and touch only LC_CTYPE; every native library that
+prints numbers breaks under a comma-decimal LC_NUMERIC. And any JSON built
+by native code is untrusted input to the Python side: parse it behind a
+degrade-to-no-op guard that preserves the raw payload.
diff --git a/jarvis/plugins/wake/vosk_kws_provider.py b/jarvis/plugins/wake/vosk_kws_provider.py
index 683fa1008e..be11c351b7 100644
--- a/jarvis/plugins/wake/vosk_kws_provider.py
+++ b/jarvis/plugins/wake/vosk_kws_provider.py
@@ -81,6 +81,40 @@ from jarvis.speech.wake_constants import (
log = logging.getLogger("jarvis.wake.vosk")
+# One-shot latch so a native JSON glitch is diagnosable without log-spamming
+# a busy wake loop (the parse runs many times per second).
+_MALFORMED_RESULT_LOGGED = False
+
+
+def _parse_recognizer_json(raw: str, *, where: str) -> dict:
+ """Parse a KaldiRecognizer JSON payload; malformed output is a no-hit.
+
+ libvosk builds its result JSON in native code. A malformed payload
+ (observed in the field on macOS 2026-07-17: one bad ``Result()`` put the
+ whole parallel wake stack into a crash-loop, "Wake loop failed:
+ Expecting property name…" every ~20 s — wake effectively deaf) must
+ degrade to "heard nothing" instead of raising out of the wake loop
+ (AD-6). The first occurrence logs the raw payload so the native cause
+ stays diagnosable.
+ """
+ global _MALFORMED_RESULT_LOGGED
+ try:
+ parsed = json.loads(raw)
+ except (json.JSONDecodeError, TypeError) as exc:
+ if not _MALFORMED_RESULT_LOGGED:
+ _MALFORMED_RESULT_LOGGED = True
+ log.warning(
+ "vosk-kws: recognizer returned malformed JSON at %s (%s); "
+ "treating as no-hit. Raw payload: %r",
+ where,
+ exc,
+ raw[:400] if isinstance(raw, str) else raw,
+ )
+ else:
+ log.debug("vosk-kws: malformed recognizer JSON at %s (%s)", where, exc)
+ return {}
+ return parsed if isinstance(parsed, dict) else {}
+
# Minimum per-word grammar confidence for the verify RE-SCORE over the ring
# window. This is the precision anchor (live forensic 2026-07-06, "Hey Ruben"
# fired on plain room speech): genuine wakes re-score at ~1.0 (spike
@@ -852,7 +886,7 @@ class VoskKwsProvider:
def _grammar_hit(self, rec: Any, pcm: bytes) -> tuple[bool, float] | None:
"""Feed one chunk; return (is_final, min_conf) on a phrase hit else None."""
if rec.AcceptWaveform(pcm):
- res = json.loads(rec.Result())
+ res = _parse_recognizer_json(rec.Result(), where="grammar_hit.Result")
text = res.get("text", "")
if self._phrase.lower() in text:
words = [
@@ -862,7 +896,9 @@ class VoskKwsProvider:
conf = min((w.get("conf", 0.0) for w in words), default=0.0)
return (True, conf)
return None
- partial = json.loads(rec.PartialResult()).get("partial", "")
+ partial = _parse_recognizer_json(
+ rec.PartialResult(), where="grammar_hit.PartialResult"
+ ).get("partial", "")
if partial and self._phrase.lower() in partial:
return (False, 1.0) # partials carry no conf; the confirm decides
return None
@@ -961,12 +997,16 @@ class VoskKwsProvider:
def _grammar_pass() -> dict:
g = self._take_verify_rec(model_path, "grammar")
g.AcceptWaveform(pcm)
- return json.loads(g.FinalResult())
+ return _parse_recognizer_json(
+ g.FinalResult(), where="verify.grammar_final"
+ )
def _free_pass() -> dict:
f = self._take_verify_rec(model_path, "free")
f.AcceptWaveform(pcm)
- return json.loads(f.FinalResult())
+ return _parse_recognizer_json(
+ f.FinalResult(), where="verify.free_final"
+ )
with ThreadPoolExecutor(max_workers=2) as pool:
grammar_future = pool.submit(_grammar_pass)
diff --git a/jarvis/setup/macos_app_bundle.py b/jarvis/setup/macos_app_bundle.py
index 5afc85d52d..4b4d9a98de 100644
--- a/jarvis/setup/macos_app_bundle.py
+++ b/jarvis/setup/macos_app_bundle.py
@@ -37,7 +37,10 @@ log = logging.getLogger(__name__)
APP_NAME = "Personal Jarvis"
APP_DIR_NAME = f"{APP_NAME}.app"
BUNDLE_ID = "com.personal-jarvis.desktop"
-_BUNDLE_FORMAT_VERSION = 1
+# 2: stub launcher sets only LC_CTYPE (BUG-068 — LC_ALL leaked a de_DE
+# LC_NUMERIC into native libs; libvosk then emitted malformed JSON). Bumping
+# forces existing bundles through a rebuild on the next ensure pass.
+_BUNDLE_FORMAT_VERSION = 2
_MACHO_MAGICS = frozenset(
{
b"\xfe\xed\xfa\xce",
diff --git a/jarvis/setup/macos_stub_launcher.c b/jarvis/setup/macos_stub_launcher.c
index cd747f4b6a..3d142ae517 100644
--- a/jarvis/setup/macos_stub_launcher.c
+++ b/jarvis/setup/macos_stub_launcher.c
@@ -27,11 +27,17 @@
int main(int argc, char *argv[]) {
/* Finder-launched apps inherit no locale, which would make CPython
- * decode paths and argv as ASCII. Mirror py2app's fix: force UTF-8. */
+ * decode paths and argv as ASCII. Mirror py2app's fix: force UTF-8.
+ *
+ * ONLY LC_CTYPE — never LC_ALL (BUG-068): a plain `python` binary leaves
+ * LC_NUMERIC in the "C" locale, and native libraries rely on that when
+ * they format numbers. setlocale(LC_ALL, "") on a German macOS put
+ * LC_NUMERIC=de_DE into the whole process and libvosk then emitted
+ * `"conf" : 1,000000` — malformed JSON that crash-looped the wake stack. */
if (getenv("LC_ALL") == NULL && getenv("LC_CTYPE") == NULL && getenv("LANG") == NULL) {
setenv("LC_CTYPE", "UTF-8", 1);
}
- setlocale(LC_ALL, "");
+ setlocale(LC_CTYPE, "");
PyStatus status;
PyConfig config;
diff --git a/tests/unit/plugins/wake/test_vosk_result_parse_hardening.py b/tests/unit/plugins/wake/test_vosk_result_parse_hardening.py
new file mode 100644
index 0000000000..fa0a1eed97
--- /dev/null
+++ b/tests/unit/plugins/wake/test_vosk_result_parse_hardening.py
@@ -0,0 +1,49 @@
+"""Malformed native recognizer JSON must be a no-hit, never a wake-loop kill.
+
+Field incident (macOS, 2026-07-17): libvosk returned one malformed
+``Result()`` payload and the whole parallel wake stack died in a crash-loop
+("Wake loop failed: Expecting property name…" every ~20 s) — wake was
+effectively deaf. ``_parse_recognizer_json`` converts that into a logged
+"heard nothing" (AD-6) and preserves the raw payload for diagnosis.
+"""
+
+from __future__ import annotations
+
+import logging
+
+import jarvis.plugins.wake.vosk_kws_provider as vk
+
+
+def _reset_latch() -> None:
+ vk._MALFORMED_RESULT_LOGGED = False
+
+
+def test_valid_json_passes_through() -> None:
+ _reset_latch()
+ assert vk._parse_recognizer_json('{"text": "hey leah"}', where="t") == {
+ "text": "hey leah"
+ }
+
+
+def test_malformed_json_degrades_to_empty_dict_and_logs_payload(caplog) -> None:
+ _reset_latch()
+ raw = '{\n "result" : [{\n "conf" : nan_garbage'
+ with caplog.at_level(logging.WARNING, logger="jarvis.wake.vosk"):
+ assert vk._parse_recognizer_json(raw, where="grammar_hit.Result") == {}
+ joined = " ".join(r.message for r in caplog.records)
+ assert "malformed JSON" in joined
+ assert "nan_garbage" in joined # the raw payload stays diagnosable
+
+
+def test_malformed_json_warns_only_once(caplog) -> None:
+ _reset_latch()
+ with caplog.at_level(logging.WARNING, logger="jarvis.wake.vosk"):
+ vk._parse_recognizer_json("{broken", where="a")
+ vk._parse_recognizer_json("{broken", where="b")
+ warnings = [r for r in caplog.records if r.levelno == logging.WARNING]
+ assert len(warnings) == 1
+
+
+def test_non_dict_json_degrades_to_empty_dict() -> None:
+ _reset_latch()
+ assert vk._parse_recognizer_json("[1, 2]", where="t") == {}
diff --git a/tests/unit/setup/test_macos_app_bundle.py b/tests/unit/setup/test_macos_app_bundle.py
index f85b676922..574608e93b 100644
--- a/tests/unit/setup/test_macos_app_bundle.py
+++ b/tests/unit/setup/test_macos_app_bundle.py
@@ -438,7 +438,9 @@ def test_build_native_bundle_layout_and_clang_invocation(
info = plistlib.loads((bundle / "Contents" / "Info.plist").read_bytes())
assert info["CFBundleExecutable"] == "PersonalJarvis"
assert info["CFBundleIdentifier"] == "com.personal-jarvis.desktop"
- assert info["JarvisBundleFormatVersion"] == 1
+ from jarvis.setup.macos_app_bundle import _BUNDLE_FORMAT_VERSION
+
+ assert info["JarvisBundleFormatVersion"] == _BUNDLE_FORMAT_VERSION
assert "dictate" in info["NSAppleEventsUsageDescription"].lower()
executable = bundle / "Contents" / "MacOS" / "PersonalJarvis"
assert executable.read_bytes()[:4] == b"\xcf\xfa\xed\xfe"