Files
Teknium 21aa99db8c fix(update): retired updater shims never start an update from live code
Every retired shim called stop_for_relaunch() unconditionally, so a current-tree
caller (a plugin, a serve/dashboard/gateway, main.__getattr__'s lazy export)
reaching one ran the whole update-finish takeover: dependency sync, desktop
rebuild, gateway restart, backend kill -- and the restarted process could reach
the shim again (#122656). lazy_deps.install_specs and psutil_android's import
were already gated on in_historical_update(); the other 60 shims were not.

One shared gate, _old_updater.stop_historical_updater(hook, error): hands off
exactly as before when a historical updater entrypoint frame is on the stack
(or the process already handed off and is unwinding), otherwise raises a
catchable error (ImportError for installer-shaped shims, matching
install_specs; RetiredUpdaterHook otherwise). install_specs now uses it too.
main._write_update_incomplete_marker resolves to a gated old_updater_deps shim
instead of aliasing stop_for_relaunch. Every frozen-surface name is retained.

Fixes #124881
Fixes #122656
2026-11-14 01:03:00 -08:00

52 lines
1.9 KiB
Python

"""Shims to stop the old updater doing work until relaunch.
An updater already in memory imports these names after replacing its checkout.
They must not install anything, delegate to PM, or return a falsy value that
would send that old process down its pip fallback. New code must not use them.
"""
from pathlib import Path
from typing import NoReturn
from hermes_cli._old_updater import stop_historical_updater
def _reload_hermes_constants() -> NoReturn:
# Shim to suppress old updater work until relaunch. Callers dereference the
# result, so None crashes. Stop without re-executing live globals.
stop_historical_updater("hermes_cli.managed_uv._reload_hermes_constants")
def ensure_uv(*args, **kwargs) -> NoReturn:
# Shim to stop the old updater doing work until relaunch. Older releases
# expect a tuple, newer ones a path. Exit before either can consume it.
stop_historical_updater("hermes_cli.managed_uv.ensure_uv", ImportError)
def update_managed_uv(*args, **kwargs) -> NoReturn:
# Shim to stop the old updater doing work until relaunch.
stop_historical_updater("hermes_cli.managed_uv.update_managed_uv", ImportError)
def resolve_uv(*args, **kwargs) -> NoReturn:
# Shim to stop the old updater doing work until relaunch, not enable pip.
stop_historical_updater("hermes_cli.managed_uv.resolve_uv", ImportError)
def managed_python_env(
project_root: Path | None = None,
*,
install_dir: Path | None = None,
base_env: dict[str, str] | None = None,
**kwargs,
) -> NoReturn:
# Shim to stop the old updater doing work until relaunch, not prepare a child.
stop_historical_updater("hermes_cli.managed_uv.managed_python_env", ImportError)
def rebuild_venv(
uv_bin: str, venv_dir: Path, python_version: str = "3.11", **kwargs
) -> NoReturn:
# Shim to stop the old updater doing work until relaunch, not claim a rebuild.
stop_historical_updater("hermes_cli.managed_uv.rebuild_venv", ImportError)