fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered#58943
Conversation
Greptile SummaryThis PR fixes a real regression on Windows machines where Key changes:
Confidence Score: 4/5Safe to merge with low risk; the core fix is sound but the The primary fix (pre-check + fallback label routing) is logically correct and addresses the stated bug. No P0/P1 issues found. One P2 concern: src/infra/windows-task-restart.ts — the Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/windows-task-restart.ts
Line: 46-47
Comment:
**`start /b` shares the parent console instead of detaching**
The fallback uses `start "" /b cmd.exe /d /c <path>`, which starts the gateway script *within the same hidden console* as the restart helper. When the helper script exits and its `cmd.exe` closes, Windows sends a `CTRL_CLOSE_EVENT` to all processes attached to that console – including the gateway launched with `/b`.
For reference, `buildStartupLauncherScript` in `schtasks.ts` uses `/min` precisely to create a new, separate console window:
```ts
lines.push(`start "" /min cmd.exe /d /c ${quoteCmdScriptArg(params.scriptPath)}`);
```
And `launchFallbackTaskScript` achieves the same isolation with `spawn(..., { detached: true, windowsHide: true })`.
Consider using `/min` here to match the same detachment semantics:
```suggestion
` start "" /min cmd.exe /d /c ${quotedScript}`,
```
This minimises the risk of the gateway receiving a console-close signal when the helper script terminates.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/infra/windows-task-restart.test.ts
Line: 177-179
Comment:
**Weak assertions in startup fallback test**
The test verifies `:fallback`, `"start"`, and the script path, but `"start"` would also match partial words (e.g. if future lines contain `"restart"` or `"setlocal"`). More importantly, the test does not assert the `schtasks /Query` pre-check (the other key change in this PR) or the exact launch command.
Consider strengthening to:
```ts
expect(script).toContain(`schtasks /Query /TN`);
expect(script).toContain(":fallback");
expect(script).toContain(`start "" /b cmd.exe /d /c`);
expect(script).toContain(taskScriptPath);
```
This would lock in the full behaviour introduced by this fix.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix code style problem" | Re-trigger Greptile |
|
Hi @obviyus . I’ve just submitted this PR. Could you please help take a look when you have time? Thanks a lot! |
obviyus
left a comment
There was a problem hiding this comment.
Reviewed latest changes; landing now.
…sks task is unregistered
obviyus
left a comment
There was a problem hiding this comment.
Reviewed latest changes; landing now.
|
Landed on main. Thanks @imechZhangLY. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e212c6f6e9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| export function relaunchGatewayScheduledTask(env: NodeJS.ProcessEnv = process.env): RestartAttempt { | ||
| const taskName = resolveWindowsTaskName(env); | ||
| const taskScriptPath = resolveTaskScriptPath(env); |
There was a problem hiding this comment.
Move fallback script-path resolution inside guarded try block
relaunchGatewayScheduledTask now resolves resolveTaskScriptPath(env) before entering the existing try/catch, so a missing HOME/USERPROFILE (or other path-resolution error) will throw out of this function instead of returning a structured { ok: false } restart result. This is a regression from the previous behavior and can make /restart crash on Windows environments with stripped service env vars, because resolveTaskScriptPath delegates to state-dir resolution that throws when home variables are absent.
Useful? React with 👍 / 👎.
…enclaw#58943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (openclaw#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#58943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (openclaw#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#58943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (openclaw#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#58943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (openclaw#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#58943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (openclaw#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered
Summary
schtasks /Query /TN <taskName>and skips retries if the task doesn't exist, and (2) falls back to launching script which resolved by resolveTaskScriptPath() directly viastart "" /b cmd.exe /d /c <path>, matching the startup folder path already used by schtasks.ts for install/stop/restart. resolveTaskScriptPath() is now imported from schtasks.ts to resolve the script path consistently.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write
N/A. If the cause is unclear, writeUnknown.git blame, prior PR, issue, or refactor if known):Regression Test Plan (if applicable)
For bug fixes or regressions, name the smallest reliable test coverage that should have caught this. Otherwise write
N/A.User-visible / Behavior Changes
List user-visible changes (including defaults/config).
If none, write
None.Diagram (if applicable)
For UI changes or non-trivial logic flows, include a small ASCII diagram reviewers can scan quickly. Otherwise write
N/A.Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation:Repro + Verification
Environment
Steps
openclaw onboard --install-daemonwithout UAC/restartto restart gatewayExpected
gateway was restared
Actual
gateway was stopped without restarting
Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
openclaw onboard --install-daemonwithout UAC and then input/restartin webchatopenclaw onboard --install-daemonwith UAC and then input/restartin webchatReview Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No)Yes/No)Yes/No)Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.