Repository navigation
fix: gateway stop throws when port is busy without identified owner - #126085
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 1:34 AM ET / 05:34 UTC. ClawSweeper reviewWhat this changesThe PR changes unmanaged Gateway stop to use the selected service’s configuration and to error when its configured port is busy or cannot be verified free without an identified Gateway owner. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThe exact PR head correctly scopes unowned-stop port and bind resolution to the selected service, fails safely on busy or indeterminate listeners, and includes focused regressions plus exact-head CLI evidence. Keep it open for current-main refresh and completion of exact-head checks. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway lifecycle commands resolve the installed service command and configuration before either signalling a verified Gateway process or reporting a state to the operator. The changed fallback runs when the service manager is not loaded and process ownership discovery finds no Gateway PID. flowchart LR
A[Gateway stop command] --> B[Service-manager status]
B -->|not loaded| C[Selected service context]
C --> D[Verified owner lookup]
D -->|owner found| E[Send stop signal]
D -->|no owner| F[Probe configured port]
F -->|free| G[Not-loaded result]
F -->|busy or unknown| H[Diagnostic error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests +24. Total +23 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge only after refreshing against current main confirms the scoped fallback remains intact and exact-head checks validate the busy, free, and indeterminate listener outcomes. Do we have a high-confidence way to reproduce the issue? Yes — the lifecycle source and regressions establish the no-owner fallback, and the PR body provides an exact-head CLI run with busy and free-port controls. Is this the best way to solve the issue? Yes — resolving configuration and probe hosts at the selected-service lifecycle boundary avoids downstream guesses and preserves the existing scoped host resolver. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f5553a8fee0e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
When `openclaw gateway stop` cannot find the owning process via lsof or the lock file, probe the port using gateway-configured bind hosts (resolveGatewayServiceProbeHosts) before reporting success. If the port is provably busy on a configured interface, throw with actionable guidance (`openclaw gateway status --deep`) instead of silently returning. Uses gateway-scoped probe hosts to avoid false positives from unrelated listeners on different interfaces (e.g. another process on 127.0.0.2 does not trigger an error when the gateway binds 127.0.0.1). Co-authored-by: Cursor <[email protected]>
The port probe in stopGatewayWithoutServiceManager passed an empty object to resolveGatewayServiceProbeHosts, causing it to read the caller's process.env instead of the selected service's command environment. A gateway running under a different profile or state directory was probed against the wrong bind configuration. Inline the probe logic from the deleted lifecycle-port-probe.ts wrapper into the lifecycle caller, which already resolves the service command and merged environment. Add regression coverage for the differing-context case. Production LOC: -19 (lifecycle.ts -1, deleted wrapper -18). Co-authored-by: Cursor <[email protected]>
resolveGatewayLifecycleContext used readBestEffortConfig() which always
reads config from process.env. When the selected service has a different
state directory with its own gateway.port, the stop path would probe the
caller's port instead, producing false "not loaded" results.
Use createConfigIO({ env: mergedEnv }) to load config through the merged
service environment — the same pattern resolveGatewayServiceProbeHosts
already uses for bind host resolution.
Compress mock infrastructure to stay within max-lines limits.
Production: net -3 lines. Tests: net +27 lines.
Co-authored-by: Cursor <[email protected]>
acc0107 to
782ec44
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Signed-off-by: sallyom <[email protected]>
|
Maintainer edit pushed in d0a51cc to address the latest review findings:
Focused tests, changed-path checks, and local autoreview passed. Exact-head Crabbox behavior proof is in progress; I’ll update the PR body with that result. |
|
Merged via squash.
|
|
Congratulations on your first merged OpenClaw contribution, @Schimuneck! Thanks for tracking this down and sticking with the review iterations. 🎉 🥳 |
…penclaw#126085) * fix: gateway stop throws when port is busy without identified owner When `openclaw gateway stop` cannot find the owning process via lsof or the lock file, probe the port using gateway-configured bind hosts (resolveGatewayServiceProbeHosts) before reporting success. If the port is provably busy on a configured interface, throw with actionable guidance (`openclaw gateway status --deep`) instead of silently returning. Uses gateway-scoped probe hosts to avoid false positives from unrelated listeners on different interfaces (e.g. another process on 127.0.0.2 does not trigger an error when the gateway binds 127.0.0.1). Co-authored-by: Cursor <[email protected]> * fix: thread selected service context into gateway stop port probe The port probe in stopGatewayWithoutServiceManager passed an empty object to resolveGatewayServiceProbeHosts, causing it to read the caller's process.env instead of the selected service's command environment. A gateway running under a different profile or state directory was probed against the wrong bind configuration. Inline the probe logic from the deleted lifecycle-port-probe.ts wrapper into the lifecycle caller, which already resolves the service command and merged environment. Add regression coverage for the differing-context case. Production LOC: -19 (lifecycle.ts -1, deleted wrapper -18). Co-authored-by: Cursor <[email protected]> * fix: load gateway port from selected service config for stop probe resolveGatewayLifecycleContext used readBestEffortConfig() which always reads config from process.env. When the selected service has a different state directory with its own gateway.port, the stop path would probe the caller's port instead, producing false "not loaded" results. Use createConfigIO({ env: mergedEnv }) to load config through the merged service environment — the same pattern resolveGatewayServiceProbeHosts already uses for bind host resolution. Compress mock infrastructure to stay within max-lines limits. Production: net -3 lines. Tests: net +27 lines. Co-authored-by: Cursor <[email protected]> * fix(gateway): harden unowned stop verification Signed-off-by: sallyom <[email protected]> --------- Signed-off-by: sallyom <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: sallyom <[email protected]>
Fixes #119065
What Problem This Solves
openclaw gateway stopsilently reports success when neitherlsofnor the gateway lock file can identify the owning process—even when the configured port is provably in use. This happens in minimal containers (distroless, Alpine) that lacklsofand when the lock file is stale or missing.Additionally, the port probe resolver and config reader both used the caller's
process.envinstead of the selected service's command environment. A gateway running under a different profile or state directory was probed against the wrong bind configuration and wrong port, producing either a false "not loaded" or a spurious "busy port" error.Why This Change Was Made
The prior implementation had two separate context bugs:
resolveGatewayServiceProbeHostswas called with{}, falling back to caller's env.readBestEffortConfig()always reads fromprocess.env. When a service's port is set only in its own state-dir config (not via--port), the probe used the caller's port.Both are now fixed: the selected service's merged environment is passed to both
resolveGatewayServiceProbeHosts(for bind hosts) andcreateConfigIO({ env })(for port config), matching the canonical pattern already used by the probe hosts resolver.User Impact
gateway stopnow correctly detects a busy port when the owning process can't be identified, providing a diagnostic error instead of silently reporting "not loaded."Evidence
Real behavior proof — port resolution divergence
Production code trace using actual
createConfigIO,mergeGatewayServiceEnv,resolveGatewayPort, andresolveGatewayServiceProbeHosts. A service command points to a state directory containing{"gateway":{"port":19500}}with no--portarg:The trace calls the same production functions that
resolveGatewayLifecycleContextcalls atlifecycle.ts:115-127. The old behavior (readBestEffortConfig()→process.env→ default port 18789) and the new behavior (createConfigIO({ env: mergedEnv })→ service config → port 19500) diverge when a service-specific state directory contains a differentgateway.port.Unit tests — 44 passed (verbose output)
Key regression test: "resolves port and probe hosts from selected service config/env (no --port arg)" sets up a service command with
OPENCLAW_STATE_DIRbut no--port, mocksresolveGatewayPortto return 19000 for that env, and verifies:createConfigIOreceives{ env: { OPENCLAW_STATE_DIR: "/tmp/service-state", ... } }resolveGatewayServiceProbeHostsreceives{ command: serviceCommand }probePortUsageprobes port 19000 (not 18789)Checks — all green
LOC delta
Root cause
readBestEffortConfig()callscreateConfigIO({})with no env parameter, defaulting toprocess.env. When the selected service hasOPENCLAW_STATE_DIR=/custom/pathin its command environment,gateway.portfrom that state dir's config was never read. The fix usescreateConfigIO({ env: mergedEnv, pluginValidation: "skip", suppressFutureVersionWarning: true })— the same patternresolveGatewayServiceProbeHostsalready uses atgateway-service-probe-hosts.ts:16-22.Real CLI behavior proof — Linux (Crabbox)
Tested the exact public PR head
d0a51cc2fac6505f470d50432afc84b2a5e2b575.awscbx_e3b48dd347f6(jade-barnacle)CIeligible for forwardinggit rev-parse HEADexactly matched the public PR SHA before executing PR codepnpm buildpassednode openclaw.mjs gateway stop --json --forcepr126085proof; port39501Observed controls:
This proves the exact public revision fails closed when the configured port is busy but no verified Gateway owner can be found, while preserving the successful
not-loadedresult when the port is actually free. The one-shot lease terminated successfully after the run (leaseStopped: true).