The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): keep runtime safety, config debt and carried serves separate from exit 0
Tekniumbdf1b44f4484
diff --git a/hermes_cli/update_cmd_config.py b/hermes_cli/update_cmd_config.pyindex fd99c81a6b1..5e91cc1c726 100644--- a/hermes_cli/update_cmd_config.py+++ b/hermes_cli/update_cmd_config.py@@ -205,6 +205,10 @@ def _check_and_apply_config_migration(except Exception as _mig_err:print(f" ⚠️ Config format update failed: {_mig_err}")print(" Run 'hermes config migrate' to retry.")+ # Not a silent success: the caller's owed-step guard records ``config_migration`` as+ # a receipt follow-up and keeps the source-update tail pending, so it is retried.+ raise RuntimeError(+ f"config format v{current_ver} → v{latest_ver} was not written: {_mig_err}") from _mig_errelif needs_migration:print()# Show WHAT changed, not just a count, for an informed yes/no.diff --git a/hermes_cli/update_cmd_fleet_verify.py b/hermes_cli/update_cmd_fleet_verify.pyindex c7be2947416..4197ad1b32b 100644--- a/hermes_cli/update_cmd_fleet_verify.py+++ b/hermes_cli/update_cmd_fleet_verify.py@@ -327,8 +327,8 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re_record_owed_gateway_inventory(_pre_update_plan)with _best_effort('Update receipt finalize failed: %s'):from hermes_cli.update_receipt import finalize_update_receipt- # ``update_complete`` is kept for the historical takeover caller; a False verdict (the- # SQLite runtime) is reported as a follow-up by the maintenance step, not a failed run.+ # A False ``update_complete`` (unsafe SQLite runtime, owed tail work) never fails the+ # run: maintenance already reported it as a follow-up. It only vetoes migration below._receipt_path = finalize_update_receipt("success", fleet=_fleet_snapshot)if _receipt_path is not None:logger.info("Update receipt written: %s", _receipt_path)@@ -337,8 +337,8 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_rereturnfleet._clear_fleet_restart_pending_marker()if not update_complete:- # Fleet caught up, but the selected runtime's SQLite is unsafe (reported by maintenance):- # leave the topology alone until the runtime is repaired.+ # Fleet caught up, but the selected runtime's SQLite is unsafe or the tail is still owed+ # (both reported by the completion): leave the topology alone until they are repaired.return# Fleet is healthy on the new code: fold per-profile gateways into one multiplexer when nothing# blocks it (deterministic; never prompts), else print the blockers and the one-liner to run later.diff --git a/hermes_cli/update_completion.py b/hermes_cli/update_completion.pyindex d71216038b4..e0112f8fcb3 100644--- a/hermes_cli/update_completion.py+++ b/hermes_cli/update_completion.py@@ -276,8 +276,13 @@ def _complete_selected(request: dict) -> bool:# Launchers, products and post-build maintenance live in one place so an# install and an update cannot end in different states.followups: list[tuple[str, str]] = []+ # Exit status and runtime safety are separate facts (R8): an unsafe SQLite runtime keeps the+ # committed update at exit 0 (reported as the ``sqlite_runtime`` follow-up), but fleet+ # verification still needs the real verdict so it never auto-migrates the gateway topology+ # on a runtime that can corrupt sessions. Unknown (the tail raised) is not proven safe.+ runtime_safe = Falsetry:- complete_source_checkout(+ runtime_safe = complete_source_checkout(root, desktop=request["desktop"], assume_yes=request["assume_yes"],gateway_mode=request["gateway_mode"], pre_update_snapshot_id=request["snapshot_id"],pre_update_version=request["pre_update_version"],@@ -318,7 +323,8 @@ def _complete_selected(request: dict) -> bool:record_stage("restart", "failed" if getattr(restart, "incomplete", False) else "success")update_cmd._resume_windows_gateways_and_merge_outcome(restart, request["windows_resume"], request["gateway_mode"])update_cmd._verify_fleet_after_update(- restart, _pre_update_plan=plan, _windows_gateway_resume=request["windows_resume"], update_complete=True)+ restart, _pre_update_plan=plan, _windows_gateway_resume=request["windows_resume"],+ update_complete=bool(runtime_safe) and complete)return completediff --git a/hermes_cli/update_finish.py b/hermes_cli/update_finish.pyindex 32b3845dd0e..ac2801e3c8b 100644--- a/hermes_cli/update_finish.py+++ b/hermes_cli/update_finish.py@@ -8,31 +8,55 @@ import sysdef finish_update(*, root, assume_yes, gateway_mode, pre_update_snapshot_id,had_desktop_app_before_update, pre_update_version,- plan, windows_resume) -> None:- """Finish the selected checkout; never fetch, switch branches or restore a stash."""+ plan, windows_resume, followups=None) -> None:+ """Finish the selected checkout; never fetch, switch branches or restore a stash.++ Same contract as the current completion (C3): the code is committed, so a failed build or+ maintenance step is owed work, never a failed update. ``followups`` carries the steps that+ already failed (the product build); while any is owed the install stamp is withheld, the+ source-update tail stays pending for the next launch, and the gateway topology is left+ alone. An unsafe SQLite runtime is reported by maintenance and vetoes migration only.+ """from hermes_cli.update_cmd import (_run_post_update_maintenance,_restart_gateway_fleet_after_update, _verify_fleet_after_update,_write_gateway_update_exit_code, _resume_windows_gateways_and_merge_outcome,)+ from hermes_cli.update_receipt import TAIL_FOLLOWUPS, record_followup, record_stage- complete = _run_post_update_maintenance(- assume_yes=assume_yes, gateway_mode=gateway_mode,- pre_update_snapshot_id=pre_update_snapshot_id,- had_desktop_app_before_update=had_desktop_app_before_update,- pre_update_version=pre_update_version,- )- if complete:+ owed = followups if followups is not None else []+ runtime_safe = False+ try:+ runtime_safe = _run_post_update_maintenance(+ assume_yes=assume_yes, gateway_mode=gateway_mode,+ pre_update_snapshot_id=pre_update_snapshot_id,+ had_desktop_app_before_update=had_desktop_app_before_update,+ pre_update_version=pre_update_version, followups=owed,+ )+ except (Exception, SystemExit) as exc: # noqa: BLE001 — the code is committed; retry later+ reason = str(exc) or type(exc).__name__+ record_followup("maintenance", reason)+ owed.append(("maintenance", reason))+ tail_owed = any(step in TAIL_FOLLOWUPS for step, _ in owed)+ record_stage("build", "failed" if tail_owed else "success")+ if not tail_owed:from hermes_cli.source_stamp import write_source_stamp-- write_source_stamp(Path(root))- # Restart can kill this process's gateway cgroup; record its result first.+ from hermes_cli.venv_sync import clear_completion++ try:+ write_source_stamp(Path(root))+ except (OSError, ValueError) as exc:+ print(f"⚠ Source update completed, but the install stamp could not be written: {exc}",+ file=sys.stderr)+ clear_completion(Path(root))+ # Restart can kill this process's gateway cgroup; record its result first. The code is+ # committed, so the watcher sees success; owed work is on the receipt.if gateway_mode:- _write_gateway_update_exit_code(complete)+ _write_gateway_update_exit_code(True)restarted = _restart_gateway_fleet_after_update(plan, gateway_mode)_resume_windows_gateways_and_merge_outcome(restarted, windows_resume, gateway_mode)- _verify_fleet_after_update(restarted, _pre_update_plan=plan,- _windows_gateway_resume=windows_resume, update_complete=complete)+ _verify_fleet_after_update(restarted, _pre_update_plan=plan, _windows_gateway_resume=windows_resume,+ update_complete=bool(runtime_safe) and not tail_owed)def _restore_plan(data):@@ -80,6 +104,7 @@ def main(context: Path, result: Path) -> int:from hermes_cli.source_build import build_update_productsfrom hermes_cli.update_lock import UpdateLock, describe_holderfrom hermes_cli.update_cmd_windows import _resume_windows_gateways_after_update+ from hermes_cli.venv_sync import arm_completioncli.PROJECT_ROOT = rootif restarting:@@ -105,13 +130,25 @@ def main(context: Path, result: Path) -> int:desktop_dir = root / "apps" / "desktop"desktop = (_desktop_packaged_executable(desktop_dir) is not Noneor _desktop_dist_exists(desktop_dir))- build_update_products(root, desktop=desktop)+ # The tail is owed from here until it finishes: a failure or a kill leaves the+ # pending marker, so the next launch finishes it (same as the current completion).+ try:+ arm_completion(root)+ except OSError as exc: # stale dependencies still trigger the next launch's sync+ print(f" ⚠ Could not record the owed source-update tail: {exc}")+ owed: list[tuple[str, str]] = []+ try:+ build_update_products(root, desktop=desktop)+ except (Exception, SystemExit) as exc: # noqa: BLE001 — committed code: owed, not failed+ reason = str(exc) or type(exc).__name__+ update_receipt.record_followup("build", reason)+ owed.append(("build", reason))finish_update(root=root, assume_yes=request["assume_yes"], gateway_mode=request["gateway_mode"],pre_update_snapshot_id=request.get("pre_update_snapshot_id"),had_desktop_app_before_update=desktop,pre_update_version=request.get("pre_update_version"),- plan=plan, windows_resume=token,+ plan=plan, windows_resume=token, followups=owed,)code = 0except SystemExit as exc:diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex 16c11f7c3d3..d7a423f4ed6 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -289,8 +289,10 @@ def begin_update_receipt(*, previous: dict | None = None, correlation_id: str |receipt.data.setdefault("pid_create_time", _process_create_time(receipt.data["pid"]))if not previous:reconcile_interrupted_runs()- # The running record is about to replace latest.json: snapshot the previous record's- # manual serve rows (raw, no side effects) for finalize's carry-forward.+ # The running record is about to replace latest.json: snapshot the previous record's+ # manual serve rows (raw, no side effects) for finalize's carry-forward. A handed-off+ # receipt from an older interpreter predates the field, so it needs the same snapshot.+ if not previous or "carried_manual_serves" not in previous:with suppress(Exception):prior = read_latest_receipt() or {}rows = list((prior.get("plan") or {}).get("runtimes") or [])