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(installer): show why the UI build died and give it room on macOS (#1084)

Ruben Lütkec4eed24f2fcf
diff --git a/.github/workflows/installer-smoke.yml b/.github/workflows/installer-smoke.yml
index ac5584a811..c7547a93d9 100644
--- a/.github/workflows/installer-smoke.yml
+++ b/.github/workflows/installer-smoke.yml
@@ -172,6 +172,16 @@ jobs:
with:
python-version: "3.11"
+ # The installer builds the UI with npm when the checkout has no bundle
+ # (main tracks none). Pin the same Node as ci.yml's frontend build; the
+ # macOS image's Homebrew node@24 aborted in vite (#1033).
+ - name: Set up Node 22 (UI build)
+ uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
+ with:
+ node-version: "22"
+ cache: npm
+ cache-dependency-path: dodaios/ui/web/frontend/package-lock.json
+
- name: Run the real Stage-1 Bash bootstrap through the Linux desktop step
if: matrix.os == 'ubuntu-latest'
shell: bash
diff --git a/install/installer.py b/install/installer.py
index 50a32bee18..0965caa04e 100644
--- a/install/installer.py
+++ b/install/installer.py
@@ -176,7 +176,12 @@ def run_quiet(cmd: list[str], *, label: str, cwd: Path | None = None) -> int:
def run_captured(
- cmd: list[str], *, label: str, cwd: Path | None = None, timeout: float | None = None
+ cmd: list[str],
+ *,
+ label: str,
+ cwd: Path | None = None,
+ timeout: float | None = None,
+ env: dict[str, str] | None = None,
) -> subprocess.CompletedProcess[str]:
"""Run a captured command behind the standard gold spinner.
@@ -191,7 +196,7 @@ def run_captured(
def _run() -> subprocess.CompletedProcess[str]:
return subprocess.run(
cmd, cwd=cwd, capture_output=True, text=True,
- encoding="utf-8", errors="replace", timeout=timeout,
+ encoding="utf-8", errors="replace", timeout=timeout, env=env,
)
if console.is_terminal:
@@ -887,6 +892,36 @@ def step_desktop_integration(*, enabled: bool, dry_run: bool) -> bool:
return False
+# The UI build (tsc + vite) outgrows V8's default heap on a small machine: the
+# macOS installer smoke runner (7 GB) aborted in vite with "Abort trap: 6"
+# (#1033). A user's own NODE_OPTIONS always wins.
+UI_BUILD_NODE_OPTIONS = "--max-old-space-size=4096"
+# Lines worth keeping from a long build log even when they are not in its tail:
+# a V8 OOM prints its "FATAL ERROR ... heap out of memory" header first and
+# then a 50-frame native stack that pushes it out of any short tail.
+_UI_BUILD_KEY_LINE = r"fatal|error|heap|out of memory|abort|killed|signal"
+
+
+def _ui_build_env() -> dict[str, str]:
+ env = dict(os.environ)
+ if not env.get("NODE_OPTIONS", "").strip():
+ env["NODE_OPTIONS"] = UI_BUILD_NODE_OPTIONS
+ return env
+
+
+def _ui_build_diagnostics(output: str, *, tail: int = 15, key_lines: int = 10) -> list[str]:
+ """The tail of a failed build's output, preceded by its key lines from before it."""
+ import re
+
+ lines = [line for line in output.splitlines() if line.strip()]
+ head, last = lines[:-tail], lines[-tail:]
+ pattern = re.compile(_UI_BUILD_KEY_LINE, re.IGNORECASE)
+ keys = [line for line in head if pattern.search(line)][:key_lines]
+ if keys:
+ return [*keys, "...", *last]
+ return last
+
+
def _build_ui_bundle(index: Path) -> bool:
"""Build the UI for a checkout that has none (main tracks no bundle).
@@ -908,13 +943,16 @@ def _build_ui_bundle(index: Path) -> bool:
"is missing"
)
return False
+ env = _ui_build_env()
for args, label in (
(["ci"], "installing the UI build tools (npm ci)"),
(["run", "build"], "building the UI (npm run build)"),
):
cmd_name = f"npm {' '.join(args)}"
try:
- result = run_captured([npm, *args], cwd=frontend, label=label, timeout=1800)
+ result = run_captured(
+ [npm, *args], cwd=frontend, label=label, timeout=1800, env=env
+ )
except (OSError, subprocess.TimeoutExpired) as exc:
note(f"UI build command '{cmd_name}' failed: {rich_escape(str(exc))}")
return False
@@ -931,9 +969,9 @@ def _build_ui_bundle(index: Path) -> bool:
)
if part and part.strip()
)
- output_tail = combined.splitlines()[-15:]
+ output_tail = _ui_build_diagnostics(combined)
if output_tail:
- note("npm output tail:")
+ note("npm output (key lines, then the tail):")
for line in output_tail:
note(rich_escape(line))
return False
diff --git a/tests/unit/install/test_installer_update_contract.py b/tests/unit/install/test_installer_update_contract.py
index e429088f12..da1a85cc58 100644
--- a/tests/unit/install/test_installer_update_contract.py
+++ b/tests/unit/install/test_installer_update_contract.py
@@ -153,7 +153,7 @@ def test_ui_bundle_check_builds_a_missing_bundle_with_npm(
dist = tmp_path / "dodaios" / "ui" / "web" / "dist"
calls: list[list[str]] = []
- def fake_build(cmd, *, label, cwd=None, timeout=None):
+ def fake_build(cmd, *, label, cwd=None, timeout=None, env=None):
calls.append(cmd[1:])
if cmd[1:] == ["run", "build"]:
(dist / "assets").mkdir(parents=True)
@@ -190,7 +190,7 @@ def test_ui_bundle_check_reports_npm_nonzero_exit_and_stderr_tail(
(frontend / "package-lock.json").write_text("{}\n", encoding="utf-8")
stderr_lines = "\n".join(f"npm-err-{idx}" for idx in range(20))
- def fake_build(cmd, *, label, cwd=None, timeout=None):
+ def fake_build(cmd, *, label, cwd=None, timeout=None, env=None):
if cmd[1:] == ["run", "build"]:
return subprocess.CompletedProcess(
cmd, 2, "vite build started\n", stderr_lines
@@ -222,7 +222,7 @@ def test_ui_bundle_check_reports_incomplete_build_output_when_index_missing(
monkeypatch.setattr(
installer,
"run_captured",
- lambda cmd, *, label, cwd=None, timeout=None: subprocess.CompletedProcess(
+ lambda cmd, *, label, cwd=None, timeout=None, env=None: subprocess.CompletedProcess(
cmd, 0, "", ""
),
)
@@ -341,3 +341,59 @@ def test_macos_launch_survives_missing_editable_import(
out = capsys.readouterr().out
assert "/usr/bin/open -a Dodaios" in out
+
+
+def _failing_build(monkeypatch, tmp_path: Path, stdout: str, stderr: str) -> list[dict]:
+ frontend = tmp_path / "dodaios" / "ui" / "web" / "frontend"
+ frontend.mkdir(parents=True)
+ (frontend / "package-lock.json").write_text("{}\n", encoding="utf-8")
+ envs: list[dict] = []
+
+ def fake_build(cmd, *, label, cwd=None, timeout=None, env=None):
+ envs.append(env)
+ if cmd[1:] == ["run", "build"]:
+ return subprocess.CompletedProcess(cmd, 134, stdout, stderr)
+ return subprocess.CompletedProcess(cmd, 0, "", "")
+
+ monkeypatch.setattr(installer, "repo_root", lambda: tmp_path)
+ monkeypatch.setattr(installer.shutil, "which", lambda name: "npm")
+ monkeypatch.setattr(installer, "run_captured", fake_build)
+ return envs
+
+
+def test_ui_build_failure_keeps_the_fatal_header_above_a_long_stack(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys
+) -> None:
+ """#1033: a V8 abort prints its reason first, then a 50-frame native stack."""
+ stack = "\n".join(
+ f"{idx}: 0x10679d540 node::Frame{idx}() [libnode.dylib]" for idx in range(53)
+ )
+ stderr = (
+ "<--- Last few GCs --->\n"
+ "FATAL ERROR: Ineffective mark-compacts near heap limit "
+ "Allocation failed - JavaScript heap out of memory\n"
+ + stack
+ + "\nsh: line 1: 13287 Abort trap: 6 vite build --outDir ../dist\n"
+ )
+ _failing_build(monkeypatch, tmp_path, "vite v7 building for production...\n", stderr)
+
+ assert installer.step_ui_bundle_check() is False
+ out = capsys.readouterr().out
+ assert "exit code 134" in out
+ assert "JavaScript heap out of memory" in out
+ assert "Abort trap: 6" in out
+ assert "node::Frame52()" in out
+ assert "node::Frame5()" not in out # the middle of the stack stays out
+
+
+def test_ui_build_raises_the_node_heap_unless_the_user_set_node_options(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ monkeypatch.delenv("NODE_OPTIONS", raising=False)
+ envs = _failing_build(monkeypatch, tmp_path, "", "boom")
+ installer.step_ui_bundle_check()
+ assert envs
+ assert all(env["NODE_OPTIONS"] == installer.UI_BUILD_NODE_OPTIONS for env in envs)
+
+ monkeypatch.setenv("NODE_OPTIONS", "--max-old-space-size=8192")
+ assert installer._ui_build_env()["NODE_OPTIONS"] == "--max-old-space-size=8192"