Skip to content

The agent that grows with you

fix(update): mark current updater frames with a sentinel, not missing locals

kshitijk4poordb17e07389da
diff --git a/hermes_cli/_old_updater.py b/hermes_cli/_old_updater.py
index 1e4f264081d..4d53148bfc8 100644
--- a/hermes_cli/_old_updater.py
+++ b/hermes_cli/_old_updater.py
@@ -34,18 +34,19 @@ def _is_historical_update_frame(frame: Any) -> bool:
and frame.f_code.co_name in names)
-def in_historical_update(depth: int = 1) -> bool:
+def in_historical_update() -> bool:
"""True when an ancestor frame is a historical updater entrypoint.
- Only the old on-disk updaters define these entrypoints with
- ``pre_update_version`` as a local; code loaded in a CURRENT tree must keep
- running instead of handing control to a takeover child.
+ The current tree's updater sets ``_hermes_current_updater_frame`` in its
+ entrypoints; no historical on-disk version contains that local, so its
+ presence proves the caller is current code that must keep running rather
+ than hand control to a takeover child.
"""
- frame = sys._getframe(depth + 1)
+ frame = sys._getframe(1)
try:
while frame is not None:
if (_is_historical_update_frame(frame)
- and "pre_update_version" in frame.f_code.co_varnames):
+ and "_hermes_current_updater_frame" not in frame.f_code.co_varnames):
return True
frame = frame.f_back
finally:
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index ac7c36e06e8..b85bf11fe71 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -2487,6 +2487,10 @@ from hermes_cli.update_receipt import update_receipt_scope
@update_receipt_scope()
def cmd_update(args):
"""Update Hermes Agent: hangup protection + update lock around ``_cmd_update_impl``."""
+ # Marks this frame as the CURRENT updater for
+ # _old_updater.in_historical_update(); historical on-disk updaters do not
+ # declare this local, so only they hand off through retired shims.
+ _hermes_current_updater_frame = True
from hermes_cli.update_owning_install import retarget_to_owning_install
retarget_to_owning_install(PROJECT_ROOT)
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 95fc075d43c..20a665821ef 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1421,6 +1421,10 @@ def _apply_pulled_update(
def _cmd_update_impl(args, gateway_mode: bool):
"""Apply the update; the command boundary owns errors, receipts and stdio."""
+ # Marks this frame as the CURRENT updater for
+ # _old_updater.in_historical_update(); historical on-disk updaters do not
+ # declare this local, so only they hand off through retired shims.
+ _hermes_current_updater_frame = True
git_operation = git_operation_in_progress(_m().PROJECT_ROOT)
if git_operation:
root = _m().PROJECT_ROOT
diff --git a/tests/hermes_cli/test_old_updater_shims.py b/tests/hermes_cli/test_old_updater_shims.py
index 51c5ed70bcd..2c011fd47b2 100644
--- a/tests/hermes_cli/test_old_updater_shims.py
+++ b/tests/hermes_cli/test_old_updater_shims.py
@@ -119,20 +119,23 @@ def test_retired_dependency_entrypoints_handoff_without_fallback(module, name, a
assert (args, kwargs) == before
[email protected]("module,name,specs", [
- ("hermes_cli.main", "cmd_update", []),
- ("hermes_cli.update_cmd", "_cmd_update_impl", ["honcho-ai"]),
[email protected]("module,name,specs,declares_version", [
+ ("hermes_cli.main", "cmd_update", [], True),
+ ("hermes_cli.update_cmd", "_cmd_update_impl", ["honcho-ai"], True),
+ # 2026-07-26..08-16 updaters predate the pre_update_version local
+ ("hermes_cli.update_cmd", "_cmd_update_impl", [], False),
])
-def test_lazy_installer_inside_historical_update_hands_off(module, name, specs, fresh_child):
+def test_lazy_installer_inside_historical_update_hands_off(module, name, specs, declares_version, fresh_child):
from tools.lazy_deps import install_specs
# Run a frozen old-caller-shaped function, not a mocked context detector.
- # The historical entrypoints declare pre_update_version; the walk crosses
- # the intermediate helper frame to reach the matching frame.
+ # The walk crosses the intermediate helper frame to reach the matching
+ # frame; neither carries the current-updater sentinel local.
+ version_line = " pre_update_version = '1.0'\n" if declares_version else ""
namespace = {"__name__": module, "install_specs": install_specs}
exec(
f"def {name}():\n"
- f" pre_update_version = '1.0'\n"
+ f"{version_line}"
f" _helper()\n"
f"def _helper():\n"
f" install_specs({specs!r}, timeout=120)\n",
diff --git a/tests/tools/test_lazy_deps_runtime.py b/tests/tools/test_lazy_deps_runtime.py
index 98b4b82eb9a..4ccf9357dff 100644
--- a/tests/tools/test_lazy_deps_runtime.py
+++ b/tests/tools/test_lazy_deps_runtime.py
@@ -4,12 +4,14 @@ from unittest.mock import Mock
import pytest
[email protected]("module,name", [
- ("community_plugin", "cmd_update"),
- ("hermes_cli.main", "serve"),
- ("hermes_cli.update_cmd", "cmd_update"), # current updater: no pre_update_version local
[email protected]("module,name,locals_", [
+ ("community_plugin", "cmd_update", ""),
+ ("hermes_cli.main", "serve", ""),
+ # current updater entrypoints carry the sentinel local
+ ("hermes_cli.update_cmd", "_cmd_update_impl",
+ " _hermes_current_updater_frame = True\n"),
])
-def test_runtime_lookalikes_do_not_start_updates(module, name, monkeypatch):
+def test_runtime_lookalikes_do_not_start_updates(module, name, locals_, monkeypatch):
from hermes_cli import _old_updater
from tools.lazy_deps import install_specs
@@ -17,7 +19,7 @@ def test_runtime_lookalikes_do_not_start_updates(module, name, monkeypatch):
monkeypatch.setattr(_old_updater, "_run_child", child)
monkeypatch.setattr(_old_updater, "_result", None)
namespace = {"__name__": module, "install_specs": install_specs}
- exec(f"def {name}():\n install_specs(['hindsight-all'])\n", namespace)
+ exec(f"def {name}():\n{locals_} install_specs(['hindsight-all'])\n", namespace)
with pytest.raises(ImportError, match="retired"):
namespace[name]()
child.assert_not_called()