GitHub Issue: Windows gateway restart does not wait for active tasks
Problem
On Windows (using Scheduled Task), openclaw gateway restart immediately returns success but does not actually restart the Gateway properly. More critically, it forcefully terminates any running tasks without waiting for them to complete, and does not recover sessions after restart.
Current Behavior
- Run
openclaw gateway restart
- Command returns immediately with "success"
- Gateway process may still be running or restarting
- Any active tasks are killed abruptly
- Sessions are lost, no recovery after restart
- User must manually
stop + start to get a clean restart
Expected Behavior
gateway restart should use the existing graceful restart mechanism (deferGatewayRestartUntilIdle)
- Wait for active tasks to complete (or timeout)
- Write restart sentinel for session recovery
- Only return after Gateway is healthy and sessions are restored
Technical Details
- OpenClaw version: 2026.3.24
- Platform: Windows 11 (win32)
- Installation: Windows Scheduled Task
- Gateway functions exist but not wired:
deferGatewayRestartUntilIdle()
writeRestartSentinel()
consumeRestartSentinel()
scheduleGatewaySigusr1Restart() (Unix only)
Key finding: These functions are implemented in pi-embedded-BaSvmUpW.js but gateway restart on Windows does not call them.
Reproduction Steps
- Start a long-running task (e.g., a cron job or interactive session)
- Execute
openclaw gateway restart
- Observe: command returns immediately
- Check task status: it is aborted, not completed
- Check session store: no recovery, task lost
Workaround
Currently must use:
openclaw gateway stop
# Wait manually
openclaw gateway start
But even this does not trigger session recovery because sentinel is not written.
Proposed Fix
Modify runDaemonRestart() in daemon-cli.js (or lifecycle-core-gBCZgGHS.js) to implement graceful restart for Windows:
async function runDaemonRestart(opts = {}) {
// ... existing code ...
if (process.platform === 'win32') {
// Windows graceful restart
const gatewayPort = await resolveGatewayLifecyclePort(service);
// 1. Wait for active tasks to complete (or timeout)
await deferGatewayRestartUntilIdle({
timeoutMs: 300000 // 5 minutes
});
// 2. Write restart sentinel for session recovery
await writeRestartSentinel({
reason: 'manual restart',
timestamp: new Date().toISOString()
});
// 3. Graceful stop
await runServiceStop({ graceful: true });
// 4. Start new instance
await runServiceStart();
// 5. Wait for health check
const health = await waitForGatewayHealthyRestart({
port: gatewayPort,
attempts: 20,
delayMs: 500
});
if (!health.success) {
throw new Error(`Gateway restart failed: ${health.message}`);
}
return { outcome: 'restarted', message: 'Gateway restarted gracefully with session recovery' };
} else {
// Unix: send SIGUSR1 (existing behavior)
return await scheduleGatewaySigusr1Restart({ reason: '/restart' });
}
}
Related Files
daemon-cli-BgoyP3Ke.js - Gateway CLI commands
lifecycle-core-gBCZgGHS.js - Service lifecycle (restart, stop, start)
pi-embedded-BaSvmUpW.js - Contains the graceful restart functions
status-D8mZfs6u.js - Health check utilities (waitForGatewayHealthyRestart)
Additional Context
This issue is critical for users who run automated tasks via cron or have long-running agent sessions. Forcing abrupt termination leads to:
- Lost task results
- Incomplete workflows
- Poor user experience
OpenClaw already has all the necessary infrastructure for graceful restart and session recovery; it just needs to be wired up for Windows service manager.
Documentation: See internal analysis at .proactivity/gateway-graceful-restart-best-practices.md
Tested on: OpenClaw 2026.3.24, Windows 11, Scheduled Task installation
Acceptable Solutions
Priority: High (affects core reliability)
Difficulty: Medium (functions already exist, just need to connect them)
Contributor: @YOUR_GITHUB_USERNAME (contact via OpenClaw workspace)
GitHub Issue: Windows gateway restart does not wait for active tasks
Problem
On Windows (using Scheduled Task),
openclaw gateway restartimmediately returns success but does not actually restart the Gateway properly. More critically, it forcefully terminates any running tasks without waiting for them to complete, and does not recover sessions after restart.Current Behavior
openclaw gateway restartstop+startto get a clean restartExpected Behavior
gateway restartshould use the existing graceful restart mechanism (deferGatewayRestartUntilIdle)Technical Details
deferGatewayRestartUntilIdle()writeRestartSentinel()consumeRestartSentinel()scheduleGatewaySigusr1Restart()(Unix only)Key finding: These functions are implemented in
pi-embedded-BaSvmUpW.jsbutgateway restarton Windows does not call them.Reproduction Steps
openclaw gateway restartWorkaround
Currently must use:
openclaw gateway stop # Wait manually openclaw gateway startBut even this does not trigger session recovery because sentinel is not written.
Proposed Fix
Modify
runDaemonRestart()indaemon-cli.js(orlifecycle-core-gBCZgGHS.js) to implement graceful restart for Windows:Related Files
daemon-cli-BgoyP3Ke.js- Gateway CLI commandslifecycle-core-gBCZgGHS.js- Service lifecycle (restart, stop, start)pi-embedded-BaSvmUpW.js- Contains the graceful restart functionsstatus-D8mZfs6u.js- Health check utilities (waitForGatewayHealthyRestart)Additional Context
This issue is critical for users who run automated tasks via cron or have long-running agent sessions. Forcing abrupt termination leads to:
OpenClaw already has all the necessary infrastructure for graceful restart and session recovery; it just needs to be wired up for Windows service manager.
Documentation: See internal analysis at
.proactivity/gateway-graceful-restart-best-practices.mdTested on: OpenClaw 2026.3.24, Windows 11, Scheduled Task installation
Acceptable Solutions
deferGatewayRestartUntilIdleto CLI as--gracefulflagPriority: High (affects core reliability)
Difficulty: Medium (functions already exist, just need to connect them)
Contributor: @YOUR_GITHUB_USERNAME (contact via OpenClaw workspace)