The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): drop the cached live plugin catalog after an update
Brooklyn Nicholson97e0bae47ceb
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.pyindex 0f81d1b71e8..0b932e74dbc 100644--- a/hermes_cli/plugin_catalog.py+++ b/hermes_cli/plugin_catalog.py@@ -309,6 +309,22 @@ def _live_cache_path() -> Path:return get_hermes_home() / "cache" / "plugin-catalog.json"+def invalidate_live_cache_for_home(home: Path) -> None:+ """Best-effort removal of the cached live catalog under *home* (any profile's home).++ ``hermes update`` drops it for every profile after the checkout changes: a snapshot fetched+ before the bump would otherwise out-vote the newer in-tree catalog (pins the update just+ changed, entries it just added) for the rest of :data:`LIVE_CATALOG_TTL_SECONDS` (#119340).+ The next :func:`fetch_live_catalog` re-fetches the published doc, or falls back to the+ in-tree catalog while the network is down — both newer than what was deleted. Safe when the+ cache is absent (first run, other profiles that never opened the plugins hub).+ """+ try:+ (Path(home) / "cache" / "plugin-catalog.json").unlink(missing_ok=True)+ except Exception as exc:+ logger.debug("Plugin catalog: could not drop the live cache under %s: %s", home, exc)++# Wall-clock deadline of the last failed live fetch. Without it a dead catalog host costs one# full request timeout PER CALL (the plugins hub and ``plugins list`` used to ask once per# installed plugin), so the dashboard event loop stalled for minutes.diff --git a/hermes_cli/update_cmd_maint.py b/hermes_cli/update_cmd_maint.pyindex 2a503275289..c9970c5fa58 100644--- a/hermes_cli/update_cmd_maint.py+++ b/hermes_cli/update_cmd_maint.py@@ -500,6 +500,25 @@ def _verify_and_restore_state_dbs_post_update() -> None:_verify_and_restore_one_state_db(profile_home, label=f"profile {name}")+def _invalidate_live_plugin_catalog_caches() -> None:+ """Drop the cached live plugin catalog under the active home AND every sibling profile's.++ The checkout is shared across profiles, so an update's code swap changes every profile's+ catalog truth at once: a live snapshot cached before the swap would out-vote the newer+ in-tree catalog (the pin it just bumped, the entry it just added) for the rest of the cache+ TTL (#119340). Mirrors the state.db guard's home + siblings iteration. Never raises —+ :func:`plugin_catalog.invalidate_live_cache_for_home` is best-effort per home.+ """+ from hermes_cli.update_cmd import get_hermes_home+ home = get_hermes_home()+ from hermes_cli.plugin_catalog import invalidate_live_cache_for_home+ invalidate_live_cache_for_home(home)+ with suppress(Exception):+ from hermes_cli.backup import _sibling_profile_homes+ for _name, profile_home in _sibling_profile_homes(home):+ invalidate_live_cache_for_home(profile_home)++def _print_bundled_skills_sync_report() -> None:"""Run ``sync_skills`` (copies new, updates changed, respects user deletions) and print its summary."""from tools.skills_sync import sync_skills@@ -1007,6 +1026,12 @@ def _run_post_update_maintenance(if seed_cache_from_checkout(_m().PROJECT_ROOT):print(" ✓ Model catalog cache refreshed from checkout")+ # Drop the cached live plugin catalog under every profile: the checkout is shared, so a+ # pre-update snapshot must not out-vote the pins/entries this update just installed for the+ # rest of the cache TTL (#119340).+ with _best_effort('Live plugin catalog cache invalidation failed: %s'):+ _invalidate_live_plugin_catalog_caches()+with _best_effort('Skills sync during update failed: %s'):print()print("→ Syncing bundled skills...")diff --git a/tests/hermes_cli/test_plugins_hub_live_catalog.py b/tests/hermes_cli/test_plugins_hub_live_catalog.pyindex 02199cfabd5..ce9b1a89a3d 100644--- a/tests/hermes_cli/test_plugins_hub_live_catalog.py+++ b/tests/hermes_cli/test_plugins_hub_live_catalog.py@@ -106,3 +106,46 @@ def test_hub_rebuild_and_plugins_list_resolve_the_kill_list_once(monkeypatch, tmrows = {row["name"]: row["removed"] for row in json.loads(capsys.readouterr().out)}assert rows == {"demo": "exfiltrated env vars", "second": None, "third": None}assert unreachable.attempts == 2 # one more for the whole listing, not one per row+++def test_dropped_cache_no_longer_outvotes_the_in_tree_catalog(monkeypatch):+ """The #119340 shape: a snapshot cached before an update answers every lookup while it+ is fresh, even with the catalog host dead. After the update drops it, the same dead host+ yields ``None`` — callers fall back to the in-tree catalog the update just installed —+ instead of resurrecting the pre-update snapshot for the rest of the TTL."""+ monkeypatch.setattr("httpx.get", _UnreachableCatalog())+ cache = pc._live_cache_path()+ cache.parent.mkdir(parents=True)+ cache.write_text(json.dumps({"entries": [], "removed": []}))++ assert pc.fetch_live_catalog() == {"entries": [], "removed": []} # the stale snapshot wins++ pc.invalidate_live_cache_for_home(cache.parent.parent)++ assert pc.fetch_live_catalog() is None # nothing left to serve: in-tree takes over+++def test_update_invalidates_the_live_catalog_cache_for_every_profile(tmp_path, monkeypatch):+ """Post-update maintenance drops the cached live catalog under the active home AND every+ sibling profile's — the checkout is shared, so one profile's update changes every+ profile's catalog truth at once (#119340)."""+ from hermes_cli import update_cmd+ from hermes_cli import update_cmd_maint+ from hermes_cli import backup as _backup++ root = tmp_path / "home"+ alpha = root / "profiles" / "alpha"+ beta = root / "profiles" / "beta"+ caches = []+ for home in (root, alpha, beta):+ cache = home / "cache" / "plugin-catalog.json"+ cache.parent.mkdir(parents=True)+ cache.write_text(json.dumps({"entries": [], "removed": []}))+ caches.append(cache)++ monkeypatch.setattr(update_cmd, "get_hermes_home", lambda: root)+ monkeypatch.setattr(_backup, "_sibling_profile_homes", lambda _home: [("alpha", alpha), ("beta", beta)])++ update_cmd_maint._invalidate_live_plugin_catalog_caches()++ assert not any(cache.exists() for cache in caches)