Skip to content

The agent that grows with you

fix: a failed shared identity write defers the setup profile release

alt-glitch563dfcb4d60c
diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.py
index b22d728438e..5565104cd78 100644
--- a/hermes_cli/auth_nous.py
+++ b/hermes_cli/auth_nous.py
@@ -446,10 +446,10 @@ def _nous_shared_shape(src: dict[str, Any]) -> dict[str, Any]:
if src.get(k) not in (None, "")}}
-def _write_shared_nous_state(state: dict[str, Any]) -> None:
- """Persist a minimal copy of the Nous OAuth state to the shared store.
+def _write_shared_nous_state(state: dict[str, Any]) -> bool:
+ """Persist a minimal copy of the Nous OAuth state to the shared store; False when the save failed.
- Best-effort: failures are logged and swallowed; per-profile auth.json stays the source of truth.
+ Best-effort: failures are logged, not raised; per-profile auth.json stays the source of truth.
"""
from hermes_cli.auth import _nonempty_str, _save_private_json
refresh_token = state.get("refresh_token")
@@ -457,7 +457,7 @@ def _write_shared_nous_state(state: dict[str, Any]) -> None:
# or a guest's anon_ credential, which is the whole identity and may not have been exchanged yet.
is_guest = _nonempty_str(state.get("anon_token"))
if not is_guest and not (_nonempty_str(refresh_token) and _nonempty_str(state.get("access_token"))):
- return
+ return True
shared = {
"_schema": 1, **_nous_shared_shape(state),
"updated_at": datetime.now(UTC).isoformat()}
@@ -470,6 +470,8 @@ def _write_shared_nous_state(state: dict[str, Any]) -> None:
refresh_token_fp=_token_fingerprint(refresh_token))
except Exception as exc:
logger.debug("Failed to write shared Nous auth store: %s", exc)
+ return False
+ return True
def _read_shared_nous_state() -> Optional[dict[str, Any]]:
diff --git a/hermes_cli/onboarding_migrations.py b/hermes_cli/onboarding_migrations.py
index 2d48f4b9f34..9fa2ebfaa69 100644
--- a/hermes_cli/onboarding_migrations.py
+++ b/hermes_cli/onboarding_migrations.py
@@ -50,11 +50,18 @@ def release_setup_profiles() -> None:
marked = {path: _read_marker(path) for path in _iter_named_profile_dirs() if (path / _MARKER).is_file()}
if _old_guide_done(marked.values(), config_path):
_settle_run(config_path)
+ # A profile whose identity did not reach the shared store keeps its marker and the latch stays
+ # open, so the next boot retries instead of leaving the install without that identity.
+ unshared = {path for path in marked if not _share_identity(path)}
for path, marker in marked.items():
- _share_identity(path)
- _release(path, marker)
+ if path not in unshared:
+ _release(path, marker)
for home in (root, *_iter_named_profile_dirs()):
_uninstall_retired_skills(home)
+ if unshared:
+ logger.warning("setup profile release deferred: could not share the identity of %s",
+ ", ".join(sorted(path.name for path in unshared)))
+ return
mark_seen(config_path, _RELEASED_FLAG)
@@ -93,18 +100,18 @@ def _write_run(config_path: Path, value: bool) -> None:
config_mod.atomic_config_write(config_path, config)
-def _share_identity(profile: Path) -> None:
+def _share_identity(profile: Path) -> bool:
"""A guest or sign-in made inside the setup profile becomes the install's shared Nous identity
- when the shared store has none (the shared store stays the identity of record otherwise)."""
+ when the shared store has none (the shared store stays the identity of record otherwise).
+ False only when that write failed."""
from hermes_cli.auth import _load_auth_store, _provider_state_in
from hermes_cli.auth_nous import _nous_shared_store_lock, _read_shared_nous_state, _write_shared_nous_state
state = _provider_state_in(_load_auth_store(profile / "auth.json"), "nous")
if not state:
- return
+ return True
with _nous_shared_store_lock():
- if _read_shared_nous_state() is None:
- _write_shared_nous_state(state)
+ return _read_shared_nous_state() is not None or _write_shared_nous_state(state)
def _release(profile: Path, marker: dict) -> None: