Skip to content

fix(daemon): keep hidden Windows launcher alive for the daemon's lifetime - #123774

Closed
bmorenmiami-droid wants to merge 1 commit into
openclaw:mainfrom
bmorenmiami-droid:fix/orphan-gateway-launcher
Closed

bmorenmiami-droid wants to merge 1 commit into
openclaw:mainfrom
bmorenmiami-droid:fix/orphan-gateway-launcher

Conversation

@bmorenmiami-droid

Copy link
Copy Markdown

PR body

Resolves the orphan-on-restart wedge where the .vbs launcher generated for OPENCLAW_WINDOWS_TASK_HIDDEN_LAUNCHER=1 exits with code 0 immediately after launching cmd.exe. schtask then records Last Result: 0 and loses its handle to the actual gateway process tree, so the next openclaw gateway start wedges with "gateway already running (pid ); lock timeout after 5000ms."

What changes

buildHiddenLauncherScript() in src/daemon/schtasks-layout.ts now emits:

CreateObject("WScript.Shell").Run """<path-to-gateway.cmd>""", 0, True

instead of , 0, False. bWaitOnReturn=True keeps the WScript host alive for the entire lifetime of the cmd.exe + node.exe process tree, so schtask correctly tracks the daemon and restart logic sees the real state.

A regression test asserts both True is present and False is absent in the generated .vbs.

Files

  • src/daemon/schtasks-layout.ts — 1-line behavioral change + explanatory comment
  • src/daemon/schtasks.install.test.ts — 3 existing assertions + 1 new regression test
  • src/infra/windows-launcher-encoding.test.ts — 3 fixture-string updates (UTF-16 LE round-trip)

Test plan

  • Existing src/daemon/schtasks.install.test.ts and src/infra/windows-launcher-encoding.test.ts suites continue to pass (assertions flipped from False to True).
  • New regression test: "emits a hidden launcher that waits for the cmd tree so the daemon is not orphaned on restart" — installs a default gateway task with OPENCLAW_WINDOWS_TASK_HIDDEN_LAUNCHER=1, reads the generated .vbs, and asserts on the bWaitOnReturn flag.
  • Verified end-to-end on Windows 10 by invoking the generator directly and inspecting the output (the host's Node 25.6.1 SQLite runtime is incompatible with the openclaw test harness' SQLite version check; the fix is verified by direct generator invocation rather than full vitest run).

Out of scope (follow-ups)

  • Hard-kill resilience. schtasks /End still only kills the top-level WScript; the cmd.exe and node.exe children survive. Wrapping node.exe in a Win32 Job Object (JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE) and invoking the daemon via a small PowerShell launcher would close that gap. Happy to send a follow-up PR.
  • openclaw gateway start orphan detection. The CLI's lock-file check still only verifies "is the PID alive," not "is the PID's parent still tracked by schtask." A second follow-up could teach the CLI to detect and reap true orphans.

Risk

  • Behavioral change: the schtask record will now reflect actual daemon exit codes (good — currently masked by the 0 artifact).
  • WScript host stays alive for the lifetime of the daemon; if the host is killed, the .cmd's exit propagation works the same as the non-hidden path (which already does this correctly).
  • No changes to the non-hidden path (gateway.cmd only, no .vbs).
  • UTF-16 LE encoding layer unchanged.

Reproduction / verification

Before the fix, on the host running openclaw 2026.6.34:

$ schtasks /Query /TN "OpenClaw Gateway" /FO LIST /V | grep -E "Last Run Time|Last Result|Status"
Last Run Time:                        8/14/2026 10:46:16 AM
Last Result:                          0
Status:                               Ready

i.e., the task "ran" (and finished cleanly) two minutes before the failed restart attempt at 10:47:44.

After the fix, Last Run Time and Status: Running track the actual daemon lifetime, and Last Result reflects the daemon's exit code on shutdown.

…time

The .vbs launcher generated for OPENCLAW_WINDOWS_TASK_HIDDEN_LAUNCHER=1 used
bWaitOnReturn=False, which made WScript exit immediately after launching
cmd.exe. schtask then recorded "Last Result: 0" and treated the task as
complete, leaving the gateway process as an untracked orphan holding the
bind port. The next `openclaw gateway start` would wedge with:

  Gateway failed to start: gateway already running (pid <orphan>);
  lock timeout after 5000ms

Switching bWaitOnReturn to True keeps the WScript host alive for the entire
lifetime of the cmd.exe + node.exe tree, so schtask tracks the daemon and
restart logic can see the real state.

Verified locally by inspecting generated .vbs content and adding a
regression test that asserts both the True flag and the absence of False.
@clawsweeper

clawsweeper Bot commented Aug 14, 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 gateway Gateway runtime size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 29, 2026, 11:18 PM ET / September 30, 2026, 03:18 UTC.

ClawSweeper review

What this changes

The branch makes the optional hidden Windows Scheduled Task launcher wait for the Gateway command and updates launcher and UTF-16 encoding tests.

Merge readiness

⛔ Blocked before merge - 6 items remain

Current main and v2026.9.1 already contain the waiting-launcher repair, but the merged replacement has no verified formal GitHub closing link to this PR. Its supersession therefore needs explicit maintainer disposition before closure.

Priority: P2
Reviewed head: 473f4abf0abf9fc2b8b88b6c86f807492dd8874f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The narrow change has useful historical signal, but its lifecycle proof is incomplete and current main has a fuller shipped repair.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The branch changes the installed WScript wait behavior, but its Windows 10 generator inspection and before-fix Scheduler output do not show an after-fix Scheduled Task remaining Running or a successful Gateway restart. A redacted native task start/restart trace would cover that gap if this branch remains a candidate; updating the PR body should trigger re-review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The branch changes the installed WScript wait behavior, but its Windows 10 generator inspection and before-fix Scheduler output do not show an after-fix Scheduled Task remaining Running or a successful Gateway restart. A redacted native task start/restart trace would cover that gap if this branch remains a candidate; updating the PR body should trigger re-review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 10 items Pinned branch change: The introduced production hunk changes WScript Run from False to True and adds an explanatory comment containing a placeholder URL.
Current main launcher: The current hidden launcher waits for the command and passes its exit result to WScript.Quit.
Installation path: The installer writes that launcher when the hidden task path is selected.
Findings 1 actionable finding [P3] Remove the placeholder issue URL
Security None None.

How this fits together

Windows Gateway installation writes a command script and, when hidden launching is enabled, a WScript wrapper for Task Scheduler. Task Scheduler observes the wrapper while the command starts and runs the Gateway.

flowchart LR
  A[Hidden launcher setting] --> B[Gateway task installer]
  B --> C[Command script]
  B --> D[WScript launcher]
  D --> E[Task Scheduler]
  E --> F[Running Gateway]
  F --> G[Task status and exit result]
Loading

Decision needed

Question Recommendation
Does merged #132186 fully supersede this PR, allowing explicit closure despite the missing formal GitHub closing link? Confirm supersession: Close this PR after confirming the merged supervisor is the intended replacement.

Why: The exact behavior is shipped, but the review contract does not permit an automatic PR close without a verified formal connection to the request.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The branch changes the installed WScript wait behavior, but its Windows 10 generator inspection and before-fix Scheduler output do not show an after-fix Scheduled Task remaining Running or a successful Gateway restart. A redacted native task start/restart trace would cover that gap if this branch remains a candidate; updating the PR body should trigger re-review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Remove the placeholder issue URL (P3) - The new source comment contains a literal &lt;this-fix> URL that would remain broken in landed code; a human review has already requested its removal or replacement.
  • Resolve merge risk (P1) - The branch currently conflicts with main, and no verified test-merge result establishes a safe reconciliation with the newer supervisor.
  • Resolve merge risk (P1) - The six added production comment lines are avoidable growth for a one-line behavior change and include an invalid placeholder link.
  • Complete next step (P2) - Confirm whether the merged Windows supervisor supersedes this PR; preserve branch work only if a distinct current-main gap is identified.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P3] Remove the placeholder issue URL — src/daemon/schtasks-layout.ts:337
Agent review details

Security

None.

PR surface

Source +6, Tests +27. Total +33 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 1 +6
Tests 2 33 6 +27
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 40 7 +33

Review metrics

Metric Value Why it matters
Production versus test LOC production +6, tests +27 Production growth is explanatory comment text around a single changed flag; the tests chiefly assert generated launcher text.

Root-cause cluster

Relationship: superseded
Canonical: #132186
Summary: The merged Windows supervisor contains the central waiting-launcher repair; later merged work extends shutdown handling.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the released supervisor and its exit propagation; if any branch work is reused, fold its useful explanation into a short comment at the current launcher owner.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the released supervisor and its exit propagation; if any branch work is reused, fold its useful explanation into a short comment at the current launcher owner.

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

No current-main failure was reproduced: its installer emits a waiting launcher, while the pinned pre-fix source shows the historical non-waiting path.

Is this the best way to solve the issue?

No. The merged supervisor is the better owner-boundary fix because it waits and propagates the command result; this branch waits but discards that result.

Full review comments:

  • [P3] Remove the placeholder issue URL — src/daemon/schtasks-layout.ts:337
    The new source comment contains a literal &lt;this-fix> URL that would remain broken in landed code; a human review has already requested its removal or replacement.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b2cda568987e; fix evidence: release v2026.9.1, commit 14e26a380d34.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This concerns Windows Gateway task reliability on an optional hidden-launcher path, with the central repair already shipped.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The branch changes the installed WScript wait behavior, but its Windows 10 generator inspection and before-fix Scheduler output do not show an after-fix Scheduled Task remaining Running or a successful Gateway restart. A redacted native task start/restart trace would cover that gap if this branch remains a candidate; updating the PR body should trigger re-review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the placeholder URL noted in human review if this branch is retained.
  • If the branch remains a landing candidate, show redacted after-fix Windows Scheduled Task and Gateway restart output.

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.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. P2 Normal backlog priority with limited blast radius. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 22, 2026

@Ayushdevo Ayushdevo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bWaitOnReturn change is internally consistent across the launcher generation and UTF-16 regression coverage, but there is one cleanup item before merge: the production source comment contains the literal placeholder URL https://github.com/openclaw/openclaw/issues/<this-fix>. That will land verbatim. Please replace it with the actual issue/PR reference or remove the URL.

@vincentkoc vincentkoc self-assigned this Sep 30, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks for the launcher repair. The same waiting behavior is already merged in #132186 with explicit exit-code propagation, and #141744 covers descendant shutdown and fresh starts. Current main retains both repairs and their regression coverage, so this PR can close as superseded. If a refreshed installation still shows a distinct orphan or restart failure, please share the reproduction so we can reopen that gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants