The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): inspect inherited schemas and clear held rollbacks
ethernet70fd476dd33b
diff --git a/hermes_cli/source_check.py b/hermes_cli/source_check.pyindex 3128f8f2065..5a67a576988 100644--- a/hermes_cli/source_check.py+++ b/hermes_cli/source_check.py@@ -394,7 +394,7 @@ def _hold_refused_release(result: dict, co: _Checkout, home: Path) -> None:or the only ledgered profile can be removed, between checks."""target = result.get("targetSha")if result.get("updateAvailable") and target and _update_refuses(co, target, home):- result.update(updateAvailable=False, behind=0, held="downgrade")+ result.update(updateAvailable=False, behind=0, held="downgrade", rollback=False)def _resolve_channel(result: dict, channel: str, co: _Checkout, *, forward_only: bool = False):diff --git a/hermes_cli/update_downgrade_guard.py b/hermes_cli/update_downgrade_guard.pyindex 06b29ba8517..f0af9195350 100644--- a/hermes_cli/update_downgrade_guard.py+++ b/hermes_cli/update_downgrade_guard.py@@ -58,7 +58,7 @@ def target_predates_runtime(git_cmd, root: Path, target_ref: str, *,if git("merge-base", "--is-ancestor", "HEAD", target_ref) == 0:return False # forward update: whatever the target's schema, it was written knowing this one# grep can return 1 for unreadable blobs too: establish completeness before trusting no match.- if git("rev-list", "--objects", "--no-walk", "--missing=error", target_ref, "--", STATE_MODULES) != 0:+ if git("rev-list", "--objects", "--no-walk", "--sparse", "--missing=error", target_ref, "--", STATE_MODULES) != 0:return remote is not None and remote(target_ref) is True# Exit 1 = no match in a complete local schema; 0 = found; anything else is a git error.result = git("grep", "-q", "-F", _RUNTIME_SCHEMA_MARKER, target_ref, "--", STATE_MODULES)diff --git a/tests/hermes_cli/test_source_check.py b/tests/hermes_cli/test_source_check.pyindex e507745f7a5..972f6822661 100644--- a/tests/hermes_cli/test_source_check.py+++ b/tests/hermes_cli/test_source_check.py@@ -593,23 +593,29 @@ def test_stable_release_the_checkout_already_contains_is_a_rollback(installation@pytest.mark.parametrize("ledgered", [True, False])-def test_stable_release_the_updater_refuses_is_held_not_offered(installation, tmp_path, monkeypatch, ledgered):- """A release off this checkout's history that predates the gateway runtime is held while a store- has runtime history (#139099): `hermes update` refuses it, so the check must not offer it."""[email protected]("divergent", [True, False], ids=["beside-history", "in-history"])+def test_stable_release_the_updater_refuses_is_held_not_offered(+ installation, tmp_path, monkeypatch, capsys, ledgered, divergent):+ """A pre-runtime release is held while a store has runtime history (#139099), even when the+ checkout already contains it: neither an update offer nor a rollback promise is valid."""+ from hermes_cli import _startup_fastfrom hermes_cli.source_check import check_for_updatesfrom tests.hermes_cli.test_update_downgrade_guard import _ledgered_storeroot, _linked, home, base, _head, responses, requests, git = installationsibling = tmp_path / "sibling"monkeypatch.setattr("hermes_cli.backup._sibling_profile_homes", lambda h: [("sibling", sibling)])- (root / "hermes_state_common.py").write_text("SCHEMA_SQL = 'CREATE TABLE IF NOT EXISTS session_admissions (seq)'\n")- git("add", "hermes_state_common.py")- git("commit", "-q", "-m", "gateway runtime")git("checkout", "-q", "-b", "release-line", base)(root / "hermes_state_common.py").write_text("SCHEMA_SQL = 'CREATE TABLE IF NOT EXISTS sessions (id)'\n")git("add", "hermes_state_common.py")git("commit", "-q", "-m", "release from the older line")release = git("rev-parse", "HEAD")+ git("checkout", "-q", "main")+ if not divergent:+ git("merge", "--no-ff", "-qm", "release on main's history", "release-line")+ (root / "hermes_state_common.py").write_text("SCHEMA_SQL = 'CREATE TABLE IF NOT EXISTS session_admissions (seq)'\n")+ git("add", "hermes_state_common.py")+ git("commit", "-q", "-m", "gateway runtime")bare = tmp_path / "origin.git"git("clone", "-q", "--bare", str(root), str(bare), cwd=tmp_path)git("tag", "v1.2.3", release, cwd=bare)@@ -624,21 +630,29 @@ def test_stable_release_the_updater_refuses_is_held_not_offered(installation, tmstatus = check_for_updates(install_root=root, home=home, channel="stable", force=True)assert status.get("targetSha") == release, status- assert status["rollback"] is False # off-history: the ancestry test alone cannot see itassert status["updateAvailable"] is not ledgeredassert status.get("held") == ("downgrade" if ledgered else None)+ held_status = statusif not ledgered:# The first runtime turn lands after an offer was cached: the next passive check holds it._ledgered_store(sibling)- cached = check_for_updates(install_root=root, home=home, channel="stable")- assert cached["updateAvailable"] is False and cached.get("held") == "downgrade", cached+ held_status = check_for_updates(install_root=root, home=home, channel="stable")+ assert held_status["updateAvailable"] is False and held_status.get("held") == "downgrade", held_status++ # --version consumes this status too, and checks rollback before the behind count.+ with monkeypatch.context() as version:+ version.setattr("hermes_cli.source_check.check_for_updates", lambda **kw: held_status)+ _startup_fast.print_fast_version_info()+ assert "moves back to it" not in capsys.readouterr().out+ assert held_status["rollback"] is False# Removing the only ledgered profile clears a cached hold without re-resolving the release.shutil.rmtree(sibling)seen = list(requests)allowed = check_for_updates(install_root=root, home=home, channel="stable")assert allowed["updateAvailable"] is True and allowed["behind"] == -1, allowed+ assert allowed["rollback"] is not divergentassert "held" not in allowed and allowed["fetchedAt"] == status["fetchedAt"]assert requests == seendiff --git a/tests/hermes_cli/test_update_downgrade_guard.py b/tests/hermes_cli/test_update_downgrade_guard.pyindex 842ea849944..1a2cc3a78d6 100644--- a/tests/hermes_cli/test_update_downgrade_guard.py+++ b/tests/hermes_cli/test_update_downgrade_guard.py@@ -140,14 +140,26 @@ def test_the_runtime_schema_marker_is_still_in_this_trees_state_schema():@pytest.mark.parametrize("remote_result", [True, False, None, "no-reader"])[email protected]("runtime", [False, True], ids=["pre-runtime", "runtime"])def test_present_commit_with_missing_schema_blobs_uses_remote_without_git_writes(- repo, tmp_path, monkeypatch, remote_result):+ repo, tmp_path, monkeypatch, remote_result, runtime):from hermes_cli.source_check import source_git_env+ # Release commits change the version, not the schema: pathspec history simplification must+ # not skip their inherited schema objects (Git 2.53 does; newer Git can mask the regression).+ _git(repo, "checkout", "-q", "-b", "release-line", "HEAD" if runtime else "old-release")+ (repo / "VERSION").write_text("1.2.3\n", encoding="utf-8")+ _git(repo, "add", "VERSION")+ _git(repo, "commit", "-qm", "release version bump")+ target = _git(repo, "rev-parse", "HEAD")+ _git(repo, "checkout", "-q", "main")+ (repo / "hermes_state_common.py").write_text(+ "SCHEMA_SQL = '''CREATE TABLE IF NOT EXISTS session_admissions (seq INTEGER, extra TEXT)'''\n",+ encoding="utf-8")+ _git(repo, "commit", "-qam", "newer runtime schema")_git(repo, "config", "uploadpack.allowFilter", "true")clone = tmp_path / "partial"_git(tmp_path, "clone", "--filter=blob:none", "--no-checkout", repo.as_uri(), str(clone))- target = _git(clone, "rev-parse", "old-release")trace = tmp_path / "git-trace.jsonl"monkeypatch.setenv("GIT_TRACE2_EVENT", str(trace))