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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(updater): attach the update disk image again when hdiutil is busy (#951)
Ruben Lütkeafca2e035ef3
diff --git a/dodaios/core/installer_update.py b/dodaios/core/installer_update.pyindex f622a81ada..abacdb5737 100644--- a/dodaios/core/installer_update.py+++ b/dodaios/core/installer_update.py@@ -908,6 +908,39 @@ def _handover_windows(MACOS_OPEN = "/usr/bin/open"+#: Pauses before re-trying an ``hdiutil attach`` that failed only because the+#: disk-image machinery was busy (EAGAIN, "Resource temporarily unavailable").+_ATTACH_BUSY_RETRY_DELAYS_S = (2.0, 5.0)+_ATTACH_BUSY_MARKER = "resource temporarily unavailable"+++def _attach_dmg(dmg: Path, mountpoint: Path, runner: CommandRunner) -> tuple[int, str]:+ """``hdiutil attach`` the image read-only; a busy refusal is tried again.++ macOS answers an attach with EAGAIN while diskarbitrationd is still busy+ with another image (seen on CI runners right after one was detached). It+ is transient, so it gets a short bounded retry instead of failing the+ update. Every other error is final at once. Returns ``(rc, stderr)``.+ """+ command = [+ "hdiutil",+ "attach",+ str(dmg),+ "-nobrowse",+ "-readonly",+ "-mountpoint",+ str(mountpoint),+ ]+ rc, _out, err = runner.run(command, timeout_s=180.0)+ for delay in _ATTACH_BUSY_RETRY_DELAYS_S:+ if rc == 0 or _ATTACH_BUSY_MARKER not in err.lower() or _is_mounted(mountpoint):+ break+ log.info("[update] hdiutil is busy, attaching %s again in %.0fs", dmg.name, delay)+ time.sleep(delay)+ rc, _out, err = runner.run(command, timeout_s=180.0)+ return rc, err++def _is_mounted(path: Path) -> bool:"""Whether a volume is mounted at ``path`` (a seam for the tests)."""return os.path.ismount(path)@@ -961,18 +994,7 @@ def _handover_macos(mountpoint = Path(tempfile.mkdtemp(prefix="jarvis-dmg-"))attached = Falsetry:- rc, _out, err = runner.run(- [- "hdiutil",- "attach",- str(dmg),- "-nobrowse",- "-readonly",- "-mountpoint",- str(mountpoint),- ],- timeout_s=180.0,- )+ rc, err = _attach_dmg(dmg, mountpoint, runner)if rc != 0:raise InstallerUpdateError(f"could not mount {dmg.name}: {err.strip()[:200] or 'hdiutil failed'}"diff --git a/tests/unit/core/test_installer_update.py b/tests/unit/core/test_installer_update.pyindex 52ad273804..4478595503 100644--- a/tests/unit/core/test_installer_update.py+++ b/tests/unit/core/test_installer_update.py@@ -556,6 +556,82 @@ def test_macos_handover_keeps_the_old_app_when_the_mount_fails(tmp_path: Path) -assert runner.spawned == []+def test_macos_handover_attaches_again_when_hdiutil_is_busy(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """EAGAIN from ``hdiutil attach`` is transient: retried, then the swap runs."""+ dmg = tmp_path / "PersonalJarvis-macOS-arm64.dmg"+ dmg.write_bytes(PAYLOAD)+ app = tmp_path / "Applications" / "Personal Jarvis.app"+ (app / "Contents" / "MacOS").mkdir(parents=True)+ (app / "Contents" / "MacOS" / "PersonalJarvis").write_text("old", encoding="utf-8")+ pauses: list[float] = []+ monkeypatch.setattr(iu.time, "sleep", pauses.append)++ runner = _mounting_runner("Personal Jarvis.app", "new")+ mount = runner.on_run+ busy = RunResult(+ returncode=1, stderr="hdiutil: attach failed - Resource temporarily unavailable"+ )+ attempts: list[int] = []++ def _busy_once(command: list[str]) -> None:+ if command[:2] == ["hdiutil", "attach"]:+ attempts.append(1)+ if len(attempts) == 1:+ runner.results["hdiutil attach"] = busy+ return+ runner.results.pop("hdiutil attach", None)+ mount(command)++ runner.on_run = _busy_once+ apply_installer(dmg, platform_name="darwin", runner=runner, app_path=app, relaunch=False)++ assert len(attempts) == 2+ assert pauses == [iu._ATTACH_BUSY_RETRY_DELAYS_S[0]]+ assert _bundle_payload(app) == "new"+++def test_macos_handover_gives_up_on_a_dmg_that_stays_busy(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ dmg = tmp_path / "PersonalJarvis-macOS-arm64.dmg"+ dmg.write_bytes(PAYLOAD)+ app = tmp_path / "Applications" / "Personal Jarvis.app"+ (app / "Contents" / "MacOS").mkdir(parents=True)+ (app / "Contents" / "MacOS" / "PersonalJarvis").write_text("old", encoding="utf-8")+ monkeypatch.setattr(iu.time, "sleep", lambda _s: None)+ runner = FakeCommandRunner(+ results={+ "hdiutil attach": RunResult(+ returncode=1, stderr="hdiutil: attach failed - Resource temporarily unavailable"+ )+ }+ )++ with pytest.raises(InstallerUpdateError, match="Resource temporarily unavailable"):+ apply_installer(dmg, platform_name="darwin", runner=runner, app_path=app)++ attaches = [cmd for cmd in runner.ran if cmd[:2] == ["hdiutil", "attach"]]+ assert len(attaches) == 1 + len(iu._ATTACH_BUSY_RETRY_DELAYS_S)+ assert _bundle_payload(app) == "old"+++def test_macos_handover_does_not_retry_a_real_mount_error(tmp_path: Path) -> None:+ dmg = tmp_path / "PersonalJarvis-macOS-arm64.dmg"+ dmg.write_bytes(PAYLOAD)+ app = tmp_path / "Applications" / "Personal Jarvis.app"+ (app / "Contents").mkdir(parents=True)+ runner = FakeCommandRunner(+ results={"hdiutil attach": RunResult(returncode=1, stderr="image not recognized")}+ )++ with pytest.raises(InstallerUpdateError, match="could not mount"):+ apply_installer(dmg, platform_name="darwin", runner=runner, app_path=app)++ assert sum(cmd[:2] == ["hdiutil", "attach"] for cmd in runner.ran) == 1++def test_macos_handover_refuses_without_a_resolvable_app(tmp_path: Path) -> None:dmg = tmp_path / "PersonalJarvis-macOS-arm64.dmg"dmg.write_bytes(PAYLOAD)