The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(onboarding): set_run writes run and the offer flag in one save
alt-glitchf0918ccb4b6d
diff --git a/hermes_cli/onboarding_run.py b/hermes_cli/onboarding_run.pyindex fbb842c9b87..1ad99992948 100644--- a/hermes_cli/onboarding_run.py+++ b/hermes_cli/onboarding_run.py@@ -63,13 +63,17 @@ def should_run() -> bool:return value if isinstance(value, bool) else not install_has_history(get_default_hermes_root())-def set_run(value: bool) -> None:- """Persist ``onboarding.run`` in the root ``config.yaml``, keeping every other key and comment."""- from hermes_cli.config import atomic_config_write, read_user_config_raw+def set_run(value: bool, *, mark_profile_offered: bool = False) -> None:+ """Persist ``onboarding.run`` (and, with *mark_profile_offered*, ``onboarding.seen.profile_build_offered``)+ in the root ``config.yaml`` as one write, keeping every other key and comment. A failed write raises."""+ from agent.onboarding import PROFILE_BUILD_FLAG+ from hermes_cli import config as config_modpath = _root_config()- config = read_user_config_raw(path)- if not isinstance(config.get("onboarding"), dict):- config["onboarding"] = {}- config["onboarding"]["run"] = value- atomic_config_write(path, config)+ with config_mod._CONFIG_LOCK:+ config = config_mod.read_user_config_raw(path)+ section = config_mod._ensure_dict(config, "onboarding")+ section["run"] = value+ if mark_profile_offered:+ config_mod._ensure_dict(section, "seen")[PROFILE_BUILD_FLAG] = True+ config_mod.atomic_config_write(path, config)diff --git a/tests/tui_gateway/test_onboarding_run_rpc.py b/tests/tui_gateway/test_onboarding_run_rpc.pyindex ac36a7fafc0..65d98071cfc 100644--- a/tests/tui_gateway/test_onboarding_run_rpc.py+++ b/tests/tui_gateway/test_onboarding_run_rpc.py@@ -69,6 +69,25 @@ def test_skip_leaves_the_first_chat_offer_alone(launched_under_work):assert PROFILE_BUILD_FLAG not in (_onboarding(root).get("seen") or {})+def test_a_failed_write_fails_the_call_and_writes_nothing(launched_under_work, monkeypatch):+ # The offer flag and run land in one write: if it fails the caller sees an error and neither is applied.+ from hermes_cli import config as config_mod++ root, _work = launched_under_work+ real_write = config_mod.atomic_config_write++ def refuse_the_offer_flag(path, data, **kwargs):+ if PROFILE_BUILD_FLAG in ((data.get("onboarding") or {}).get("seen") or {}):+ raise OSError("disk full")+ real_write(path, data, **kwargs)++ monkeypatch.setattr(config_mod, "atomic_config_write", refuse_the_offer_flag)++ assert "error" in _call("onboarding.set_run", {"run": False, "mark_profile_offered": True})+ assert "run" not in _onboarding(root)+ assert PROFILE_BUILD_FLAG not in (_onboarding(root).get("seen") or {})++def test_set_run_requires_a_bool(launched_under_work):assert "error" in _call("onboarding.set_run", {})assert "error" in _call("onboarding.set_run", {"run": "yes"})diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex f3ebf2d6af7..fd50445c967 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -57,14 +57,14 @@ def _(rid, params: dict) -> dict:@method("onboarding.set_run")def _(rid, params: dict) -> dict:- from agent.onboarding import PROFILE_BUILD_FLAG, mark_seenfrom hermes_cli.onboarding_run import set_run- from hermes_constants import get_default_hermes_rootif not isinstance(params.get("run"), bool):return _err(rid, 4002, "onboarding.set_run requires a boolean 'run'")- set_run(params["run"])- if params.get("mark_profile_offered"):- mark_seen(get_default_hermes_root() / "config.yaml", PROFILE_BUILD_FLAG)+ try:+ set_run(params["run"], mark_profile_offered=bool(params.get("mark_profile_offered")))+ except Exception as e:+ logger.exception("onboarding.set_run failed")+ return _err(rid, 5077, str(e))return _ok(rid, _run_state())