The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope keychain reset to the legacy ad-hoc fallback only
David Metcalfe91dcca9a9b42
diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex e54fd13bd98..07a1cd8769a 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -7628,21 +7628,31 @@ def _desktop_macos_has_valid_real_signature(app: Path) -> bool:return False-def _desktop_macos_update_keychain_acl(app: Path) -> None:- """Update the 'Hermes Safe Storage' keychain item's ACL after re-signing.+def _desktop_macos_reset_keychain_safe_storage(app: Path) -> None:+ """Delete the 'Hermes Safe Storage' keychain item after an ad-hoc re-sign.++ NOTE: this does NOT update the item's ACL — it deletes the item, which+ permanently orphans every credential encrypted under it. It is only safe+ on the LEGACY AD-HOC fallback path, where every rebuild produces a new+ cdhash so the keychain ACL can never match and the alternative is a+ recurring prompt. It MUST NOT be called on the stable signing path: there+ the designated requirement is certificate-anchored and stable, so after+ the first launch under the new identity the ACL already matches and+ deleting the item only destroys credentials that were working fine.Electron's ``safeStorage`` stores its encryption key in a Keychain itemnamed ``<productName> Safe Storage`` (here: "Hermes Safe Storage"). macOS- ties each keychain item's Access Control List to the Designated Requirement- of the app that created it. When the self-updater rebuilds and re-signs- the bundle (ad-hoc or with a different identity), the new DR no longer- matches the stored ACL, so macOS re-prompts on every launch.-- After re-signing, delete the existing keychain item so Electron recreates- it with the correct ACL for the newly-signed app on next launch. The- trade-off: previously encrypted tokens become unreadable (the user- re-enters the gateway token once), but the keychain prompt stops appearing- on every launch.+ ties each keychain item's Access Control List to the code signature of+ the app that created it. When the self-updater rebuilds and re-signs the+ bundle ad-hoc, the new cdhash no longer matches the stored ACL, so macOS+ re-prompts on every launch.++ Deleting the item makes Electron recreate it with the correct ACL for the+ newly-signed app on next launch. The trade-off: previously encrypted+ tokens become unreadable (the user re-enters the gateway token once), but+ the keychain prompt stops appearing on every launch. The durable fix is+ a stable signing identity (``desktop.macos_signing_identity``), which+ makes this path unreachable.If the item doesn't exist yet (first launch), this is a no-op.@@ -7815,7 +7825,6 @@ def _desktop_macos_relaunchable_fixup(if _desktop_macos_local_codesign(app, desktop_dir=desktop_dir, identity=identity):label = "keychain identity" if identity != "-" else "stable ad-hoc identity"print(f" → macOS desktop signed with {label}; TCC grants persist across rebuilds")- _desktop_macos_update_keychain_acl(app)return Trueexcept Exception as exc:if identity != "-":@@ -7826,7 +7835,13 @@ def _desktop_macos_relaunchable_fixup(print(f" (warning: stable macOS signing failed ({exc}); using legacy ad-hoc sign)")try:subprocess.run([codesign, "--force", "--deep", "--sign", "-", str(app)], check=False)- _desktop_macos_update_keychain_acl(app)+ # Legacy ad-hoc fallback only: every rebuild produces a new cdhash, so+ # the keychain ACL can never match and the alternative is a recurring+ # prompt. This deletes the item (credentials are re-entered once per+ # update); it is intentionally NOT called on the stable identity path+ # above, where the cert-anchored DR is stable and the deletion would+ # destroy working credentials on every update.+ _desktop_macos_reset_keychain_safe_storage(app)except Exception as exc:print(f" (warning: macOS relaunch fixup skipped: {exc})")return Falsediff --git a/tests/hermes_cli/test_gui_command.py b/tests/hermes_cli/test_gui_command.pyindex e7744672aaf..dadb094522c 100644--- a/tests/hermes_cli/test_gui_command.py+++ b/tests/hermes_cli/test_gui_command.py@@ -741,6 +741,82 @@ def test_cmd_gui_setup_tcc_identity_exits_before_build(tmp_path, monkeypatch):mock_install.assert_not_called()+def test_relaunchable_fixup_stable_identity_skips_keychain_reset(tmp_path, monkeypatch):+ """A successful stable-identity re-sign must NOT delete the safeStorage item.++ Regression for review feedback on #90961: the keychain reset deletes the+ item, permanently orphaning every safeStorage-backed credential (gateway+ token, native OAuth access/refresh tokens — see electron/main.ts). On the+ stable path the cert-anchored designated requirement is stable across+ rebuilds, so after the first launch the keychain ACL already matches and+ deleting the item would destroy working credentials on every update.+ """+ root = _make_desktop_tree(tmp_path)+ desktop_dir = root / "apps" / "desktop"+ monkeypatch.setattr(cli_main, "PROJECT_ROOT", root)+ monkeypatch.delenv("CSC_LINK", raising=False)+ monkeypatch.delenv("APPLE_SIGNING_IDENTITY", raising=False)+ exe = _make_packaged_executable(root, monkeypatch)+ app = exe.parents[2]++ resets: list[Path] = []+ monkeypatch.setattr(cli_main, "_desktop_macos_has_valid_real_signature", lambda a: False)+ monkeypatch.setattr(+ cli_main, "_desktop_macos_local_signing_identity", lambda: "Developer ID Application: Example"+ )+ monkeypatch.setattr(cli_main, "_desktop_macos_local_codesign", lambda app, **kw: True)+ monkeypatch.setattr(+ cli_main, "_desktop_macos_reset_keychain_safe_storage", lambda app: resets.append(app)+ )++ assert cli_main._desktop_macos_relaunchable_fixup(desktop_dir) is True+ assert resets == []+++def test_relaunchable_fixup_legacy_adhoc_still_resets_keychain_item(tmp_path, monkeypatch):+ """The legacy ad-hoc fallback keeps the keychain reset (documented trade-off).++ On the ad-hoc path every rebuild produces a new cdhash, so the keychain+ ACL can never match and the alternative is a recurring prompt. The reset+ is the documented trade-off there (re-enter credentials once per update);+ the durable fix is a stable signing identity, which makes this path+ unreachable.+ """+ root = _make_desktop_tree(tmp_path)+ desktop_dir = root / "apps" / "desktop"+ monkeypatch.setattr(cli_main, "PROJECT_ROOT", root)+ monkeypatch.delenv("CSC_LINK", raising=False)+ monkeypatch.delenv("APPLE_SIGNING_IDENTITY", raising=False)+ exe = _make_packaged_executable(root, monkeypatch)+ app = exe.parents[2]++ calls: list[list[str]] = []+ resets: list[Path] = []++ def fake_run(cmd, **kwargs):+ calls.append(list(cmd))+ return subprocess.CompletedProcess(cmd, 0)++ monkeypatch.setattr(+ cli_main.shutil, "which", lambda name: "/usr/bin/codesign" if name == "codesign" else None+ )+ monkeypatch.setattr(cli_main.subprocess, "run", fake_run)+ monkeypatch.setattr(cli_main, "_desktop_macos_has_valid_real_signature", lambda a: False)+ monkeypatch.setattr(cli_main, "_desktop_macos_local_signing_identity", lambda: None)++ def boom(*a, **kw):+ raise subprocess.CalledProcessError(1, ["codesign"])++ monkeypatch.setattr(cli_main, "_desktop_macos_local_codesign", boom)+ monkeypatch.setattr(+ cli_main, "_desktop_macos_reset_keychain_safe_storage", lambda app: resets.append(app)+ )++ assert cli_main._desktop_macos_relaunchable_fixup(desktop_dir) is False+ assert ["/usr/bin/codesign", "--force", "--deep", "--sign", "-", str(app)] in calls+ assert resets == [app]++# --- desktop.* launch options (config.yaml) -------------------------------