diff --git a/docker/stage2-hook.sh b/docker/stage2-hook.sh index 6165eedf19..a07b8eec31 100755 --- a/docker/stage2-hook.sh +++ b/docker/stage2-hook.sh @@ -470,6 +470,29 @@ if [ -f "$HERMES_HOME/.env" ]; then fi fi +# --- Grant the gateway access to the Fly Machines API socket (scale-to-zero) --- +# On Fly, flyd mounts the local Machines API ("flaps") unix socket at /.fly/api +# owned root:root 0755. The gateway's scale-to-zero self-suspend +# (gateway/scale_to_zero.py suspend_self) must POST to it, but the gateway runs +# as the unprivileged `hermes` user — without this it gets EACCES on every +# suspend attempt and the machine can never sleep (fail-awake; verified live on +# staging 2026-08-20: "flaps suspend request failed: [Errno 13]"). This hook +# runs as root before user services (the gateway) start, so grant group access +# here. Scope note: group-write exposes the WHOLE local Machines API to the +# hermes group (any group member could e.g. stop/suspend this machine), not +# just the suspend endpoint — accepted because the agent already executes +# arbitrary user code as that same principal and the socket only controls THIS +# machine. No-op off Fly (socket absent). +if [ -S /.fly/api ]; then + if refuse_symlinked_path "chgrp/chmod" /.fly/api; then + : + elif chgrp hermes /.fly/api 2>/dev/null && chmod g+w /.fly/api 2>/dev/null; then + echo "[stage2] Granted hermes group access to the Fly Machines API socket" + else + echo "[stage2] Warning: could not grant group access to /.fly/api — scale-to-zero self-suspend will fail EACCES (fail-awake)" + fi +fi + # --- Migrate persisted config schema --- # Docker image upgrades replace the code under $INSTALL_DIR but preserve # $HERMES_HOME on the mounted volume. Run the same safe, non-interactive