openclaw - 💡(How to fix) Fix [Bug]: Windows — openclaw update 期间 Scheduled Task PT3M 重复触发器重新拉起 gateway 导致竞态 [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fixed

Code Example

async function stopScheduledTask({ stdout, env }) {
    // ...
    const res = await execSchtasks(["/End", "/TN", taskName]);
    // 终止 gateway 进程 + 等待端口释放
    // ❌ 但任务本身没有被 disable
}

---

<LogonTrigger>
  <Repetition>
    <Interval>PT3M</Interval>
    <Duration>P9999D</Duration>
  </Repetition>
</LogonTrigger>

---

1. openclaw update 开始
2. stopScheduledTask() → schtasks /End   ← 仅停止实例,触发器仍在
3. npm install -g openclaw@latest         ← 可能出现 1-3 分钟
4.   ┌─ PT3M 触发 → 拉起 gateway ──┐      ← 竞态!
     │ 旧代码 / 部分更新文件 = 崩溃风险 │
5. npm install 完成
6. restartScheduledTask() → 再次重启

---

schtasks /Change /TN "OpenClaw Gateway" /DISABLE

---

schtasks /Change /TN "OpenClaw Gateway" /ENABLE
RAW_BUFFERClick to expand / collapse

概述

在 Windows 上运行 openclaw update 时,stopScheduledTask() 调用 schtasks /End 停止了当前运行的 gateway 实例,但 没有 disable 计划任务本身OpenClaw Gateway 任务的 LogonTrigger 带有 PT3M 重复间隔,会在 npm install 进行中的 3 分钟内重新拉起 gateway,导致新旧代码混合运行的竞态条件。

影响版本

v2026.5.22+(P1D → P9999D 修复后)。5.22 之前重复时长仅 1 天,登录超过 1 天后触发器已过期,问题被掩盖。

根因

stopScheduledTask()dist/schtasks-B45z-tnx.js:840-876 中:

async function stopScheduledTask({ stdout, env }) {
    // ...
    const res = await execSchtasks(["/End", "/TN", taskName]);
    // 终止 gateway 进程 + 等待端口释放
    // ❌ 但任务本身没有被 disable
}

schtasks /End 只停止当前运行实例。计划任务的 XML 定义中:

<LogonTrigger>
  <Repetition>
    <Interval>PT3M</Interval>
    <Duration>P9999D</Duration>
  </Repetition>
</LogonTrigger>

PT3M 重复触发器仍然活跃,任务调度器会在下一个 3 分钟窗口自动重新执行 gateway.cmd

竞态窗口

1. openclaw update 开始
2. stopScheduledTask() → schtasks /End   ← 仅停止实例,触发器仍在
3. npm install -g openclaw@latest         ← 可能出现 1-3 分钟
4.   ┌─ PT3M 触发 → 拉起 gateway ──┐      ← 竞态!
     │ 旧代码 / 部分更新文件 = 崩溃风险 │
5. npm install 完成
6. restartScheduledTask() → 再次重启

为什么 macOS/Linux 不受影响

  • macOS: launchctl bootout 完全卸载 agent,不会自动重启
  • Linux: systemctl --user stop 停止服务,不会自动重启
  • Windows: schtasks /End 只停止运行中实例,重复触发器保持活跃

修复建议

stopScheduledTask() 应在 schtasks /End 后 disable 任务:

schtasks /Change /TN "OpenClaw Gateway" /DISABLE

restartScheduledTask() 或更新后的重启阶段重新 enable:

schtasks /Change /TN "OpenClaw Gateway" /ENABLE

如果出于保守考虑不想改动通用 stop/restart 语义,也可以在 update 流程中单独处理——在 maybeStopManagedServiceBeforePackageUpdate() 之后 disable,在 maybeRestartService() 之前 enable。

复现步骤

  1. Windows 环境,OpenClaw >= 5.22
  2. 确认 OpenClaw Gateway 计划任务存在且 PT3M 重复触发
  3. 运行 openclaw update(确保 npm install 耗时 > 3 分钟,或在此期间观察任务调度器)
  4. 观察 gateway 在 npm install 期间被重新拉起

实际观察

用户在多次 update 中观察到:更新流程输出 "Stopping managed gateway service before package update..." 并停止了 Scheduled Task,但看门狗(内置 PT3M 触发器)在升级过程中反复拉起 gateway。

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: Windows — openclaw update 期间 Scheduled Task PT3M 重复触发器重新拉起 gateway 导致竞态 [2 pull requests]