Skip to content

The agent that grows with you

fix(update): a committed ZIP swap is never reported failed over its journal unlink (review F19)

Teknium8c5abbf3de9f
diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.py
index 0c89cc65076..4477b177498 100644
--- a/hermes_cli/update_cmd_zip.py
+++ b/hermes_cli/update_cmd_zip.py
@@ -462,7 +462,10 @@ def _journaled_stage_and_swap(extracted: str, entries: list[str], root: Path, ta
write_zip_swap_journal(root, "swapping", journal_entries)
_commit_staged_replacements(
staged, on_committed=lambda: write_zip_swap_journal(root, "committed", journal_entries))
- (root / ZIP_SWAP_JOURNAL).unlink(missing_ok=True)
+ # Committed: the new tree is whole. A journal that cannot go now (AV/indexer holding it) says
+ # "committed", which the next launch's recovery settles by keeping the new tree.
+ with suppress(OSError):
+ (root / ZIP_SWAP_JOURNAL).unlink(missing_ok=True)
return staged
diff --git a/tests/hermes_cli/test_update_zip_two_phase.py b/tests/hermes_cli/test_update_zip_two_phase.py
index 728d4b0cabf..c895da858bb 100644
--- a/tests/hermes_cli/test_update_zip_two_phase.py
+++ b/tests/hermes_cli/test_update_zip_two_phase.py
@@ -573,3 +573,27 @@ def test_a_failed_swap_keeps_a_file_the_user_made_at_a_never_installed_entry(tmp
assert user_file.is_file() and user_file.read_text(encoding="utf-8-sig") == "USER NOTE"
assert (live / "a" / "v.txt").read_text(encoding="utf-8-sig") == "old"
assert not [p.name for p in live.iterdir() if "hermes-update-staging" in p.name or p.name.endswith("-old")]
+
+def test_a_journal_that_cannot_be_dropped_after_the_commit_never_fails_the_update(tmp_path, monkeypatch):
+ """The swap committed: an AV scan holding the journal must not turn it into a reported failure
+ that disarms the new tree's completion obligations (F19)."""
+ from hermes_cli import update_cmd_commit
+
+ live, extracted = tmp_path / "live", tmp_path / "extracted"
+ _live_tree(live, {"payload": "old"})
+ _live_tree(extracted, {"payload": "new"})
+ real = Path.unlink
+
+ def held(self, *args, **kwargs):
+ if self.name == update_cmd_zip.ZIP_SWAP_JOURNAL:
+ raise PermissionError(13, "being used by another process", str(self))
+ return real(self, *args, **kwargs)
+
+ update_cmd_commit.reset_for_tests()
+ monkeypatch.setattr(Path, "unlink", held)
+ try:
+ update_cmd_zip._journaled_stage_and_swap(str(extracted), ["payload"], live, "b" * 40)
+ assert update_cmd_commit.commit_obligations_armed()
+ finally:
+ update_cmd_commit.reset_for_tests()
+ assert (live / "payload" / "version.txt").read_text() == "new"