Repository navigation
fix(windows): keep managed Gateway startup alive and stoppable - #136980
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 3, 2026, 12:24 AM ET / 04:24 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +111, Docs 0. Total +111 across 9 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
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 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.tsHistorical native proof used lease 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. |
|
Merged via squash.
|
|
Fresh native Windows 2025 qualification passed for this PR's exact head, Native job 100524676947 ran on GitHub-hosted The downloaded proof artifact has The workflow definition is the independently reviewed proof-separation commit The normal exact-head CI run 33714478763 and required |
…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.
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.
…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
…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
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. PassNULLtoCreateProcessWwhen 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.
/codex statusselected/rejected env-specified 0.144.5, then initialized managed 0.152.1 in a fresh PID after User/ProcessOPENCLAW_CODEX_APP_SERVER_BINremoval 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:
d1bf55e3176cfd4afbac27f134996f1d5762c72eplus 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
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.