Skip to content

fix: report unmanaged Gateway restarts truthfully - #105241

Merged
steipete merged 1 commit into
mainfrom
codex/crestodian-unmanaged-restart
Jul 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/crestodian-unmanaged-restart

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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.port could miss the still-running process on its active port, and Crestodian could print a successful done line and write a success audit when the daemon restart returned false.

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 false lifecycle 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

  • Live Golden Gate reproduction on current main: after gateway.port changed from 18789 to 19001, Crestodian missed the active 18789 process and printed [crestodian] done: gateway.restart after Gateway service not loaded.
  • Blacksmith Testbox tbx_01kxasbccc25549p43d36qex73: 107 focused lifecycle and Crestodian operation tests passed.
  • Same Testbox: pnpm check:test-types, pnpm lint --threads=8, and pnpm format:check passed.
  • Fresh structured autoreview: clean, correctness 0.91.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +344 to +345
const unmanagedPort =
(await readActiveGatewayLockPort().catch(() => undefined)) ?? managedRestartPort;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof:

  • Exact PR head 62108c5005654df2da88e653cca59abf35f7d664 is green in hosted CI.
  • Blacksmith Testbox tbx_01kxasbccc25549p43d36qex73: 107 focused lifecycle/Crestodian tests passed; test types, lint, and formatting passed.
  • Fresh structured autoreview found no actionable issue (correctness 0.91).
  • Golden Gate live before-proof reproduced the bug: an unmanaged Gateway running on its active CLI port was missed after gateway.port changed, and Crestodian reported a false done result.
  • Review artifacts validated with no findings; repo-native prepare-run passed using hosted exact-head gates.

Packaged after-proof will run from the exact landed main head before the Golden Gate source snapshot is released.

@steipete
steipete merged commit cc3dfc9 into main Jul 12, 2026
126 of 130 checks passed
@steipete
steipete deleted the codex/crestodian-unmanaged-restart branch July 12, 2026 09:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
steipete pushed a commit to masatohoshino/openclaw that referenced this pull request Jul 19, 2026
`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
steipete pushed a commit that referenced this pull request Jul 19, 2026
`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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 20, 2026
…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
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant