openclaw - ✅(Solved) Fix gateway install can early-return already-installed while loaded LaunchAgent still embeds stale OPENCLAW_GATEWAY_TOKEN [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70752Fetched 2026-04-24 05:54:05
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

On macOS, openclaw gateway install can exit with Gateway service already loaded even when the currently loaded LaunchAgent still embeds a stale OPENCLAW_GATEWAY_TOKEN.

That leaves the machine stuck in a token_mismatch / unauthorized loop after a config token rotation or post-update auth change until the operator manually runs:

openclaw gateway install --force

This is a product bug in the non---force install path, not just an ops mistake.

Root Cause

On macOS, openclaw gateway install can exit with Gateway service already loaded even when the currently loaded LaunchAgent still embeds a stale OPENCLAW_GATEWAY_TOKEN.

That leaves the machine stuck in a token_mismatch / unauthorized loop after a config token rotation or post-update auth change until the operator manually runs:

openclaw gateway install --force

This is a product bug in the non---force install path, not just an ops mistake.

Fix Action

Fixed

PR fix notes

PR #70850: fix(gateway-install): refresh install when loaded service embeds stale OPENCLAW_GATEWAY_TOKEN (#70752)

Description (problem / solution / changelog)

Summary

Closes #70752.

After a token rotation (e.g. post-upgrade), the loaded LaunchAgent / systemd unit still embeds the old `OPENCLAW_GATEWAY_TOKEN`. Plain `openclaw gateway install` then returns `already-installed` and the machine is stuck in a `token_mismatch` loop until the operator remembers to re-run with `--force`.

Change

Mirror the existing NODE_EXTRA_CA_CERTS drift branch in `src/cli/daemon-cli/install.ts`. When:

  1. The service is loaded
  2. `--force` is not set
  3. The loaded service definition has an embedded `OPENCLAW_GATEWAY_TOKEN`
  4. The operator's current invocation environment has a different `OPENCLAW_GATEWAY_TOKEN`

...log `Gateway service embeds a stale OPENCLAW_GATEWAY_TOKEN; refreshing the install.` and fall through to the full install path instead of returning early.

Scope

Intentionally narrow:

  • Only fires when `process.env.OPENCLAW_GATEWAY_TOKEN` is set and differs from the embedded one. Absent or matching tokens keep the existing early-return — we don't want plain `openclaw gateway install` to silently rewrite the plist on every invocation.
  • `--force` path is untouched.
  • No changes to configure-time token resolution or to the systemd side (the same helper runs on both).

Test plan

  • `pnpm oxlint src/cli/daemon-cli/install.ts` → 0 warnings, 0 errors
  • Manual (macOS LaunchAgent): install with token A → rotate config to token B, set `OPENCLAW_GATEWAY_TOKEN=<B>` in shell, re-run `openclaw gateway install` → now sees the drift message + refreshes, instead of returning `already-installed`. With `OPENCLAW_GATEWAY_TOKEN` unset, behavior unchanged from main.

Changed files

  • src/cli/daemon-cli/install.ts (modified, +35/-0)

Code Example

openclaw gateway install --force

---

openclaw gateway install --force

---

Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install.

---

Gateway service is loaded but embeds stale gateway auth. Re-run with: openclaw gateway install --force

---

Gateway service already loaded.
Reinstall with: openclaw gateway install --force

---

openclaw gateway install

---

openclaw gateway install --force

---

const currentCommand = await service.readCommand(env)
if (readEmbeddedGatewayToken(currentCommand)) {
  return "Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install."
}
RAW_BUFFERClick to expand / collapse

Summary

On macOS, openclaw gateway install can exit with Gateway service already loaded even when the currently loaded LaunchAgent still embeds a stale OPENCLAW_GATEWAY_TOKEN.

That leaves the machine stuck in a token_mismatch / unauthorized loop after a config token rotation or post-update auth change until the operator manually runs:

openclaw gateway install --force

This is a product bug in the non---force install path, not just an ops mistake.

Concrete incident

Observed on 2026.4.21 after an upgrade on macOS LaunchAgent install.

What happened:

  1. Upgrade rotated the effective gateway auth token in ~/.openclaw/openclaw.json
  2. The existing LaunchAgent plist still had stale embedded gateway auth state
  3. A normal openclaw gateway install / updater flow saw the service was already loaded and returned early
  4. The plist was never refreshed
  5. Gateway itself was healthy, but app connections were rejected with reason=token_mismatch / unauthorized on every connect attempt

Recovery that worked:

openclaw gateway install --force

That regenerated the LaunchAgent plist from current config, restarted the gateway, and immediately restored authenticated RPC traffic.

Why this is the real bug

The service installer already has logic to auto-refresh a loaded service for certain drift states (for example the NODE_EXTRA_CA_CERTS refresh path).

But it does not auto-refresh when the currently loaded service definition still embeds OPENCLAW_GATEWAY_TOKEN.

In dist/install-*.js the non---force path effectively does:

  • if service is loaded
  • and the special TLS refresh case does not apply
  • return already-installed

So any repair/update automation that calls plain openclaw gateway install silently no-ops in exactly the state where the service definition most needs to be refreshed.

Expected behavior

If the currently loaded service definition still embeds OPENCLAW_GATEWAY_TOKEN, openclaw gateway install should auto-refresh the install instead of returning already-installed.

At minimum it should emit a warning like:

Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install.

or, if auto-refresh is not desired:

Gateway service is loaded but embeds stale gateway auth. Re-run with: openclaw gateway install --force

But the current silent early return is the dangerous behavior.

Actual behavior

openclaw gateway install returns success with:

Gateway service already loaded.
Reinstall with: openclaw gateway install --force

while the loaded LaunchAgent still contains stale embedded auth and the app is failing every connection attempt with token mismatch / unauthorized.

Repro sketch

  1. Install gateway as LaunchAgent on macOS
  2. Ensure the service definition embeds OPENCLAW_GATEWAY_TOKEN
  3. Change or rotate the effective gateway token in config / migration / update flow
  4. Keep the LaunchAgent loaded
  5. Run:
openclaw gateway install
  1. Observe that it exits early as already-installed
  2. Observe that the plist/service definition was not refreshed
  3. App/device connections fail with token mismatch until:
openclaw gateway install --force

Suggested fix

In the non---force install path, add an auto-refresh reason alongside the existing TLS CA refresh logic.

Pseudo-shape:

const currentCommand = await service.readCommand(env)
if (readEmbeddedGatewayToken(currentCommand)) {
  return "Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install."
}

Then continue through the normal reinstall path instead of returning already-installed.

Related issues

  • #62140
  • #53742
  • #54521
  • #29373

This issue is narrower / more actionable than the broader token-drift family: the specific failure is that the installer’s loaded-service fast path skips a clearly stale service definition.

extent analysis

TL;DR

To fix the issue where openclaw gateway install exits with Gateway service already loaded even when the currently loaded LaunchAgent still embeds a stale OPENCLAW_GATEWAY_TOKEN, modify the non---force install path to auto-refresh the install when a stale token is detected.

Guidance

  • Modify the dist/install-*.js file to check for the presence of a stale OPENCLAW_GATEWAY_TOKEN in the currently loaded service definition.
  • If a stale token is found, auto-refresh the install instead of returning already-installed.
  • Consider emitting a warning message to indicate that the install is being refreshed due to a stale token.
  • To verify the fix, test the openclaw gateway install command after rotating the gateway auth token and ensure that the LaunchAgent plist is updated correctly.

Example

const currentCommand = await service.readCommand(env)
if (readEmbeddedGatewayToken(currentCommand)) {
  console.warn("Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install.")
  // Continue with the normal reinstall path
}

Notes

This fix assumes that the readEmbeddedGatewayToken function is already implemented and can correctly detect the presence of a stale OPENCLAW_GATEWAY_TOKEN in the service definition.

Recommendation

Apply the suggested fix to modify the non---force install path to auto-refresh the install when a stale token is detected, as this will ensure that the LaunchAgent plist is updated correctly and prevent the token_mismatch / unauthorized loop.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

If the currently loaded service definition still embeds OPENCLAW_GATEWAY_TOKEN, openclaw gateway install should auto-refresh the install instead of returning already-installed.

At minimum it should emit a warning like:

Gateway service still embeds OPENCLAW_GATEWAY_TOKEN; refreshing the install.

or, if auto-refresh is not desired:

Gateway service is loaded but embeds stale gateway auth. Re-run with: openclaw gateway install --force

But the current silent early return is the dangerous behavior.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix gateway install can early-return already-installed while loaded LaunchAgent still embeds stale OPENCLAW_GATEWAY_TOKEN [2 pull requests, 1 participants]