Skip to content

The agent that grows with you

wip compat surface

ethernet4dd7ff4a35f4
diff --git a/hermes_cli/update_handoff.py b/hermes_cli/update_handoff.py
new file mode 100644
index 00000000000..661d7670283
--- /dev/null
+++ b/hermes_cli/update_handoff.py
@@ -0,0 +1,65 @@
+"""Frozen compat surface for releases that finish `hermes update` via the post-swap hand-off.
+
+Releases from 2026-09-16 (94ced1a2b2) lazily import ``hermes_cli.update_handoff``
+from the NEW tree after the checkout swap. Like every other retired updater
+hook, this module keeps that import working by routing into the historical
+takeover (``hermes_cli._old_updater`` → ``_update_takeover.py``) instead of
+re-executing ``hermes update --post-swap``; the pulled tree is never imported
+into the pre-pull interpreter.
+
+Guarded by tests/compat/old_updater_surface.json — do not remove a public name
+without regenerating the frozen surface and proving no shipped release loads it.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+from pathlib import Path
+from typing import Any
+
+# Set on the post-swap child: the receipt header says "continued", the lock is the parent's.
+POST_SWAP_ENV = "HERMES_UPDATE_POST_SWAP"
+
+
+def is_post_swap_child() -> bool:
+ return os.environ.get(POST_SWAP_ENV) == "1"
+
+
+def write_handoff(payload: dict[str, Any]) -> Path:
+ """Persist the post-swap payload under HERMES_HOME; returns its path."""
+ from hermes_constants import get_hermes_home
+
+ directory = get_hermes_home() / "logs" / "update_receipts"
+ directory.mkdir(parents=True, exist_ok=True)
+ path = directory / f"post_swap_{os.getpid()}.json"
+ path.write_text(json.dumps(payload, indent=2, default=str), encoding="utf-8")
+ return path
+
+
+def read_handoff(path: str | Path) -> dict[str, Any]:
+ payload = json.loads(Path(path).read_text(encoding="utf-8"))
+ if not isinstance(payload, dict):
+ raise ValueError(f"post-swap hand-off {path} is not a JSON object")
+ return payload
+
+
+def continue_update_in_fresh_interpreter(payload: dict[str, Any], *, argv_tail: list[str] | None = None) -> int | None:
+ """Run the post-swap tail in a child interpreter on the pulled code.
+
+ The old caller's payload carries the same fields the completion request
+ needs (receipt, plan, windows_resume, gateway_mode, ...); ``argv_tail`` is
+ accepted and ignored because the takeover tail does not re-parse update
+ flags. Returns the child's exit code, or ``None`` when no child could be
+ started.
+ """
+ from hermes_cli._old_updater import _run_child
+
+ write_handoff(payload)
+ try:
+ code, _completed = _run_child(dict(payload))
+ return int(code)
+ except OSError as exc:
+ print(f" ⚠ Could not start the post-update interpreter: {exc}")
+ print(" The code update is applied. Finish it with: hermes update")
+ return None
diff --git a/hermes_cli/update_serve_obligations.py b/hermes_cli/update_serve_obligations.py
new file mode 100644
index 00000000000..f7979d81335
--- /dev/null
+++ b/hermes_cli/update_serve_obligations.py
@@ -0,0 +1,54 @@
+"""Frozen compat surface for releases that defer manual serves via update_serve_obligations.
+
+Releases from 2026-09-16 lazily import ``hermes_cli.update_serve_obligations``
+from the NEW tree during the update tail. This tree owns the same obligation
+through the durable fleet-restart-pending marker and the incarnation-based
+survivor sweep (``update_abort_recovery._surviving_pre_update_serve_runtimes``),
+so these names forward there instead of duplicating the write logic.
+"""
+
+from __future__ import annotations
+
+
+def defer_manual_serve(runtime: dict, *, require_alive: bool = False) -> bool:
+ """Transfer an identified manual runtime to its own durable restart reminder."""
+ from hermes_cli.update_abort_recovery import _surviving_pre_update_serve_runtimes
+
+ if runtime.get("kind") not in ("serve", "dashboard") or runtime.get("supervisor") != "manual-serve" or runtime.get("restart_via") != "respawn-argv":
+ return False
+ # Single-runtime write: the survivor sweep already persists the durable
+ # marker from the whole plan; one row rides along by asking with a plan
+ # shim carrying just this runtime.
+ plan = type("_SingleRuntimePlan", (), {"runtimes": [_RuntimeRow(runtime)]})()
+ _surviving_pre_update_serve_runtimes(plan)
+ return True
+
+
+def retain_receipt_manual_serves(receipt: dict) -> list[dict]:
+ """Return transfers still owed so receipt rotation cannot discard failed writes."""
+ rows = list((receipt.get("plan") or {}).get("runtimes") or []) + list(receipt.get("pending_manual_serves") or [])
+ pending = []
+ for row in rows:
+ if not isinstance(row, dict) or row.get("kind") not in ("serve", "dashboard") or row.get("supervisor") != "manual-serve":
+ continue
+ if row not in pending:
+ pending.append(row)
+ return pending
+
+
+def warn_pending_manual_serves(*, startup: bool = False, pending_manual: list[dict] | None = None) -> None:
+ """Cheap CLI-startup hint. Never restarts; never raises."""
+ from hermes_cli.update_cmd_fleet import _warn_pending_fleet_restart
+
+ _warn_pending_fleet_restart(startup=startup)
+
+
+class _RuntimeRow:
+ """Attribute view over one runtime dict, for the plan-shaped shim above."""
+
+ def __init__(self, runtime: dict):
+ self.kind = runtime.get("kind")
+ self.profile = runtime.get("profile", "")
+ self.pid = runtime.get("pid")
+ self.supervisor = runtime.get("supervisor", "")
+ self.detail = runtime.get("detail") if isinstance(runtime.get("detail"), dict) else {}
diff --git a/tests/compat/old_updater_surface.json b/tests/compat/old_updater_surface.json
index 86ab08f07ea..f56f82141b1 100644
--- a/tests/compat/old_updater_surface.json
+++ b/tests/compat/old_updater_surface.json
@@ -1370,6 +1370,14 @@
"hermes_cli.update_contract::evaluate_update_admission",
"hermes_cli.update_contract::is_commit_build",
"hermes_cli.update_contract::record_refusal_receipt",
+ "hermes_cli.update_handoff::POST_SWAP_ENV",
+ "hermes_cli.update_handoff::continue_update_in_fresh_interpreter",
+ "hermes_cli.update_handoff::is_post_swap_child",
+ "hermes_cli.update_handoff::post_swap_child_env",
+ "hermes_cli.update_handoff::post_swap_command",
+ "hermes_cli.update_handoff::post_swap_python",
+ "hermes_cli.update_handoff::read_handoff",
+ "hermes_cli.update_handoff::write_handoff",
"hermes_cli.update_inventory::collect_runtime_inventory",
"hermes_cli.update_inventory::match_runtime_outcomes",
"hermes_cli.update_inventory::print_update_plan",
@@ -1389,6 +1397,9 @@
"hermes_cli.update_receipt::read_latest_receipt",
"hermes_cli.update_receipt::record_gateway_restart",
"hermes_cli.update_receipt::record_step",
+ "hermes_cli.update_serve_obligations::defer_manual_serve",
+ "hermes_cli.update_serve_obligations::retain_receipt_manual_serves",
+ "hermes_cli.update_serve_obligations::warn_pending_manual_serves",
"hermes_cli.urllib_security::open_credentialed_url",
"hermes_cli.urllib_security::url_origin",
"hermes_cli.venv_sync::publish_launchers",