Skip to content

systemd gateway service can fail to restart after update when env-backed gateway auth token is not loaded #91554

Closed as not planned

Description

@jeremyosga-cmyk

Summary

After an OpenClaw update, a Linux/WSL install using the systemd user gateway service can enter a failed restart loop because the service process does not receive OPENCLAW_GATEWAY_TOKEN, even though the token exists in ~/.openclaw/openclaw.env and the config correctly references it via gateway.auth.token.

In the observed case, the issue surfaced immediately after the OpenClaw update path restarted the gateway service. The failure mode is severe because the local dashboard and WebSocket gateway stay down (ECONNREFUSED) until the unit is manually corrected and restarted.

Environment

  • Platform: Linux under WSL2
  • Node: 22.22.2
  • OpenClaw: 2026.6.1
  • Service mode: systemd --user
  • Gateway bind: 127.0.0.1
  • Gateway port: 18789
  • Config path: ~/.openclaw/openclaw.json
  • Service unit: ~/.config/systemd/user/openclaw-gateway.service

Trigger context

The failure was observed after an OpenClaw update, when the update path restarted the systemd user gateway service.

Relevant restart-log entries:

[2026-06-09T00:44:23Z] openclaw restart attempt source=update target=openclaw-gateway.service
[2026-06-09T00:44:23Z] openclaw restart done source=update

Immediately after that update/restart cycle, the service failed to come back and entered repeated startup failures.

Symptom

The gateway service repeatedly exits with status 1 and eventually lands in:

  • Active: failed (Result: exit-code)
  • Start request repeated too quickly

Connectivity symptoms:

  • WebSocket probe fails with connect ECONNREFUSED 127.0.0.1:18789
  • local dashboard is unavailable until the unit is fixed

Relevant config

The OpenClaw config resolves gateway auth from an environment variable:

"gateway": {
  "auth": {
    "mode": "token",
    "token": {
      "source": "env",
      "provider": "default",
      "id": "OPENCLAW_GATEWAY_TOKEN"
    }
  }
}

The token itself existed in the env file used by the local install:

~/.openclaw/openclaw.env

with entries for:

  • OPENCLAW_GATEWAY_TOKEN
  • TELEGRAM_BOT_TOKEN

Observed failure

Journal output showed the root cause clearly:

SecretRefResolutionError: Environment variable "OPENCLAW_GATEWAY_TOKEN" is missing or empty.
Gateway failed to start: Startup failed: required secrets are unavailable.

A generated stability bundle captured the same failure:

{
  "reason": "gateway.startup_failed",
  "error": {
    "message": "Startup failed: required secrets are unavailable. SecretRefResolutionError: Environment variable \"OPENCLAW_GATEWAY_TOKEN\" is missing or empty."
  }
}

Why this is surprising

The token was present on disk in ~/.openclaw/openclaw.env, and the config was explicitly set to resolve the token from env. The problem was not missing secret material. The problem was that the systemd unit did not actually load the env file into the service process.

The fact that this surfaced immediately after an update/restart cycle makes it look like the update path may preserve or regenerate a unit shape that is inconsistent with the configured secret source.

Faulty unit shape

The installed service unit had inline Environment= entries, but did not load the OpenClaw env file containing OPENCLAW_GATEWAY_TOKEN.

Representative shape:

[Service]
ExecStart=/usr/bin/node /home/.../.npm-global/lib/node_modules/openclaw/dist/index.js gateway --port 18789
Restart=always
...
Environment=HOME=/home/...
Environment=TMPDIR=/tmp
Environment=PATH=/usr/bin:...
Environment=OPENCLAW_GATEWAY_PORT=18789

Notably, it was missing:

EnvironmentFile=/home/.../.openclaw/openclaw.env

As a result, the service process had no OPENCLAW_GATEWAY_TOKEN in its environment and secret resolution failed during startup.

Reproduction outline

I cannot guarantee these are the only triggering steps, but the failure was reproducible in the following shape:

  1. Install/configure OpenClaw with gateway auth token stored in ~/.openclaw/openclaw.env
  2. Use config with gateway.auth.token.source = env and id = OPENCLAW_GATEWAY_TOKEN
  3. Run an OpenClaw update that restarts the systemd user gateway service, or restart that service after the update
  4. Observe startup failure because the service runtime does not load the env file

Manual fix that restored the service

Adding the env file to the systemd unit fixed the problem immediately:

EnvironmentFile=/home/jerem/.openclaw/openclaw.env

Then:

systemctl --user daemon-reload
systemctl --user reset-failed openclaw-gateway.service
systemctl --user restart openclaw-gateway.service

Post-fix verification

After adding EnvironmentFile and restarting:

  • systemctl --user is-active openclaw-gateway.service → active
  • curl http://127.0.0.1:18789/ returned HTTP 200
  • openclaw gateway probe reported:
    • Reachable: yes
    • Capability: admin-capable
    • local loopback connect OK

The gateway returned to a healthy state with no further secret-resolution startup failures.

Expected behavior

If OpenClaw installs or manages a systemd user gateway service while gateway auth is configured from env, the generated unit should reliably load the env source used by the install, or otherwise materialize the required secret into the runtime environment in a consistent way.

That guarantee should continue to hold across update-triggered service restarts.

At minimum, the service should not be generated in a state where:

  • config expects OPENCLAW_GATEWAY_TOKEN from env
  • ~/.openclaw/openclaw.env contains the token
  • an OpenClaw update restarts the service
  • but the systemd unit does not load that env file

Actual behavior

After an OpenClaw update/restart cycle, the generated/installed service can start in a broken configuration where the token exists on disk but is unavailable to the systemd service process, causing the gateway to fail hard at startup.

Possible fix directions

  1. When installing/updating the systemd user gateway service, always include the OpenClaw env file via EnvironmentFile=... if env-backed secrets are in use.
  2. Validate the effective runtime environment during service installation/update, not just config serialization.
  3. Add a targeted preflight check that detects:
    • gateway.auth.token.source = env
    • missing runtime env injection in the service manager
  4. Improve the service installer/updater to keep secret source wiring consistent across updates.

Notes

This report intentionally omits personal identifiers and secret values. The issue is about service/env wiring after update-triggered restart behavior, not the token contents.

Activity

  1. clawsweeper commented on Jun 9, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 9:02 AM ET / 13:02 UTC.

    Summary
    Keep open: current main and v2026.6.9 have improved fresh/forced systemd installs and stale literal env-reference cleanup, but update-mode doctor still deliberately leaves live Linux systemd units unchanged, so a legacy or drifted unit missing the needed EnvironmentFile can survive an update-triggered restart.

    Reproducibility: no. live high-confidence WSL2 reproduction was run in this read-only review. Source inspection does show the remaining update-mode path still leaves live Linux systemd units unchanged, which preserves the reported failure shape for legacy or drifted units.

    Root-cause cluster
    Relationship: canonical
    Canonical: #91554
    Summary: This issue is the best current canonical report for the env-backed gateway auth token missing after update-triggered systemd restart; related items cover broader provenance or narrower literal-reference behavior.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.
    • Include redacted logs or terminal output.

    Next step
    Manual review is needed because the remaining repair requires a maintainer decision about safe update-mode systemd rewrite/provenance and the credential env-file contract.

    Security
    Needs attention: The issue is security-sensitive because the remaining fix changes how gateway auth tokens are carried into a supervised process during upgrades.

    Review details

    Best possible solution:

    Keep the current generated-env-file and literal-reference protections, then add a maintainer-approved update/doctor path that safely repairs legacy env-backed gateway service units without overwriting operator-owned systemd directives.

    Do we have a high-confidence way to reproduce the issue?

    No live high-confidence WSL2 reproduction was run in this read-only review. Source inspection does show the remaining update-mode path still leaves live Linux systemd units unchanged, which preserves the reported failure shape for legacy or drifted units.

    Is this the best way to solve the issue?

    Unclear until maintainers choose the service-update contract. Fresh and forced installs have the right generated-env-file direction, but the best remaining fix needs safe update-mode migration or generated-unit provenance rather than an unconditional rewrite.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The exact WSL2 update/restart failure was not live-reproduced in this read-only pass; the remaining confidence comes from source and test behavior.
    • Automatically correcting legacy or modified systemd units would touch a credential and operator-owned service boundary, so maintainers need to choose the safe migration/provenance contract before a fix ships.

    Codex review notes: model internal, reasoning high; reviewed against c85113e30e2a.

    Label changes

    Label changes:

    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority Linux/WSL gateway service bug with real outage impact but limited platform scope and no confirmed current-main live repro.
    • impact:security: The issue concerns how a gateway auth token is delivered to a supervised service process without exposing or dropping credential material.
    • impact:auth-provider: The failure is a SecretRef/env-backed auth-token resolution problem that prevents the gateway from authenticating correctly at startup.
    • impact:crash-loop: The reported service exits repeatedly under systemd until the unit env-file wiring is manually repaired.
    Evidence reviewed

    Security concerns:

    • [medium] Settle credential env-file upgrade contract
      A repair must avoid both dropping env-backed gateway tokens and silently overwriting operator-owned systemd directives that may protect local credential handling.
      Confidence: 0.84

    What I checked:

    • Current main still defers update-mode Linux systemd service rewrites: The doctor repair path returns after noting that update-mode systemd drift was left unchanged, so it will not automatically repair a live legacy unit that lacks the generated env file. (src/commands/doctor-gateway-services.ts:547, c85113e30e2a)
    • Latest release has the same deferral behavior: The v2026.6.9 tag contains the same update-mode deferral block, so the remaining update-time repair gap is not solved in the latest release. (src/commands/doctor-gateway-services.ts:547, c645ec4555c0)
    • Fresh/forced systemd staging now writes generated env files: Current staging reads the state-dir dotenv, writes a generated gateway systemd env file, and passes that file to the unit renderer; this helps new or forced installs but does not override the update-mode deferral above. (src/daemon/systemd.ts:851, c85113e30e2a)
    • Current parser skips unresolved shell references: Current main skips whole-value unresolved shell references from state-dir dotenv parsing, which addresses the latest comment's literal-reference class when the service is re-staged. (src/config/state-dir-dotenv.ts:35, c85113e30e2a)
    • Regression tests cover EnvironmentFile parsing and stale literal cleanup: Tests verify systemd EnvironmentFile token loading and stale literal-reference removal on re-stage, but the doctor tests still assert update-mode systemd repairs are deferred rather than automatically applied. (src/commands/doctor-gateway-services.test.ts:792, c85113e30e2a)
    • Related canonical provenance work remains open: The broader systemd unit provenance issue is still open, and its candidate PR is open but conflicting, so it cannot be treated as a merged fix for this report.

    Likely related people:

    • tmimmanuel: Authored the merged systemd repair change that moved dotenv-sourced secrets such as OPENCLAW_GATEWAY_TOKEN from inline Environment entries into a generated EnvironmentFile. (role: original generated-env-file contributor; confidence: high; commits: a2ab9e6a8e4c; files: src/daemon/systemd.ts, src/daemon/systemd-unit.ts, src/daemon/systemd.test.ts)
    • Alix-007: Authored the merged unresolved shell-reference fix that is directly related to the latest comment's literal ${...} EnvironmentFile failure mode. (role: recent env-file safety contributor; confidence: high; commits: 909c24e3b70d; files: src/config/state-dir-dotenv.ts, src/daemon/systemd.ts, src/daemon/systemd.test.ts)
    • Peter Steinberger: Authored earlier env-file auth provenance work and provided maintainer review context for the related shell-reference fix, so this person is a strong route for the service auth/update contract decision. (role: recent area contributor and product reviewer; confidence: medium; commits: a2cb80b9c4be; files: src/daemon/systemd.ts)
    • Josh Avant: Authored shared auth hardening across systemd and related gateway runtime surfaces, adjacent to the env-backed gateway auth behavior under review. (role: adjacent auth/runtime contributor; confidence: medium; commits: 25252ab5ab15; files: src/daemon/systemd.ts, src/gateway)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. changed the title [-]systemd gateway service can fail to start when secret-backed gateway auth token is not loaded into the service environment[/-] [+]systemd gateway service can fail to restart after update when env-backed gateway auth token is not loaded[/+] on Jun 9, 2026
  3. added
    P2Normal backlog priority with limited blast radius.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on Jun 9, 2026
  4. added
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    on Jun 19, 2026
  5. LINSUISHENG034 commented on Jun 21, 2026

    @LINSUISHENG034

    I can confirm similar issues on my setup. After investigating, I found the current v2026.6.6 implementation uses gateway.systemd.env with proper EnvironmentFile configuration, which works correctly.

    My working setup:

    • OpenClaw 2026.6.6 (8c802aa)
    • Linux 5.15.0-131-generic
    • systemd user service with EnvironmentFile=-/home/lin/.openclaw/gateway.systemd.env
    • Gateway auth token configured as env SecretRef

    What I observed in past updates:
    The gateway.systemd.env file sometimes gets regenerated with OPENCLAW_GATEWAY_TOKEN=${OPENCLAW_GATEWAY_AUTH_TOKEN} (literal string). systemd's EnvironmentFile does NOT expand ${...} references, causing the gateway to receive the literal string instead of the actual token value.

    Current workaround that works:
    After each update, verify and fix if needed:

    # Check if token has literal ${...}
    grep "OPENCLAW_GATEWAY_TOKEN=\${" ~/.openclaw/gateway.systemd.env
    
    # If found, substitute with actual value
    AUTH_TOKEN=$(grep OPENCLAW_GATEWAY_AUTH_TOKEN ~/.openclaw/gateway.systemd.env | cut -d= -f2)
    sed -i "s|^OPENCLAW_GATEWAY_TOKEN=.*|OPENCLAW_GATEWAY_TOKEN=${AUTH_TOKEN}|" ~/.openclaw/gateway.systemd.env
    systemctl --user restart openclaw-gateway.service

    This is similar to the WSL2 case reported, but the root cause is that systemd's EnvironmentFile directive does not perform shell variable expansion.

  6. openclaw-barnacle commented on Jul 6, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  7. openclaw-barnacle commented on Jul 14, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.

  8. locked as resolved and limited conversation to collaborators on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions