Skip to content

fix: Companion rejects the Gateway once it listens on a second port - #266

Merged
paulcam206 merged 2 commits into
mainfrom
paulcam206-attest-multi-listener-ownership
Nov 17, 2026
Merged

paulcam206 merged 2 commits into
mainfrom
paulcam206-attest-multi-listener-ownership

Conversation

@paulcam206

@paulcam206 paulcam206 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

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 with mcp.apps off (#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 --json now reports gateway.ownership whenever the running Gateway's listeners are attested.
  • A port pinned for the launch in the launcher's gateway-config.json is reported as gateway.port when it is one of those listeners.
  • Companion releases before that change still reject a port-less status. As a workaround with this Gateway, pin the Companion port in gateway-config.json ({"schemaVersion":1,"port":<Companion port>}), then restart the Gateway service.
  • Single-listener behavior is unchanged.

Why This Change Was Made

gateway-service status set gateway.port only 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:

  • FromOwnership now 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 status resolves its port with the same GatewayAddress.ResolvePort rule 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 --port for 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-free connect.challenge probe.

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.ps1 and git diff --check origin/main...HEAD: passed.

  • .\scripts\Test-NativeAotCli.Tests.ps1: passed. 43 NativeAOT scenarios ran as clawctl.exe; the wrong-name control failed its alias scenario, as the gate requires.

  • ProgramTests.GatewayStatusAttestsEveryOwnedListenerAndReportsOnlyAnObservedPinnedPort drives clawctl gateway-service status --json through Program.RunControlAsync. The inspection has two listeners on non-adjacent ports (51789 and 52535, the Codex proxy shape). Cases:

    • unpinned: port omitted, both listeners attested;
    • pinned 51789: port 51789, both attested;
    • pinned 51700 (not observed): port omitted, both attested.
  • That test fails on origin/main (ownership omitted). The pinned case also fails at ca69e93 without the ResolvePort change.

  • ClawCtlReadinessOutputTests.ReportedPortOutsideTheAttestedListenersIsNotOwnershipProof keeps the reported-port consistency rule.

  • Local ClawSweeper (read-only --local-range review 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 hyperv lease 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-base from origin/main c6ef88e (clawctl --version 0.1.2511.63809, c6ef88e) and p260-fix from this head (0.1.2511.64149, 451747d). In each case mcp.apps.enabled was 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.

    • base: the node PID then also listened on 57118, and status reported state: running with neither gateway.port nor gateway.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.
    • fix, unpinned: gateway.port omitted, 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.
    • fix, gateway-config.json pinned to 63979: gateway.port: 63979 with 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 --desktop lease cbx_b7ad41589320, payload OpenClaw 2026.11.4 d843d6af, clawctl --version 0.1.2511.9002 / 451747d):

    • Companion from fix: native Gateway is rejected once it listens on a second port openclaw-windows-node#2263 (7dedc058) completed native setup through its real setup pages and reached "Set up your AI". The proof plugin then opened 127.0.0.1:54208 in the Gateway's node PID 7604, and status attested [18789/pid 7604, 54208/pid 7604] with gateway.port omitted.
    • That page's Refresh reran provider discovery through Companion's credential gate. The setup log recorded Verified the Gateway listener on port 18789 (PID 7604). 62 times with no warnings.
    • Companion from origin/main (a0a2a24e), set up against the same running Gateway, failed at verification with "does not expose Companion's isolated-session contract".
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:

  • base: status running with 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).
  • fix: ownership [63979/pid 1280, 63980/pid 1280]. The matching Companion authorized; 63979 answered connect.challenge and 63980 returned 404.
  • fix with the Gateway moved to 63978, so the sandbox sits on Companion's 63979: ownership [63978, 63979]. Companion denied 63979 without stopping the Gateway.

With mcp.apps.enabled: false, both builds reported the single port with ownership.

paulcam206 and others added 2 commits November 16, 2026 17:36
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.
@clawsweeper

clawsweeper Bot commented Nov 17, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The 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.

  • Before: Status omits both gateway.port and gateway.ownership, so Companion rejects the Gateway.
  • After: Status attests both listeners; matching Companion verifies port 63979, and pinning that port also supports older Companion builds.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused producer patch has strong behavior evidence and no findings; overall scope remains partial until the paired consumer change delivers unpinned recovery.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied current-head Windows results exercise development-registered packaged clawctl status after a real late listener opens: both identities remain attested, matching Companion authorizes reconnects, and the observed pinned-port case supports older Companion; Store acquisition, WinUI, real Codex OAuth, and ARM64 runtime were not exercised.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Companion rejects a running Gateway and can repeatedly roll back starts after an auxiliary listener opens.
Reason: The maintainer-authored producer repair has clear value, but complete unpinned recovery also requires openclaw/openclaw-windows-node#2263.

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
Reviewed head: 451747d138a6775dc3e4cb320e901b9672bd6cd2

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Ownership projection and Companion contract documentation changes intended behavior with a stated reason (9743772: Support isolated-agent configuration and credential handoff using trustworthy listener identities rather than host-profile configuration.)
  • Gateway status port selection changes intended behavior with a stated reason (6b6b148: The existing handler was carried through the progress-output refactor; the earlier address resolver explicitly supports a confirmed configured port among multiple listeners.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Paul Campbell (AgOS): Raw commit 9743772 adds src/OpenClaw.Launcher/ClawCtlJson.cs:305 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9743772d6175; files: src/OpenClaw.Launcher/ClawCtlJson.cs)

Preflight source

Source 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

Metric Value Why it matters
Focused production change Production +11/-4 lines; tests +100; documentation +9/-4 The implementation reuses existing owners, while regression coverage exercises three multi-listener status cases and rejects inconsistent port attestation.

Labels

Label changes:

  • add P0: The linked affected-user reports establish blocked Companion setup and repeated Gateway rollbacks without an in-product recovery; existing workarounds require commands or configuration edits.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P0: The linked affected-user reports establish blocked Companion setup and repeated Gateway rollbacks without an in-product recovery; existing workarounds require commands or configuration edits.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 10:22 PM ET / November 17, 2026, 03:22 UTC.

@paulcam206
paulcam206 marked this pull request as ready for review November 17, 2026 19:24
@paulcam206
paulcam206 merged commit a691d59 into main Nov 17, 2026
26 checks passed
@paulcam206
paulcam206 deleted the paulcam206-attest-multi-listener-ownership branch November 17, 2026 19:31
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

Companion rejects the Native Gateway when mcp.apps.enabled is true (second listener on port+1)

1 participant