Skip to content

Tray keep-alive can still start during Windows session end and its repair adapter ignores the cancellation token #1573

Open

Description

@petruslin

What

The tray's WSL gateway keep-alive can still run its ensure/start path during a Windows session-end sequence. The resulting wsl.exe creation fails with STATUS_DLL_INIT_FAILED (0xc0000142), which is what produces the shutdown "Application Error" dialog recorded as Application Popup, Event ID 26.

This issue covers one production file. It is the second of three spawn paths described in #1571. The first (the provenance probe's process start) is tracked separately; read #1571 for the evidence trail.

Where

src/OpenClaw.Tray.WinUI/App.xaml.cs

  • :956–:957 — the keep-alive is started in a detached task:
    var wslKeepAlive = new WslGatewayKeepAliveService(() => _settings, () => _gatewayRegistry);
    _ = Task.Run(wslKeepAlive.TryEnsureAsync);
  • :973 — the managed-local auto-repair adapter invokes _ => wslKeepAlive.TryEnsureAsync() and discards the cancellation token it is handed.
  • WslGatewayKeepAliveService.TryEnsureAsync accepts no cancellation token, and can launch WSL after asynchronous preparation — i.e. after the point where a caller could have decided not to.
  • The repair monitor that drives :973 is src/OpenClaw.Tray.WinUI/Services/ManagedLocalGatewayAutoRepairMonitor.cs (5 s poll, 90 s cooldown); it keeps evaluating during teardown. Its IsTransportUnreachable path treats a Connecting state with no classified error as unreachable, which is exactly the state observed after the WSL VM disappears at session end.

Scope — deliberately one file

  • Change only src/OpenClaw.Tray.WinUI/App.xaml.cs.
  • Do not change ManagedLocalGatewayAutoRepairMonitor.cs, ManagedLocalGatewayRepairCoordinator.cs, WslGatewayKeepAliveService.cs beyond what this file's call sites require, or any document/config/schema.
  • Do not alter the 5 s poll interval, the 90 s cooldown, or the 3-restart budget.
  • 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 keep-alive path must not start a gateway — the detached task at :957 and the repair adapter at :973 must both decline.
  2. The repair adapter at :973 must honour the cancellation token it is given rather than discarding it with _ =>.
  3. Normal operation is unchanged: at startup, and on every managed-local auto-repair while no session end is in progress, the keep-alive must still run.
  4. The session-ending signal must come from the same injected abstraction introduced for the provenance probe (separate issue), so there is one source of truth rather than a second ad-hoc check. If that abstraction is not available yet, define the call site against it rather than re-deriving the state locally.
  5. Refusal must be logged at the point of refusal so the tray log alone shows why nothing was started.

Acceptance

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

Required regression test

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

  • substitutes a session-ending signal that reports "ending",
  • drives the keep-alive entry point (and the repair adapter),
  • asserts that no gateway start was attempted — and, separately, that the adapter's cancellation token is observed (a cancelled token must also prevent the start).

The test must not launch a real wsl.exe or need WSL installed.

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 the keep-alive/reconnect activity during teardown.
  • 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 open: current main still discards repair cancellation and launches keep-alive processes without observing Windows session ending; the shared lifecycle prerequisite remains unresolved.

    Reproducibility: Current source establishes token loss and unguarded process creation after asynchronous preparation; no builds, tests, or live shutdown reproduction ran in this read-only review.

    Maintainer decision needed

    • Question: Should the shared lifecycle prerequisite land separately before this consumer repair, or accompany it?
    • Recommendation: Land the prerequisite first: Establish Provide one shared Windows session-ending signal and wire it for production use #1575 and its production lifecycle semantics, then repair the keep-alive consumers against that contract.
    • Why: The required signal is still absent, and the reporter deliberately split the earlier cross-subsystem repair while allowing minimal keep-alive service changes.

    Next step
    Settle prerequisite sequencing, then forward cancellation and establish failing zero-launch regressions for session ending or cancellation before entry and during preparation.

    Review details

    Best possible solution:

    Use the shared Windows lifecycle source and forwarded cancellation at keep-alive launch boundaries while preserving normal operation and logging refusals.

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

    Current source establishes token loss and unguarded process creation after asynchronous preparation; no builds, tests, or live shutdown reproduction ran in this read-only review.

    Is this the best way to solve the issue?

    The reporter's revised service-boundary scope is appropriate, but coverage must include WSL enumeration and cancellation during preparation rather than only App entry guards.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The shared lifecycle contract must define recovery from a canceled Windows session-end request before consumers depend on it.
    • Source proves the cancellation gap, but the reported Event 26 failures have not been independently attributed to this particular launch path.

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

    Label changes

    Label changes:

    No label changes.

    Label justifications:

    • P2: The cancellation defect and reported shutdown dialogs warrant repair without evidence of data loss or an unusable core workflow.
    • impact:ux-friction: Shutdown-time application-error dialogs cause confusion and support burden, while the reporter confirms that the Gateway returns on the next boot.
    Evidence reviewed

    Acceptance criteria:

    • ./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
    • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --no-restore
    • Establish failing-then-passing regressions for cancellation and session ending before entry and during preparation, asserting zero WSL launches.

    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, 2:24 AM ET / 07:24 UTC.

  3. petruslin commented on Oct 1, 2026

    @petruslin
    Author

    Yes to widening this to the keep-alive cancellation boundary, now that #1575 exists

    Filed as reporter: #1575 — Provide one shared Windows session-ending signal and wire it for production use. It owns the shared signal, its Windows source, and the production wiring, and it deliberately does not touch the consumer call sites.

    On the question the review raises — whether this split repair may include minimal keep-alive service and regression-test changes — from the reporter's side: yes, and I think it has to.

    The review's reasoning matches what I can observe from the outside: WslGatewayKeepAliveService.TryEnsureAsync accepts no cancellation token, so once its asynchronous preparation is under way there is nothing at the App.xaml.cs layer that can stop it from reaching the start path. An App-only guard therefore closes the two obvious entries (:957, :973) without delivering the guarantee this issue claims.

    The narrowest form that does deliver it:

    • src/OpenClaw.Tray.WinUI/App.xaml.cs — no start while a session end is in progress; the repair adapter at :973 must respect the cancellation token it is already handed.
    • src/OpenClaw.Tray.WinUI/Services/WslGatewayKeepAliveService.cs — a minimal cancellation boundary inside TryEnsureAsync, so it can observe the signal before it starts anything.
    • Focused regression coverage: with the signal reporting a session end, TryEnsureAsync does not reach a process start; with no session end, it behaves exactly as today.

    Explicitly not in scope, as before: the 5 s poll interval, the 90 s cooldown, and the 3-restart budget. I am not asking to change keep-alive behaviour in normal operation — only to give it a way to stop when Windows is ending.

    If the maintainer prefers to keep this issue at one file and track the service change separately, that is fine too; the two are separable as long as both land. I would just rather say plainly that the one-file version does not fully close the reported defect.

  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:fix-shape-clear
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Nov 3, 2026
  7. github-actions commented on Nov 18, 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. added
    clawsweeper:fix-shape-clear
    on Nov 18, 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:fix-shape-clearclawsweeper: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