Tray spawns `wsl.exe` during session teardown, producing an "Application Error 0xc0000142" popup on every shutdown/restart
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 64/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- csharp
- Domain
- desktop, operating-systems
Research direction
Trace _reArmKeepAliveAsync, reconnectIfCurrentAsync, probeReachableAsync, and WslGatewayKeepAliveService.TryEnsureAsync to find every reconnect or keepalive spawn. Add session-ending guards and logging for the repair/probe command, then reproduce with a Windows shutdown or restart. Done means teardown produces no new wsl.exe spawn or Application Popup event while normal reconnect behavior remains intact.
Written by the indexing model from the issue text.
Description
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
- Start the tray normally and let it reach the steady state (keepalive running,
i.e. a long-livedwsl.exe -d OpenClawGateway -- sleep infinityis present). - 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: falsedoes 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 lefttrue(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: falsewould 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.exeruns 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\DontShowUIdoes 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
- Before any keepalive/reconnect spawn, bail out if the session is ending. Either:
- check
Environment.HasShutdownStarted, and/or - subscribe once to
Microsoft.Win32.SystemEvents.SessionEndingand 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.
- check
- 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
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 321
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 173
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openclaw/openclaw-windows-node
-
clawsweeper:fix-shape-clear clawsweeper:needs-maintainer-review clawsweeper:no-new-fix-pr clawsweeper:not-repro-on-main impact:ux-release-blocker issue-rating: 🦪 silver shellfish P0
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
openclaw/openclaw-windows-node#1843 · 1 comment · 2 reactions ·
Maintainers usually reply within 1 day
-
clawsweeper:needs-product-decision clawsweeper:needs-security-review clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:security impact:ux-friction issue-rating: 🦞 diamond lobster P2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
openclaw/openclaw-windows-node#1763 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openclaw/openclaw-windows-node#1762 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
clawsweeper:source-repro impact:ux-release-blocker issue-rating: 🦞 diamond lobster P0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
openclaw/openclaw-windows-node#1723 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
clawsweeper:needs-live-repro clawsweeper:needs-maintainer-review clawsweeper:no-new-fix-pr impact:ux-release-blocker issue-rating: 🐚 platinum hermit P0
Difficulty 3/5 1-2 days Newbie friendliness 48/100
openclaw/openclaw-windows-node#1882 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
All issues in openclaw/openclaw-windows-node
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
README says main uses .NET 9 while the current branch targets .NET 10Possibly taken @dajiaohuang claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 94/100
ardalis/CleanArchitecture#1098 ·
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 88/100
madeyoga/AuthEndpoints#365 ·
Maintainers usually reply within 1 day
-
ConnectionOpened reports pre-redirect URL when OnConnectingAsync changes the targetPossibly taken @akashchamp claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
majorsilence/Reporting#493 ·
Maintainers usually reply within 1 day