The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: the recovery closure is read from git in one cat-file spawn
Teknium44e59c39046b
diff --git a/hermes_cli/update_cmd_commit.py b/hermes_cli/update_cmd_commit.pyindex 911515acd37..7b53f0c9e12 100644--- a/hermes_cli/update_cmd_commit.py+++ b/hermes_cli/update_cmd_commit.py@@ -248,12 +248,11 @@ def publish_recovery_closure(git_cmd, root: Path, pre: str) -> Path:if meta.split()[1:2] == ["blob"]:ids[rel] = meta.split()[2]blobs = {RECOVERY_CLOSURE_INIT: b""}+ shown = read_target_files(git_cmd, root, pre, RECOVERY_CLOSURE) # one spawn, not a cat-file per filefor rel in RECOVERY_CLOSURE:- shown = run_git(git_cmd, ["cat-file", "blob", ids.get(rel, "")], cwd=str(root), capture_output=True,- stdin=subprocess.DEVNULL, timeout=120) if rel in ids else None- if shown is None or shown.returncode != 0 or blob_id(shown.stdout or b"", pre) != ids[rel]:+ if rel not in ids or shown[rel] is None or blob_id(shown[rel], pre) != ids[rel]:raise OSError(f"{rel} is not in {pre[:10]}")- blobs[rel] = shown.stdout+ blobs[rel] = shown[rel]manifest = "".join(f"{blob_id(data, pre)} {rel}\n" for rel, data in blobs.items()).encode("utf-8")staging = dest.with_name(f".{pre}.{os.getpid()}.staging")shutil.rmtree(staging, ignore_errors=True)diff --git a/tests/hermes_cli/test_update_recovery_closure.py b/tests/hermes_cli/test_update_recovery_closure.pyindex 83408224bf5..7837641ab93 100644--- a/tests/hermes_cli/test_update_recovery_closure.py+++ b/tests/hermes_cli/test_update_recovery_closure.py@@ -220,3 +220,30 @@ def test_a_stdlib_named_file_in_the_tree_never_runs_before_the_repair(tmp_path,assert launch.returncode == 0 and "APP_REACHED" in launch.stdout, launch.stderrassert (root / "hermes_bootstrap.py").read_bytes() == originalassert not (root / ".git/hermes-update-pull").exists()+++def test_the_closure_is_pres_committed_bytes_read_in_one_cat_file_spawn(tmp_path, monkeypatch):+ """The published repair is ``pre``'s committed bytes, not the working tree's, read with one+ ``git cat-file --batch`` (the preflight's batched reader), not a ``cat-file`` per file."""+ from hermes_cli import update_cmd_commit as commit+ from hermes_cli._early_recovery import RECOVERY_CLOSURE++ root = tmp_path / "checkout"+ for rel in RECOVERY_CLOSURE:+ (root / rel).parent.mkdir(parents=True, exist_ok=True)+ (root / rel).write_bytes(f"# {rel} at pre\n".encode())+ env = {**os.environ, "GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": os.devnull}+ for args in (("init", "-q", "-b", "main"), ("add", "-A"),+ ("-c", "user.name=t", "-c", "[email protected]", "commit", "-qm", "pre")):+ subprocess.run(["git", "-C", str(root), *args], env=env, check=True)+ pre = subprocess.check_output(["git", "-C", str(root), "rev-parse", "HEAD"], text=True).strip()+ (root / RECOVERY_CLOSURE[0]).write_bytes(b"# a working-tree edit, never published\n")+ spawns = []+ real = commit.run_git+ monkeypatch.setattr(commit, "run_git", lambda git_cmd, args, **kw: spawns.append(args[0]) or real(git_cmd, args, **kw))++ closure = commit.publish_recovery_closure(["git"], root, pre)++ for rel in RECOVERY_CLOSURE:+ assert (closure / rel).read_bytes() == f"# {rel} at pre\n".encode()+ assert spawns == ["ls-tree", "cat-file"]