Skip to content

fix(windows): keep managed Gateway startup alive and stoppable - #136980

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-windows-upgrade-136203
Sep 3, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-windows-upgrade-136203

Conversation

@steipete

@steipete steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Related: #136203 — Windows upgrade maintenance, workspace and stale-Codex reports.

Additional instructions

Maintainers can update this same-repository branch.

What Problem This Solves

Resolves a problem where starting a managed Gateway on native Windows could exit before the Gateway started, and stopping it immediately could report success while its supervisor later launched a Gateway. These are reproduced current-main startup/lifecycle defects discovered while investigating the Windows upgrade report.

Why This Change Was Made

Keep the service relay's real child handle referenced through admission and lineage completion, removing the premature unref() and redundant retention map. Pass NULL to CreateProcessW when the command environment is omitted, preserving native inheritance; explicitly supplied environments, including {}, remain replacements. For pre-admission stop, recognize the exact installed supervisor argv while preferring the actual Gateway PID and preserving the full-argv, port and identity fences.

The native fixture now proves deliberate exit 23 and extinction of that exact child and supervisor, requests recovery explicitly, and reads current numeric Running state rather than treating historical LastTaskResult as liveness. It retains the complete service lifecycle and ownership assertions. Its external temporary cwd receives test-owned dependency resolution through the public tsx export and checkout tsconfig. No production retry or keepalive was added. Workspace migration instructions now identify the intended per-agent workspace and verify it without rerunning onboarding.

User Impact

Native Windows operators can start, restart and stop the managed Gateway, including stopping before its child is admitted. Omitted child environments inherit normally; intentional sanitized environments and explicit Codex overrides retain their meaning. Production is +17/-17 (net 0); tests/support +232/-121 (net +111); docs +3/-3. There are no configuration, dependency, SQLite-schema or protocol changes.

Thanks to @hermannmetzker-ai and @DasX for the reports that prompted the investigation.

Evidence

266 distinct local passes and 63 distinct native Windows passes; repeated subsets are not added. Local coverage includes POSIX cancellation, parent loss and descendant extinction. Final changed checks and formatting passed. A fresh, secret-scanned, isolated Codex review before commit found no actionable P0 findings; this is a P0-scoped result.

Native proof used Azure Windows Server 2022, amd64, en-US, Node 24.15.0 and pnpm 12.1.0, with the same interactive user and InteractiveToken/Limited Scheduled Tasks. It used Crabbox's documented connect workflow after a run-transport ownership failure was safely resolved; these are not signed Crabbox run receipts. No operator state, provider credentials or inference were used.

Boundary Before / after evidence
Idle caller and environment Independent idle-host regressions failed before repair; inherited, replacement and empty environments pass afterward without diagnostic keepalive/ref interventions.
Managed service Actual built CLI install/start/status/stop/restart passed, with PID-generation replacement and descendant cleanup. Immediate stop before admission left no supervisor or late Gateway and the port remained free.
Scheduled Task fixture 5/5 passed with the default external temp root: Ready=3/result=23 and exact failed identities extinct, explicit recovery, directly observed Running=4, three distinct successful PIDs, stop/start/restart/stop/uninstall, task-origin/argv/port checks, default-task preservation and cleanup. Main lifecycle used no Startup fallback.
Workspace Four actual Doctor cases independently verified SQLite imports and synthetic corpus preservation. Live managed-write rejection preserved the last-good runtime; post-Doctor explicit pin activation and normal restart passed.
Codex Actual Gateway /codex status selected/rejected env-specified 0.144.5, then initialized managed 0.152.1 in a fresh PID after User/Process OPENCLAW_CODEX_APP_SERVER_BIN removal and normal managed restart. Separate launcher, state.env and config.env overrides remained effective; config command won. Exact official launcher contracts were inspected for 0.144.5, 0.151.0 and 0.152.1.

Proof base: d1bf55e3176cfd4afbac27f134996f1d5762c72e plus intentional patch. Native five-case source-patch SHA256: e1bcece65140b347b777f2df2f765eaccc3b1f8ea7251b009c2bbea77f35bb62. Final source-patch SHA256 excluding docs: f23017c5a4bb0f2baa0c15b69143e8571017866d29b54ed87b842e4bf46b7073. Full candidate including docs: 5a357bfa857dc1451549096e15d96aba7dd57f57a9779edc3f6a0c38be7453cb.

All production postimages are native-tested. After native 5/5, a max-lines check required moving two byte-identical process-liveness/wait helper bodies into their already-imported test-support owner. The 30-second/200ms behavior and assertions are unchanged; final local tests, checks and fresh review passed. The lease expired after cleanup, so the final test-helper layout is not claimed as identical native-executed bytes.

Exact focused commands and prior failures
node scripts/run-vitest.mjs src/process/supervisor/supervisor.anchored-shell.real.test.ts src/process/supervisor/service-child-relay-host.test.ts src/process/supervisor/supervisor.scope-extinction.test.ts src/process/supervisor/supervisor.cancellation-reason.test.ts src/process/supervisor/adapters/child.service-lifecycle.test.ts src/infra/process-env.test.ts
# Local: 78 passed. Native, excluding POSIX-only adapters/child.service-lifecycle.test.ts: 55 passed.
node scripts/run-vitest.mjs src/daemon/schtasks.stop.test.ts src/daemon/schtasks.test.ts src/daemon/schtasks.install.test.ts src/daemon/schtasks.startup-fallback.test.ts
# Local: 184 passed.
node scripts/run-vitest.mjs src/daemon/schtasks.stop.test.ts -t 'stops the exact installed Windows'
# Native: 3 passed; 29 excluded by the explicit filter.
OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_E2E_SKIP_BUILD=1 node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts
# Final local: 4 passed, 1 native-only skip.
pnpm test:windows:schtasks:integration
# Native: 5 passed; CI_WINDOWS_SCHTASKS_ROOT unset; prebuilt QA runtime.
pnpm build
# Full native build: passed.
node scripts/check-changed.mjs -- src/daemon/schtasks.integration.e2e.test.ts src/daemon/schtasks.task-supervisor.native-test-support.ts
# Final changed gate: passed; prior producer changed gates also passed.
git diff --check

Before-results remain preserved: idle native host exit 13; omitted-env failure isolated separately; successful immediate stop followed by a late Gateway; the old unsupported automatic-retry expectation; external-root loader/alias resolution failures; one local check process killed with 137; and max-lines 1010 > 1000. Fixture dependency ownership and duplicate-helper consolidation corrected the test failures. No assertions, timeouts or lint limits were suppressed.

Limits and follow-up: #136578 already addressed locale/Doctor/retained-root/admission behavior. This repair does not establish the reporter's historical Windows 11/de-DE stale-Codex cause or reconstruct lost intent in an already-keyed workspace roster; #136203 remains open. A separate refusal during overlapping live config rewrite, automatic handoff and manual restart remains a follow-up. The current native matrix used credential-free diagnostics, not authenticated model inference. Main comparison found no changes in the repaired daemon/supervisor paths; additive cloud-worker resolver and unrelated dependency/CI drift do not alter the repaired owner contracts.

Keep the relay child referenced through admission and lineage cleanup,
removing the redundant retention map. Preserve native inheritance for an
omitted Windows environment while explicit environments remain replacements.
Recognize the exact installed supervisor when stopping before admission.

Cover idle callers, environment isolation and pre-admission stop. Correct the
native Scheduled Task fixture to verify failed-run extinction, explicit
recovery and current Running state from an external temporary workspace.
Clarify how to retain an intended agent workspace when moving machines.

Refs #136203. Thanks to hermannmetzker-ai and DasX for the reports.
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 04:17
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 3, 2026, 12:24 AM ET / 04:24 UTC.

ClawSweeper review

What this changes

The PR keeps the managed Windows Gateway relay alive through startup, preserves omitted-environment inheritance, recognizes a pre-admission task supervisor during stop, and updates related tests and workspace guidance.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open. This is a fresh maintainer-owned repair; current main still has the pre-fix relay unref and only matches the inner Gateway argv during pre-admission stop. The introduced owner-boundary changes and supplied native lifecycle evidence support the patch, with no actionable correctness or security finding found.

Priority: P1
Reviewed head: 1b62928e5526bd7a9e20f9827850b1ab48c17646

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral lifecycle repair with strong source-consistent native evidence and no identified introduced defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied Azure Windows Server 2022 terminal evidence nevertheless directly covers the changed relay, Job-anchor, and Scheduled Task lifecycle through failed admission, cleanup, recovery, and stop/restart.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied Azure Windows Server 2022 terminal evidence nevertheless directly covers the changed relay, Job-anchor, and Scheduled Task lifecycle through failed admission, cleanup, recovery, and stop/restart.
Evidence reviewed 8 items Relay ownership repair: The introduced relay change removes the unref call that allowed an otherwise idle host to exit before supervisor admission; the adapter still owns IPC, startup, cancellation, and extinction through its returned lifecycle handle.
Pre-admission stop owner: The PID resolver now checks the exact persisted Gateway argv first and then the exact generated supervisor argv, retaining the port and full-argv identity fences before taskkill can act.
Caller and supervisor contract: The generated task appends the internal supervisor flag, task parsing deliberately removes it for the inner Gateway identity, and the supervisor rebuilds the child command without that flag.
Findings None None.
Security None None.

How this fits together

The Windows Gateway service starts OpenClaw through a Scheduled Task and a child-process supervisor. Service control must identify either the actual Gateway or its startup supervisor so stop and cleanup cannot leave a late Gateway process behind.

flowchart LR
  A[Windows Scheduled Task] --> B[Task supervisor]
  B --> C[Gateway child]
  C --> D[Gateway port and runtime]
  E[Service stop command] --> F[Owned process lookup]
  F --> B
  F --> C
  B --> G[Child cleanup]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +111, Docs 0. Total +111 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 17 17 0
Tests 4 232 121 +111
Docs 1 3 3 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 252 141 +111

Review metrics

Metric Value Why it matters
Production versus test delta production +17/-17 (net 0); tests/support +232/-121; docs +3/-3 The production fix is net-neutral while the added test support covers native startup, ownership, environment, and cleanup boundaries.

Technical review

Best possible solution:

Land the single relay and Scheduled Task ownership repair after normal exact-head CI and maintainer review, retaining its native lifecycle coverage and the existing workspace guidance.

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

Yes, from source and supplied native evidence: the pre-fix idle relay unrefs its only child handle, and the new native Scheduled Task scenario exercises failed pre-admission cleanup followed by explicit recovery and stop/restart.

Is this the best way to solve the issue?

Yes. The patch repairs lifecycle ownership at the relay and Scheduled Task control owners while preserving the existing exact argv and port fences, rather than adding retries or downstream cleanup workarounds.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against aaee9426072b.

Labels

Label changes:

  • add P1: Managed Gateway startup and stop failures can leave Windows operators without a usable Gateway or with a late-starting process.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied Azure Windows Server 2022 terminal evidence nevertheless directly covers the changed relay, Job-anchor, and Scheduled Task lifecycle through failed admission, cleanup, recovery, and stop/restart.

Label justifications:

  • P1: Managed Gateway startup and stop failures can leave Windows operators without a usable Gateway or with a late-starting process.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied Azure Windows Server 2022 terminal evidence nevertheless directly covers the changed relay, Job-anchor, and Scheduled Task lifecycle through failed admission, cleanup, recovery, and stop/restart.

Evidence

What I checked:

Likely related people:

  • steipete: 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.

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 1b62928e5526bd7a9e20f9827850b1ab48c17646: exact-head CI run 33714478763 has passed on attempt 1. Fresh managed, secret-scanned Codex review of the committed target found zero actionable P0 findings. The current ClawSweeper review also has no actionable findings or rank-up moves. Native review artifacts validated and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 136980 completed on the same head using hosted CI. Merge will use the repository wrapper.

The repair keeps the relay's authority child referenced, preserves omitted-env inheritance versus explicit replacement, and recognizes the exact installed supervisor during pre-admission stop. Production is +17/-17 (net 0); tests/support +232/-121. Real native Azure Windows Server 2022/en-US/amd64 proof covered otherwise-idle callers, same-user InteractiveToken/Limited Scheduled Tasks, actual built Gateway lifecycle and PID-generation replacement, immediate stop before admission, descendant cleanup, Doctor/workspace recovery, and the actual Gateway Codex status/override matrix. Totals: 266 distinct local and 63 distinct native passes; repeated subsets are excluded.

Focused commands (full case breakdown is in the PR body):

node scripts/run-vitest.mjs src/process/supervisor/supervisor.anchored-shell.real.test.ts src/process/supervisor/service-child-relay-host.test.ts src/process/supervisor/supervisor.scope-extinction.test.ts src/process/supervisor/supervisor.cancellation-reason.test.ts src/process/supervisor/adapters/child.service-lifecycle.test.ts src/infra/process-env.test.ts
node scripts/run-vitest.mjs src/daemon/schtasks.stop.test.ts src/daemon/schtasks.test.ts src/daemon/schtasks.install.test.ts src/daemon/schtasks.startup-fallback.test.ts
OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_E2E_SKIP_BUILD=1 node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts
pnpm test:windows:schtasks:integration
pnpm build
node scripts/check-changed.mjs -- src/daemon/schtasks.integration.e2e.test.ts src/daemon/schtasks.task-supervisor.native-test-support.ts

Historical native proof used lease cbx_0ea67e2a5ae1 through documented connect sessions, not signed run receipts. run_ed00c29a753c was a failed transport attempt and is not passing proof. All production postimages were native-tested. Native 5/5 preceded the final byte-identical test-helper move; final local checks/review passed with unchanged 30-second/200ms behavior, and that final layout is not claimed as native-executed. The VM's task/profile/process/registry fixtures were cleaned; the expired lease was not reused for landing.

The broader historical Windows 11/de-DE cause and lost already-keyed workspace intent remain unproven, so issue #136203 stays open. Explicit Codex overrides remain valid; no provider auth/inference was used. The separate overlapping config/handoff/manual-restart refusal remains follow-up. Draft CI run 33714438281 was skipped; the draft iOS cancellation was superseded by successful run 33714478754.

@steipete
steipete merged commit c0daa2c into main Sep 3, 2026
277 of 279 checks passed
@steipete
steipete deleted the steipete/fix-windows-upgrade-136203 branch September 3, 2026 04:46
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Fresh native Windows 2025 qualification passed for this PR's exact head, 1b62928e5526bd7a9e20f9827850b1ab48c17646, before the merge at c0daa2ca4019f7fca9f65d5cb54b95328b0b064c.

Native job 100524676947 ran on GitHub-hosted windows-2025, Node 22.23.2, pnpm 12.1.0, and Vitest 4.1.11. The unchanged interactive preflight reported session 2, UserInteractive=True, and administrator status. The test reported 5 passed, 0 failed, 0 skipped; the real lifecycle took 65.981 seconds, wrapper 71.85 seconds.

The downloaded proof artifact has result: pass and head: 1b62928e5526bd7a9e20f9827850b1ab48c17646. It records the deliberate exit 23 with Ready state 3 and failed child/supervisor identities, explicit recovery, three distinct successful PIDs, stop/start/restart/stop/uninstall, port release/rebind, no Startup substitution, unchanged default task, and effective InteractiveToken/least-privilege principal (logonType=3, runLevel=0). The executed test also asserts numeric Running state, task origin, and descendant liveness/extinction at the successful phases. Cleanup confirmed the task absent and no cleanup errors; upload and retained-evidence removal passed.

The workflow definition is the independently reviewed proof-separation commit 619aa0a82e237ca2aee537eea4fed361cf74b594; the checked-out/tested source is this PR's 1b62928e5526bd7a9e20f9827850b1ab48c17646. The exact checkout guard and artifact bind those separate identities. This is new final-head Windows 2025 proof, not relabeled historical Server 2022 evidence. It closes the prior final-helper-layout native qualification gap without weakening assertions or increasing deadlines.

The normal exact-head CI run 33714478763 and required openclaw/ci-gate are also successful. The companion headless job in the qualification workflow was still running at native-artifact collection; it is not being claimed as passed here. This proof does not claim reproduction of the historical Windows 11/de-DE upgrade cascade or authenticated model inference.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…law#136980)

Keep the relay child referenced through admission and lineage cleanup,
removing the redundant retention map. Preserve native inheritance for an
omitted Windows environment while explicit environments remain replacements.
Recognize the exact installed supervisor when stopping before admission.

Cover idle callers, environment isolation and pre-admission stop. Correct the
native Scheduled Task fixture to verify failed-run extinction, explicit
recovery and current Running state from an external temporary workspace.
Clarify how to retain an intended agent workspace when moving machines.

Refs openclaw#136203. Thanks to hermannmetzker-ai and DasX for the reports.
steipete added a commit that referenced this pull request Sep 8, 2026
Bind the supervisor and its descendants to a kill-on-close Job whose final handle is held by the validated WScript task launcher. Consume the existing hidden-launcher marker before admitting children, preserve detached Startup launches, and cover both raw Scheduler stop paths without CLI cleanup masking orphans. Related: #137813 and #136980.
steipete added a commit that referenced this pull request Sep 8, 2026
…141744)

* fix(windows): log supervised Gateway startup failures

Record the supervised Gateway exit code, signal, and bounded stderr tail before joining child-tree cleanup. Log supervisor failures and preserve nonzero task results while retaining clean shutdown behavior.

Related: #137813 and #136980.

* fix(windows): tear down Gateway descendants when its task ends

Bind the supervisor and its descendants to a kill-on-close Job whose final handle is held by the validated WScript task launcher. Consume the existing hidden-launcher marker before admitting children, preserve detached Startup launches, and cover both raw Scheduler stop paths without CLI cleanup masking orphans. Related: #137813 and #136980.

* docs(windows): clarify Scheduled Task failure retry limits
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…penclaw#141744)

* fix(windows): log supervised Gateway startup failures

Record the supervised Gateway exit code, signal, and bounded stderr tail before joining child-tree cleanup. Log supervisor failures and preserve nonzero task results while retaining clean shutdown behavior.

Related: openclaw#137813 and openclaw#136980.

* fix(windows): tear down Gateway descendants when its task ends

Bind the supervisor and its descendants to a kill-on-close Job whose final handle is held by the validated WScript task launcher. Consume the existing hidden-launcher marker before admitting children, preserve detached Startup launches, and cover both raw Scheduler stop paths without CLI cleanup masking orphans. Related: openclaw#137813 and openclaw#136980.

* docs(windows): clarify Scheduled Task failure retry limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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