diff --git a/electron/gateway/manager.ts b/electron/gateway/manager.ts index 415274a6a..e61172087 100644 --- a/electron/gateway/manager.ts +++ b/electron/gateway/manager.ts @@ -297,11 +297,13 @@ export class GatewayManager extends EventEmitter { process.kill(pid, 0); // Still alive — keep this.process so later cleanup can reach it } catch { - // Process is gone — safe to clear the handle + // Process is gone — safe to clear the handle and ownership flag this.process = null; + this.ownsProcess = false; } } else { this.process = null; + this.ownsProcess = false; } } }, diff --git a/electron/gateway/startup-orchestrator.ts b/electron/gateway/startup-orchestrator.ts index 102618554..4036a6efe 100644 --- a/electron/gateway/startup-orchestrator.ts +++ b/electron/gateway/startup-orchestrator.ts @@ -98,14 +98,15 @@ export async function runGatewayStartupSequence(hooks: StartupHooks): Promise { logger.warn('Failed to terminate owned process before retry:', err); }); } + await hooks.delay(1000); hooks.assertLifecycle('start/retry-pre-port-wait'); // Wait for port to become free before retrying (handles lingering processes). // Use a short-polling AbortController so that a superseding stop()/restart() @@ -122,6 +123,12 @@ export async function runGatewayStartupSequence(hooks: StartupHooks): Promise((resolve) => {