The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): keep the catalog date probe off lazy fetches on treeless clones
liuhao1024f99518333d32
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.pyindex 09057524df4..4fb6d442d25 100644--- a/hermes_cli/plugin_catalog.py+++ b/hermes_cli/plugin_catalog.py@@ -402,9 +402,17 @@ def in_tree_catalog_time() -> Optional[float]:resolved: Optional[float] = Noneif (root / ".git").exists():try:+ import osimport subprocess+ # The pathspec makes git open every commit's tree. On a treeless partial clone+ # (tree:0, the layout ``hermes update`` produces) those trees are absent and each one+ # triggers a lazy fetch against the remote; on a bad network that is minutes of+ # fetch-fail-retry for a passive date probe (#125683). Scoping GIT_NO_LAZY_FETCH to+ # this call — never the process env, ``hermes update`` needs lazy fetch — makes the+ # missing objects fail fast into the documented ``None`` fallback below.out = subprocess.run(["git", "-C", str(root), "log", "-1", "--format=%ct", "--", "plugin-catalog"],- capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=10, stdin=subprocess.DEVNULL)+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=10, stdin=subprocess.DEVNULL,+ env={**os.environ, "GIT_NO_LAZY_FETCH": "1"})resolved = float(out.stdout.strip()) if out.returncode == 0 and out.stdout.strip() else Noneexcept Exception as exc:logger.debug("Plugin catalog: could not date the in-tree catalog: %s", exc)diff --git a/hermes_cli/plugins_cmd_catalog.py b/hermes_cli/plugins_cmd_catalog.pyindex a6f6e5b30c9..9fbdcee61b5 100644--- a/hermes_cli/plugins_cmd_catalog.py+++ b/hermes_cli/plugins_cmd_catalog.py@@ -867,3 +867,18 @@ def catalog_versions() -> Dict[str, str]:return {e.name: e.version for e in load_catalog_live() if e.version}except Exception:return {}+++def catalog_rows_maps() -> tuple[Dict[str, str], Dict[str, str], Dict[str, str]]:+ """The pins/versions/titles maps from ONE live-catalog resolution. Listing callers (``_plugin_rows``)+ need all three; taking them via :func:`catalog_pins`/:func:`catalog_versions`/:func:`catalog_titles`+ would pay the whole ``load_catalog_live()`` pass — git probe, ~300 catalog YAMLs, prefer-in-tree+ merges — three times per inventory request (#125683). Best effort like the per-map helpers: an+ empty triple on failure."""+ try:+ entries = load_catalog_live()+ except Exception:+ return {}, {}, {}+ return ({e.name: e.sha for e in entries},+ {e.name: e.version for e in entries if e.version},+ {e.name: e.title for e in entries if e.title})diff --git a/tests/hermes_cli/test_plugin_catalog.py b/tests/hermes_cli/test_plugin_catalog.pyindex de8edcbe623..ceb857ff40e 100644--- a/tests/hermes_cli/test_plugin_catalog.py+++ b/tests/hermes_cli/test_plugin_catalog.py@@ -198,3 +198,46 @@ def test_curated_fields_the_published_doc_lacks_come_from_the_checkout(tmp_path,assert (by_name["same"].onboarding, by_name["same"].title) == (True, "T")assert by_name["says-no"].onboarding is False and by_name["says-no"].title == "T"assert by_name["repinned"].onboarding is False and by_name["repinned"].sha == "b" * 40+++def test_in_tree_catalog_time_does_not_lazy_fetch_on_treeless_clones(tmp_path, monkeypatch):+ """``in_tree_catalog_time`` dates the checkout with a pathspec'd ``git log``; the pathspec makes git+ open every commit's tree. On a treeless (``tree:0``) partial clone — the layout ``hermes update``+ produces — none of those trees exist locally, so an unrestricted probe lazy-fetches each one against+ the remote: measured 40-80 s per inventory request, past the desktop's 30 s RPC limit (#125683).+ The probe must scope ``GIT_NO_LAZY_FETCH`` to itself so missing trees fail fast into the documented+ ``None`` fallback — never into network work — while a full checkout keeps resolving its time."""+ import shutil+ import subprocess as sp+ if shutil.which("git") is None:+ pytest.skip("git not available")+ src = tmp_path / "src"+ (src / "plugin-catalog").mkdir(parents=True)+ (src / "plugin-catalog" / "a.yaml").write_text("name: a\n")+ env = {**os.environ, "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",+ "GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t"}+ sp.run(["git", "init", "-q"], cwd=src, check=True, env=env)+ sp.run(["git", "add", "-A"], cwd=src, check=True, env=env)+ sp.run(["git", "commit", "-qm", "seed"], cwd=src, check=True, env=env)+ sp.run(["git", "config", "uploadpack.allowFilter", "true"], cwd=src, check=True, env=env)++ def local_object_types(repo):+ out = sp.run(["git", "cat-file", "--batch-all-objects", "--batch-check"], cwd=repo,+ capture_output=True, text=True, env=env)+ return {line.split()[1] for line in out.stdout.splitlines() if line}++ dst = tmp_path / "treeless"+ # file:// (not a plain path) so the clone goes through upload-pack and honors the filter.+ sp.run(["git", "clone", "-q", "--filter=tree:0", "--no-checkout", src.as_uri(), str(dst)],+ check=True, env=env)+ if "tree" in local_object_types(dst): # transport ignored the filter: no missing objects to protect+ pytest.skip("file:// transport did not honor --filter=tree:0")++ monkeypatch.setattr(pc, "get_catalog_dir", lambda: dst / "plugin-catalog")+ monkeypatch.setattr(pc, "_in_tree_catalog_time", -1.0) # resolve afresh in this test+ assert pc.in_tree_catalog_time() is None+ assert "tree" not in local_object_types(dst) # the probe lazy-fetched nothing++ monkeypatch.setattr(pc, "get_catalog_dir", lambda: src / "plugin-catalog")+ monkeypatch.setattr(pc, "_in_tree_catalog_time", -1.0)+ assert pc.in_tree_catalog_time() is not None # a full checkout still resolves its commit timediff --git a/tests/hermes_cli/test_plugins_cmd_catalog.py b/tests/hermes_cli/test_plugins_cmd_catalog.pyindex dbe12ae5216..f97d931bc45 100644--- a/tests/hermes_cli/test_plugins_cmd_catalog.py+++ b/tests/hermes_cli/test_plugins_cmd_catalog.py@@ -381,3 +381,28 @@ def test_repin_that_widens_the_plugin_requires_consent_on_every_surface(world, m# Consent given → applied.assert pc.dashboard_update_user_plugin("cat-plugin", accept_capabilities=True)["unchanged"] is Falseassert _head(target) == wide+++def test_catalog_rows_maps_resolves_the_live_catalog_once(monkeypatch):+ """``_plugin_rows`` needs pins, versions and titles together; taking them via the three single-map+ helpers pays the whole ``load_catalog_live()`` pass — git probe, ~300 catalog YAMLs, prefer-in-tree+ merges — three times per inventory request (#125683). ``catalog_rows_maps`` must resolve once and+ stay best effort like the per-map helpers: an empty triple on failure."""+ calls = []++ def fake_live():+ calls.append(1)+ return [pc_cat.PluginCatalogEntry(name="a", repo="https://github.com/o/r", sha="a" * 40,+ description="d", maintainer="t", version="1.2.3", title="Alpha"),+ pc_cat.PluginCatalogEntry(name="b", repo="https://github.com/o/r2", sha="b" * 40,+ description="d", maintainer="t")]++ monkeypatch.setattr(cat, "load_catalog_live", fake_live)+ assert cat.catalog_rows_maps() == ({"a": "a" * 40, "b": "b" * 40}, {"a": "1.2.3"}, {"a": "Alpha"})+ assert len(calls) == 1++ def boom():+ raise RuntimeError("catalog unavailable")++ monkeypatch.setattr(cat, "load_catalog_live", boom)+ assert cat.catalog_rows_maps() == ({}, {}, {})diff --git a/tests/tui_gateway/test_plugins_manage_install.py b/tests/tui_gateway/test_plugins_manage_install.pyindex 51b2b12389e..b2fd5002c7c 100644--- a/tests/tui_gateway/test_plugins_manage_install.py+++ b/tests/tui_gateway/test_plugins_manage_install.py@@ -67,7 +67,7 @@ def test_plugins_manage_list_reports_desktop_half(tmp_path):with patch("hermes_cli.plugins_cmd._discover_all_plugins", return_value=rows), \patch("hermes_cli.plugins_cmd._get_enabled_set", return_value=set()), \patch("hermes_cli.plugins_cmd._get_disabled_set", return_value=set()), \- patch("hermes_cli.plugins_cmd_catalog.catalog_pins", return_value={}):+ patch("hermes_cli.plugins_cmd_catalog.catalog_rows_maps", return_value=({}, {}, {})):resp = server.handle_request({"id": "1", "method": "plugins.manage", "params": {"action": "list"}})by_name = {r["name"]: r for r in resp["result"]["plugins"]}@@ -113,8 +113,6 @@ def test_plugins_manage_list_resolves_the_live_catalog_once_per_listing(tmp_pathwith patch.object(plugins_cmd, "_discover_all_plugins", return_value=rows), \patch.object(plugins_cmd, "_get_enabled_set", return_value=set()), \patch.object(plugins_cmd, "_get_disabled_set", return_value=set()), \- patch.object(plugins_cmd_catalog, "catalog_pins", return_value={}), \- patch.object(plugins_cmd_catalog, "catalog_versions", return_value={}), \patch.object(plugins_cmd_catalog, "catalog_install_record",side_effect=lambda d: {"catalog_name": f"example-{d.name.removeprefix('plug')}"}), \patch.object(plugin_catalog, "load_catalog_live", side_effect=counting_load), \diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex bab934c0740..41b835d169e 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -1679,9 +1679,9 @@ def _plugin_rows() -> list[dict]:pc = _tools_mod("hermes_cli.plugins_cmd")cat = _tools_mod("hermes_cli.plugins_cmd_catalog")enabled, disabled = pc._get_enabled_set(), pc._get_disabled_set()- pins = cat.catalog_pins() # powers the desktop's "Update to <pin>" affordance- versions = cat.catalog_versions()- titles = cat.catalog_titles() # server-sentence display names: ONE live-catalog resolution+ # pins power the desktop's "Update to <pin>" affordance; titles are the server-sentence display+ # names. One live-catalog resolution for the whole listing (see ``catalog_rows_maps``).+ pins, versions, titles = cat.catalog_rows_maps()ref_pins = pc._read_install_metadata() # ``--ref`` installs: pinned_sha so the desktop can show the pinout = []active = pc._category_active_names()