Appearance
OpenClaw gateway 在 Windows 上每约 50 分钟自动重启:reason=none 循环排查
问题
OpenClaw gateway 运行时出现周期性自动重启,日志显示:
gateway tool: restart requested (delayMs=default, reason=none)重启间隔从最初约 1 小时逐渐缩短到 5 分钟,形成加速循环。每次重启后服务自动恢复,但间隔越来越短,严重影响使用。
根本原因(Windows 服务模式):Windows 服务检测到 gateway 进程以 exit code 1 退出,自动触发服务重启。实际崩溃原因是 gateway 启动时读取配置文件存在竞态条件,输出:
Missing config. Run `openclaw setup` or set gateway.mode=local进程自杀,Windows 服务立即重拉,如此循环。reason=none 是因为崩溃原因状态在重启中丢失,无法持久化到下一次启动。
解决方案
Windows 临时绕过方案(已验证稳定 70+ 分钟)
步骤 1:停止 Windows 服务
powershell
Stop-Service -Name 'OpenClaw' -Force步骤 2:创建端口检查启动脚本
保存为 C:\Users\<用户名>\.openclaw\start-gateway-if-needed.ps1:
powershell
$port = 18789
$check = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if ($check) {
Write-Host "Port $port is in use (PID: $($check.OwningProcess)) - gateway already running"
exit 0
}
Write-Host "Starting OpenClaw gateway..."
Start-Process -FilePath "openclaw" -ArgumentList "gateway", "start" -NoNewWindow步骤 3:通过 Windows 任务计划程序定期运行该脚本(替代 Windows 服务的自动重启机制)
步骤 4:诊断是否真正解决
bash
# 观察 gateway 运行时间是否稳定
openclaw gateway status
# 查看重启历史
openclaw logs --follow | grep "restart\|Missing config"排查加速重启的根本原因
bash
# 1. 确认配置文件完整性
openclaw doctor
# 2. 检查是否是自动更新触发
openclaw config get update
# 3. 查看 cron 任务(排除 cron 触发重启)
openclaw cron list
# 4. 检查 token 计数是否异常
openclaw status --deep如果是 Linux/macOS,推荐用 systemd/launchd daemon 模式,比 Windows 服务模式更稳定。