Skip to content

Reconnect retry loop invokes reconnect authorization with no Windows session-ending check #1574

Open

Description

@petruslin

What

The WebSocket reconnect retry loop keeps running during a Windows session-end sequence. Its next step is ReconnectAuthorizationAsync, which routes through endpoint provenance and can reach the managed-local port probe — the code path that starts wsl.exe. Creating that process at teardown fails with STATUS_DLL_INIT_FAILED (0xc0000142) and produces the shutdown "Application Error" dialog recorded as Application Popup, Event ID 26.

This issue covers one production file. It is the third of three spawn paths described in #1571; read #1571 for the evidence trail (the 16-day Event 26 burst census, the tray log excerpts, and why the unrelated XLGuard.sys boot popup must be counted separately).

Where

src/OpenClaw.Shared/WebSocketClientBase.cs

  • The reconnect retry loop sits around :594. It checks disposal, its cancellation token, the reconnect policy and the socket generation, then continues into authorization.
  • ReconnectAuthorizationAsync is declared at :156–:157 and invoked at :618–:621:
    await ReconnectAuthorizationAsync(_cts.Token).ConfigureAwait(false);
  • _cts is the client's own token source (:102, created at :228); it is cancelled by the client's teardown, but that teardown is order-dependent and does not observe a Windows session-end sequence.
  • Neither this loop nor the authorization path consults a session-ending signal.

Scope — deliberately one file

  • Change only src/OpenClaw.Shared/WebSocketClientBase.cs.
  • Do not change src/OpenClaw.Connection/ManagedLocalGatewayPortProvenanceService.cs (separate issue), src/OpenClaw.Tray.WinUI/App.xaml.cs (separate issue), or any document/config/schema.
  • Do not change reconnect backoff, the reconnect policy, or the disposal ordering.
  • Do not add a new user-facing setting.

A previous single issue covering all three spawn paths produced an autonomous fix artifact that spanned three subsystems and was rejected upstream as too broad for autonomous execution. Keeping this to one file is the point of the split.

Required behaviour

  1. Once the process has observed that the Windows session is ending, the reconnect loop must exit before invoking ReconnectAuthorizationAsync — the call at :621 must not be reached.
  2. Normal reconnects are unchanged: with no session end in progress, the loop must behave exactly as today, including its existing token/policy/generation checks.
  3. The check must not depend on the client's own _cts being cancelled at the right moment; that race is the current gap.
  4. The session-ending signal must come from the same injected abstraction used by the other two call sites, so there is one source of truth. If that abstraction is not yet available, code the call site against it rather than re-deriving the state locally.
  5. Declining must be logged at the point of refusal.
  6. WebSocketClientBase lives in a shared library with no window; do not add a Win32/tray dependency to it. Take the signal as an abstraction.

Acceptance

./build.ps1
dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore

Required regression test

In tests/OpenClaw.Shared.Tests, a test that:

  • substitutes a session-ending signal that reports "ending",
  • drives the reconnect path,
  • asserts that ReconnectAuthorizationAsync is not invoked,
  • and that with the signal reporting "not ending" it is invoked.

Assert on a substituted ReconnectAuthorizationAsync delegate (it is already settable at :156), not on a real socket or a real wsl.exe.

What I can and cannot contribute

  • I can confirm the reported behaviour on Windows 11 Home China build 10.0.26300 with OpenClaw Companion 2026.9.4.0, including tray-log lines showing Connection closed prematurely followed by reconnecting in … during teardown, and the matching Event 1074 → Event 26 ordering.
  • I do not have a working build environment for this repository, so I cannot run ./build.ps1 or the test projects. Someone else needs to verify.

Activity

  1. added
    P2
    clawsweeper:needs-maintainer-review
    clawsweeper:no-new-fix-pr
    clawsweeper:source-repro
    impact:ux-friction
    issue-rating: 🦞 diamond lobster
    on Oct 1, 2026
  2. clawsweeper commented on Oct 1, 2026

    @clawsweeper

    Codex review: this still needs some work.

    Summary
    Keep this issue open: current main still reaches reconnect authorization without observing Windows session end, and the shared lifecycle prerequisite remains unresolved.

    Reproducibility: Current source proves authorization remains reachable after backoff without observing Windows session end; the delegate seam supports a deterministic regression, but no tests or live shutdown reproduction ran in this read-only review.

    Root-cause cluster
    Relationship: partial_overlap
    Canonical: #1571
    Summary: The reporter preserves one evidence umbrella with separate repairs for the shared lifecycle producer and individual launch-admission boundaries.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    Establish the wired lifecycle contract in #1575, then guard authorization with failing regressions for session end before retry, during backoff, and normal operation.

    Review details

    Best possible solution:

    Use one host-owned lifecycle signal to stop and log reconnect admission during session end while preserving normal retries and endpoint authorization.

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

    Current source proves authorization remains reachable after backoff without observing Windows session end; the delegate seam supports a deterministic regression, but no tests or live shutdown reproduction ran in this read-only review.

    Is this the best way to solve the issue?

    An injected admission guard fits the defect, but the requested one-file repair depends on the shared lifecycle producer and real production wiring rather than an independent flag or no-op default.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A consumer-only guard cannot protect production until the shared Windows lifecycle signal is implemented and supplied to the clients.
    • The lifecycle contract must define recovery after a canceled Windows session-end request.
    • The shutdown popup has not been independently reproduced, and this guard cannot explain the reporter's separate mid-session failures.

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

    Label changes

    Label changes:

    No label changes.

    Label justifications:

    • P2: Shutdown-time background process failures warrant repair without evidence of data loss or a blocked first-use workflow.
    • impact:ux-friction: Reconnect work during shutdown can produce alarming Windows application-error dialogs.
    Evidence reviewed

    Acceptance criteria:

    • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --filter FullyQualifiedName~WebSocketClientBaseTests
    • ./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
    • Verify both production client roles receive the shared lifecycle signal and canceled session-end requests restore reconnect eligibility.

    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 19, 2026, 10:56 PM ET / November 20, 2026, 03:56 UTC.

  3. petruslin commented on Oct 1, 2026

    @petruslin
    Author

    The prerequisite now exists: #1575

    Filed as reporter: #1575 — Provide one shared Windows session-ending signal and wire it for production use. It owns the abstraction, the concrete Windows source and its production registration, and it does not touch this call site or the other two.

    That resolves the gap the review identified here — that all three split issues depend on one signal which the source does not currently provide, and that independently-defined seams could end up incompatible or unwired. Nothing about this issue's own scope changes: still one production file, src/OpenClaw.Shared/WebSocketClientBase.cs, and still no Win32 or tray dependency in that shared library.

    Two things the review asked for, which I agree to:

    It has to expose the transition, not just a latched state. The interesting case is a session end that begins while the reconnect loop is already sitting in its backoff wait. A flag that only becomes readable once teardown is under way can be sampled too early and miss it. #1575 asks for the transition for exactly this reason; if the implementation only offers a latched state, this issue will not be able to honour its own requirement 1 reliably.

    The regression cases. Happy to have these as the acceptance evidence:

    1. Signal reports a session end → ReconnectAuthorizationAsync is not invoked.
    2. No session end in progress → it is invoked, and the loop behaves exactly as today, including its existing token / policy / generation checks.
    3. A session end that begins during the backoff wait → the loop exits at the next observation rather than continuing into authorization.

    All three should be driven through the settable delegate at :156, with no real socket and no real wsl.exe.

  4. github-actions commented on Oct 16, 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.

  5. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Oct 20, 2026
  6. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Nov 4, 2026
  7. github-actions commented on Nov 19, 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.

  8. removed
    clawsweeper:fix-shape-clear
    on Nov 19, 2026
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

    P2clawsweeper:needs-maintainer-reviewclawsweeper: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