fix(update): scope install-method stamp to the code tree, not $HERMES_HOME (#48188)

The install method (docker/git/pip/...) describes the *running binary*, but
detect_install_method() read it from $HERMES_HOME/.install_method — a shared
DATA directory. The Docker docs deliberately bind-mount $HERMES_HOME
(~/.hermes:/opt/data) so config/sessions/memory persist and can be shared with
a host-side Desktop/CLI install.

When a containerized gateway and a host install share one $HERMES_HOME, the
home-scoped stamp is a single slot describing two installs: the published image
stamps 'docker' on every boot, the host install then reads 'docker' and the
in-app updater refuses to run 'hermes update' ("doesn't apply inside the Docker
container"). Reinstalling the Desktop app from the DMG doesn't help because the
contaminated stamp is re-read every time.

Fix (option 1 — code-scoped stamp):
- detect_install_method() reads <install tree>/.install_method first (next to
  the running code, immune to the shared data dir). It falls back to the legacy
  $HERMES_HOME stamp for back-compat, but IGNORES a 'docker' home stamp when
  not actually containerized — so already-poisoned shared homes self-heal.
- stamp_install_method() writes the code-scoped stamp.
- install.sh stamps $INSTALL_DIR instead of $HERMES_HOME.
- Dockerfile bakes 'docker' into /opt/hermes/.install_method at build time
  (inside the immutable block); stage2-hook.sh no longer writes the home stamp
  and proactively removes a stale 'docker' one to heal existing shared homes.

Genuine containers still resolve to 'docker' (baked stamp, or legacy home stamp
honored when containerized). Unstamped installs in generic containers still fall
through to git/pip (preserves the #34397 fix).
This commit is contained in:
Ben Barclay 2026-06-18 14:14:41 +10:00 committed by GitHub
parent 3769dff5dd
commit 4440d77bf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 352 additions and 34 deletions

View file

@ -2732,7 +2732,12 @@ run_stage_body() {
detect_os
resolve_install_layout
print_success
echo "git" > "$HERMES_HOME/.install_method"
# Code-scoped stamp: write next to the install tree, not into
# $HERMES_HOME. $HERMES_HOME is a shared data dir (it can be
# bind-mounted into a Docker gateway too), so a stamp there gets
# clobbered by the container's 'docker' stamp and wrongly blocks
# 'hermes update' on this host install. See detect_install_method().
echo "git" > "$INSTALL_DIR/.install_method"
;;
*)
log_error "Unknown stage: $stage"
@ -2811,7 +2816,12 @@ main() {
print_success
echo "git" > "$HERMES_HOME/.install_method"
# Code-scoped stamp: write next to the install tree, not into $HERMES_HOME.
# $HERMES_HOME is a shared data dir (it can be bind-mounted into a Docker
# gateway too), so a stamp there gets clobbered by the container's 'docker'
# stamp and wrongly blocks 'hermes update' on this host install.
# See detect_install_method().
echo "git" > "$INSTALL_DIR/.install_method"
}
if [ "$MANIFEST_MODE" = true ]; then