Repository navigation
fix(gateway): gateway stays offline after agent restart on Windows - #134549
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 8:49 PM ET / September 2, 2026, 00:49 UTC. ClawSweeper reviewWhat this changesThe PR routes plain Windows Gateway-service restarts initiated from the Gateway process through the existing safe restart request and documents the limited behavior change. Merge readinessKeep open: current main and v2026.8.2 retain the failing plain-restart routing, while this exact branch introduces a narrow, source-consistent repair with no actionable correctness finding. Priority: P1 Review scores
Verification
How this fits togetherAn agent shell command inherits its Gateway service environment and invokes the shared Gateway/daemon lifecycle CLI. The resolver chooses either native service control or the running Gateway’s deferred restart coordinator, which then relaunches the Windows Scheduled Task. flowchart LR
A[Agent shell command] --> B[Gateway service environment]
B --> C[CLI restart routing]
C --> D[Safe Gateway request]
D --> E[Restart coordinator]
E --> F[Scheduled Task handoff]
F --> G[Replacement Gateway]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +11, Tests +128, Docs +4. Total +143 across 4 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the eligibility policy at the shared command-routing boundary, retain the explicit exclusions, and land the existing Gateway-owned safe restart path rather than changing native task-tree termination. Do we have a high-confidence way to reproduce the issue? Yes at high confidence from source: on Windows a Gateway-descendant plain restart reaches native taskkill /T unless the new service-environment route selects safe RPC. This read-only review did not execute a Windows service, while the PR body supplies three reported native after-fix runs. Is this the best way to solve the issue? Yes. Reusing the running Gateway’s existing safe restart owner before native task-tree termination is narrower and safer than weakening the Scheduled Task cleanup path or routing every Windows restart through safe mode. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c7277fb99e69. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
ad57179 to
6c6728e
Compare
Maintainer reviewBest-fix verdict: best fix at the command-routing owner. The native Windows restart ends the Scheduled Task and terminates the Gateway process tree before relaunch ( The candidate selects the existing safe RPC only for plain Windows Gateway-service calls. Alternatives considered: making every Windows restart safe would break stopped-Gateway recovery for external terminals; suppressing tree cleanup in the task owner changes verified native cleanup and can leave the old listener alive (also observed by @nerclid in #120230 (comment)). The existing safe owner is preferable to either alternative. Code read includes the resolver and real Commander registration for both Gateway and legacy daemon, lifecycle and safe/external-supervisor owners, Scheduled Task control/process/runtime owners, service environment producer, restart coordinator/run loop/respawn/helper, update handoff and restart-helper siblings, supervisor markers, and the adjacent tests. I personally checked Codex's ClawSweeper remaining items addressed: accept the narrowly scoped command-boundary predicate; no separate repair job or new lower-level restart flow is warranted. Production is +13/-2 (net +11), tests +129/-1 (net +128), and documentation +6/-2. The production growth represents the missing routing decision plus preservation of the shipped force/wait/preserve-definition/skip-deferral contracts and external-supervisor ownership. Folding that decision into native task control would duplicate Gateway-safe policy; deleting those exclusions would change public behavior. No unrelated consolidation was used to offset the count. No config, dependency, storage, or schema changes. Independent regression proof: Windows evidence is explicitly separate: the contributor reports three failing-before and three passing-after Windows 11 model-backed webchat runs. I could not repeat that live flow on this Mac. The dedicated Windows probe was dispatched with target_ref The initial local changed gate stopped on five due plugin-compatibility records; main already carried the owning fix, #135322 ( The uncommitted full-diff autoreview returned: The refreshed ClawSweeper review covers the final head; its two maintainer decisions are explicitly accepted above: preserve the narrow eligibility boundary and avoid a separate repair job. Exact-head CI is green. Exact-head landing updateThe rebase was patch-identical for both commits ( The earlier LandedMerged via Final local verification: |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
4f7a071 to
0a8b47d
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…penclaw#134549) * fix(gateway): keep agent restart alive on Windows * docs(gateway): clarify Windows agent restart routing --------- Co-authored-by: Josh <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
* fix(update): restore Gateway after partial stop failure Adapt the service-mutation recovery invariant to the 2026.8 updater owner. (cherry picked from commit ad682b4) * fix(update): replace unsupported service Node runtimes Adapt the recorded-service runtime probe to the 2026.8 daemon install plan. (cherry picked from commit fe79d36) * fix(gateway): gateway stays offline after agent restart on Windows (#134549) * fix(gateway): keep agent restart alive on Windows * docs(gateway): clarify Windows agent restart routing --------- Co-authored-by: Josh <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 3a0a623) * fix: published Linux upgrades leave unchanged gateways stopped (#151049) * fix(update): preserve service fingerprints across published upgrades Keep known-empty systemd override metadata out of the fingerprint retained by published updaters through 2026.9.4. Preserve full command metadata for runtime pinning and reject actual protected service changes. * test: group silence failures with error payload coverage Keep the required sealed-answer fixture field while moving its related failure-policy cases into the existing error payload test module. Preserve every case and assertion without growing the over-cap payload test file. (cherry picked from commit 4475640) * fix(doctor): preserve explicitly configured profile workspaces (#145976) * fix(doctor): preserve configured profile workspaces * fix(doctor): avoid assuming workspace ownership Co-authored-by: ericcaiwx-star <[email protected]> (cherry picked from commit 1e8ba48) * fix(plugins): stop relocated install records from shadowing bundled plugins (#144843) * fix(plugins): stop relocated install records from shadowing bundled plugins A `path` install record stores an absolute directory. When that directory is another OpenClaw installation's bundled plugin tree, the record survives the installation move and is rediscovered as an `origin: "global"` candidate. `global` outranks `bundled`, so the stale pin won the duplicate-id contest and the plugin resolved from the old installation. `resolvePluginTrust` then saw `record.source === "path"` and downgraded it to `origin-path`, which revokes trusted plugin state and fails trusted-only APIs mid-turn. `isIntentionalInstalledBundledDuplicate` also suppressed the duplicate warning, because installed-shadows-bundled is normally deliberate, so the swap was silent. Treat a plugin directory inside a *different* installation's bundled roots as stale: it no longer outranks the current bundled copy, and it no longer counts as an intentional shadow, so the existing duplicate warning reports it. * fix(plugins): name the stale install record instead of a generic duplicate The duplicate-id warning reported "global plugin will be overridden by bundled plugin", which describes the mechanism but gives an operator nothing to act on. A pin into another installation's bundled tree is a stale record rather than a deliberate override, so report it as one and name the remedy. * docs(agents): record that a stored absolute path is not provenance The stale-pin defect this branch fixes came from a persisted absolute path that kept conferring bundled status after the installation it named was replaced. Record the invariant so the next record type does not repeat it. * fix(plugins): narrow the stale-pin gate to relocated compiled trees Review of the preceding guard found two ways it misfired. It answered "foreign" by negating a membership test against the running package roots, so an install whose root resolves from neither argv nor the module URL saw every bundled tree as foreign, including its own. Compiled sibling trees and the module walk-up fallback resolve exactly that way, so the gate now fails open when the running root is unknown. It also accepted `<root>/extensions/<id>`, the documented `plugins install --link` development target, which made a deliberate local override report as a stale record and told the developer to delete it. Only compiled `dist`/`dist-runtime` trees travel with an installation, so the shape check is limited to those, and a plugin inside the configured dev source root is excluded at the call site, where importing it raises no cycle. * test(auth): pin external credential refresh timing (#152771) --------- Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 5ec3614) * fix(plugins): archive updates fail on development-only dependencies (#143350) * fix(plugins): isolate npm manifest resolution * fix(plugins): preserve hook host dependencies * test(plugins): align npm isolation coverage with CI limits * fix(plugins): link optional-only OpenClaw host dependencies * test(gateway): settle companion databases before fixture cleanup * test(plugins): cover optional hosts in native import preparation * test(skills): close status watchers before retiring fixture roots --------- Co-authored-by: Gio Della-Libera <[email protected]> Co-authored-by: Jason (Json) <[email protected]> (cherry picked from commit cbf935b) * fix(gateway): release agent leases when shutdown completes (#151435) Drain the existing agent database lifecycle during final Gateway retirement before shared state closes. Preserve sibling ownership and surface native-close failures without dropping their lease. Four new regressions fail on the original code. The repair passes 92 focused cases and an isolated four-case rerun, changed checks, and independent P0-P2 review. (cherry picked from commit 3381de9) * fix: restore Gateway restarts after Git updates (#138781) * fix: restore Gateway restarts after Git updates * test: align update installer mock with eager import (cherry picked from commit 24d8119) --------- Co-authored-by: josh <[email protected]> Co-authored-by: Josh <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Eric Cai <[email protected]> Co-authored-by: Gio Della-Libera <[email protected]> Co-authored-by: Gio Della-Libera <[email protected]> Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: Jason O'Neal <[email protected]>
Hello! Please review the proposed solution and tests. I chose this route because it executes an existing, known good and reliable restart route. There were some simpler, but more blunt, solutions like routing all the relevant calls instead of filtering them as I have. If you would like me to make changes, please let me know. Codex was used to assist, however, I personally reviewed the code, and made changes as stated herein.
I also did some testing on #120134 and #120230, and decided a different solution was needed.
Thank you for looking, and giving consideration.
Below this point, I have asked the agent to write the remaining portion of the PR based on my notes and progress.
What Problem This Solves
Fixes #120134.
A windows user can reliably restart the gateway through the gateway agent.
Fixes an issue where users asking an agent running inside a Windows Gateway to run plain
openclaw gateway restartwould see the Gateway stop and remain offline until someone manually started it again.The affected workflow is an agent-initiated restart from inside the running Gateway process tree on Windows.
Why This Change Was Made
For a plain Windows restart issued from the Gateway service environment, this change selects the existing Gateway-aware safe restart path so the running Gateway owns the deferred Scheduled Task handoff.
It deliberately preserves native routing for external callers, external-supervisor mode, stopped-Gateway recovery from external terminals without Gateway-service markers, non-Windows and node-service callers, and explicit
--force,--wait,--preserve-definition, and--skip-deferralbehavior.User Impact
This also addresses @nerclid’s September 1, 2026 report in Discord #clawtributors: on Windows 11 Pro with default user permissions, asking the agent to restart the Gateway left it offline.
Users can ask an on-Gateway agent to restart a Windows Scheduled Task Gateway and expect a replacement Gateway to start, become healthy, and reconnect the webchat without manual recovery.
Existing external restart workflows and explicit lifecycle controls retain their prior behavior.
Evidence
Maintainer verification (September 1, 2026)
The maintainer independently reproduced the routing regression: with the pre-fix resolver and this PR’s unchanged tests,
pnpm test src/cli/daemon-cli/register-service-commands.test.tsfailed exactly 1/36 cases (uses safe restart for a plain Windows Gateway service restart, expectedsafe: true, receivedsafe: false). The contributor resolver was restored byte-for-byte afterward; the identical focused command then passed 36/36 with exit 0. The native task cleanup and respawn/helper suites also passed 65/65, and the safe-RPC acknowledgement test passed. The untouched external-supervision suite twice timed out in its 180-second import hook while building worker bundles, so that broader local run is not claimed as passing. Native Windows live execution is unavailable on the maintainer Mac; the Windows observations below remain contributor-reported, not independently repeated live runs. The original exact-head aggregate CI passed, but its Windows job was skipped. A separate Windows probe, dispatched with the exact contributor SHA astarget_ref, passed its Windows CI test step; its native Scheduled Task preflight failed because the runner reporteduser_interactive=False, so it does not provide independent live restart proof. After a patch-identical rebase, the focused routing, safe-RPC, respawn/helper, and native cleanup command passed all 103 tests with exit 0.Both the Gateway and legacy daemon CLI docs now describe implicit safe routing and distinguish request acceptance from successor health.
Contributor-reported environment
2026.8.1, revisionea80657.24.18.0.openclaw gateway restart.Before the change
The failure reproduced in
3/3independent runs.In each run, the restart controller was inside the Gateway process tree, the Gateway stopped, the controller did not reach Scheduled Task relaunch, and no replacement Gateway appeared.
After the change
The same end-to-end webchat-agent workflow passed in
3/3consecutive runs.1864 -> 6320safe-rpc mode=deferred30.502 s0, RPC healthy, webchat reconnected6320 -> 1196safe-rpc mode=deferred30.294 s0, RPC healthy, webchat reconnected1196 -> 6664safe-rpc mode=deferred29.371 s0, RPC healthy, webchat reconnectedNo duplicate task handoff, stale listener, unexpected in-process managed restart, configuration drift, or plugin-version drift was found.
Routing and preservation
11/11runnable restart transitions completed with distinct replacement PIDs, Scheduled Task result0, and healthy RPC.13/13.18/18outside the identified external-supervisor overlap.10/10focused offline cases, including normalized mixed-case and whitespace-padded values.--saferemains safe in external-supervisor mode.Contributor-reported repository validation
node scripts/run-vitest.mjs src/cli/daemon-cli/register-service-commands.test.ts-36/36passed on Windows with Node24.18.0against base0f0ae34d9a2b84cff53a4540ab50d3666e197b71.pnpm build- passed on Windows with Node24.18.0and pnpm12.1.0against base0f0ae34d9a2b84cff53a4540ab50d3666e197b71; exit0, total build time5m 33.4s, all9/9unified tsdown invocations completed, and no tracked files changed beyond the two candidate files.pnpm check- passed on Windows with Node24.18.0and pnpm12.1.0against base0f0ae34d9a2b84cff53a4540ab50d3666e197b71; exit0in854.788 s. All18preflight guards,5typecheck targets,23lint shards, the32,063-file format pass, and8policy guards completed successfully.pnpm test- attempted on native Windows with Node24.18.0and pnpm12.1.0; manually stopped after approximately16m 40swhen unrelated Windows EPERM, platform, and temporary-file locking failures accumulated. The run produced no final exit status, and no observed failure named either candidate file. The focused candidate suite separately passed36/36.Regression proof: with the test patch applied before the production repair, the same focused command failed exactly
1/36cases because the plain Windows Gateway-service restart producedsafe: falseinstead ofsafe: true; the repaired source-and-test patch then passed36/36. The later check cleanup removed a redundant boolean wrapper and formatted the test without changing behavior.Build proof: the candidate source-and-test patch completed the repository build with exit
0; the log contained noFAILED,ERROR,FATAL, or[INEFFECTIVE_DYNAMIC_IMPORT]markers. The later check cleanup was a semantic no-op in production code and formatter-only in the test.Check proof: the check first identified one unnecessary boolean conversion and one formatting issue in the candidate; both were corrected minimally. The final tracked diff remains limited to the production resolver and its focused test,
git diff --checkpasses, and the lockfile matchesHEAD.Provenance and related-PR clarification
I have observed this behavior throughout my approximately four to five months using OpenClaw. No earlier known-good release or introducing change has been identified, so I believe this should be classified as a longstanding defect with regression provenance unknown, rather than a probable regression.
PR #120230 is not a demonstrated alternative fix, and should not be considered partial overlap. I tested its current head
d4b40a7f32aa597302c7c7852e3db1109c36e33fin the native model-backed Windows workflow. The restart controller survived andschtasks /Endsucceeded, but the existing Gateway retained the port, no successor Gateway was created, and restart failed. The detailed result is recorded in my comment on that PR.Evidence boundaries
The broad
pnpm testattempt is not claimed as a pass or a failure.The implicit repair intentionally applies only to a plain Windows Gateway-service restart.
The same command run from an external interactive terminal is not affected.
It does not claim to change Gateway-descendant explicit
--force,--wait,--preserve-definition, or--skip-deferralbehavior, or any non-Windows, node-service, external-caller, stopped-Gateway recovery, or external-supervisor path.Preservation claims for other entry points rest on the separate
11/11runnable transitions,13/13route-selection checks,18/18option-parity checks, and focused external-supervisor matrix rather than an equivalent deep-capture series for every path.Safe RPC acknowledges the accepted restart request before successor health is known; all three independent external observations nevertheless proved a distinct healthy replacement and webchat reconnection.
External-supervisor mode was not active during the three live runs, so that exclusion is supported by the focused
10/10routing matrix rather than a live external-supervisor restart.No UI was changed, so before-and-after screenshots are not applicable.
Final exact-head gate
Head
0a8b47ddd0e06b8bd953119ad17f1f20125136b6has green exact-head CI and a fresh clean branch autoreview. Rebase preserved both patches exactly and retained @nerclid’s authorship. See the maintainer review and full evidence boundaries.node scripts/check-changed.mjs -- docs/cli/daemon.md docs/cli/gateway.md src/cli/daemon-cli/register-service-commands.ts src/cli/daemon-cli/register-service-commands.test.tscompleted with exit 0 after the rebase, including core/test typechecks, all three zero-entry dead-export scans, targeted lint, and policy guards.