The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): date a treeless checkout by its files when history is unreadable
liuhao10248f628e2e81be
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.pyindex 4fb6d442d25..3598dec07ab 100644--- a/hermes_cli/plugin_catalog.py+++ b/hermes_cli/plugin_catalog.py@@ -388,13 +388,15 @@ def fetch_live_catalog(*, force: bool = False) -> Optional[Dict[str, Any]]:return _stale_live_cache(cache)-_in_tree_catalog_time: Optional[float] = -1.0 # -1 = not resolved yet; None = no git checkout+_in_tree_catalog_time: Optional[float] = -1.0 # -1 = not resolved yet; None = no usable in-tree timedef in_tree_catalog_time() -> Optional[float]:"""Commit time (epoch) of the last change to this checkout's ``plugin-catalog/``, or ``None`` whenthe install is not a git checkout (a release/pip install cannot be newer than the published doc).- Resolved once per process."""+ On a git checkout whose path history is unreadable without network — the treeless ``tree:0`` layout+ ``hermes update`` produces — the newest checked-out catalog file's mtime stands in for it, so a+ freshly updated checkout still outranks a doc fetched before the bump. Resolved once per process."""global _in_tree_catalog_timeif _in_tree_catalog_time != -1.0:return _in_tree_catalog_time@@ -409,17 +411,34 @@ def in_tree_catalog_time() -> Optional[float]:# 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.+ # missing objects fail fast into the 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,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)+ if resolved is None:+ # "History unreadable without network" must not collapse into "not a git checkout":+ # ``None`` feeds the frozen-copy rule that defers to the live doc, which would let a+ # cache fetched before ``hermes update`` re-pin the old sha on exactly the installs+ # that just bumped it. A treeless clone still has its checked-out files — only the+ # historical trees are missing — and their mtime dates the checkout that wrote them.+ resolved = _catalog_worktree_mtime()_in_tree_catalog_time = resolvedreturn resolved+def _catalog_worktree_mtime() -> Optional[float]:+ """Newest mtime under the checkout's ``plugin-catalog/``: a no-network freshness signal for clones+ whose path history is unreachable (treeless or offline). ``None`` when nothing is checked out."""+ try:+ times = [p.stat().st_mtime for p in get_catalog_dir().rglob("*") if p.is_file()]+ except OSError:+ return None+ return max(times) if times else None++def _live_generated_time(data: Dict[str, Any]) -> Optional[float]:raw = data.get("generated_at")if not isinstance(raw, str) or not raw:diff --git a/tests/hermes_cli/test_plugin_catalog.py b/tests/hermes_cli/test_plugin_catalog.pyindex ceb857ff40e..e1a7f2ac2db 100644--- a/tests/hermes_cli/test_plugin_catalog.py+++ b/tests/hermes_cli/test_plugin_catalog.py@@ -204,9 +204,10 @@ def test_in_tree_catalog_time_does_not_lazy_fetch_on_treeless_clones(tmp_path, m"""``in_tree_catalog_time`` dates the checkout with a pathspec'd ``git log``; the pathspec makes gitopen 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."""+ the remote: measured 40-80 s per inventory request, past the desktop's 30s RPC limit (#125683).+ The probe must scope ``GIT_NO_LAZY_FETCH`` to itself so missing objects fail fast into the+ worktree-mtime fallback — never into network work — while a full checkout keeps resolving its time.+ This clone is never checked out, so there is no mtime to fall back to either: ``None`` all the way."""import shutilimport subprocess as spif shutil.which("git") is None:@@ -241,3 +242,59 @@ def test_in_tree_catalog_time_does_not_lazy_fetch_on_treeless_clones(tmp_path, mmonkeypatch.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 time+++def test_treeless_checkout_still_outranks_a_doc_fetched_before_the_bump(tmp_path, monkeypatch):+ """On the treeless layout the history probe fails fast, and ``None`` would feed the frozen-copy+ rule that lets the live doc win — re-pinning the old sha on exactly the checkouts ``hermes+ update`` just bumped. The checked-out files' mtime must stand in for the unreadable commit time+ (fresh checkout ⇒ in-tree pin wins; catalog files older than the doc ⇒ live pin wins), with no+ tree lazy-fetch anywhere (#125716 review)."""+ 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)+ (src / "plugin-catalog" / "a.yaml").write_text("name: a2\n")+ sp.run(["git", "add", "-A"], cwd=src, check=True, env=env)+ sp.run(["git", "commit", "-qm", "bump"], 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")+ # Checking out only fetches HEAD's trees; the seed commit's tree stays missing, so the+ # pathspec'd probe keeps failing — while the worktree files (and their mtimes) land.+ sp.run(["git", "-C", str(dst), "checkout", "-q"], check=True, env=env)+ probe = sp.run(["git", "-C", str(dst), "log", "-1", "--format=%ct", "--", "plugin-catalog"],+ capture_output=True, env={**env, "GIT_NO_LAZY_FETCH": "1"})+ assert probe.returncode != 0 # the probe really is blind on this layout, like a real update++ old, new = SHA, "a" * 40+ _fresh_cache(tmp_path, monkeypatch, {"generated_at": "2026-09-22T10:00:00Z",+ "entries": [_entry("shared", sha=old)], "removed": []})+ monkeypatch.setattr(pc, "load_catalog", lambda catalog_dir=None: [pc.entry_from_mapping(_entry("shared", sha=new), "t")])+ monkeypatch.setattr(pc, "get_catalog_dir", lambda: dst / "plugin-catalog")+ monkeypatch.setattr(pc, "_in_tree_catalog_time", -1.0) # resolve afresh: probe fails, mtime stands in+ assert {e.name: e.sha for e in pc.load_catalog_live()}["shared"] == new++ # Control: catalog files older than the doc mean the checkout is the stale side — live pin wins.+ for p in (dst / "plugin-catalog").rglob("*"):+ os.utime(p, (0, 0))+ monkeypatch.setattr(pc, "_in_tree_catalog_time", -1.0)+ assert {e.name: e.sha for e in pc.load_catalog_live()}["shared"] == old