mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(installer): never let a stale --commit pin roll an install backwards
hermes-setup.exe bakes its build-time commit into the binary (BUILD_PIN_COMMIT) and passes it as -Commit on every install-mode run, including the retry the desktop's "Update didn't finish" screen kicks off. The repository stage checked that SHA out unconditionally, so an installer built months earlier rewound a current managed checkout to its build commit -- 9,160 commits in the reported case -- leaving ancient source against a current venv. npm then failed on workspaces that did not exist yet at that commit, and every later update ran against the wrong tree. Skip the pin when its target is already an ancestor of HEAD. Fresh clones have no such ancestry so reproducible/CI pinning is unchanged, and --force-commit / -ForceCommit still rolls back on purpose.
This commit is contained in:
parent
fc551f9691
commit
b3daf1609c
3 changed files with 199 additions and 4 deletions
|
|
@ -22,6 +22,12 @@ param(
|
|||
# cloning the full default-branch history) and then `git checkout`s the
|
||||
# exact ref. Precedence: Commit > Tag > Branch.
|
||||
[string]$Commit = "",
|
||||
# Apply -Commit even when it would roll an existing install BACKWARDS.
|
||||
# Without this the repository stage skips a pin that is already an ancestor
|
||||
# of HEAD, so a stale baked-in BUILD_PIN_COMMIT can't downgrade a current
|
||||
# checkout. Reproducible/CI installs that genuinely want an older SHA on an
|
||||
# existing tree pass -ForceCommit.
|
||||
[switch]$ForceCommit,
|
||||
[string]$Tag = "",
|
||||
[string]$HermesHome = $(if ($env:HERMES_HOME) { $env:HERMES_HOME } else { "$env:LOCALAPPDATA\hermes" }),
|
||||
[string]$InstallDir = $(if ($env:HERMES_HOME) { "$env:HERMES_HOME\hermes-agent" } else { "$env:LOCALAPPDATA\hermes\hermes-agent" }),
|
||||
|
|
@ -1505,8 +1511,32 @@ function Install-Repository {
|
|||
# Make sure we have the commit locally (a tag-less commit
|
||||
# SHA isn't always reachable from any one branch fetch).
|
||||
git -c windows.appendAtomically=false fetch origin $Commit
|
||||
git -c windows.appendAtomically=false checkout --detach $Commit
|
||||
if ($LASTEXITCODE -ne 0) { throw "git checkout $Commit failed (exit $LASTEXITCODE)" }
|
||||
# A commit pin must never move an existing install
|
||||
# BACKWARDS. hermes-setup.exe bakes its build-time commit
|
||||
# into the binary (BUILD_PIN_COMMIT) and passes it as
|
||||
# -Commit on every install-mode run -- including the retry
|
||||
# the desktop's "Update didn't finish" screen kicks off. An
|
||||
# installer built months ago would otherwise rewind a
|
||||
# current checkout to its build commit, leaving ancient
|
||||
# code against a current venv (npm workspaces and Python
|
||||
# deps that no longer match: the #74xxx report). Skip the
|
||||
# pin when the target is already an ancestor of HEAD; a
|
||||
# fresh clone has no such ancestry and pins normally.
|
||||
$skipRollback = $false
|
||||
if (-not $ForceCommit) {
|
||||
git -c windows.appendAtomically=false merge-base --is-ancestor $Commit HEAD 2>$null
|
||||
$isAncestor = ($LASTEXITCODE -eq 0)
|
||||
$pinnedSha = (& git -c windows.appendAtomically=false rev-parse "$Commit^{commit}" 2>$null)
|
||||
$headSha = (& git -c windows.appendAtomically=false rev-parse HEAD 2>$null)
|
||||
$skipRollback = $isAncestor -and ($pinnedSha -ne $headSha)
|
||||
}
|
||||
if ($skipRollback) {
|
||||
Write-Warn "Ignoring -Commit $Commit`: the checkout is already newer."
|
||||
Write-Warn "Pinning to it would roll this install back. Pass -ForceCommit to override."
|
||||
} else {
|
||||
git -c windows.appendAtomically=false checkout --detach $Commit
|
||||
if ($LASTEXITCODE -ne 0) { throw "git checkout $Commit failed (exit $LASTEXITCODE)" }
|
||||
}
|
||||
} elseif ($Tag) {
|
||||
git -c windows.appendAtomically=false fetch origin "refs/tags/${Tag}:refs/tags/${Tag}"
|
||||
git -c windows.appendAtomically=false checkout --detach "refs/tags/$Tag"
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ SKIP_BROWSER=false
|
|||
NO_SKILLS=false
|
||||
BRANCH="main"
|
||||
INSTALL_COMMIT=""
|
||||
FORCE_COMMIT=false
|
||||
ENSURE_DEPS=""
|
||||
|
||||
MANIFEST_MODE=false
|
||||
|
|
@ -117,6 +118,10 @@ while [[ $# -gt 0 ]]; do
|
|||
INSTALL_COMMIT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--force-commit|-ForceCommit)
|
||||
FORCE_COMMIT=true
|
||||
shift
|
||||
;;
|
||||
--manifest|-Manifest)
|
||||
MANIFEST_MODE=true
|
||||
shift
|
||||
|
|
@ -165,6 +170,8 @@ while [[ $# -gt 0 ]]; do
|
|||
echo " 'hermes update' runs never inject bundled skills either"
|
||||
echo " --branch NAME Git branch to install (default: main)"
|
||||
echo " --commit SHA Pin checkout to a specific commit after clone/update"
|
||||
echo " (ignored when it would roll an existing install back)"
|
||||
echo " --force-commit Apply --commit even if it rolls the install backwards"
|
||||
echo " --manifest Print desktop bootstrap stage manifest as JSON"
|
||||
echo " --stage NAME Run one desktop bootstrap stage"
|
||||
echo " --json Print a JSON result frame for --stage"
|
||||
|
|
@ -1330,11 +1337,31 @@ EOF
|
|||
cd "$INSTALL_DIR"
|
||||
|
||||
if [ -n "$INSTALL_COMMIT" ]; then
|
||||
log_info "Pinning checkout to commit $INSTALL_COMMIT..."
|
||||
# A commit pin must never move an existing install BACKWARDS. The
|
||||
# bootstrap installer bakes its build-time commit into the binary
|
||||
# (BUILD_PIN_COMMIT) and passes it as --commit on every install-mode
|
||||
# run -- including the one the desktop's failure screen retries. An
|
||||
# installer built months ago would otherwise rewind a current checkout
|
||||
# to its build commit, stranding the user on ancient code with a
|
||||
# current venv. Only pin when the target is not already an ancestor of
|
||||
# HEAD; a fresh clone has no such ancestry and pins normally.
|
||||
if ! git cat-file -e "$INSTALL_COMMIT^{commit}" 2>/dev/null; then
|
||||
git fetch origin "$INSTALL_COMMIT" || true
|
||||
fi
|
||||
git checkout --detach "$INSTALL_COMMIT"
|
||||
if git rev-parse --verify --quiet HEAD >/dev/null 2>&1 \
|
||||
&& git merge-base --is-ancestor "$INSTALL_COMMIT" HEAD 2>/dev/null \
|
||||
&& [ "$(git rev-parse "$INSTALL_COMMIT^{commit}" 2>/dev/null)" != "$(git rev-parse HEAD)" ]; then
|
||||
if [ "$FORCE_COMMIT" = true ]; then
|
||||
log_warn "--force-commit: rolling this install back to $INSTALL_COMMIT."
|
||||
git checkout --detach "$INSTALL_COMMIT"
|
||||
else
|
||||
log_warn "Ignoring --commit $INSTALL_COMMIT: the checkout is already newer."
|
||||
log_warn "Pinning to it would roll this install back. Pass --force-commit to override."
|
||||
fi
|
||||
else
|
||||
log_info "Pinning checkout to commit $INSTALL_COMMIT..."
|
||||
git checkout --detach "$INSTALL_COMMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
log_success "Repository ready"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue