The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(update): name the parked rollback once and reuse the test helpers
kshitijk4poore59df70a12f5
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 505cafaacee..f2af68d7612 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -823,16 +823,16 @@ def _rollback_if_pulled_syntax_error(git_cmd, pre_pull_sha, *, rollback_branch=Nif pre_pull_sha:# Restore the checkout the update left, never reset the update branch onto commits from# a parked feature branch or a detached checkout.+ parked = rollback_branch not in (None, "HEAD")if rollback_branch == "HEAD":rollback_args = ["checkout", "--detach", pre_pull_sha]- elif rollback_branch is not None:+ elif rollback_branch:rollback_args = ["checkout", rollback_branch]else:rollback_args = ["reset", "--hard", pre_pull_sha]- target = rollback_branch if rollback_branch not in (None, "HEAD") else pre_pull_sha[:10]- print(f"→ Rolling back to {target}...")+ print(f"→ Rolling back to {rollback_branch if parked else pre_pull_sha[:10]}...")rollback_result = _git_run(git_cmd, rollback_args)- if rollback_result.returncode != 0 and rollback_branch not in (None, "HEAD"):+ if rollback_result.returncode != 0 and parked:# The parked branch can be unavailable (e.g. checked out in another worktree): restore# its commit detached so the install still boots the code it ran before.print(f" ✗ Could not check out {rollback_branch}; restoring its commit detached.")@@ -855,14 +855,11 @@ def _rollback_if_pulled_syntax_error(git_cmd, pre_pull_sha, *, rollback_branch=Ndef _update_movement_baseline(git_cmd, pre_pull_sha, pre_sync_sha, rollback_branch, target_sha):"""Distinguish a branch awaiting repair from an already-applied early sync."""if rollback_branch is not None and pre_pull_sha and target_sha:- # A target already contained in the branch cannot advance it. In that- # case checkout/early sync supplied the movement, even if pushing the- # sync back to origin failed. Otherwise verify the pending repair from- # the stale/diverged branch tip, not the original detached checkout.+ # Target already in the branch => checkout/early sync did the moving (even if its push+ # failed), so count from pre_sync. Anything else (rc 1, or 128 for an unresolvable SHA)+ # verifies from the branch tip, so a no-op merge fails loudly instead of passing.contains_target = _git_run(git_cmd, ["merge-base", "--is-ancestor", target_sha, pre_pull_sha])- # Anything but "contained" (rc 1, or rc 128 for a SHA git cannot resolve) keeps the strict- # baseline: the worst case is a loud "did not move" refusal, never a silent success.if contains_target.returncode != 0:return pre_pull_shareturn pre_sync_sha or pre_pull_shadiff --git a/tests/hermes_cli/test_update_existing_branch_baseline.py b/tests/hermes_cli/test_update_existing_branch_baseline.pyindex 6a245560dcb..ed0d4c97dd9 100644--- a/tests/hermes_cli/test_update_existing_branch_baseline.py+++ b/tests/hermes_cli/test_update_existing_branch_baseline.py@@ -48,6 +48,19 @@ def pull(plan, **kwargs):)+def complete(plan, movement_baseline, monkeypatch):+ """Finish a pulled update and return the completion request it handed off."""+ completed = []+ monkeypatch.setattr(update_cmd, "_complete_source_update", completed.append)+ request = {}+ update_cmd._apply_pulled_update(+ ["git"], "main", movement_baseline, plan,+ _windows_gateway_resume=None, completion_request=request,+ )+ assert completed == [request]+ return request++def test_existing_main_counts_from_running_detached_code(checkout):root, old, tip = checkoutplan = prepare(root)@@ -90,7 +103,6 @@ def test_syntax_failure_returns_to_original_checkout_without_rewriting_main(checassert (root / "cli.py").read_text(encoding="utf8") == "value = 1\n"-def test_rollback_restores_the_commit_when_the_parked_branch_is_taken(checkout, tmp_path):"""Another worktree holding the parked branch must not leave the install on broken code."""root, old, tip = checkout@@ -176,24 +188,12 @@ def test_fork_sync_after_stale_branch_repair(checkout, monkeypatch, upstream_resreturn Truemonkeypatch.setattr(update_cmd._m(), "_sync_with_upstream_if_needed", sync)- kwargs = dict(prompt_for_restore=False, gw_input_fn=None,- discard_local_changes=False, keep_stash=False,- pre_sync_sha=plan.pre_sync_sha, rollback_branch=plan.rollback_branch,- sync_upstream=True)if upstream_result in {"wrong-branch", "reverted"}:with pytest.raises(SystemExit) as exc:- update_cmd._pull_updates(["git"], "main", plan.auto_stash_ref, **kwargs)+ pull(plan, sync_upstream=True)assert exc.value.code == 1else:- before_pull = update_cmd._pull_updates(["git"], "main", plan.auto_stash_ref, **kwargs)- completed = []- monkeypatch.setattr(update_cmd, "_complete_source_update", completed.append)- request = {}- update_cmd._apply_pulled_update(- ["git"], "main", before_pull, plan,- _windows_gateway_resume=None, completion_request=request,- )- assert completed == [request]+ request = complete(plan, pull(plan, sync_upstream=True), monkeypatch)assert request["expected_sha"] == (upstream_tip if upstream_result == "original" else tip)assert git(root, "rev-parse", "main") == (upstream_tip if upstream_result == "original" else tip)assert git(root, "rev-parse", "--abbrev-ref", "HEAD") == "main"@@ -217,15 +217,7 @@ def test_early_fork_sync_without_push_still_completes(checkout, monkeypatch):assert plan.upstream_checkedassert git(root, "rev-parse", "HEAD") == upstream_tipassert git(root, "rev-parse", "origin/main") == tip- before_pull = pull(plan, sync_upstream=True)- completed = []- monkeypatch.setattr(update_cmd, "_complete_source_update", completed.append)- request = {}- update_cmd._apply_pulled_update(- ["git"], "main", before_pull, plan,- _windows_gateway_resume=None, completion_request=request,- )- assert completed == [request]+ request = complete(plan, pull(plan, sync_upstream=True), monkeypatch)assert request["expected_sha"] == upstream_tipdiff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.mdindex bebadc87ec7..1d37d0e3d3c 100644--- a/website/docs/getting-started/updating.md+++ b/website/docs/getting-started/updating.md@@ -135,7 +135,7 @@ For an admitted source checkout, `hermes update` runs these phases:1. **Pre-update snapshot** — Hermes saves selected state files for every profile in that profile's `state-snapshots/` directory. These include pairing data, cron jobs, `config.yaml`, `.env`, and `auth.json`. Automatic quick snapshots skip individual files larger than 1 GiB. `updates.pre_update_backup` selects `quick`, `full`, or `off`. Full archives use the [backup exclusions](../reference/faq.md#hermes-backup-vs-hermes-profile-export). Recovery uses [Snapshots and rollback](../user-guide/checkpoints-and-rollback.md). Quick snapshots recover state files, not application code. The snapshot is best-effort: if it fails, the update prints a `⚠ Pre-update snapshot FAILED` warning and continues, and the receipt records `pre_update_backup` as a failed step (a deliberate `off`/`--no-backup` lands in the receipt's skips with its reason instead).2. **Code update** — applies the configured source branch or stable release tag and updates submodules.-3. **Post-pull syntax validation + auto-rollback** — after the pull, Hermes compiles the nine critical files every `hermes` invocation imports at startup. If any fails to parse (e.g. an orphan merge-conflict marker, an accidentally truncated file), Hermes rolls the install back so your shell stays bootable: `git reset --hard <pre-pull-sha>` on the update branch, or, when the update started from a detached checkout or a parked feature branch, `git checkout --detach <sha>` / `git checkout <branch>` back to where it started (a branch it cannot check out again is restored detached at the same commit). Re-run `hermes update` once the upstream fix lands.+3. **Post-pull syntax validation + auto-rollback** — after the pull, Hermes compiles the nine critical files every `hermes` invocation imports at startup. If any fails to parse (e.g. an orphan merge-conflict marker, an accidentally truncated file), Hermes rolls the install back so your shell stays bootable: it resets the checkout to the commit it ran before the pull (`git reset --hard <pre-pull-sha>`), or, when the update switched away from a detached checkout or a parked feature branch, returns there with `git checkout --detach <sha>` / `git checkout <branch>` (a branch it cannot check out again is restored detached at the same commit). Re-run `hermes update` once the upstream fix lands.4. **Dependency preparation** — PM provisions required tools and prepares a complete Python environment from the new lock, existing extras, and enabled plugin requirements. It validates that environment before publishing its selection. A plugin never fails the update. A plugin that no longer fits the new core is added to `plugins.disabled` in every profile that enables it (a memory provider has `memory.provider` cleared). That covers a `requires-python` that excludes Hermes's Python, a `manifest_version` newer than this Hermes supports, and dependencies that the resolver proves can't resolve alongside core and earlier plugins in config order, or that fail their own build. A download or network failure gets one retry and is disabled if it fails again. The update prints `⚠ Disabled plugin '<name>' in <home>: <reason>`, records it in the receipt's warnings, and continues. Re-enable it with `hermes plugins enable <name>` once the plugin ships a compatible release, or once the network is back. A `requires_hermes` range the running version misses never disables a plugin, because a source checkout without release tags can read as an older release. That plugin sits out instead (`⚠ Left plugin '<name>' … out of this update`), stays enabled, and rejoins once Hermes reports a version it accepts. A secondary profile whose config cannot be read sits out the same way until the config is fixed. Only a core that cannot build on its own fails this step.5. **Config migration** — detects new config options added since your version and prompts you to set them6. **Desktop rebuild (stage-and-swap)** — if the Hermes Desktop app was built from this checkout, it is rebuilt so the GUI matches the new code. The rebuild packs into a temporary staging directory next to `apps/desktop/release/`, verifies the staged app, and only then renames it over the previous build (on Windows a real-time scanner briefly holding `release/win-unpacked` is ridden out with a few short retries). A rebuild that fails at any point — corrupt Electron download, missing dependency, disk full — leaves the previous app untouched and launchable; the update fails at that step, and `hermes desktop --build-only --force-build` or the next `hermes update` retries the rebuild. On macOS the rebuilt bundle is then copied (with `ditto`, signature intact) over a stale `/Applications/Hermes.app` or `~/Applications/Hermes.app`, so the copy Finder and the Dock launch matches the backend; an installed copy that is currently running is left alone and the update tells you to quit it and run `hermes update` again. On Windows, when the update finishes from inside the Desktop app it would rebuild (the app completing an interrupted update at launch), the rebuild is skipped with a notice instead: Windows locks a running app's files, and stopping the app would end the update with it. The rest of the update completes; quit Hermes Desktop and run `hermes desktop` from a terminal, or use **Update now** in **Settings → About**, to rebuild and reopen it.