#9460: fix(gateway): clean up lock file on service stop
cli
commands
stale
Cluster:
Gateway and Session Fixes
## Problem
Running `openclaw gateway stop` then `openclaw gateway run` fails with:
The lock file persists after service stop, causing stale PID detection.
## Solution
Delete the gateway lock file in `runDaemonStop()` after stopping the service.
## Changes
- `src/infra/gateway-lock.ts`: Export `resolveGatewayLockPath()` for reuse
- `src/cli/daemon-cli/lifecycle.ts`: Delete lock file after service stop
Fixes #9434
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes a stale gateway lock scenario by exporting `resolveGatewayLockPath()` from `src/infra/gateway-lock.ts` and using it in `runDaemonStop()` to delete the lock file after stopping the gateway service.
It also adds user-facing warnings when URLs include the gateway token (dashboard/onboarding), and updates `withTimeout()` to treat AbortErrors as a fallback condition (with new unit tests).
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe but needs a stop/lock ordering fix to avoid concurrency issues.
- The lock-file cleanup addresses a real usability issue, but removing the lock immediately after `service.stop()` can reintroduce a race where a second gateway instance starts before the service has fully exited. The rest of the changes are straightforward and covered by tests for the timeout behavior.
- src/cli/daemon-cli/lifecycle.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11147: fix(daemon): stop gateway by port when no daemon service is active
by jasonthewhale · 2026-02-07
81.3%
#10259: fix(sessions): clean up orphaned .jsonl.lock files on startup (#10170)
by nu-gui · 2026-02-06
80.1%
#17835: Fix misleading gateway stop hints for standalone listeners
by ConnorCallison · 2026-02-16
79.3%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
78.3%
#7155: fix(gateway): use kill SIGTERM instead of bootout for stop
by rafaelreis-r · 2026-02-02
78.3%
#23760: fix(gateway-lock): use port binding as primary liveness signal
by Operative-001 · 2026-02-22
77.6%
#23584: fix(daemon): improve gateway service detection to avoid false posit...
by mohandshamada · 2026-02-22
77.3%
#15903: fix(doctor): stricter gateway service detection to prevent false po...
by Shuai-DaiDai · 2026-02-14
77.2%
#22804: fix: prioritize loopback for internal gateway calls (issue #22706)
by ambicuity · 2026-02-21
77.0%
#13084: fix(daemon): multi-layer defense against zombie gateway processes
by openperf · 2026-02-10
77.0%