Repository navigation
fix: report unmanaged Gateway restarts truthfully - #105241
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62108c5005
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const unmanagedPort = | ||
| (await readActiveGatewayLockPort().catch(() => undefined)) ?? managedRestartPort; |
There was a problem hiding this comment.
Honor explicit gateway port before lock metadata
When OPENCLAW_GATEWAY_PORT is set and an active unmanaged lock exists for the same profile, this now chooses the lock port instead of the explicit target. The public precedence is --port → OPENCLAW_GATEWAY_PORT → gateway.port (docs/gateway/index.md:104), and the TUI resolver skips active-lock lookup when an env/url target is present (src/tui/gateway-chat.ts:434-442). With this change, OPENCLAW_GATEWAY_PORT=19001 openclaw gateway restart can signal and health-check the old locked port, e.g. 18789, leaving the intended gateway untouched; only consult the lock when no explicit port target is present.
Useful? React with 👍 / 👎.
|
Land-ready proof:
Packaged after-proof will run from the exact landed |
|
Merged via squash.
|
`openclaw gateway stop` resolved the unmanaged fallback port from config and discovered pids through lsof only. On hosts without lsof, and whenever the gateway runs on a port other than the configured one, discovery came back empty and the command reported `Gateway service disabled.` with `ok:true` and exit 0 while the gateway kept serving. The gateway lock already holds the verified owner pid and port. Restart learned to read the lock port in openclaw#105241 to keep an unmanaged restart honest when the configured port drifts; stop's fallback never did. Read the lock identity once in the not-loaded fallback, use its port for discovery, and signal its owner when no listener is found. Verified listeners still win when lsof is available. Signalling still goes through `signalVerifiedGatewayPidSync`, which re-reads argv immediately before SIGTERM, and lock identities are only returned after a liveness and start-time or argv check, so dead, recycled, port-less and non-gateway lock owners are refused and the command stays `not-loaded`. Closes openclaw#72948
`openclaw gateway stop` resolved the unmanaged fallback port from config and discovered pids through lsof only. On hosts without lsof, and whenever the gateway runs on a port other than the configured one, discovery came back empty and the command reported `Gateway service disabled.` with `ok:true` and exit 0 while the gateway kept serving. The gateway lock already holds the verified owner pid and port. Restart learned to read the lock port in #105241 to keep an unmanaged restart honest when the configured port drifts; stop's fallback never did. Read the lock identity once in the not-loaded fallback, use its port for discovery, and signal its owner when no listener is found. Verified listeners still win when lsof is available. Signalling still goes through `signalVerifiedGatewayPidSync`, which re-reads argv immediately before SIGTERM, and lock identities are only returned after a liveness and start-time or argv check, so dead, recycled, port-less and non-gateway lock owners are refused and the command stays `not-loaded`. Closes #72948
…111378) `openclaw gateway stop` resolved the unmanaged fallback port from config and discovered pids through lsof only. On hosts without lsof, and whenever the gateway runs on a port other than the configured one, discovery came back empty and the command reported `Gateway service disabled.` with `ok:true` and exit 0 while the gateway kept serving. The gateway lock already holds the verified owner pid and port. Restart learned to read the lock port in openclaw#105241 to keep an unmanaged restart honest when the configured port drifts; stop's fallback never did. Read the lock identity once in the not-loaded fallback, use its port for discovery, and signal its owner when no listener is found. Verified listeners still win when lsof is available. Signalling still goes through `signalVerifiedGatewayPidSync`, which re-reads argv immediately before SIGTERM, and lock identities are only returned after a liveness and start-time or argv check, so dead, recycled, port-less and non-gateway lock owners are refused and the command stays `not-loaded`. Closes openclaw#72948
…111378) `openclaw gateway stop` resolved the unmanaged fallback port from config and discovered pids through lsof only. On hosts without lsof, and whenever the gateway runs on a port other than the configured one, discovery came back empty and the command reported `Gateway service disabled.` with `ok:true` and exit 0 while the gateway kept serving. The gateway lock already holds the verified owner pid and port. Restart learned to read the lock port in openclaw#105241 to keep an unmanaged restart honest when the configured port drifts; stop's fallback never did. Read the lock identity once in the not-loaded fallback, use its port for discovery, and signal its owner when no listener is found. Verified listeners still win when lsof is available. Signalling still goes through `signalVerifiedGatewayPidSync`, which re-reads argv immediately before SIGTERM, and lock identities are only returned after a liveness and start-time or argv check, so dead, recycled, port-less and non-gateway lock owners are refused and the command stays `not-loaded`. Closes openclaw#72948
Related: #105109
Follow-up to #105153
What Problem This Solves
Fixes two issues found during the exact-landed-main macOS CLI soak: restarting an unmanaged Gateway after editing
gateway.portcould miss the still-running process on its active port, and Crestodian could print a successfuldoneline and write a success audit when the daemon restart returnedfalse.Why This Change Was Made
Unmanaged restarts now use the live Gateway lock port for both verified process signaling and the post-restart health proof, preserving intentional CLI/environment port precedence. Managed service restarts retain the existing config-directed repair path. Crestodian treats a
falselifecycle result as a failed operation, so it neither reports nor audits success.User Impact
Foreground Gateways restart reliably even when config changed underneath their fixed runtime port, and Crestodian no longer claims a refused or incomplete restart succeeded. Managed LaunchAgent port repair behavior from #105153 is unchanged.
Evidence
main: aftergateway.portchanged from 18789 to 19001, Crestodian missed the active 18789 process and printed[crestodian] done: gateway.restartafterGateway service not loaded.tbx_01kxasbccc25549p43d36qex73: 107 focused lifecycle and Crestodian operation tests passed.pnpm check:test-types,pnpm lint --threads=8, andpnpm format:checkpassed.