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): a rebuild loop wipes the granted permissions only once (BUG-159)

Haraldaf1e7111486d
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 12bd6d213c..4d8e47204f 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -11174,6 +11174,13 @@ banner both render it, plus a hint naming the stranded-grant case.
is back, so the re-ask is explained instead of looking amnesic.
(e) `_launchable_issue()` and diagnostics on both identity probes make every
rebuild log WHY it is rebuilding, at WARNING, naming that it resets permissions.
+(f) `_reset_or_explain()` wipes the grants at most ONCE per unresolved round: a
+recurring rebuild (failing identity probe, churning interpreter) would otherwise
+discard the permissions the user just re-granted on every single start, which is
+precisely the "I allow everything, restart, and it asks again" loop. While the
+marker from the previous reset is unanswered, the sweep is skipped and only the
+explanation is refreshed; the per-row "Ask again" stays available for the rows
+the user actually wants reset.
**Class rule.** A permission flag that outlives the condition it describes is a
lie the user cannot clear. Anything the UI derives from a probe must die the
diff --git a/jarvis/platform/permissions.py b/jarvis/platform/permissions.py
index f9aa877b2a..e0035bcef9 100644
--- a/jarvis/platform/permissions.py
+++ b/jarvis/platform/permissions.py
@@ -80,6 +80,17 @@ def _read_identity_reset() -> dict[str, Any] | None:
return payload if isinstance(payload, dict) else None
+def identity_reset_pending() -> bool:
+ """Whether an earlier grant reset has not yet been answered by the user.
+
+ The marker is retired by :meth:`SystemPermissionPort.snapshot` as soon as
+ every TCC-governed grant is back. While it survives, the previous reset did
+ NOT get the user to a working state — so repeating it can only wipe grants
+ again, never fix anything.
+ """
+ return _read_identity_reset() is not None
+
+
def _clear_identity_reset() -> None:
try:
identity_reset_marker_path().unlink(missing_ok=True)
diff --git a/jarvis/setup/macos_app_bundle.py b/jarvis/setup/macos_app_bundle.py
index 5a2de9849f..aacfaaa229 100644
--- a/jarvis/setup/macos_app_bundle.py
+++ b/jarvis/setup/macos_app_bundle.py
@@ -232,16 +232,6 @@ def _reset_stale_tcc_grants(runner=subprocess.run) -> None:
else:
detail = (result.stderr or result.stdout or "unknown error").strip()
log.warning("TCC reset for %s failed: %s", service, detail[-300:])
- # Whether or not every individual reset succeeded, the signature DID
- # change: from here on the user faces an app macOS treats as a stranger.
- # Record that so the permissions view explains the re-ask instead of
- # silently showing everything as missing again (BUG-159).
- try:
- from jarvis.platform.permissions import record_identity_reset
-
- record_identity_reset(_TCC_SERVICES)
- except Exception: # noqa: BLE001 - the explanation is never load-bearing
- log.debug("Could not record the TCC reset marker.", exc_info=True)
def _launchable_issue(candidate: Path) -> str | None:
@@ -797,13 +787,45 @@ def _install_native_bundle(install_root: Path, bundle: Path) -> Path:
if previous.exists() or previous.is_symlink():
previous.rename(bundle)
raise
- if _tcc_reset_needed(previous_cdhash, _bundle_cdhash(bundle)):
- # The rebuild changed the app's TCC identity: every recorded grant is
- # now orphaned and would read as silently DENIED (BUG-083).
- _reset_stale_tcc_grants()
+ # The rebuild changed the app's TCC identity: every recorded grant is now
+ # orphaned and would read as silently DENIED (BUG-083).
+ _reset_or_explain(bundle, previous_cdhash)
return bundle
+def _reset_or_explain(bundle: Path, previous_cdhash: str | None) -> None:
+ """Reset the orphaned TCC rows once — never in a loop (BUG-159).
+
+ A rebuild that keeps recurring (a failing identity probe, a churning
+ interpreter) would otherwise wipe the user's permissions on every single
+ start: they grant everything, restart, and are asked again. The pending
+ marker says the LAST reset never got them to a working state, so repeating
+ it can only destroy grants. Skip it then and keep the explanation up — the
+ permissions view carries a per-row "Ask again" that resets exactly the row
+ the user chooses.
+ """
+ from jarvis.platform.permissions import (
+ identity_reset_pending,
+ record_identity_reset,
+ )
+
+ if not _tcc_reset_needed(previous_cdhash, _bundle_cdhash(bundle)):
+ return
+ if identity_reset_pending():
+ log.warning(
+ "The app signature changed again while an earlier permission reset "
+ "is still unresolved — NOT resetting the macOS grants a second time. "
+ "Rebuilds are recurring on this install; fix the cause above."
+ )
+ else:
+ _reset_stale_tcc_grants()
+ # Either way the user now faces an app macOS treats as a stranger. Record
+ # it so the permissions view explains the re-ask instead of just showing
+ # everything as missing again; snapshot() retires the note once the grants
+ # are back.
+ record_identity_reset(_TCC_SERVICES)
+
+
def ensure_macos_app_bundle(
*,
install_dir: Path | None = None,
diff --git a/tests/unit/setup/test_macos_app_bundle.py b/tests/unit/setup/test_macos_app_bundle.py
index ee43e8a4aa..c1051fa329 100644
--- a/tests/unit/setup/test_macos_app_bundle.py
+++ b/tests/unit/setup/test_macos_app_bundle.py
@@ -599,3 +599,32 @@ def test_reset_stale_tcc_grants_survives_a_failing_tccutil() -> None:
mab._reset_stale_tcc_grants(runner=runner)
assert attempts == list(mab._TCC_SERVICES)
+
+
+def test_a_recurring_rebuild_wipes_the_grants_only_once(tmp_path: Path, monkeypatch) -> None:
+ """BUG-159: a rebuild loop must not re-ask for every permission each start.
+
+ The reset is the right move once. Repeating it while the user has not yet
+ answered the first one destroys the grants they just re-gave — which is
+ exactly what "I allow everything, restart, and it asks again" looks like.
+ """
+ import jarvis.platform.permissions as permissions
+ import jarvis.setup.macos_app_bundle as mab
+
+ marker = tmp_path / "macos-tcc-reset.json"
+ monkeypatch.setattr(permissions, "identity_reset_marker_path", lambda: marker)
+ hashes = iter(["cdhash-two", "cdhash-three"])
+ monkeypatch.setattr(mab, "_bundle_cdhash", lambda _bundle: next(hashes))
+ sweeps: list[int] = []
+ monkeypatch.setattr(mab, "_reset_stale_tcc_grants", lambda: sweeps.append(1))
+
+ bundle = tmp_path / APP_DIR_NAME
+ mab._reset_or_explain(bundle, "cdhash-one")
+ assert sweeps == [1]
+ assert marker.is_file()
+
+ # Second rebuild, first reset still unanswered: explain, never wipe again.
+ mab._reset_or_explain(bundle, "cdhash-two")
+
+ assert sweeps == [1]
+ assert marker.is_file()