Skip to content

fix(gateway): detect Docker/Podman containers for /restart service path - #25264

Closed
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/docker-restart-service-path
Closed

fix(gateway): detect Docker/Podman containers for /restart service path#25264
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/docker-restart-service-path

Conversation

@zccyman

@zccyman zccyman commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

The /restart gateway command only detected systemd (INVOCATION_ID) when choosing between the detached-subprocess and service-restart approaches. In Docker/Podman containers, the detached subprocess approach fails because the container stops when PID 1 exits, killing the helper before it can restart anything.

Problem

In a Docker container (e.g. nousresearch/hermes-agent:latest on Unraid):

  1. User sends /restart
  2. Gateway exits to spawn a detached restart helper
  3. tini (PID 1) exits because the gateway exited
  4. Docker stops the container
  5. The detached helper is killed before it can restart anything
  6. Gateway stays dead until manually restarted

Fix

Detect Docker (/.dockerenv) and Podman (/run/.containerenv) alongside systemd. In container environments, use the service restart path (exit code 75) instead of the detached subprocess approach. Combined with a restart policy (unless-stopped or on-failure), Docker/Podman handles the restart correctly.

_under_service = bool(
    os.environ.get("INVOCATION_ID")       # systemd
    or os.path.isfile("/.dockerenv")       # Docker
    or os.path.isfile("/run/.containerenv") # Podman
)

Testing

  • All 132 gateway restart-related tests pass

Files Changed

File Change
gateway/run.py Added Docker/Podman detection to _under_service check

Closes #25217

The /restart command only detected systemd (via INVOCATION_ID) when
choosing between the detached-subprocess and service-restart approaches.
In Docker/Podman containers, the gateway runs as PID 1 under tini or
directly, and the detached subprocess restart fails because the container
stops when PID 1 exits, killing the detached helper before it can
restart anything.

Fix: Detect Docker (/.dockerenv) and Podman (/run/.containerenv) alongside
systemd. In container environments, use the service restart path (exit
code 75) so the container restart policy (unless-stopped / on-failure)
handles the restart.

Closes NousResearch#25217
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/docker Docker image, Compose, packaging labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #25219 — same fix (Docker/Podman container detection for /restart service path) targeting the same file gateway/run.py and closing the same issue #25217. Also competes with #25263.

@zccyman

zccyman commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @alt-glitch for the catch. Closing as duplicate of #25219 — same Docker/Podman detection fix for the same file and issue #25217. Also competing with #25263. 🙏

@zccyman zccyman closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docker Docker image, Compose, packaging comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/restart shuts down gateway instead of restarting in Docker containers

2 participants