Repository navigation
fix: Companion rejects the Gateway once it listens on a second port - #266
Conversation
With mcp.apps enabled, OpenClaw also serves its MCP App sandbox host beside the gateway port. gateway-service status cannot identify the gateway endpoint among two observed ports, so it omitted gateway.port and, because ownership required that port, gateway.ownership too. Companion then had no listener attestation and refused to send credentials (#260). Ownership is now reported whenever the running gateway's listeners are attested, independent of endpoint resolution. A reported port must still be one of those listeners; Companion selects the port it prepared. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gateway-service status now resolves its port like start results: a launch-pinned port that is one of the observed listeners is reported, so a second owned listener (MCP App sandbox, a plugin's loopback proxy) no longer hides it.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe PR reports attested Gateway listeners when several ports are open and resolves an observed launch-pinned port. Example: The Gateway owns listeners on ports 63979 and 57122.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes a verified status-contract defect still present on main, with no actionable introduced bugs found. Priority: P0 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe isolated session observes Gateway process and listener identities, clawctl projects those observations into JSON, and Companion verifies its endpoint before sending credentials. flowchart LR
A[Gateway process and listeners] --> B[Session host inspection]
B --> C[Gateway controller]
C --> D[clawctl status JSON]
D --> E[Companion endpoint verification]
E --> F[Credential handoff]
Technical reviewBest possible solution: Deliver the producer and matching Companion updates together, preserving endpoint verification and visible retry guidance. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically drops both fields with multiple listeners, supported by affected-user reports and supplied base-versus-head Windows results; this review ran no reproduction. Is this the best way to solve the issue? This is a small producer repair using the existing port resolver and ownership projection, with unpinned endpoint verification correctly retained in Companion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c6ef88e098ae. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 16, 2026, 10:22 PM ET / November 17, 2026, 03:22 UTC. |
Closes #260
Producer half of the fix. Companion half: openclaw/openclaw-windows-node#2263. Both releases are needed.
What Problem This Solves
Fixes: OpenClaw Companion rejects the package-managed Gateway ("does not expose Companion's isolated-session contract"), and restart-loops it, once the Gateway listens on a second port. Two known triggers: the MCP App sandbox host with
mcp.apps.enabled: true(#260), and the Codex plugin's loopback inference proxy. The proxy opens on an OS-assigned port on the first agent turn, even withmcp.appsoff (#260 comment).User Impact
User impact: with this Gateway and the matching Companion change (openclaw/openclaw-windows-node#2263), Companion connects to a Gateway that owns extra listeners, including ones that open after it connected.
clawctl gateway-service status --jsonnow reportsgateway.ownershipwhenever the running Gateway's listeners are attested.gateway-config.jsonis reported asgateway.portwhen it is one of those listeners.gateway-config.json({"schemaVersion":1,"port":<Companion port>}), then restart the Gateway service.Why This Change Was Made
gateway-service statussetgateway.portonly when exactly one listener was observed (Program.cs), and projected ownership only when that port was known (ClawCtlJson.FromOwnership). A running Gateway with a second listener therefore reported neither, and Companion could verify nothing. The same projection is in the 2026.11.100.0 release commit 30b5db3, which is the Store build in #260.Two changes, both in
gateway-service status:FromOwnershipnow attests the session-owned listeners independent of endpoint resolution. The existing requirements stay: running state, sandbox and agent SID present, every listener with a nonzero OS process sequence. A reported port must still be one of the attested listeners.gateway-service statusresolves its port with the sameGatewayAddress.ResolvePortrule that start results already use (AConfirmedConfiguredPortWinsOverOtherObservedListeners). A launch-pinned port that is among the observed listeners is reported. A port that was configured but not observed is still not reported.A pinned port is passed to OpenClaw as
--portfor that launch record, and the Gateway's own listener binds it (the MCP App sandbox host binds after it, and a plugin proxy uses an OS-assigned port). So a pinned port among the running Gateway's owned listeners is the applied endpoint, not merely saved configuration. Companion-prepared launches are not pinned, so for them endpoint selection stays with Companion: it picks its prepared port among the attested listeners and confirms it live with a credential-freeconnect.challengeprobe.Evidence
Head: 451747d (rebased on origin/main c6ef88e).
.\scripts\Test-DotNetQuality.ps1: passed.dotnet test .\OpenClaw.Gateway.MSIX.slnx --configuration Release --no-restore: 1683 passed, 0 failed..\scripts\Test-DocReferences.ps1andgit diff --check origin/main...HEAD: passed..\scripts\Test-NativeAotCli.Tests.ps1: passed. 43 NativeAOT scenarios ran asclawctl.exe; the wrong-name control failed its alias scenario, as the gate requires.ProgramTests.GatewayStatusAttestsEveryOwnedListenerAndReportsOnlyAnObservedPinnedPortdrivesclawctl gateway-service status --jsonthroughProgram.RunControlAsync. The inspection has two listeners on non-adjacent ports (51789 and 52535, the Codex proxy shape). Cases:That test fails on origin/main (ownership omitted). The pinned case also fails at ca69e93 without the
ResolvePortchange.ClawCtlReadinessOutputTests.ReportedPortOutsideTheAttestedListenersIsNotOwnershipProofkeeps the reported-port consistency rule.Local ClawSweeper (read-only
--local-rangereview against origin/main): on 451747d: patch correct, no findings, security cleared, proof sufficient (🦞 diamond lobster), patch 🐚 platinum hermit, next step none.Real packaged behavior at this head: Crabbox
hypervlease cbx_42ac499fb637, Windows 11 Insider 10.0.29683, interactive session, Developer Mode. Two development registrations from the same OpenClaw 2026.11.3 payload (847611dc), each with its own isolated session:p260-basefrom origin/main c6ef88e (clawctl --version0.1.2511.63809, c6ef88e) andp260-fixfrom this head (0.1.2511.64149, 451747d). In each casemcp.apps.enabledwas false and the Gateway started with one listener. Companion connected, then a proof-only local plugin (no provider credentials) opened a loopback listener on an OS-assigned port inside the Gateway's node process, the same shape as the Codex inference proxy.state: runningwith neithergateway.portnorgateway.ownership. Companion from origin/main failed with "does not expose Companion's isolated-session contract", matching the Companion rejects the Native Gateway when mcp.apps.enabled is true (second listener on port+1) #260 comment.gateway.portomitted, ownership[57122/pid 10700, 63979/pid 10700]. The matching Companion verified 63979 and authorized both reconnects. Companion from origin/main still failed with the generic error.gateway-config.jsonpinned to 63979:gateway.port: 63979with ownership[57131, 63979]. Companion from origin/main authorized both reconnects, which proves the workaround above. The matching Companion also authorized.Real Companion app at this head (Crabbox
hyperv --desktoplease cbx_b7ad41589320, payload OpenClaw 2026.11.4 d843d6af,clawctl --version0.1.2511.9002 / 451747d):[18789/pid 7604, 54208/pid 7604]withgateway.portomitted.Verified the Gateway listener on port 18789 (PID 7604).62 times with no warnings.Earlier live runs with MCP apps (first commit, now ca69e93)
Lease cbx_9e215bc15c45/cbx_04d33ef14a4b; base 59a9816, fix efe52a77, with the same tree as ca69e93 before the rebase. All with
mcp.apps.enabled: true:runningwith neither port nor ownership while node listened on 63969 and 63970. Companion from origin/main rolled back its start on every attempt (3 starts, 3 rollbacks).[63979/pid 1280, 63980/pid 1280]. The matching Companion authorized; 63979 answeredconnect.challengeand 63980 returned 404.[63978, 63979]. Companion denied 63979 without stopping the Gateway.With
mcp.apps.enabled: false, both builds reported the single port with ownership.