Repository navigation
Description
Repository stage stash/local-changes handling is fragile and can leave the tree in unrecoverable dirty state after interrupted updates
Observed failure
The repository stage in the bootstrap installer (and the equivalent path in hermes update) has extensive defensive logic for local changes because a dirty tree aborts git checkout / git pull with "Your local changes would be overwritten by checkout".
When this logic itself fails (or a prior run was interrupted), the tree is left with:
- Unmerged index entries
- A pending stash that may or may not be restorable
- Modified generated files (package-lock.json etc.) that the next update attempt also chokes on
This is exactly the class of dirt that produced the unrecoverable state in #46763 (GUI users hitting "git checkout main failed", manual CLI update also failing until the tree was manually cleaned, and redownload hitting the same state).
Root cause
scripts/install.ps1 (repository stage, ~lines 1162-1266) contains the full logic:
- Pins
core.autocrlf=falseto avoid creating dirt on checkout. - Runs
git status --porcelain; if dirty, doesgit stash push --include-untracked. - Special handling for previously interrupted updates: checks
ls-files --unmerged, runsgit resetto clear conflict markers before stashing (otherwisegit stashand subsequentgit checkoutboth abort). - After fetch/checkout/pull, attempts
git stash apply+ drop. - Console detection hack (
UserInteractive && !InputRedirected && !OutputRedirected && ConsoleHost) to decide whether to prompt; in desktop handoff / bootstrap runs (no usable TTY) it forces restore. - On any failure in the restore block or earlier throw: leaves the stash behind and emits instructions, but the stage has already failed or the tree is in a half-applied state.
- The finally block only cleans up the stash ref if we never reached the restore section.
The same patterns exist (with less defensive code) in the hermes update path and install.sh.
A single interrupted update, a stash-apply failure, or a non-interactive restore that re-introduces dirt (e.g. the exact package-lock.json that the dirty-tree resolver targets) leaves the managed checkout in the state that makes the next handoff or reinstall also fail.
Impact on casual users
This is the mechanical reason the "dirty tree → broken exe → redownload also fails" loop exists. The stash machinery is intended as a safety net, but its own failure modes (unmerged index, non-interactive restore, partial failures) are exactly what produces the unrecoverable checkout that #46763 describes.
The current resolver proposal in #46763 helps once the dirt is detected, but does not address the source of the dirt coming from the stash/local-changes handling itself.
Proposed direction
- Make the stash handling a first-class "resolver" step that can be invoked both by the repository stage and by the recovery path in No automatic recovery or repair path after desktop update handoff fails, leaving users unable to launch or reinstall #46782.
- On detecting unmerged entries or a pending hermes-install-autostash, offer (or auto-apply in the desktop handoff case) a clean
git reset --merge+ targeted stash pop for generated files only, before the main checkout. - After any successful update, always attempt a non-destructive cleanup of known generated dirt (package-lock.json, etc.) even if a stash was involved.
- Improve the finally-block logic so that an interrupted stash push still leaves a usable tree + clear marker for the recovery UI.
- Surface the stash ref and the exact commands in the bootstrap progress / desktop error UI instead of just "git checkout failed".
This turns the existing defensive hacks into an explicit, recoverable part of the update contract instead of a source of permanent dirt.
Activity
apoapostolov commentedon Jun 15, 2026
Part of the desktop updater / bootstrap + handoff cluster:
baoyu0 commentedon Jun 16, 2026
Additional failure pattern: interactive stash-restore loop + stale update cache
I hit a variant of this today after having 43 locally-modified source files on
main. The failure loop and root-cause analysis may be useful for the resolver proposal.Reproduction (interactive CLI, not desktop)
agent/auxiliary_client.py,gateway/,hermes_cli/etc.) that overlap with upstream changes.hermes update— it stashes changes, fetches, pulls successfully._restore_stashed_changes(main.py:6102) hits merge conflicts because local changes overlap with new upstream code. It prints the conflicted files and runsgit reset --hard HEAD, leaving the working tree clean but leaving the stash in place.hermes --versionre-checks, cache still returns old stale count becauseVERSIONhasn't bumped (same v0.16.0), so the check_for_updates() cache not invalidated after pip upgrade, showing stale "1 commit behind" #34491 guard seescached["ver"] == VERSIONas a match.hermes updateagain — same cycle, another autostash piles up.After 4 runs we had 4
hermes-update-autostash-*entries, HEAD still at the old commit, andhermes --versionstuck on "10 commits behind" due to the stale cache.Two gaps not fully covered yet
1. No interactive "discard local changes and finish update" option
main.py:8424-8443— Thediscard_local_changespath only activates in non-interactive mode (--yes, gateway, non-TTY). In interactive mode, the code always tries_restore_stashed_changes, and if that conflicts, the user is stuck in a loop with no way to say "I give up, just throw away my changes and finish the update."It would help to add a prompt in the conflict handler along the lines of:
2. Stale update-check cache survives even after a manual
git pullthat succeedsAfter we manually fixed the tree (
git reset --hard HEAD && git pull --ff-only),hermes --versionstill showed "10 commits behind" because the.update_checkcache had{"behind": 10, "ver": "0.16.0"}and VERSION hadn't changed. The cache was only invalidated once we manually deleted~/.hermes/.update_check.The
_invalidate_update_cache()function (main.py:6477) deletes the cache file, butcheck_for_updates()(banner.py:290) re-creates it on every check. If the cache was written before the update succeeded (HEAD not moved), it keeps returning the old count until it expires (6h TTL).Suggestion: when
_check_via_local_git()returns 0, write{"behind": 0}to the cache unconditionally so a subsequent check immediately shows "Up to date."Environment
hermes update(no desktop app)teknium1 commentedon Jul 14, 2026
This is an automated hermes-sweeper review: the reported recovery paths are implemented on current
main.573b964dc780a9aae91eaf7b5a64497cfdfd2828added unmerged-index recovery before autostashing in bothscripts/install.ps1andscripts/install.sh; the current installer code clears the index before its stash/checkout path.hermes_cli/main.py:6574–6604detects a failed/conflicted stash restore, resets the checkout to cleanHEAD, preserves the stash with its exact recovery reference, and allows the completed update to continue.hermes_cli/main.py:6929–6953invalidates stale update-check caches across profiles;hermes_cli/main.py:9271–9305removes managedpackage-lock.jsonchurn before autostashing.tests/test_install_unmerged_index.py:87–127and stash-conflict cleanup coverage intests/hermes_cli/test_update_autostash.py:247–304.These changes are included in
v2026.7.1.