Skip to content

The agent that grows with you

fix(update): name this run's unsettled autostash before any update outcome (#122557)

finn763f77f1a2a37bc
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 0ff09efbdbd..6dd2f37737a 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -70,11 +70,13 @@ from hermes_cli.update_cmd_zip import ( # noqa: F401
_is_zip_preserved_entry_status_line, _is_zip_staging_artifact_status_line, _stage_replacement,
_update_via_zip, _zip_overlay_block_reason)
from hermes_cli.update_cmd_stash import ( # noqa: F401
- _AUTOSTASH_NAME_PREFIX, _AUTOSTASH_WARN_AGE_DAYS, _discard_stashed_changes,
+ _AUTOSTASH_NAME_PREFIX, _AUTOSTASH_WARN_AGE_DAYS, _clear_pending_autostash,
+ _discard_stashed_changes,
_git_untracked_paths, _park_stashed_changes, _print_stash_cleanup_guidance,
_reject_unsafe_stash_restore, _resolve_stash_selector, _restore_stashed_changes,
_restored_python_paths, _stash_apply_failed_only_on_existing_untracked,
- _stash_local_changes_if_needed, _warn_orphaned_update_autostashes)
+ _stash_local_changes_if_needed, _surface_pending_autostash,
+ _warn_orphaned_update_autostashes)
from hermes_cli.update_cmd_config import ( # noqa: F401
_LAST_SIBLING_SNAPSHOTS, _check_and_apply_config_migration, _migrate_sibling_profile_configs,
_print_items, _reload_config_modules, _run_config_check_fresh, _run_migrate_config_fresh)
@@ -718,6 +720,10 @@ def _source_completion_request(opts, plan, snapshot_id, windows_resume, desktop,
def _complete_source_update(request: dict | None) -> None:
+ # Success boundary: completion must never be reported while this run's local
+ # patches sit unrestored and unnamed in the stash (#122557). No-op once the
+ # stash was restored, parked or discarded.
+ _surface_pending_autostash()
if request is None:
stop_for_relaunch(incomplete=True)
from copy import deepcopy
@@ -951,6 +957,7 @@ def _pull_updates(
if not update_succeeded:
print(f" ℹ️ Local changes preserved in stash (ref: {auto_stash_ref})")
print(" Restore manually with: git stash apply")
+ _clear_pending_autostash() # named just above; a later boundary must not repeat it
elif discard_local_changes:
# Non-interactive + updates.non_interactive_local_changes: discard.
_m()._discard_stashed_changes(git_cmd, _m().PROJECT_ROOT, auto_stash_ref)
@@ -1300,7 +1307,13 @@ def _current_branch_name(git_cmd, *, check: bool = False) -> str:
def _handle_update_called_process_error(
e, args, gateway_mode: bool, had_desktop_app_before_update: bool,
*, target_sha: str | None = None, target_repository: str | None = None, completion_request=None) -> None:
- """Git/installer failure: ZIP-fallback when safe, else report and ``sys.exit(1)``."""
+ """Git/installer failure: ZIP-fallback when safe, else report and ``sys.exit(1)``.
+
+ A stash created this run that no settle step touched is named first (#122557):
+ neither verdict below may leave the patches invisible in ``git stash list``, and
+ the ZIP fallback in particular goes on to report success.
+ """
+ _surface_pending_autostash()
stage = _format_update_failure_stage(e)
if _should_zip_fallback_on_update_error(e):
print(f"⚠ {stage}: {e}")
diff --git a/hermes_cli/update_cmd_stash.py b/hermes_cli/update_cmd_stash.py
index 7a76c7d2c69..c1225dbe570 100644
--- a/hermes_cli/update_cmd_stash.py
+++ b/hermes_cli/update_cmd_stash.py
@@ -26,6 +26,14 @@ _AUTOSTASH_WARN_AGE_DAYS = 7
_STASH_LEFT_IN_PLACE = " The stash was left in place. You can remove it manually after checking the result."
+#: This run's autostash while still unsettled: (stash ref, stashed path count).
+#: Set the moment the update stashes local patches; cleared as soon as they are
+#: restored, parked or discarded (_record_stash_disposition), when the failed-pull
+#: branch has already reported them, or when _surface_pending_autostash names them.
+#: Any update outcome reported while this is still set would claim the patches were
+#: handled when they were not (#122557).
+_pending_autostash: Optional[tuple[str, int]] = None
+
def _git_quiet(git_cmd: list[str], args: list[str], cwd: Path, **kwargs):
"""``subprocess.run`` of a git command with captured output; None when git cannot run."""
@@ -74,6 +82,7 @@ def _print_first_line(text: str) -> None:
def _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[str]:
+ global _pending_autostash
from hermes_cli.update_cmd_git import _git_run
status = _git_run(git_cmd, ["status", "--porcelain", "-z"], cwd, check=True)
if not status.stdout.strip():
@@ -120,6 +129,8 @@ def _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[st
# A partially-failed push also skips cleanup of TRACKED modifications; they'd break the following
# pull. Safe to reset: all is in the stash.
_reset_hard(git_cmd, cwd)
+ _pending_autostash = (
+ stash_ref, len([entry for entry in status.stdout.split("\0") if entry]))
return stash_ref
@@ -138,6 +149,35 @@ def _resolve_stash_selector(git_cmd: list[str], cwd: Path, stash_ref: str) -> Op
return None
+def _clear_pending_autostash() -> None:
+ """Forget this run's unsettled autostash after it was already reported (#122557)."""
+ global _pending_autostash
+ _pending_autostash = None
+
+
+def _surface_pending_autostash() -> bool:
+ """Loudly name this run's unsettled autostash; True when something was printed (#122557).
+
+ Called by every update outcome boundary (failure verdicts and the completion request)
+ so local patches parked mid-run can never be invisible in ``git stash list`` while the
+ command claims success or reports a bare failure. Deliberately separate from
+ ``_warn_orphaned_update_autostashes``, which surfaces leftovers from EARLIER runs by age.
+ """
+ global _pending_autostash
+ pending, _pending_autostash = _pending_autostash, None
+ if pending is None:
+ return False
+ stash_ref, file_count = pending
+ print()
+ print(f"! hermes update stashed {file_count} local modification(s) and could not restore them.")
+ print(" The install may be functional, but your local patches are NOT applied.")
+ print(f" Stash ref: {stash_ref}")
+ print(f" Review with: git stash show --stat {stash_ref}")
+ print(f" Re-apply with: git stash show -p {stash_ref} | git apply --3way")
+ print(f" Discard with: git stash drop {stash_ref}")
+ return True
+
+
def _warn_orphaned_update_autostashes(git_cmd: list[str], cwd: Path) -> int:
"""Print a notice for update autostashes older than the warn threshold; return the count (0 on any git failure).
@@ -191,6 +231,8 @@ def _record_stash_disposition(outcome: str, stash_ref: str, detail: str = "") ->
"""Note the autostash disposition in the update receipt so a parked stash is visible
to automation reading receipts instead of stdout (#115363: an update that ended with
local changes parked in the stash reported a bare success with no trace of them)."""
+ global _pending_autostash
+ _pending_autostash = None # this run's stash was reported: restored, parked or discarded
from hermes_cli.update_receipt import record_step
record_step(
"local_changes_stash",
@@ -315,6 +357,7 @@ def _reject_unsafe_stash_restore(
print(f" Your local changes remain preserved in stash: {stash_ref}")
print(f" Inspect them with: git stash show --stat {stash_ref}")
print(f" Restore manually after fixing them: git stash apply {stash_ref}")
+ _clear_pending_autostash() # reported loudly right above; not "silent" anymore
raise SystemExit(1)