Skip to content

fix(setup): recognize the gateway service on its own port after install - #1349

Closed
steipete wants to merge 6 commits into
mainfrom
codex/setup-port-self-conflict
Closed

steipete wants to merge 6 commits into
mainfrom
codex/setup-port-self-conflict

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem and root cause

Local Windows gateway setup can reject the gateway it just installed. The initial Windows port preflight succeeds, openclaw gateway install --force starts the WSL user service, and the later WSL check sees the now-occupied port. Main accepts that listener only when ss output contains openclaw; the real gateway process can be named node, so setup reports a foreign listener and may roll back.

This preserves the core diagnosis from Peter Steinberger and supersedes #1334 by @Elliot-Construct. #1334 correctly reproduced the bug but removed the post-install ownership check entirely. Closed #547 identified the node process-name case, but a blanket process-name exemption would also accept unrelated Node.js servers.

Fix

  • query the exact configured listener with ss -H -ltnp 'sport = :<port>'
  • compare every reported listener PID with the positive systemd user-service MainPID
  • accept the listener only when ownership is proven, not from a process name substring
  • fail closed for missing ownership, mixed owners, invalid MainPID, or inspection failure
  • include available process names in genuine conflict diagnostics
  • preserve the existing start and health-wait flow after ownership succeeds

The root CHANGELOG.md added by the original patch was removed because this repository has no owned changelog convention. The existing setup architecture documentation remains updated.

Relationship to #1344

#1344 is an independent runtime reconnect P0. It concerns an unbounded ClientWebSocket.ConnectAsync HTTP-upgrade wait after a Gateway restart. #1349 concerns setup-time WSL listener ownership after service installation. They can produce adjacent “Gateway did not come back” symptoms, but #1349 does not fix or close #1344.

Required proof pools

  • windows-wsl-gateway-e2e: verified on current head by real managed WSL service ownership and foreign-listener rejection tests in GitHub CI.
  • windows-wsl-mxc: required setup/connect closeout. Attempted locally and through Azure Crabbox without -AllowSkip; blocked because no available host combined working WSL setup with OpenClaw's required unaugmented MXC BaseContainer tier.

windows-clean-installer-upgrade is not selected. This patch changes no installer layout, packaged payload selection, persisted schema, migration, repair, or uninstall behavior. The current-head real WSL test performs a clean managed setup and then reruns production StartGatewayStep against the already-installed, already-running service, which is the compatibility boundary affected by this ownership check. Exact signed-installer execution would invoke the same setup code without adding ownership coverage.

Validation

Current head: a813f775.

  • focused StartGateway and PreflightPort tests: 16 passed
  • dotnet build .\tests\OpenClaw.E2ETests\OpenClaw.E2ETests.csproj -c Debug -r win-x64: passed
  • .\build.ps1: passed
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,937 passed, 32 skipped
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,860 passed
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore: 1,084 passed
  • GitHub Setup and connect E2E: 43 passed
  • GitHub Tray, setup, and integration tests: passed
  • GitHub CI Gate and CodeQL: passed
  • git diff --check: passed
  • python .agents\skills\autoreview\scripts\autoreview --mode branch --base origin/main --stream-engine-output: clean, no accepted/actionable findings

Repeated validation exposed unrelated baseline timing/file-sharing races in CommandRunnerTests, BoundedProcessOutputTests, PiperVoiceExtractionTests, and McpHttpServerTests. Their focused reruns passed and the final full local closeout is green.

Real behavior proof

GitHub run 34099646730, setup/connect job 101671061479, executed the production setup path against a real app-owned WSL distribution on current head:

  • FullSetup_ForeignWslListener_IsRejectedBeforeGatewayStart: passed. A directly owned foreign Node listener was visible in ss; production StartGatewayStep reported Port 44121 is in use by another process. Owning process: node. and the test proved openclaw gateway start was not invoked.
  • FullSetup_AlreadyRunningGateway_IsRecognizedAsServiceOwned: passed. After full setup, the test required every real ss listener PID to match the systemd user service MainPID, reran production StartGatewayStep, and required the service-owned success result.
  • Complete setup/connect shard: 43 passed; CI Gate passed.

Additional evidence and boundaries:

  • Pinned upstream v2026.6.34 uses a systemd user service whose ExecStart launches the Node Gateway process; the generated unit has Restart=always and KillMode=control-group.
  • Local .\scripts\validate-mxc-e2e.ps1 ran without -AllowSkip, but WSL could not attach its temporary swap.vhdx (E_ACCESSDENIED) before distro creation.
  • Crabbox v0.51.0 was installed from its stable Windows release with SHA-256 verification. Azure direct-mode runs returned no portal URL (portal=-, logs=-).
  • Azure Windows Server lease cbx_14f4b42c0be4, run run_c3162c2e444e: exact head built; formal MXC command reported 11 passed and 6 skipped because Windows Server does not support OpenClaw MXC containment. Lease stopped.
  • Azure Windows 11 24H2 lease cbx_718fc34376bd, run run_ed82af3dff46: exact head built; formal MXC command reported 11 passed and 6 skipped because build 26100 exposed only appcontainer-dacl, not the required unaugmented BaseContainer tier. Lease stopped.
  • Azure Windows 11 26H2 preview lease cbx_e6fa429c1b02, probe run run_dd8d06761d50: build 26300 still reported appcontainer-dacl, baseContainerSupportsDenyPaths=false, and isolationSessionAvailable=false. The policy was not weakened to admit DACL augmentation. Lease stopped.
  • The local Windows 26340 host reports base-container, baseContainerSupportsDenyPaths=true, and isolationSessionAvailable=true, but its independent WSL install failure prevents the combined proof.
  • All task-owned Azure resources were deleted; crabbox list --provider azure is empty.

Adversarial review

Both reviewers agreed the PID-based direction is safer than #1334’s removal or #547’s process-name exemption. Both identified runtime compatibility proof as the primary merge risk and noted a sampling race between listener and MainPID reads. The existing three-attempt step retry limits that race; the current-head real E2E asserts all observed listener PIDs match the service MainPID and proves both positive and negative production paths. One reviewer recommended warning and proceeding on ambiguity, but that was rejected because later setup steps could contact a foreign listener and trigger bootstrap or pairing operations. Fail-closed ownership remains intentional.

ClawSweeper's current-head review reports no actionable patch defect, marks direct real behavior proof sufficient, and rates the PR 4/6. The remaining block is the repository-required non-skipping MXC host proof described above.

Security impact

No credential authority changes. This check occurs before bootstrap minting and pairing. Unknown or conflicting listeners remain blocked; PairOperatorStep and managed endpoint provenance remain the authoritative credential boundary.

Compare listener PIDs with the managed systemd gateway MainPID so a gateway reported as node is accepted without exempting foreign Node.js listeners. Include available owner names in conflict diagnostics and cover install/start sequences. Related context: #547.
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex review: blocked before merge. Reviewed September 7, 2026, 11:05 AM ET / 15:05 UTC.

ClawSweeper review

What this changes

The setup engine recognizes its installed gateway by the service’s process ID, reports conflicting process names, and adds unit and real WSL regression coverage.

Merge readiness

⛔ Blocked before merge - 2 items remain

This fix remains necessary: current main and the latest release retain the faulty process-name check. No actionable patch defect remains, and direct runtime proof is sufficient, but repository-required MXC validation is still blocked.

Priority: P0
Reviewed head: a813f775b4420df7044d2725460d555a023d9968

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful positive and negative runtime proof and no remaining code finding; host-validation status does not reduce patch quality.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The supplied current-head WSL results exercise production StartGatewayStep and CommandRunner after clean setup: the running managed service succeeds, while a real foreign Node listener is rejected before gateway start. This proves the changed behavior; the separate mandatory MXC host validation remains blocked.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The supplied current-head WSL results exercise production StartGatewayStep and CommandRunner after clean setup: the running managed service succeeds, while a real foreign Node listener is rejected before gateway start. This proves the changed behavior; the separate mandatory MXC host validation remains blocked.
Evidence reviewed 9 items Current main still needs the fix: The fetched main revision still accepts an occupied port only when ss output contains openclaw, rejecting a service reported as node.
Latest release retains the same check: The supplied latest release v2026.7.1-4 also contains the process-name heuristic; no shipped implementation of this repair was established.
Narrow ownership check: The introduced check queries the configured port and requires every reported listener PID to equal a positive systemd MainPID. Unknown owners, mixed owners, and inspection failures stop before gateway start; existing restart and health behavior remains.
Findings None None.
Security None None.

How this fits together

Windows setup installs a gateway service inside its managed WSL distribution, checks the configured port, and starts the gateway before pairing. The changed check distinguishes that service from unrelated listeners.

flowchart TD
  A[Setup configuration] --> B[Windows port preflight]
  B --> C[Install WSL gateway service]
  C --> D[Compare listener and service process IDs]
  D -->|Matching owners or free port| E[Start gateway and check health]
  D -->|Unknown or conflicting owners| F[Report conflict]
  E --> G[Pair operator and node]
Loading

Before merge

  • Resolve merge risk (P1) - The required combined WSL gateway-to-Windows MXC containment path remains unverified on a host supporting both working WSL and the required BaseContainer tier.
  • Complete next step (P2) - Complete .\scripts\validate-mxc-e2e.ps1 without skipped MXC proofs on a host with working WSL and the required BaseContainer support, and attach the redacted results before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +27/-22; tests +269/-1; docs +8 The small production change is justified by listener ownership and conflict diagnostics, with most growth devoted to regression coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain service-PID ownership checks and existing pairing authorization, with the required combined MXC validation completed before landing.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain service-PID ownership checks and existing pairing authorization, with the required combined MXC validation completed before landing.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the failure: install starts the service, then current main rejects its listener when ss reports node. This read-only review did not execute a failing current-main run.

Is this the best way to solve the issue?

Yes. Checking the installed service’s PID repairs the false conflict without accepting arbitrary Node servers or deleting the guard, and real WSL evidence covers both outcomes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d4707db710d6.

Labels

Label justifications:

  • P0: The existing defect can reject the gateway immediately after installation and roll back first-run setup without a demonstrated in-product recovery path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied current-head WSL results exercise production StartGatewayStep and CommandRunner after clean setup: the running managed service succeeds, while a real foreign Node listener is rejected before gateway start. This proves the changed behavior; the separate mandatory MXC host validation remains blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied current-head WSL results exercise production StartGatewayStep and CommandRunner after clean setup: the running managed service succeeds, while a real foreign Node listener is rejected before gateway start. This proves the changed behavior; the separate mandatory MXC host validation remains blocked.

Evidence

What I checked:

Likely related people:

  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Barbara Kudiess: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the required non-skipping MXC validation on a host with working WSL and the required BaseContainer support.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-07T01:38:16.474Z sha 6a1bc73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-07T06:37:40.620Z sha 6a1bc73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-07T07:08:55.139Z sha af1aca9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-07T07:30:49.135Z sha 0054db2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-07T07:58:58.897Z sha f25c3a9 :: needs real behavior proof before merge. :: [P2] Dispose the foreign-listener logger before reading its file
  • reviewed 2026-09-07T08:19:33.077Z sha a813f77 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-07T08:59:55.059Z sha a813f77 :: blocked before merge. :: none
  • reviewed 2026-09-07T13:05:15.731Z sha a813f77 :: blocked before merge. :: none

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 7, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 7, 2026
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. and removed P1 Urgent regression or broken agent/channel workflow affecting real users now. labels Sep 7, 2026
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
Dispose the setup logger before reading its JSONL proof, matching the service-owned E2E path and avoiding Windows file sharing failures.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
@shanselman

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 7, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. label Sep 7, 2026
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 7, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

Superseded by #1382 (fix(setup): verify gateway listener service ownership), which transplants this PID-based service ownership fix onto current main after #1312/#1381, strengthens failure diagnostics and coverage, and runs the real install-service → start-gateway E2E sequence. Peter Steinberger's diagnosis and ownership design are preserved.

@shanselman shanselman closed this Sep 9, 2026
shanselman added a commit that referenced this pull request Sep 9, 2026
Transplants and strengthens the PID-based post-install Gateway listener ownership fix from #1349 onto current main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows Companion can hang forever in ClientWebSocket.ConnectAsync after gateway restart; node mode never reconnects

2 participants