Skip to content

Auto-repair force-terminates the WSL distro but skips the keepalive re-arm when the restart fails #2092

Closed

Description

@marianoluzza

Summary

When auto-repair restarts a setup-managed local WSL gateway, it force-terminates the distro first. That also kills the keepalive (wsl.exe -d <distro> -- sleep infinity). The keepalive is re-armed only when the restart succeeds. If the restart fails or is aborted after the terminate, the distro is left with no keepalive until something else calls TryEnsureAsync. In my case that took about 6 hours.

Version

  • OpenClaw Windows companion 2026.11.1 (04f413d26531)
  • Setup-managed local gateway in the WSL distro OpenClawGateway, running OpenClaw 2026.10.6

Code path (v2026.11.1)

  1. WslGatewayController.cs:130: TerminateDistroAsync, i.e. wsl.exe --terminate <distro>. This kills every wsl.exe session of the distro, the keepalive included.
  2. ManagedLocalGatewayRepairCoordinator.cs:403-417: when the restart throws, returns !restart.Success, or hits GetRestartAbortResult, the method returns RestartFailed or an abort result.
  3. ManagedLocalGatewayRepairCoordinator.cs:419-421: _reArmKeepAliveAsync is reached only on success, so the early returns above skip it.

Evidence (tray log, local time UTC-3)

[2026-11-08 20:53:08.412] [INFO] Running OpenClaw gateway restart in WSL distro 'OpenClawGateway'.
[2026-11-08 20:53:09.945] [INFO] Force-terminating WSL distro 'OpenClawGateway' before restart (in-place restart failed).
[2026-11-08 20:53:09.946] [INFO] [WSL] wsl.exe --terminate OpenClawGateway
[2026-11-08 20:53:10.035] [INFO] Running OpenClaw gateway restart in WSL distro 'OpenClawGateway'.
...
[2026-11-08 21:06:53.411] [INFO] Running OpenClaw gateway restart in WSL distro 'OpenClawGateway'.
[2026-11-08 21:06:55.202] [INFO] Force-terminating WSL distro 'OpenClawGateway' before restart (in-place restart failed).
[2026-11-08 21:06:55.202] [INFO] [WSL] wsl.exe --terminate OpenClawGateway
  • The previous [WslKeepAlive] Started keepalive line is from 2026-11-07 17:25.
  • After these terminates, the next [WslKeepAlive] line is at 2026-11-09 03:18:20.
  • The log does not record the outcome of either repair, so I can't tell whether it was RestartFailed or an abort. Because no re-arm happened, it was not a success.
  • The gateway was slow and failing at startup at the time, which makes a failed restart likely.

Impact

Expected

After any repair attempt that has already issued --terminate, the keepalive should be re-armed, for example from a finally once the terminate has run, whether the restart succeeds or not. A more robust alternative would be for the keepalive service to watch its own process and respawn it whenever it exits.

Workaround

A per-user scheduled task at logon that runs wsl.exe -d OpenClawGateway -- sleep infinity in a loop and relaunches it when it exits.

Activity

  1. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    P1
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:crash-loop
    issue-rating: 🦞 diamond lobster
    no-stale
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Nov 9, 2026
  2. clawsweeper commented on Nov 9, 2026

    @clawsweeper

    Codex review: this still needs some work.

    Summary
    Keep this issue open: current main still skips keepalive restoration when a forced WSL restart fails, and no matching fix PR was identified.

    Reproducibility: Current source establishes the path: a definitive in-place failure triggers distro termination, a failed cold restart returns RestartFailed, and the coordinator exits before re-arm; no build, test, or native reproduction ran during this read-only review, and WinApp CLI is unavailable on this host.

    Next step
    Fix failure-path keepalive restoration and first establish a failing regression covering termination followed by a failed cold restart, with no unintended restart after Stop or cancellation.

    Review details

    Best possible solution:

    Restore keepalive after failed forced restarts while retaining lifecycle ownership, cancellation, and explicit user-intent safeguards.

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

    Current source establishes the path: a definitive in-place failure triggers distro termination, a failed cold restart returns RestartFailed, and the coordinator exits before re-arm; no build, test, or native reproduction ran during this read-only review, and WinApp CLI is unavailable on this host.

    Is this the best way to solve the issue?

    A focused lifecycle repair is justified, but an unconditional finally or a new respawn supervisor is broader than necessary and could defeat intentional shutdown.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • An unconditional finally-based re-arm could revive a gateway after Stop, Disconnect, gateway switching, cancellation, or session teardown.
    • The reported six-hour gap, channel suppression, and disk exhaustion were not independently reproduced or causally isolated.

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

    Label changes

    Label changes:

    • add P1: A source-confirmed failure in default managed-local recovery can prolong an existing gateway outage on an official affected release.
    • add impact:crash-loop: Losing the WSL keepalive after forced termination undermines gateway process availability and can permit repeated distro idle shutdowns.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P1: A source-confirmed failure in default managed-local recovery can prolong an existing gateway outage on an official affected release.
    • impact:crash-loop: Losing the WSL keepalive after forced termination undermines gateway process availability and can permit repeated distro idle shutdowns.
    Evidence reviewed

    Acceptance criteria:

    • ./build.ps1
    • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore --filter "FullyQualifiedNameManagedLocalGatewayRepairCoordinatorTests|FullyQualifiedNameWslGatewayControllerTests|FullyQualifiedName~WslKeepAlivePolicyTests"
    • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
    • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
    • ./scripts/validate-mxc-e2e.ps1

    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 9, 2026, 1:27 PM ET / 18:27 UTC.

  3. locked as resolved and limited conversation to collaborators on Nov 14, 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

    P1clawsweeper:fix-shape-clearclawsweeper:queueable-fixclawsweeper:source-reproimpact:crash-loopissue-rating: 🦞 diamond lobsterno-stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions