Repository navigation
Description
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.envwith entries for:
OPENCLAW_GATEWAY_TOKENTELEGRAM_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=18789Notably, it was missing:
EnvironmentFile=/home/.../.openclaw/openclaw.envAs 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:
- Install/configure OpenClaw with gateway auth token stored in
~/.openclaw/openclaw.env - Use config with
gateway.auth.token.source = envandid = OPENCLAW_GATEWAY_TOKEN - Run an OpenClaw update that restarts the systemd user gateway service, or restart that service after the update
- 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.envThen:
systemctl --user daemon-reload
systemctl --user reset-failed openclaw-gateway.service
systemctl --user restart openclaw-gateway.servicePost-fix verification
After adding EnvironmentFile and restarting:
systemctl --user is-active openclaw-gateway.service→activecurl http://127.0.0.1:18789/returned HTTP200openclaw gateway probereported:Reachable: yesCapability: 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_TOKENfrom env ~/.openclaw/openclaw.envcontains 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
- When installing/updating the systemd user gateway service, always include the OpenClaw env file via
EnvironmentFile=...if env-backed secrets are in use. - Validate the effective runtime environment during service installation/update, not just config serialization.
- Add a targeted preflight check that detects:
gateway.auth.token.source = env- missing runtime env injection in the service manager
- 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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 9, 2026
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:
canonicalCanonical: #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:
partial_overlap: Track generated gateway systemd unit provenance before update-time rewrites #80508 - This open maintainer-labeled issue tracks generated systemd unit provenance before update-time rewrites, which is a likely route for safe repair but is broader than env-backed token loading.partial_overlap: fix: track systemd unit provenance #81019 - This open conflicting PR is the candidate implementation for the broader provenance issue, not a merged fix for this issue's specific env-token restart failure.adjacent_distinct: Support using state-dir .env directly as Linux systemd EnvironmentFile #80595 - This open issue requests an opt-in direct state-dir .env EnvironmentFile mode, which is related credential-source policy but not the same update restart bug.partial_overlap: Bug: gateway service env renders Supermemory API key as literal env reference #88274 - This closed issue and its merged PR address literal shell-reference values in generated service env files, partially covering the latest comment but not the legacy unit update repair gap.partial_overlap: Bug: Gateway SecretRef Token Loss After WSL I/O Error — Gateway Unreachable #94552 - This closed WSL SecretRef outage report overlaps in auth-token availability symptoms but proposes a different fallback and does not own the systemd env-file update contract.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Ways to help us reproduce this
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:
Codex review notes: model internal, reasoning high; reviewed against c85113e30e2a.
Label changes
Label changes:
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:
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:
src/commands/doctor-gateway-services.ts:547, c85113e30e2a)src/commands/doctor-gateway-services.ts:547, c645ec4555c0)src/daemon/systemd.ts:851, c85113e30e2a)src/config/state-dir-dotenv.ts:35, c85113e30e2a)src/commands/doctor-gateway-services.test.ts:792, c85113e30e2a)Likely related people:
src/daemon/systemd.ts,src/daemon/systemd-unit.ts,src/daemon/systemd.test.ts)${...}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)src/daemon/systemd.ts)src/daemon/systemd.ts,src/gateway)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.[-]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[/+]LINSUISHENG034 commentedon Jun 21, 2026
I can confirm similar issues on my setup. After investigating, I found the current v2026.6.6 implementation uses
gateway.systemd.envwith properEnvironmentFileconfiguration, which works correctly.My working setup:
EnvironmentFile=-/home/lin/.openclaw/gateway.systemd.envWhat I observed in past updates:
The
gateway.systemd.envfile sometimes gets regenerated withOPENCLAW_GATEWAY_TOKEN=${OPENCLAW_GATEWAY_AUTH_TOKEN}(literal string). systemd'sEnvironmentFiledoes 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:
This is similar to the WSL2 case reported, but the root cause is that systemd's
EnvironmentFiledirective does not perform shell variable expansion.openclaw-barnacle commentedon Jul 6, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
openclaw-barnacle commentedon Jul 14, 2026
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.