Skip to content

[Bug] Native MSIX Gateway: startup connect is rejected while the Gateway state is starting, and Companion never retries #1903

Open

Description

@fire0220

Summary

With the native (MSIX / Store) Gateway, a cold boot leaves Companion permanently "not connected" until the app is restarted. The startup connect happens exactly once, and it is rejected while the Gateway package is still in the starting state. Nothing reconnects afterwards — not the WebSocket backoff, not the operator reconnect scheduler, and not the managed-local auto-repair monitor.

The fix is not user error and not a timing coincidence: the Gateway needs ~150 s to become reachable after boot, and the one-shot startup attempt lands inside that window every time.

Environment

  • Windows 11, Companion v2026.9.8-1 (latest release), installed from the MSIX/Store package
  • Gateway: native MSIX package, isolated-session-v1 runtime contract, endpoint ws://127.0.0.1:54610/
  • Companion autostarts on logon; the Gateway package also starts on its own at boot
  • Verified the same code exists on main (c59652f) and on tag v2026.9.8-1, so this is shipped behavior, not an outdated build

Steps to reproduce

  1. Reboot the machine with the native Gateway installed and Companion set to autostart.
  2. Let both start on their own (Gateway takes ~150 s to open its HTTP/WS listener).
  3. Open Companion.

Expected

Companion shows "connecting" and connects on its own once the Gateway is ready (the readiness budget already exists: IsolatedGatewayRuntime.StartupTimeout = 180 s by default).

Actual

Companion stays disconnected indefinitely. Restarting the app makes it connect within seconds.

Evidence from openclaw-tray.log (offsets from Gateway start)

Offset Event
T+0 Gateway package starts (its own gateway.json records the start)
T+77 s Companion tray starts
T+79 s Connecting to last successful gateway during startup: ws://127.0.0.1:54610/ (identity.DeviceToken) — and then nothing
T+148 s Gateway log: [gateway] ready
T+163 s User restarts Companion
T+169 s Connecting to gateway: ws://127.0.0.1:54610/
T+173 s Handshake complete (hello-ok)

The diagnostic signature matters: the failed attempt logs no Connecting to gateway: line, no Loaded Ed25519 device identity, and no error line at all. The connect pipeline never reaches the WebSocket layer, so there is nothing to retry.

Root cause

1. The startup connect is one-shot

src/OpenClaw.Tray.WinUI/App.xaml.cs — TryConnectGatewayIfCredentialAvailable(...) calls _connectionManager.ConnectAsync(record.Id) once during startup and only observes the task for faults. There is no scheduler behind it.

2. The pipeline refuses a Gateway that is still booting

GatewayConnectionManager.ConnectCoreAsync (src/OpenClaw.Connection/GatewayConnectionManager.cs:434) calls AuthorizeCredentialForEndpointAsync → NativeGatewayEndpointSecurity.AuthorizeAsync → IsolatedGatewayRuntime.EnsureRunningCoreAsync:

src/OpenClaw.Connection/NativeGateway/IsolatedGatewayRuntime.cs:105

if (status.State is "not-started" or "stopped")
{
    ...
    status = await StartAndWaitAsync(package, endpoint.Port, cancellationToken).ConfigureAwait(false);
}

if (status.State != "running" || status.Port != endpoint.Port)
    throw new NativeGatewayContractException(
        "The package-managed Gateway is not running on Companion's selected port. " +
        "Check clawctl gateway-service status before connecting.");

The state vocabulary (src/OpenClaw.Connection/NativeGateway/NativeGatewayPackageClient.cs:150) is running, not-started, stopped, starting, unhealthy, unknown.

So a Gateway that is already booting on its own reports starting, which:

  • does not enter the not-started/stopped branch that would wait, and
  • fails the != "running" check and throws immediately.

StartAndWaitAsync already knows how to poll starting/unhealthy until ready (IsolatedGatewayRuntime.cs:212) with a bounded budget, but that loop is unreachable from a starting state.

3. The rejection parks the connection in Error and returns

GatewayConnectionManager.cs:445

if (!endpointAuthorization.Allowed)
{
    _stateMachine.TryTransition(ConnectionTrigger.ConnectRequested);
    ...
    _stateMachine.TryTransition(...ConnectionTrigger.WebSocketError..., endpointAuthorization.Detail);
    _diagnostics.Record("setup", "Blocked strong credential before managed-local endpoint ownership was proven", ...);
    EmitStateChanged();
    return;
}

No client is created, so no WebSocket attempt, no connecting log line, no error log line — exactly the observed signature.

4. No retry path covers this failure

  • WebSocketClientBase.cs:381 schedules ReconnectWithBackoffAsync only after a socket was actually attempted.
  • IOperatorReconnectScheduler.ScheduleOperatorReconnect (GatewayConnectionManager.cs:3341) exists only for OperatorReconnectReason.PostBootstrapHandoff and operator-token recovery.
  • ManagedLocalGatewayAutoRepairMonitor deliberately ignores native records: WslKeepAlivePolicy.IsSetupManagedLocalRecord → GatewayRecord.ResolveManagedDistroName returns null when NativePackageFamilyName is not null (GatewayRecord.cs:195-199, comment: "A native gateway's display name must never confer legacy WSL ownership"). The in-app self-heal therefore never runs for the native Gateway.

Suggested fix

Minimal, two changes:

  1. IsolatedGatewayRuntime.EnsureRunningCoreAsync: treat starting (and unhealthy) as a pending start and enter the existing bounded readiness poll instead of throwing. E.g. factor the status loop out of StartAndWaitAsync into WaitForRunningAsync and call it for both the not-started/stopped branch and a starting/unhealthy pre-state. A cold boot within StartupTimeout then simply succeeds.
  2. ConnectCoreAsync: for a native record whose authorization failed with GatewayErrorKind.Network and a NoListener/UnknownListener provenance, schedule one bounded retry (new OperatorReconnectReason, reusing the existing backoff helper) instead of parking in Error forever.

A unit test with a fake package client returning starting then running (in the style of the existing IsolatedGatewayRuntime tests) would lock this in.

Workaround

A logon wrapper that polls http://127.0.0.1:54610/health and only launches Companion once the Gateway answers, plus a bounded watchdog that relaunches Companion if it does not connect, works reliably. That is what I am using now, but it is a shim for a state the client should handle itself.

Notes / limits

  • The evidence is from logs plus the source above; I did not instrument the running app, so the exact provenance kind at the failure instant is inferred from the silent branch and the code path rather than read out of the state snapshot.
  • No secrets, tokens, device ids or user names are included in this report.

Activity

  1. added
    clawsweeper:intake:bug
    P1
    clawsweeper:fix-shape-clear
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    clawsweeper:no-new-fix-pr
    clawsweeper:source-repro
    impact:ux-friction
    issue-rating: 🦞 diamond lobster
    and removed
    clawsweeper:intake:bug
    on Oct 28, 2026
  2. clawsweeper commented on Oct 28, 2026

    @clawsweeper

    ClawSweeper status: review started.

    Codex review: this still needs some work.

    Summary
    Current main still rejects an already-starting native Gateway before transport recovery can run; the linked fixes leave this failure unresolved.

    Reproducibility: An initial starting status deterministically throws before socket creation, and an existing test explicitly asserts that rejection; no live reproduction, build or tests ran in this read-only review, and WinApp CLI was unavailable.

    Maintainer decision needed

    • Question: Should Companion passively wait for the selected native Gateway's pre-existing startup without acquiring start or stop ownership?
    • Recommendation: Allow bounded passive observation: Observe package status within a finite cancellable budget, never start or stop the pre-existing launch, and authorize credentials only after fresh running status and full listener verification.
    • Why: The existing tests and documentation deliberately reject this state, so changing that behavior requires an explicit lifecycle-policy choice.

    Next step
    Decide whether to allow passive waiting, then establish a failing starting-to-running regression requiring automatic connection without lifecycle adoption or premature credential release.

    Review details

    Best possible solution:

    Provide bounded passive readiness observation without lifecycle adoption, followed by fresh listener verification and visible Retry now recovery on expiry.

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

    An initial starting status deterministically throws before socket creation, and an existing test explicitly asserts that rejection; no live reproduction, build or tests ran in this read-only review, and WinApp CLI was unavailable.

    Is this the best way to solve the issue?

    Target the pre-socket readiness boundary after resolving lifecycle policy; reusing StartAndWaitAsync would dispatch a start and introduce cleanup ownership, while generic Network or UnknownListener retries would cover unrelated failures.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Passive waiting changes an explicitly documented and tested lifecycle boundary.
    • The reported boot timing and exact failure-time provenance have not been independently observed.

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

    Label changes

    Label changes:

    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P1: A source-confirmed failure in released code breaks automatic Gateway connection after ordinary logon.
    • impact:ux-friction: Recovery requires a manual retry or Companion restart; a first-run dead end without an in-product route is not established.
    Evidence reviewed

    Acceptance criteria:

    • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --filter FullyQualifiedName~IsolatedGatewayRuntimeTests
    • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj
    • ./build.ps1
    • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
    • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore

    What I checked:

    How this review workflow works
    • 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; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 14, 2026, 10:27 PM ET / November 15, 2026, 03:27 UTC.

  3. github-actions commented on Nov 12, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale due to inactivity.
    Please add updated OpenClaw Windows details or it will be closed.

  4. added
    clawsweeper:intake:bug
    and removed
    clawsweeper:fix-shape-clear
    clawsweeper:intake:bug
    on Nov 14, 2026
  5. added
    clawsweeper:intake:bug
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:intake:bug
    on Nov 15, 2026
  6. shuweili102-hub commented on Nov 23, 2026

    @shuweili102-hub

    I can reproduce the same startup connection issue on a newer build.

    Environment

    • Windows 11
    • OpenClaw Companion: 2026.11.3
    • Native MSIX Gateway / Node: 2026.11.6
    • Gateway port: 18789

    Startup behavior

    On cold boot, the Companion log reports:

    "Gateway service status: gateway starting, session running, readiness startup-eligible (gateway-mode-local)."

    It then reports:

    "Blocked strong credential before managed-local endpoint ownership was proven"

    The Companion process remains running, but the initial connection does not recover automatically.

    Manual reconnect works

    After the Gateway is ready, manually reconnecting succeeds:

    • "hello-ok"
    • "Handshake complete"
    • "WebSocket connected"
    • "Node pairing: Paired"
    • "Node status: Connected"

    This suggests the initial connection is rejected before the WebSocket handshake, so the normal WebSocket retry mechanism may not be triggered.

    Could you confirm whether this issue is fixed in a newer build, and whether the Companion can retry automatically once the managed Gateway reaches the ready state?

    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:fix-shape-clearclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:ux-frictionissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions