Skip to content

The agent that grows with you

fix(plugins): keep other names' cached misses when a miss rescans a secondary profile

unsupportedpastels2a48f2f13efd
diff --git a/hermes_cli/web_server_plugin_profiles.py b/hermes_cli/web_server_plugin_profiles.py
index 8e873b24283..1e62e9fa24d 100644
--- a/hermes_cli/web_server_plugin_profiles.py
+++ b/hermes_cli/web_server_plugin_profiles.py
@@ -62,17 +62,18 @@ def secondary_profile_home() -> Optional[Path]:
return None if hermes_home_key(home) == hermes_home_key(get_process_hermes_home()) else Path(home)
-def profile_dashboard_plugins(home: Path, force_rescan: bool = False) -> list:
+def profile_dashboard_plugins(home: Path, force_rescan: bool = False, keep_misses: bool = False) -> list:
"""Dashboard plugins of the profile at ``home``, cached per home like the launch profile's list:
its own ``plugins/``, then the root's (as a standalone ``hermes --profile <name> serve`` scanned
- them; the profile's own copy wins a same-name conflict), then the bundled ones."""
+ them; the profile's own copy wins a same-name conflict), then the bundled ones. An explicit
+ rescan also forgets the profile's cached misses; ``keep_misses`` (a miss-driven rescan) keeps them."""
from hermes_cli.plugins import get_bundled_plugins_dir
from hermes_cli.profiles import _get_default_hermes_home
from hermes_cli.web_server_dashboard import _discover_dashboard_plugins
from hermes_constants import hermes_home_key
key = hermes_home_key(home)
with _profile_plugins_lock:
- if force_rescan:
+ if force_rescan and not keep_misses:
for unknown in [k for k in _unknown_plugins if k[0] == key]:
del _unknown_plugins[unknown]
cached = _profile_plugins.get(key)
@@ -97,12 +98,15 @@ def rescanned_plugin(home: Path, name: str) -> Optional[dict]:
with _profile_plugins_lock:
if _unknown_plugins.get(key, now) > now:
return None
- plugin = _named(profile_dashboard_plugins(home, force_rescan=True), name)
- if plugin is None:
- with _profile_plugins_lock:
- for expired in [k for k, until in _unknown_plugins.items() if until <= now]:
- del _unknown_plugins[expired]
+ # Other names' unexpired misses survive this rescan, so probes alternating names can't defeat them.
+ plugin = _named(profile_dashboard_plugins(home, force_rescan=True, keep_misses=True), name)
+ with _profile_plugins_lock:
+ for expired in [k for k, until in _unknown_plugins.items() if until <= now]:
+ del _unknown_plugins[expired]
+ if plugin is None:
_unknown_plugins[key] = now + _UNKNOWN_PLUGIN_RESCAN_SECS
+ else:
+ _unknown_plugins.pop(key, None)
return plugin
diff --git a/tests/hermes_cli/test_plugin_secondary_profile_host.py b/tests/hermes_cli/test_plugin_secondary_profile_host.py
index ba3f3bf09c7..eb1095293af 100644
--- a/tests/hermes_cli/test_plugin_secondary_profile_host.py
+++ b/tests/hermes_cli/test_plugin_secondary_profile_host.py
@@ -564,3 +564,32 @@ def test_unknown_plugin_names_do_not_rescan_the_profile_on_every_request(daemon,
_install(daemon.beta, "latest")
clock[0] += 60
assert status("latest") == 200
+
+
+def test_alternating_unknown_names_each_rescan_once_per_window(daemon, monkeypatch):
+ """One name's miss rescan keeps another name's cached miss, so probes alternating two absent
+ names scan once per name per window; an explicit rescan, or expiry, finds a plugin installed meanwhile."""
+ from hermes_cli import web_server_dashboard, web_server_plugin_profiles
+ _beta_plugin(daemon)
+ _plugins(daemon.beta, enabled=[NAME, "absent-a", "absent-b"])
+ selected = {"params": {"profile": "beta"}, "headers": daemon.owner}
+ status = lambda name: daemon.client.get(f"/api/plugins/{name}/ping", **selected).status_code
+ assert status(NAME) == 200
+ scans, discover, clock = [], web_server_dashboard._discover_dashboard_plugins, [1000.0]
+ monkeypatch.setattr(web_server_dashboard, "_discover_dashboard_plugins",
+ lambda *a, **k: scans.append(1) or discover(*a, **k))
+ monkeypatch.setattr(web_server_plugin_profiles, "time", SimpleNamespace(monotonic=lambda: clock[0]),
+ raising=False)
+
+ assert [status(n) for n in ["absent-a", "absent-b"] * 3] == [404] * 6
+ assert len(scans) == 2, "an automatic miss rescan dropped the other name's cached miss"
+
+ _install(daemon.beta, "absent-b")
+ daemon.client.get("/api/dashboard/plugins/rescan", **selected)
+ assert status("absent-b") == 200
+
+ assert status("absent-a") == 404 # the explicit rescan cleared its miss: this one scans again
+ _install(daemon.beta, "absent-a")
+ assert status("absent-a") == 404 # cached until the window ends
+ clock[0] += 60
+ assert status("absent-a") == 200