Skip to content

fix: replace running Windows services safely on reinstall - #165261

Merged
steipete merged 4 commits into
mainfrom
fix/w148-windows-service-transition
Oct 5, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/w148-windows-service-transition

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Windows Gateway reinstalls that report the replacement runtime or command while the previous process continues running.

User Impact

Reinstalling a managed Scheduled Task now stops and settles the old process before publishing and starting its replacement. This applies to Node-to-Node changes, arguments, and environment changes. Status verifies the running process against the captured registered command and reports uncertainty when it cannot establish that pair.

Update behavior: the existing updater retains stopped-state and recovery ownership. Ordinary install failures restore the previous definition and running policy when ownership is still verifiable; changed or inaccessible state is left for the existing owner to reconcile. Published-driver update proof: published 2026.9.8 → candidate passed, including a new serving PID/build identity, successful durable completion, Doctor, preserved operator content, and canonical cleanup (25m33s end to end). Managed-service reconciliation recorded the existing Triggers.LogonTrigger.UserId admission warning and preserved that released task definition; package activation and restart still completed. The documented 2026.9.4 Windows schema-upgrade refusal remains unchanged; that legacy-driver cell refused schema 17→20 before activation and completed canonical cleanup.

Why This Change Was Made

Task Scheduler's IgnoreNew policy can accept a rewritten task and a start request while retaining its old instance. The existing Windows service owner now performs the transition under its native lock, expected-runtime-pin guard, and definition/file compare-and-swap checks. The captured guard also protects node-host cleanup after process discovery, so a replacement published during /End is preserved. No new owner, configuration, or automatic runtime migration is introduced.

Production and build-tool code grows by 223 net lines to retain pre-publication recovery, distinguish live/stopped/unknown process evidence, and bind environment-supplied ports to the existing scoped owner. Pure process matching moves into the existing snapshot module; obsolete fallback status behavior and an internal re-export are removed. The live-build fence retains native Running/Queued task evidence to protect known overlapping artifacts even when the current command cannot be verified; that evidence grants no service-control authority.

Evidence

  • Native Windows Server 2022 x64 before/after using Node 24.21.0 at two executable paths: before, both installs returned success while status/pin reported B and PID 5576 still executed A. After, the actual listener, registered command, and pin all agreed on B with a new PID. Bounded status and canonical stop/uninstall also passed; no task, launcher, listener, or runtime pin remained.
  • Native replacement, package integrity, and the Windows-native process test passed at 826bdb88f86c; the subsequent node-host-only guard fix leaves those Gateway paths unchanged and passes 104 tests on Node and fork Bun. Current published-driver update: published 2026.9.8 → candidate passed, including Doctor and canonical cleanup.
  • Regression tests cover runtime/argument/environment replacement, restoration of detached processes, surviving supervisors, unavailable inspection, late definition changes, and environment-only ports. Node proof: 441 passed, with 82 affected tests repeated at the committed head after lint fixes; the Windows-native Unicode process test also passed on Windows. Fork Bun proof: 441 passed on the current shared-pin fork Bun (c999), with the same 82 affected tests repeated at the committed head; the Windows-native test passed separately.
  • The original exact-head CI exposed a stale update-probe fixture and a real live-build-fence consumer gap. Both are repaired: strict status remains unknown without matched process evidence, while native Running/Queued tasks continue to protect overlapping build files. The first three consumer suites pass on Node 24 and pinned fork Bun: 49 passed, one existing skip on each (42s / 45s command wall time). The subsequent run exposed additional registration/process assumptions in backup, maintenance and timeout fixtures. Those fixtures now model updater-held stopped custody or positive process evidence, preserving their original CAS, rollback and timeout assertions. All 16 affected suites and shared-fixture callers pass on both runtimes: 346 passed, six existing skips each (101.56s / 67.93s). No blind CI rerun was requested.
  • The branch and consumer delta are P2 scoped-clean; Madge and the runtime import-cycle check passed. The full branch changed-file check passed again after the CI repair; unchanged Knip export proof was reused because the followups change no imports or exports. The node-host followup passes targeted lint, core types, all affected test type graphs, and the line-cap guard. The second fixture repair passes its selected changed-file check, including both affected type graphs; the single dependency tree was moved inside the source checkout to satisfy the declaration-input boundary after disk consolidation.
Measured test costs

Each changed suite was measured through the repository test wrapper with --maxWorkers=1. Wall times include compiler/cache and worker startup.

Suite Wall time
schtasks-install-rollback.test.ts 33.22 s
schtasks-runtime-definition.test.ts 20.01 s
schtasks-runtime.test.ts 20.07 s
schtasks.install.test.ts 19.23 s
schtasks.settlement.test.ts 22.07 s
schtasks.startup-fallback.test.ts 23.64 s
schtasks.test.ts 18.91 s

The final combined Node run, including inspection, stop/start, runtime-pin, and CLI-install siblings, took 75.49 s. Additional consumer-suite Node/Bun test execution time: maintenance 2.79/1.34s; status gathering 4.03/2.58s; service command inspection 0.21/0.15s; backup 12.52/5.09s; backup ordering 3.32/0.76s; policy preservation 1.56/0.18s; Scheduled Task audit 0.29/0.07s; systemd maintenance 3.26/1.11s. These exclude wrapper startup. Exact-head CI 37259972611 passed at 2ada701358842b8ecbe2bdf2b57065558586c94d. ClawSweeper completed that head at 03:40 UTC with no findings or security issues.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 11:40 PM ET / October 5, 2026, 03:40 UTC (Revision 4).

ClawSweeper review

What this changes

The branch stops existing Windows Scheduled Task processes before reinstalling their launchers, restores recoverable prior service state, and verifies runtime status against the registered command.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main lacks the replacement transition, and the latest fixture repairs introduce no identified correctness blocker. The native replacement and published-driver upgrade evidence support the change.

Likely related people: steipete and fuller-stack-dev, both medium-confidence routing candidates from merged service and recovery work.

Priority: P2
Reviewed head: 2ada701358842b8ecbe2bdf2b57065558586c94d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound owner-level repair with specific native and upgrade evidence, meaningful regression coverage, and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded native Windows installation exercised the changed service owner and showed the listener, registered command, and runtime pin converge on replacement B with a new PID. Published 2026.9.8 upgrade evidence covers existing operator state and cleanup; the latest commit changes fixtures only. No stored-data format or schema contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded native Windows installation exercised the changed service owner and showed the listener, registered command, and runtime pin converge on replacement B with a new PID. Published 2026.9.8 upgrade evidence covers existing operator state and cleanup; the latest commit changes fixtures only. No stored-data format or schema contract changes.
Evidence reviewed 8 items Pinned introduction and review continuity: Reviewed the merge-base-to-head introduced changes. Comparing the previous reviewed head with the current head confirms that the latest commit changes six test or test-support files and leaves production behavior unchanged; the previous review recorded no findings.
Replacement belongs to the existing service owner: The pre-publication callback verifies launcher receipts, registration, transaction custody, and caller authority before stopping the original service. Already-stopped updater custody is preserved, and changed or unsettled ownership prevents publication.
Runtime status preserves uncertainty: Runtime inspection consumes the captured registered command, checks actual process evidence, and rereads the command before returning. Scheduler Running alone no longer attests that the replacement command is executing.
Findings None None.
Security None None.

How this fits together

The Windows service adapter translates Gateway installation, update, and status requests into Task Scheduler and process operations. Its observations also inform Doctor, update recovery, and safeguards against rebuilding artifacts used by a running Gateway.

flowchart TD
  A[Install or update request] --> B[Capture task and launcher]
  B --> C[Verify ownership and prior state]
  C --> D[Stop and settle old process]
  D --> E[Publish and start replacement]
  E --> F[Verify command and process]
  E --> G[Restore recoverable prior state]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +217, Tests +871, Docs +13, Other +3. Total +1104 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 9 389 172 +217
Tests 21 1043 172 +871
Docs 1 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 2 7 4 +3
Total 33 1452 348 +1104

Review metrics

Metric Value Why it matters
Production versus regression coverage production/tooling +223 net lines; tests/support +871 net lines The PR explains production growth through pre-publication recovery, explicit process uncertainty, and scoped environment-port ownership.

Technical review

Best possible solution:

Keep Windows replacement, settlement, and rollback under the existing service owner, with status attesting only a verified registered-command/process pair.

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

Yes, source establishes the trigger: reinstall a running IgnoreNew Scheduled Task with a changed command while main publishes and runs it without settling the old instance. The PR records native before/after observations; this review did not execute Windows code.

Is this the best way to solve the issue?

Yes, the patch repairs the existing service transition and recovery owner instead of adding another lifecycle path, and the latest fixture changes preserve meaningful ownership, rollback, and timeout assertions.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This fixes a bounded Windows service reinstall defect with native replacement and upgrade evidence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded native Windows installation exercised the changed service owner and showed the listener, registered command, and runtime pin converge on replacement B with a new PID. Published 2026.9.8 upgrade evidence covers existing operator state and cleanup; the latest commit changes fixtures only. No stored-data format or schema contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded native Windows installation exercised the changed service owner and showed the listener, registered command, and runtime pin converge on replacement B with a new PID. Published 2026.9.8 upgrade evidence covers existing operator state and cleanup; the latest commit changes fixtures only. No stored-data format or schema contract changes.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base-to-head introduced changes. Comparing the previous reviewed head with the current head confirms that the latest commit changes six test or test-support files and leaves production behavior unchanged; the previous review recorded no findings. (2ada70135884)
  • Replacement belongs to the existing service owner: The pre-publication callback verifies launcher receipts, registration, transaction custody, and caller authority before stopping the original service. Already-stopped updater custody is preserved, and changed or unsettled ownership prevents publication. (src/daemon/schtasks-install.ts:384, 2ada70135884)
  • Runtime status preserves uncertainty: Runtime inspection consumes the captured registered command, checks actual process evidence, and rereads the command before returning. Scheduler Running alone no longer attests that the replacement command is executing. (src/daemon/schtasks-runtime.ts:638, 2ada70135884)
  • Recovery and competing replacement coverage: Regression coverage exercises publication and activation failures, detached prior processes, unavailable prior-state inspection, and registration changes during stop. The node-host case asserts that a replacement published during End survives without taskkill. (src/daemon/schtasks.settlement.test.ts:21, 2ada70135884)
  • Native replacement and upgrade evidence: The captured PR body, sourceRevision 19c571e5836fcbde7c9fa6c9dfec0a90ca2f7d272f082bd299cde9ce29ac4a1a, records Windows Server 2022 with Node 24.21.0: before, PID 5576 retained executable A despite the replacement registration and pin; after, a new listener PID, command, and pin agreed on B. It also records published 2026.9.8-to-candidate upgrade completion, Doctor, preserved operator content, and canonical cleanup. Native replacement was exercised at the initial production commit; subsequent production guard coverage and the latest fixture-only delta are distinguished from that native run. (826bdb88f86c)
  • Still necessary on current main: The readable fetched-main installer publishes the launcher and activates the task without this PR's pre-publication stop callback. The central installer, runtime, and process files have no changes between the pinned merge base and fetched main. A bounded GitHub PR scan found this open PR and no other Windows replacement/reinstall match. (src/daemon/schtasks-install.ts:375, 94f1e932eedc)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-05T02:00:50.189Z sha 1127a4b :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T02:06:46.048Z sha 1127a4b :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T02:55:31.755Z sha a45df1a :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review October 5, 2026 02:02
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes scripts Repository scripts labels Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 592c082 into main Oct 5, 2026
150 checks passed
@steipete
steipete deleted the fix/w148-windows-service-transition branch October 5, 2026 03:56
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…65261)

* fix: replace the running Windows Gateway on reinstall

* fix: preserve concurrently replaced Windows node hosts

* fix: retain native Windows task occupancy in build fences

* test: model native process evidence in Windows service fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant