@@ -233,15 +233,18 @@ class EngineBundledLauncher {
233233 );
234234 await EngineConfigStore .writeAtomic (cfg);
235235
236- final runningCfg = await _waitRunningOnDiskWithin (
237- cfg.host,
238- _healthWindow,
239- expectedPid: childPid,
240- );
236+ final runningCfg = await _waitRunningOnDiskWithin (cfg.host, _healthWindow);
241237 if (runningCfg != null &&
242238 runningCfg.status == EngineStatus .running &&
243- await _strictHealth (runningCfg.host, runningCfg.port) &&
244- (runningCfg.pid == 0 || runningCfg.pid == childPid)) {
239+ await _strictHealth (runningCfg.host, runningCfg.port)) {
240+ // On Windows the engine may be a child of the started image; Python writes
241+ // os.getpid() to disk while [Process.pid] from Dart is a wrapper PID. Treat
242+ // HTTP health + disk "running" as success — do not require pid equality or we
243+ // time out, call [stopOwnedEngine], and kill the real listener in a loop.
244+ if (runningCfg.pid != 0 && runningCfg.pid != childPid) {
245+ _ownedProcess = null ;
246+ _engineStartedByApp = false ;
247+ }
245248 return EngineBootstrapOutcome (
246249 success: true ,
247250 activeHost: runningCfg.host,
@@ -305,13 +308,13 @@ class EngineBundledLauncher {
305308 } catch (_) {}
306309 }
307310
308- /// When [expectedPid] is set and disk has a non-zero pid that differs, keep waiting
309- /// (stale row). [pid] 0 on disk + healthy HTTP counts as ready (external / reconciled).
311+ /// Ready when disk says [EngineStatus.running] and HTTP health passes on [disk.port] .
312+ /// Do not require [EngineConfig.pid] to match [Process.start] 's pid: on Windows the
313+ /// listening process may be a child; the engine rewrites JSON with [os.getpid] .
310314 static Future <EngineConfig ?> _waitRunningOnDiskWithin (
311315 String connectHost,
312- Duration window, {
313- int ? expectedPid,
314- }) async {
316+ Duration window,
317+ ) async {
315318 final deadline = DateTime .now ().add (window);
316319 while (DateTime .now ().isBefore (deadline)) {
317320 final disk = await EngineConfigStore .read ();
@@ -321,12 +324,6 @@ class EngineBundledLauncher {
321324 if (disk != null &&
322325 disk.status == EngineStatus .running &&
323326 await _strictHealth (connectHost, disk.port)) {
324- if (expectedPid != null &&
325- disk.pid != 0 &&
326- disk.pid != expectedPid) {
327- await Future <void >.delayed (_healthTick);
328- continue ;
329- }
330327 return disk;
331328 }
332329 await Future <void >.delayed (_healthTick);
0 commit comments