fix(gateway): handle Windows OpenClaw process exit error during in-process restarts (#794)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
Haze
2026-04-08 12:06:12 +08:00
committed by GitHub
Unverified
parent 3021ad5089
commit 32d14b8cf9
8 changed files with 687 additions and 24 deletions

View File

@@ -242,6 +242,7 @@ export class GatewayManager extends EventEmitter {
port: this.status.port,
ownedPid: this.process?.pid,
shouldWaitForPortFree: process.platform === 'win32',
hasOwnedProcess: () => this.process?.pid != null && this.ownsProcess,
resetStartupStderrLines: () => {
this.recentStartupStderrLines = [];
},
@@ -446,7 +447,16 @@ export class GatewayManager extends EventEmitter {
logger.info(`[gateway-refresh] mode=restart requested pidBefore=${pidBefore ?? 'n/a'}`);
this.restartInFlight = (async () => {
await this.stop();
await this.start();
try {
await this.start();
} catch (err) {
// stop() set shouldReconnect=false. Restore it so the gateway
// can self-heal via scheduleReconnect() instead of dying permanently.
logger.warn('Gateway restart: start() failed after stop(), enabling auto-reconnect recovery', err);
this.shouldReconnect = true;
this.scheduleReconnect();
throw err;
}
})();
try {