Skip to content

Tray spawns wsl.exe during session teardown, producing an "Application Error 0xc0000142" popup on every shutdown/restart #1571

Open

Description

@petruslin

Summary

When the tray is running (the normal case — it autostarts), shutting down or
restarting Windows frequently pops up a Windows hard-error dialog:

wsl.exe - Application Error
应用程序无法正常启动(0xc0000142)。请单击"确定"关闭应用程序。

This is STATUS_DLL_INIT_FAILED raised via NtRaiseHardError. It happens because
the tray's reconnect timers fire after the session has started tearing down, and
each fire spawns a wsl.exe that can no longer get a conhost. Nothing is actually
broken — the gateway comes back fine on next boot — but the dialog is alarming and
users reasonably read it as "my system is failing".

Environment

OS Windows 11 Home (China), build 10.0.26300
App OpenClaw Companion 2026.9.4.0 — D:\OpenClawTray\OpenClaw.Tray.WinUI.exe
Distro app-owned OpenClawGateway (base Ubuntu-24.04, systemd enabled)
Gateway ws://127.0.0.1:18789, loopback + token auth
Data %APPDATA%\OpenClawTray\settings.json, %LOCALAPPDATA%\OpenClawTray\openclaw-tray.log
Tray autostart yes; starts 2–4 min after boot

Steps to reproduce

  1. Start the tray normally and let it reach the steady state (keepalive running,
    i.e. a long-lived wsl.exe -d OpenClawGateway -- sleep infinity is present).
  2. Shut down or restart Windows from the Start menu.

Observed on essentially every shutdown where teardown takes long enough for the
timers to fire (~45% of shutdowns on this machine, measured over 47 shutdowns
since install; when it happens it is exactly 2 dialogs, always).

Observed behaviour

The dialogs are recorded verbatim by Windows as Application Popup, System log,
Event ID 26 (Properties[0] = caption, Properties[1] = message):

10-01 12:46:xx  [wsl.exe - Application Error]  应用程序无法正常启动(0xc0000142)。请单击"确定"关闭应用程序。
10-01 12:46:xx  [wsl.exe - Application Error]  应用程序无法正常启动(0xc0000142)。请单击"确定"关闭应用程序。
10-01 14:31:xx  [wsl.exe - Application Error]  … (x2, same text)
10-01 16:44:46  [wsl.exe - Application Error]  … (x2 — 16:44:46 and 16:44:49)

Correlated with the tray log (%LOCALAPPDATA%\OpenClawTray\openclaw-tray.log,
local time — note the app logs local, not UTC):

16:44:44  User32 1074: shutdown initiated (StartMenuExperienceHost.exe, "restart")
16:44:45  <both WS sockets to the gateway close>  "Connection closed prematurely" (x2, 15-35 ms apart)
16:44:45  "node reconnecting in ~1.1s"
16:44:45  "gateway reconnecting in ~1.2s"
16:44:46  timer fires -> wsl.exe spawn          <- dialog #1
16:44:47  timer fires -> wsl.exe spawn          <- dialog #2
16:44:46+ Winlogon 6000 / 7002, FilterManager 6006, Hyper-V-VmSwitch NIC teardown

Inter-dialog spacing is not fixed (0.09 s / 0.15 s / ~3 s observed across events),
so it is not one code path firing twice on a fixed schedule — it is the two
independent reconnect paths (node + gateway) racing the teardown.

Which spawn is it

The spawn command is wsl.exe -d OpenClawGateway -- bash -s (the repair/probe
form), not the steady-state -- sleep infinity. Note that the tray logs nothing
for this spawn
— the log has no Repair/Probe line at all, which is what made
this hard to pin down from the outside. Might be worth logging it.

Ruled out (by testing, not by reading)

  • EnableManagedLocalGatewayAutoRepair: false does not prevent it. With that
    switch set, the 2026-10-01 16:44:44 restart still produced exactly 2 dialogs
    (16:44:46 and 16:44:49) — same as with it left true (12:46 → 2, 14:31 → 2).
    So the spawn is not (only) the auto-repair coordinator; it is the
    reconnect/keepalive path. Setting reverted afterwards.
  • EnableNodeMode: false would at best remove 1 of the 2, at a large functional
    cost, so it is not a fix.
  • This is not a WSL/hypervisor defect: the distro itself is fine, and the same
    wsl.exe runs happily all day while a session is alive. The problem is purely
    "spawn a console app after teardown has begun".
  • Not a WER dialog: HKCU\...\Windows Error Reporting\DontShowUI does not
    suppress it (this is a hard error, not a report).

Root cause, as best I can tell from outside

The 4 tray assemblies contain zero occurrences of SystemEvents,
SessionEnding, QUERYENDSESSION, HasShutdownStarted, or WM_ENDSESSION.
The app has no notion of "the session is ending", so when the gateway connection
drops during shutdown it treats it as an ordinary transient disconnect and re-arms
keepalive / reconnect timers (_reArmKeepAliveAsync, reconnectIfCurrentAsync,
probeReachableAsync, WslGatewayKeepAliveService.TryEnsureAsync) into a session
that is already gone.

Suggested fix

  1. Before any keepalive/reconnect spawn, bail out if the session is ending. Either:
    • check Environment.HasShutdownStarted, and/or
    • subscribe once to Microsoft.Win32.SystemEvents.SessionEnding and set a flag
      that gates _reArmKeepAliveAsync / the reconnect callbacks, and/or
    • poll GetSystemMetrics(SM_SHUTTINGDOWN) (works without a message pump).
      Any of these would also stop the pointless spawn during logoff, not just
      shutdown/restart.
  2. Log these spawns (command + reason) — their absence from the log is the main
    reason this took a full day of external tracing to attribute.

Impact

Cosmetic but loud, and in this case it is the only thing the user sees at
shutdown, so it reads as a system fault. There is no in-app workaround.

The only machine-side suppression I found is
HKLM\SYSTEM\CurrentControlSet\Control\Windows\ErrorMode = 2. I have since
verified it on a restart where the trigger chain definitely fired (same two
Connection closed prematurely lines, same two reconnect timers): the dialogs
are no longer displayed, but Windows still logs the three Application Popup
records
, so the underlying spawn still happens and the failure is only hidden —
not fixed, and now hidden machine-wide for every app. That is why this still
needs a fix in the tray.

Diagnostic commands used

# the authoritative record of a desktop popup (caption + message)
Get-WinEvent -FilterHashtable @{LogName='System';Id=26;StartTime=(Get-Date).AddDays(-7)} |
  Sort-Object TimeCreated |
  ForEach-Object { "{0:MM-dd HH:mm:ss} [{1}] {2}" -f $_.TimeCreated, $_.Properties[0].Value, (($_.Properties[1].Value -replace '\s+',' ')) }

# what initiated the shutdown
Get-WinEvent -FilterHashtable @{LogName='System';Id=1074;StartTime=(Get-Date).AddDays(-7)} |
  Sort-Object TimeCreated |
  ForEach-Object { "{0:MM-dd HH:mm:ss}  {1}" -f $_.TimeCreated, (($_.Properties | ForEach-Object {$_.Value}) -join ' | ') }

# the trigger chain in the tray's own log
Select-String -Path "$env:LOCALAPPDATA\OpenClawTray\openclaw-tray.log" `
  -Pattern 'Connection closed prematurely|reconnecting in' -Encoding UTF8

Activity

  1. added
    P2
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:ux-friction
    issue-rating: 🦞 diamond lobster
    no-stale
    on Oct 1, 2026
  2. clawsweeper commented on Oct 1, 2026

    @clawsweeper

    Codex review: this still needs some work.

    Summary
    Keep this issue as the evidence umbrella: current main still allows WSL launches without Windows session-end checks, and the reporter’s complementary repair issues remain open.

    Reproducibility: Current source establishes unchecked launch paths and discarded keepalive cancellation, supported by the reporter’s corrected traces; no live shutdown reproduction, builds, or tests ran, and WinApp CLI was unavailable.

    Root-cause cluster
    Relationship: canonical
    Canonical: #1571
    Summary: The reporter explicitly retained this evidence umbrella and split the missing lifecycle source and its consumers into complementary repairs.

    Members:

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

    Next step
    Complete the linked lifecycle prerequisite and consumer repairs with failing zero-launch regressions, then verify WSL-filtered shutdown Event 26 records while retaining this issue as their evidence trail.

    Review details

    Best possible solution:

    Use one production-wired Windows lifecycle source to stop reconnect and repair admission and guard process launches while preserving normal recovery and ordered shutdown.

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

    Current source establishes unchecked launch paths and discarded keepalive cancellation, supported by the reporter’s corrected traces; no live shutdown reproduction, builds, or tests ran, and WinApp CLI was unavailable.

    Is this the best way to solve the issue?

    The shared lifecycle prerequisite and focused consumer repairs fit the defect, provided failing regressions cover zero launches after session-end observation, transitions during backoff and preparation, and unchanged ordinary reconnect behavior.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The popup race has not been independently reproduced on current main, and the reporter’s mid-session failures remain unattributed.
    • The shared lifecycle source must handle canceled session-end requests and transitions during asynchronous preparation without permanently disabling normal recovery.

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

    Label changes

    Label changes:

    No label changes.

    Label justifications:

    • P2: Shutdown error dialogs warrant repair, with no established data loss, blocked first run, or failed recovery on the next boot.
    • impact:ux-friction: Alarming Windows application-error dialogs create avoidable confusion and support burden during shutdown.
    Evidence reviewed

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

  3. petruslin commented on Oct 1, 2026

    @petruslin
    Author

    Follow-up from the reporter: reproduction data, and a correction to my own report

    I filed this, then kept the machine running and collected a longer sample. Two things
    came out of it: the evidence the review asked for, and a claim in my original post that
    the data does not support. Retracting that first.


    1. Retraction: "exactly 2 dialogs, always" is wrong

    My original post says the popup count is always exactly two. It isn't. That was drawn
    from three consecutive shutdowns on one afternoon, all of which happened to be n=2.
    Over a 9-day window the count ranges from 1 to 15:

    n=1  : 1 burst
    n=2  : 16 bursts   <- still the mode, but not invariant
    n=3  : 4 bursts
    n=8  : 1 burst
    n=15 : 1 burst
    

    The two-reconnect-path story (node keep-alive and gateway keep-alive each spawning their
    own wsl.exe) is still the best explanation for why 2 is the mode. It is not an
    explanation for a fixed count. See §4.


    2. Popup bursts over 9 days (2026-09-22 .. 2026-10-01)

    Application Popup / System / Event ID 26, filtered to records whose joined property
    text contains wsl.exe. 68 records, grouped into bursts by a >120 s gap:

     1) 09-22 20:51:55 .. 20:51:57   n=2   span=  2.0s   1074=09-22 20:51:53
     2) 09-23 00:38:23 .. 00:38:23   n=2   span=  0.0s   1074=09-23 00:38:21
     3) 09-23 08:11:26 .. 08:11:26   n=2   span=  0.1s   1074=09-23 08:11:24
     4) 09-23 09:22:06 .. 09:23:00   n=15  span= 54.3s   1074=09-23 09:22:04
     5) 09-24 01:17:31 .. 01:17:31   n=2   span=  0.0s   1074=09-24 01:17:42
     6) 09-24 09:59:13 .. 09:59:13   n=2   span=  0.0s   1074=09-24 09:59:12
     7) 09-24 10:08:05 .. 10:08:05   n=2   span=  0.2s   1074=09-24 10:08:03
     8) 09-24 12:02:06 .. 12:02:38   n=8   span= 32.1s   1074=09-24 12:02:52
     9) 09-25 03:27:34 .. 03:27:34   n=2   span=  0.0s   1074=09-25 03:27:30
    10) 09-26 21:48:11 .. 21:48:11   n=2   span=  0.0s   1074=09-26 21:48:09
    11) 09-27 03:20:23 .. 03:20:25   n=3   span=  1.9s   1074=09-27 03:20:21
    12) 09-27 05:07:48 .. 05:07:48   n=2   span=  0.0s   1074=09-27 05:07:46
    13) 09-28 01:37:20 .. 01:37:20   n=2   span=  0.0s   1074=09-28 01:37:51
    14) 09-28 10:50:54 .. 10:50:54   n=2   span=  0.2s   1074=09-28 10:50:52
    15) 09-29 01:39:20 .. 01:39:20   n=2   span=  0.2s   1074=09-29 01:39:34
    16) 09-29 17:23:42 .. 17:23:43   n=3   span=  1.7s   1074=09-29 17:23:40
    17) 09-29 18:13:34 .. 18:13:34   n=1   span=  0.0s   1074=09-29 18:13:32
    18) 09-29 23:50:16 .. 23:50:16   n=2   span=  0.0s   1074=09-29 23:50:14
    19) 10-01 12:46:29 .. 12:46:29   n=2   span=  0.1s   1074=10-01 12:46:28
    20) 10-01 14:31:50 .. 14:31:50   n=2   span=  0.1s   1074=10-01 14:31:48
    21) 10-01 16:44:46 .. 16:44:49   n=2   span=  2.8s   1074=10-01 16:44:44
    22) 10-01 16:53:32 .. 16:53:32   n=3   span=  0.1s   1074=10-01 16:53:31
    23) 10-01 17:01:37 .. 17:01:37   n=3   span=  0.1s   1074=10-01 17:01:35
    

    All 23 bursts have a shutdown/restart initiation (Event 1074) within ±120 s — 23/23,
    no exceptions.
    The same window contains 49 boots (Event 6005) and 46 Event 1074
    records, so roughly half of teardowns produced a burst. I am deliberately not quoting a
    precise rate: a single physical restart can log two 1074s (observed 09-22 20:51:53
    StartMenuExperienceHost.exe, then 20:52:01 winlogon.exe, reason 0x500ff), so the
    denominator depends on how you dedupe.

    Note the ordering is not reliable: in 19 bursts the 1074 precedes the burst, in 4
    (rows 5, 8, 13, 15) it follows it by 11-46 s. I would not build anything on the ordering
    inside that 2-minute window.


    3. Same record verbatim

    Log:      System
    Provider: Application Popup
    Event ID: 26
    Caption:  wsl.exe - Application Error
    Message:  应用程序无法正常启动(0xc0000142)。
              [click OK to close the application]
    

    4. Why the count varies — and why the trigger chain is necessary but not sufficient

    The tray log (%LOCALAPPDATA%\OpenClawTray\openclaw-tray.log) shows, for every one of
    the four 10-01 shutdowns, both keep-alive paths detecting the drop and re-arming:

    16:53:31.353 [WARN] Connection closed prematurely
    16:53:31.366 [WARN] gateway reconnecting in 1016ms (attempt 1)
    16:53:31.371 [WARN] node    reconnecting in 1114ms (attempt 1)
    
    17:01:36.122 [WARN] Connection closed prematurely
    17:01:36.122 [WARN] Connection closed prematurely
    17:01:36.136 [WARN] node    reconnecting in 1154ms (attempt 1)
    17:01:36.148 [WARN] gateway reconnecting in 1121ms (attempt 1)
    
    17:14:31.974 [WARN] Connection closed prematurely
    17:14:31.978 [WARN] Connection closed prematurely
    17:14:31.981 [WARN] node    reconnecting in 1027ms (attempt 1)
    17:14:31.982 [WARN] gateway reconnecting in 1135ms (attempt 1)
    
    17:44:13.150 [WARN] Connection closed prematurely
    17:44:13.150 [WARN] Connection closed prematurely
    17:44:13.156 [WARN] node    reconnecting in 1193ms (attempt 1)
    17:44:13.159 [WARN] gateway reconnecting in 1204ms (attempt 1)
    

    Putting that next to the popup counts for the same four shutdowns:

    shutdown chain in tray log Event 26 records
    16:53:31 yes, both paths 3
    17:01:35 yes, both paths 3
    17:14:31 yes, both paths 0
    17:44:13 yes, both paths 0

    Identical trigger, different outcome. The chain firing is necessary but not
    sufficient — it is a race against how far the process teardown has progressed. That is
    also why I think a single reboot is not a valid non-reproduction: see §5.

    What the count is not driven by

    When I filed, I assumed each reconnect attempt spawns its own wsl.exe, so the dialog
    count would follow the number of attempts. The tray log refutes that, and I can show it
    rather than guess.

    Every connection-drop event in the log's retention window (2026-09-29 15:19 → now)
    re-armed with exactly two attempts, both attempt 1 — one on the node path, one on
    the gateway path — at 1016-1233 ms. Nothing else, ever:

    09-29 17:23:40   2 attempts (node 1, gateway 1)  ->  n=3
    09-29 18:13:32   2 attempts                      ->  n=1
    09-29 21:42:17   2 attempts                      ->  n=0
    09-29 23:32:02   2 attempts                      ->  n=0
    09-29 23:50:15   2 attempts                      ->  n=2
    10-01 11:42:46   2 attempts                      ->  n=0
    10-01 12:46:28   2 attempts                      ->  n=2
    10-01 14:31:49   2 attempts                      ->  n=2
    10-01 16:44:45   2 attempts                      ->  n=2
    10-01 16:53:31   2 attempts                      ->  n=3
    10-01 17:01:36   2 attempts                      ->  n=3
    10-01 17:14:31   2 attempts                      ->  n=0
    10-01 17:44:13   2 attempts                      ->  n=0
    

    Constant input, 0-to-3 output. So the count is not a function of the retry structure.
    The only multi-attempt sequences anywhere in the window (attempt 2 ~2.0-2.4 s,
    attempt 3 ~4.9 s) are on 10-01 14:49-14:51 and 17:49 — sessions where the gateway was
    genuinely down for minutes with no shutdown in progress — and those produced zero
    popups. More retries, no dialogs; exactly two retries, up to three dialogs. I'd call the
    backoff-count idea dead.

    Two things I'd still flag, because they're where the answer has to be:

    • n=3 > 2 logged re-arms. Three dialogs out of two logged spawns means at least one
      further wsl.exe spawn happens on this path that the two reconnecting in ... lines
      do not represent. The keep-alive service's own ensure/repair path is my candidate: it
      only logs [WslKeepAlive] Started keepalive for OpenClawGateway (PID n). on success
      at startup, so a failed ensure during teardown would leave no line at all.
    • n=15 over a 54.3 s span cannot come from two spawns 1.2 s apart. Whatever produces
      the two sustained bursts (rows 4 and 8) has to be a repeated spawner. I cannot count
      its attempts: openclaw-tray.log starts at 2026-10-01 10:51:01 and
      openclaw-tray.log.old at 2026-09-29 15:19:56, so combined retention is under two days.
      That is verified by reading both files' first lines, not assumed — rows 4 and 8 are
      permanently unverifiable from this machine.

    So the two-reconnect-path story explains why 2 is the mode, and why dialogs exist at
    all. It does not explain the spread. How many times each path actually calls spawn —
    including calls that fail before they can log — is what would settle both bullets at
    once, and that needs the source.


    5. Reproduction preconditions (the likely answer to "not independently reproduced")

    Two things have to be true, and the first is easy to miss:

    1. The tray must be up and connected before you shut down. It starts after logon and
      takes time to establish both connections. On 10-01 I shut down three times within
      ~2 minutes of logon (17:03:03, 17:07:13, 17:09:39) and got zero popups each time —
      nothing had been established yet, so there was nothing to tear down. Leave the session
      idle for several minutes before rebooting.
    2. Even then it is probabilistic. 17:14:31 had the full chain and produced nothing.

    So: reboot-from-Start-menu once, immediately, and you will very likely conclude this is
    not reproducible. The precondition above is the difference.

    And do not use "I saw no popup" as the success signal. ErrorMode=2
    (HKLM\SYSTEM\CurrentControlSet\Control\Windows) suppresses the display of these
    dialogs without stopping the spawn or the Event 26 record. I set it on 10-01 at 16:53:19;
    the very next shutdown (16:53:31) still logged 3 Event 26 records while showing nothing
    on screen. Event 26 is the ground truth; the dialog being visible is not.


    6. What I can and cannot contribute

    I can keep collecting Event 26 / tray-log data on this machine, and I can run an
    instrumented build and send you the logs. I cannot hand you a failing regression myself:
    I don't have a working build environment for the tray here, so I can't compile or run the
    test project.

    What I would assert in one, if that's useful — the observable contract, stated so it can
    fail:

    During a session-end sequence (WM_QUERYENDSESSION / WM_ENDSESSION /
    Environment.HasShutdownStarted), the tray must not spawn any child process on behalf
    of the keep-alive or reconnect paths.

    A test for that does not need the real shutdown: a fake/replaceable process-spawner
    injected into the keep-alive path, driven with "connection dropped" after a simulated
    session-end, should record zero spawns. That test fails on the current build and
    passes once the repair is in — which is what the review asked for, and it is the piece
    I can't produce without a build.


    Command I used to produce §2, if you want to run it on another machine:

    $ev = Get-WinEvent -FilterHashtable @{LogName='System'; Id=26; StartTime=(Get-Date).AddDays(-9)}
    $pop = $ev | Where-Object {
        (($_.Properties | ForEach-Object { [string]$_.Value }) -join ' ') -match 'wsl\.exe'
    } | Sort-Object TimeCreated
    $cl = @(); $cur = @()
    foreach ($p in $pop) {
        if ($cur.Count -gt 0 -and ($p.TimeCreated - $cur[-1].TimeCreated).TotalSeconds -gt 120) {
            $cl += ,$cur; $cur = @()
        }
        $cur += $p
    }
    if ($cur.Count) { $cl += ,$cur }
    $cl | ForEach-Object { "{0} .. {1}  n={2}" -f $_[0].TimeCreated, $_[-1].TimeCreated, $_.Count }

    Join all properties before matching — the caption is empty on some Event 26
    families, and matching on caption alone silently drops them.

    Environment: Windows 11 Home China 10.0.26300; OpenClaw Companion 2026.9.4.0
    (tray: %LOCALAPPDATA%\OpenClawTray\).

  4. clawsweeper commented on Oct 1, 2026

    @clawsweeper

    🦞🔧
    ClawSweeper is automatically building a fix for this issue.

    The issue review finished and no active implementation pull request was found.

    Automatic implementation progress:

    Result: implementation blocked.

  5. petruslin commented on Oct 1, 2026

    @petruslin
    Author

    Reporter follow-up: root cause, a correction to my own report, and reproduction preconditions

    I filed this, then read the source and kept collecting. The first section is where the
    bug actually lives, with line references. Section 2 retracts a claim from my original
    post that 16 days of data do not support.


    1. Root cause: nothing in the tray knows the session is ending

    wsl.exe is the victim here, not the culprit. The popups are the tray spawning wsl.exe
    while the session is being torn down.

    (a) There is no session-end handling anywhere in the source. Searched all of src/:

    grep -rn "SessionEnding|QueryEndSession|HasShutdownStarted|WM_ENDSESSION|WM_QUERYENDSESSION|SystemEvents" src/
      -> no matches
    

    Zero hits. Nothing in the tray observes WM_QUERYENDSESSION, WM_ENDSESSION,
    SystemEvents.SessionEnding, or Environment.HasShutdownStarted. This is the
    "session-ending guard" the review asked for — it does not exist today, so there is
    nothing for the keep-alive/repair paths to consult.

    (b) A 5-second poll loop keeps running through teardown.
    src/OpenClaw.Tray.WinUI/Services/ManagedLocalGatewayAutoRepairMonitor.cs:

    :83  _unhealthyThreshold = unhealthyThreshold ?? TimeSpan.FromSeconds(15);
    :84  _pollInterval       = pollInterval       ?? TimeSpan.FromSeconds(5);
    :85  _cooldown           = cooldown           ?? TimeSpan.FromSeconds(90);
    :86  _startupGrace       = startupGrace       ?? TimeSpan.FromSeconds(45);
    :97  _loop = Task.Run(() => RunAsync(_cts.Token));
    :102 while (!cancellationToken.IsCancellationRequested)
    :106     await EvaluateOnceAsync(cancellationToken)...
    :119     await _delay(_pollInterval, cancellationToken)...
    
    // DisposeAsync:
    :292 try { await Task.WhenAny(loop, Task.Delay(TimeSpan.FromSeconds(3)))...

    The loop's only exit is _cts.Cancel(), and DisposeAsync is willing to abandon it
    after 3 seconds. So the monitor is free to act during the window that matters here.

    (c) Session teardown is exactly what that loop classifies as "repairable".
    Same file, :246-271 IsTransportUnreachable returns true for Connecting with no
    classified error (:259-264). When the gateway socket dies because services are stopping,
    the operator state is precisely "connecting, no error classified" — so the monitor
    qualifies the teardown as a transport outage and calls the repair coordinator
    (:208 await _repairAsync(...)). The repair budget is 3 restarts per gateway
    (ManagedLocalGatewayRepairCoordinator.cs:142, :161, checked at :381).

    (d) The repair path spawns wsl.exe through a bare Process.Start that bypasses
    logging.
    src/OpenClaw.Tray.WinUI/Services/WslGatewayKeepAliveService.cs:

    :73-76  // ... TryEnsureAsync runs at startup AND on every managed-local auto-repair
            // (re-arm after a distro restart) ...
    :85     var psi = new System.Diagnostics.ProcessStartInfo
    :91-95  psi.ArgumentList.Add("-d"); psi.ArgumentList.Add(distroName);
            psi.ArgumentList.Add("--"); psi.ArgumentList.Add("sleep"); psi.ArgumentList.Add("infinity");
    :97     var proc = System.Diagnostics.Process.Start(psi);   // bare spawn
    :100    Logger.Info($"[WslKeepAlive] Started keepalive for {distroName} (PID {proc.Id}).");

    Two things matter here. First, it calls System.Diagnostics.Process.Start directly,
    not through the instrumented runner — compare
    src/OpenClaw.Connection/WslCommandRunner.cs:132, which builds its ProcessStartInfo
    and then logs [WSL] {fileName} {args} at :153. Second, the keepalive logs only on
    success
    (:100, inside if (proc is not null)) — so a keepalive spawn that fails
    during teardown leaves no trace in the log at all. And per its own comment at :73-76,
    this path runs on every auto-repair, not just at startup.

    Mechanism, stated plainly:

    session end (Event 1074, or any teardown)
      -> services stop; the WSL VM / distro disappears
      -> the tray's 5 s repair loop is still running and sees "Connecting, no error"
      -> it qualifies as transport-unreachable and repairs
      -> the keepalive path spawns wsl.exe -d <distro> -- sleep infinity
         (bare Process.Start; the reconnect path spawns its own wsl.exe -d <distro> -- bash -s)
      -> creating the process needs a console/DLL init that can no longer complete
      -> STATUS_DLL_INIT_FAILED (0xc0000142) -> NtRaiseHardError
      -> "wsl.exe - Application Error" dialog + Application Popup / Event ID 26
    

    This is not a WSL bug, and not specific to wsl.exe. In the same 09-16/09-17 window,
    0xc0000142 during teardown also hit whoami.exe, where.exe, powershell.exe,
    cscript.exe, runas.exe, clip.exe, wscript.exe, openfiles.exe, certutil.exe,
    tasklist.exe, timeout.exe, choice.exe, msinfo32.exe, dxdiag.exe. Anything the
    tray (or anything else) tries to launch at that moment fails the same way. The defect is
    "spawning during teardown," and wsl.exe is simply what the tray keeps spawning.


    2. Correction to my own report: "exactly 2 dialogs, always" is wrong

    My original post says the count is always exactly two. It isn't. That came from three
    consecutive shutdowns on one afternoon that all happened to be n=2. Over 16 days
    (2026-09-16 .. 2026-10-01) the real distribution is 92 records in 35 bursts:

    n=1  :  2 bursts
    n=2  : 26 bursts      <- the mode (74%), not an invariant
    n=3  :  5 bursts
    n=8  :  1 burst
    n=15 :  1 burst       <- 54.3 s span
    

    Range 1–15. Do not hardcode 2, and do not write a test that asserts 2. Full table in
    Appendix A.

    What this does not change: the two-spawn-path story is still the best explanation for
    why 2 is the mode, and for why dialogs exist at all. It does not explain the spread.

    The count is not the retry count. Every connection-drop event in the tray log's
    retention window re-armed with exactly two attempts, both attempt 1 (one node path, one
    gateway path, 1016–1233 ms):

    16:53:31.353 [WARN] Connection closed prematurely
    16:53:31.366 [WARN] gateway reconnecting in 1016ms (attempt 1)
    16:53:31.371 [WARN] node    reconnecting in 1114ms (attempt 1)
    
    17:01:36.122 [WARN] Connection closed prematurely
    17:01:36.122 [WARN] Connection closed prematurely
    17:01:36.136 [WARN] node    reconnecting in 1154ms (attempt 1)
    17:01:36.148 [WARN] gateway reconnecting in 1121ms (attempt 1)
    
    17:14:31.974 [WARN] Connection closed prematurely
    17:14:31.978 [WARN] Connection closed prematurely
    17:14:31.981 [WARN] node    reconnecting in 1027ms (attempt 1)
    17:14:31.982 [WARN] gateway reconnecting in 1135ms (attempt 1)
    
    17:44:13.150 [WARN] Connection closed prematurely
    17:44:13.150 [WARN] Connection closed prematurely
    17:44:13.156 [WARN] node    reconnecting in 1193ms (attempt 1)
    17:44:13.159 [WARN] gateway reconnecting in 1204ms (attempt 1)
    
    shutdown chain in tray log Event 26 records
    16:53:31 yes, both paths 3
    17:01:35 yes, both paths 3
    17:14:31 yes, both paths 0
    17:44:13 yes, both paths 0

    Constant input, 0-to-3 output. The only multi-attempt sequences anywhere in the window
    (attempt 2 ~2.0–2.4 s, attempt 3 ~4.9 s) are on 10-01 14:49–14:51 and 17:49 — sessions
    where the gateway was genuinely down for minutes with no shutdown in progress — and
    those produced zero popups. More retries, no dialogs; two retries, up to three
    dialogs. The backoff-count idea is dead.

    Two things I'd still flag, because they're where the answer has to be, and item (d) in
    §1 is my candidate for both:

    • n=3 out of two logged re-arms. Three dialogs from two logged spawns means at least
      one further wsl.exe spawn on this path that the reconnecting in ... lines do not
      represent. The keepalive in §1(d) logs only on success, so a failed keepalive spawn is
      invisible here.
    • n=15 over 54.3 s cannot come from two spawns 1.2 s apart. Something sustained is
      re-spawning. I cannot count its attempts: openclaw-tray.log starts at
      2026-10-01 10:51:01 and openclaw-tray.log.old at 2026-09-29 15:19:56, so combined
      retention is under two days. That is read off both files' first lines, not assumed —
      the 09-23 and 09-24 bursts are permanently unverifiable from this machine.

    And one correction I can't make go away. Of the 35 bursts, 29 have an Event 1074
    within ±120 s — not all of them.
    Five bursts have neither a nearby 1074 nor a following
    boot:

     3) 09-17 19:07:13   n=2
     4) 09-20 01:52:39   n=2
     5) 09-20 13:43:50   n=2
     6) 09-20 18:16:53   n=2
     7) 09-21 12:25:54   n=2
    

    Same binary, same error code, but mid-session, not shutdown- or boot-correlated. So
    the mechanism is not exclusive to session end — it also fires when the tray spawns
    wsl.exe while the WSL service/distro is unavailable. That is consistent with §1: the
    trigger is "spawn attempted while WSL can't come up," and session end is only the most
    common way to get there on this machine. (A sixth burst, 09-22 11:02:37, also has no
    nearby 1074; it has a boot 285 s later, which is too far to be a shutdown artifact.)
    I can't attribute these five to a specific code path, because the tray log that would
    show it is gone.


    3. Reproduction preconditions — the likely answer to "not independently reproduced"

    Two conditions, and the first is easy to miss:

    1. The tray must be up and connected before you shut down. It starts after logon and
      takes time to establish both connections. On 10-01 I shut down three times within
      ~2 minutes of logon (17:03:03, 17:07:13, 17:09:39) and got zero popups each time —
      nothing had been established, so there was nothing to tear down. Leave the session
      idle for at least ~4 minutes after logon before rebooting
      , or the sample is void.
    2. Even then it is a race, not a certainty. 17:14:31 had the complete chain and
      produced nothing — most likely because the tray process was killed before its ~1.1 s
      timers fired. So: reboot once from the Start menu immediately and you will very likely
      conclude it doesn't reproduce; the precondition above is the difference.

    Two measurement traps for anyone reproducing this:

    Do not use "no popup appeared" as the success signal. ErrorMode=2
    (HKLM\SYSTEM\CurrentControlSet\Control\Windows) suppresses only the display of these
    dialogs — creation and Event 26 recording continue. I set it on 10-01 at 16:53:19, and
    every shutdown since still logged popups that were invisible on screen:

    shutdown Event 26 records visible on screen
    16:53:31 3 no
    17:01:37 3 no
    18:03:40 3 no

    Ground truth is Application Popup / Event ID 26 in the System log, not what you saw.

    Query-window trap: the shutdown-side Event 26 is written before the next boot, so
    StartTime = <this boot's LastBootUpTime> returns nothing for shutdown popups. Query
    a window around the preceding 1074 (±120 s). Verified live: the newest wsl.exe record is
    2026-10-01 18:03:41, which precedes the 18:04:18 boot.

    Split by family before counting. Event 26 is a superset — 283 records on this machine
    over 27 days, of which only 92 are wsl.exe. On the same machine 87 are an unrelated
    boot-time driver load failure (XLGuard.sys) and 41 are an unrelated app crash. Filter on
    the joined property text; the caption (Properties[0]) is empty for some families, so
    matching caption alone silently drops them. See Appendix B.


    4. The observable contract, and the test I can't write

    If it's useful, the contract stated so it can fail:

    During a session-end sequence (WM_QUERYENDSESSION / WM_ENDSESSION /
    Environment.HasShutdownStarted), the tray must not spawn any child process on behalf
    of the keep-alive or reconnect paths.

    A test for that does not need a real shutdown: with a fake/replaceable process-spawner
    injected into the keep-alive path, drive "connection dropped" after a simulated
    session-end and assert zero spawns are recorded. That test fails on the current build
    and passes once the guard exists. Given §1, a regression test that asserts "the repair
    loop does not call the spawner once shutdown has started" is probably the cheapest form.


    5. What I can and cannot contribute

    I can keep collecting Event 26 / tray-log data on this machine, run an instrumented build
    and send you the logs, and verify a fix on real reboots (≥4 min idle after logon, then
    reboot, then check Event 26 — not the screen).

    I cannot hand you a failing regression myself: I don't have a working build
    environment for the tray here, so I can't compile or run the test project. That is the one
    piece I can't produce.


    Appendix A — wsl.exe Event 26 bursts, 2026-09-16 .. 2026-10-01

    Application Popup / System / Event ID 26, joined property text matching wsl.exe,
    grouped into bursts by a >120 s gap. 92 records, 35 bursts, 16 days.
    Δ1074 = popup time minus the nearest Event 1074 within ±120 s (positive = popup came
    after the 1074
    ); boot = next Event 6005 within [−60 s, +600 s].

         burst start          .. end         n    span     Δ1074     boot
     1) 09-16 00:55:47 .. 00:55:47        2     0.0s   +1.9s     --
     2) 09-17 13:12:32 .. 13:12:32        2     0.0s   +1.9s     --
     3) 09-17 19:07:13 .. 19:07:13        2     0.2s   --        --     <- mid-session
     4) 09-20 01:52:39 .. 01:52:39        2     0.0s   --        --     <- mid-session
     5) 09-20 13:43:50 .. 13:43:51        2     0.1s   --        --     <- mid-session
     6) 09-20 18:16:53 .. 18:16:53        2     0.0s   --        --     <- mid-session
     7) 09-21 12:25:54 .. 12:25:54        2     0.1s   --        --     <- mid-session
     8) 09-22 00:27:38 .. 00:27:38        2     0.1s   +1.7s     --
     9) 09-22 01:19:14 .. 01:19:14        2     0.1s   +2.5s     --
    10) 09-22 11:02:37 .. 11:02:37        2     0.1s   --        +285s
    11) 09-22 14:39:26 .. 14:39:26        1     0.0s   +1.6s     --
    12) 09-22 20:51:55 .. 20:51:57        2     2.0s   +1.8s     +53s
    13) 09-23 00:38:23 .. 00:38:23        2     0.0s   +2.1s     --
    14) 09-23 08:11:26 .. 08:11:26        2     0.1s   +1.6s     +67s
    15) 09-23 09:22:06 .. 09:23:00       15    54.3s   +1.7s     +71s
    16) 09-24 01:17:31 .. 01:17:31        2     0.0s  -10.8s     --
    17) 09-24 09:59:13 .. 09:59:13        2     0.0s   +1.7s     +61s
    18) 09-24 10:08:05 .. 10:08:05        2     0.2s   +1.5s     +49s
    19) 09-24 12:02:06 .. 12:02:38        8    32.1s  -45.6s     --
    20) 09-25 03:27:34 .. 03:27:34        2     0.0s   +4.7s     --
    21) 09-26 21:48:11 .. 21:48:11        2     0.0s   +1.9s     +55s
    22) 09-27 03:20:23 .. 03:20:25        3     1.9s   +1.8s     +55s
    23) 09-27 05:07:48 .. 05:07:48        2     0.0s   +1.8s     +56s
    24) 09-28 01:37:20 .. 01:37:20        2     0.0s  -31.1s     --
    25) 09-28 10:50:54 .. 10:50:54        2     0.2s   +1.7s     +56s
    26) 09-29 01:39:20 .. 01:39:20        2     0.2s  -13.7s     --
    27) 09-29 17:23:42 .. 17:23:43        3     1.7s   +1.8s     +59s
    28) 09-29 18:13:34 .. 18:13:34        1     0.0s   +1.7s     +59s
    29) 09-29 23:50:16 .. 23:50:16        2     0.0s   +1.9s     --
    30) 10-01 12:46:29 .. 12:46:29        2     0.1s   +1.8s     +59s
    31) 10-01 14:31:50 .. 14:31:50        2     0.1s   +1.7s     +67s
    32) 10-01 16:44:46 .. 16:44:49        2     2.8s   +1.6s     +54s
    33) 10-01 16:53:32 .. 16:53:32        3     0.1s   +1.4s     +51s
    34) 10-01 17:01:37 .. 17:01:37        3     0.1s   +1.5s     +51s
    35) 10-01 18:03:40 .. 18:03:41        3     0.3s   +1.6s     +52s
    

    Notes:

    • The canonical signature is the last six rows and 25 of the 35 overall: 1074 first,
      popup +1.4 .. +4.7 s later.
      That tight band is the whole 1.0–1.2 s reconnect timer
      plus spawn overhead — which is why I think the trigger is the reconnect/keepalive
      spawn, not something at boot.
    • Rows 16, 19, 24, 26 have the popup before the nearest 1074 (−10.8, −45.6, −31.1,
      −13.7 s). I would not build anything on ordering inside the ±120 s window; a single
      physical restart logs two 1074s (e.g. 09-22 20:51:53 StartMenuExperienceHost.exe,
      then 20:52:01 winlogon.exe, reason 0x500ff).
    • I'm deliberately not quoting a reproduction rate. The denominator depends on how you
      dedupe 1074s, and §3 explains why "no popup" is not a valid negative.
    • Sample record, for anyone re-running this: burst 35 (18:03:40–41, n=3) has its 1074 at
      18:03:39 and the next boot at 18:04:18. Those three popups were invisible on
      screen
      because ErrorMode=2 was already active.

    Appendix B — Event 26 is a superset; split by family first

    All 283 Event 26 records on this machine, 2026-09-05 15:55:44 .. 2026-10-01 18:04:20,
    grouped by joined property text:

    family count
    wsl.exe - Application Error / 应用程序无法正常启动(0xc0000142)。 92
    caption empty / \SystemRoot\system32\drivers\XLGuard.sys failed to load + numeric args 87
    FMAudioMonitor.exe - 应用程序错误 (0xc0000005) 41
    whoami.exe - Application Error (0xc0000142) 10
    where.exe, powershell.exe, cscript.exe, runas.exe, clip.exe, wscript.exe, openfiles.exe, certutil.exe, tasklist.exe, timeout.exe, choice.exe, msinfo32.exe, dxdiag.exe (all 0xc0000142) 1–8 each
    Windows - Virtual Memory Minimum Too Low 6
    misc (cutechess.exe missing Qt DLL, 损坏的映像 / 0xc0000022, HP Hotkey, svchost.exe - Unknown Hard Error) 1–2 each

    The 92 and the 87 must never be summed: one is a shutdown-time spawn failure, the other a
    boot-time driver load failure. Both land in Event ID 26.

    Appendix C — commands used

    Burst detection (§2 / Appendix A):

    $s = Get-Date '2026-09-05'; $e = Get-Date '2026-10-02'
    $ev  = Get-WinEvent -FilterHashtable @{LogName='System'; Id=26; StartTime=$s; EndTime=$e}
    $pop = $ev | Where-Object {
        (($_.Properties | ForEach-Object { [string]$_.Value }) -join ' ') -match 'wsl\.exe'
    } | Sort-Object TimeCreated
    
    $cl = @(); $cur = @()
    foreach ($p in $pop) {
        if ($cur.Count -gt 0 -and ($p.TimeCreated - $cur[-1].TimeCreated).TotalSeconds -gt 120) {
            $cl += ,$cur; $cur = @()
        }
        $cur += $p
    }
    if ($cur.Count) { $cl += ,$cur }
    $cl | ForEach-Object { "{0} .. {1}  n={2}" -f $_[0].TimeCreated, $_[-1].TimeCreated, $_.Count }

    Family split (Appendix B) — join all properties before matching; the caption is empty
    on some families, and matching on caption alone silently drops them:

    Get-WinEvent -FilterHashtable @{LogName='System'; Id=26; StartTime=$s; EndTime=$e} |
        Group-Object { ($_.Properties | ForEach-Object { [string]$_.Value }) -join ' ' } |
        Sort-Object Count -Descending |
        Select-Object Count, Name

    Environment: Windows 11 Home China 10.0.26300; OpenClaw Companion 2026.9.4.0
    (tray data: %LOCALAPPDATA%\OpenClawTray\).

  6. petruslin commented on Oct 1, 2026

    @petruslin
    Author

    Split into three narrower jobs

    The autonomous fix for this issue was blocked because the artifact it produced spanned three subsystems. The three spawn paths are now tracked separately, one production file each:

    This issue stays open as the evidence trail: the 16-day Event 26 census, the Event 1074 ordering, the tray-log excerpts, and the family split against the unrelated XLGuard.sys boot popup. Each split issue carries its own, narrower fix artifact, so the previously blocked implementation job on this issue does not need to be re-run.

    One note on the reported machine's local mitigation, since it can look like the defect is gone: HKLM\SYSTEM\CurrentControlSet\Control\Windows\ErrorMode = 2 suppresses the display of the "Application Error" dialog only. Process creation still fails, and Event 26 is still recorded on every affected shutdown. The failure itself is untouched.

  7. added
    clawsweeper:intake:bug
    and removed
    clawsweeper:queueable-fix
    clawsweeper:fix-shape-clear
    no-stale
    clawsweeper:intake:bug
    on Oct 20, 2026
  8. github-actions commented on Nov 4, 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.

  9. added
    clawsweeper:intake:bug
    and removed
    clawsweeper:intake:bug
    on Nov 4, 2026
  10. added
    clawsweeper:intake:bug
    and removed
    clawsweeper:intake:bug
    on Nov 15, 2026
  11. github-actions commented on Nov 29, 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.

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:source-reproimpact:ux-frictionissue-rating: 🦞 diamond lobsterstale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions