@@ -147,7 +147,7 @@ if (command === "version") {
147147 }
148148 const entry = args.at(-1);
149149 const image = args.at(-2);
150- const container = { id, labels, env, mounts, image, entry, running: false , pid: null };
150+ const container = { id, labels, env, mounts, image, entry, status: "created" , pid: null };
151151 save(container);
152152 record({ argv: args, container, journal: journalState(launchIdFor(container)) });
153153 releaseAfterMarker("hold-create", () => process.stdout.write(id + "\n"));
@@ -167,12 +167,15 @@ if (command === "version") {
167167 process.stderr.write("container worker executed before its exact identity was journaled\n");
168168 process.exit(67);
169169 }
170+ // A real engine leaves the container "created" until its start request lands,
171+ // so the marker lets a test hold the launch inside that startup window.
172+ await new Promise((resolve) => releaseAfterMarker("hold-start", resolve));
170173 const child = spawn(process.execPath, [container.entry], {
171174 detached: process.platform !== "win32",
172175 env: container.env,
173176 stdio: ["pipe", "inherit", "inherit"],
174177 });
175- container.running = true ;
178+ container.status = "running" ;
176179 container.pid = child.pid;
177180 save(container);
178181 child.stdin.end(descriptor);
@@ -183,7 +186,7 @@ if (command === "version") {
183186 child.once("exit", (code, signal) => {
184187 if (fs.existsSync(statePath(container.id))) {
185188 const current = load(container.id);
186- current.running = false ;
189+ current.status = "exited" ;
187190 current.pid = null;
188191 save(current);
189192 }
@@ -198,7 +201,11 @@ if (command === "version") {
198201 record({ argv: args });
199202 const container = readContainer(id);
200203 const format = args[args.indexOf("--format") + 1];
201- const columns = [String(container.running)];
204+ const columns = [container.status];
205+ // Releasing the startup hold here proves the supervisor observed the container
206+ // while it was still created: the launch only proceeds after that observation.
207+ const startHold = path.join(engineRoot, "hold-start");
208+ if (fs.existsSync(startHold)) fs.unlinkSync(startHold);
202209 if (format.includes("openclaw.node-worker.host")) {
203210 columns.push(
204211 container.labels["openclaw.node-worker.host"] ?? "",
@@ -210,11 +217,11 @@ if (command === "version") {
210217} else if (command === "kill") {
211218 const container = readContainer(args.at(-1));
212219 record({ argv: args, journal: journalState(launchIdFor(container)) });
213- if (! container.running) {
220+ if (container.status !== " running" ) {
214221 process.stderr.write("container is not running\n");
215222 process.exit(1);
216223 }
217- container.running = false ;
224+ container.status = "exited" ;
218225 save(container);
219226 if (container.pid) {
220227 try {
@@ -263,7 +270,7 @@ type FakeContainer = {
263270 mounts : string [ ] ;
264271 image : string ;
265272 entry : string ;
266- running : boolean ;
273+ status : "created" | "running" | "exited" ;
267274 pid : number | null ;
268275} ;
269276
@@ -339,7 +346,12 @@ function containerFixture(
339346 . split ( "\n" )
340347 . map ( ( line ) => JSON . parse ( line ) as EngineEvent ) ;
341348 } ,
342- seed ( params : { id : string ; launchId : string ; owner ?: string ; running ?: boolean } ) {
349+ seed ( params : {
350+ id : string ;
351+ launchId : string ;
352+ owner ?: string ;
353+ status ?: FakeContainer [ "status" ] ;
354+ } ) {
343355 const container : FakeContainer = {
344356 id : params . id ,
345357 labels : {
@@ -351,7 +363,7 @@ function containerFixture(
351363 mounts : [ ] ,
352364 image : "node:22-slim" ,
353365 entry : bundleEntry ,
354- running : params . running ?? true ,
366+ status : params . status ?? "running" ,
355367 pid : null ,
356368 } ;
357369 fs . writeFileSync (
@@ -435,7 +447,7 @@ describe("node worker supervisor container isolation", () => {
435447 } ,
436448 } ) ;
437449 const completed = await waitForTerminal ( fixture . supervisor , input . launchId ) ;
438- expect ( completed ?. state ) . toBe ( "completed" ) ;
450+ expect ( completed ) . toMatchObject ( { state : "completed" } ) ;
439451 expect ( JSON . parse ( completed ?. resultJson ?? "null" ) ) . toEqual ( {
440452 status : "completed" ,
441453 argv : [ ] ,
@@ -484,6 +496,32 @@ describe("node worker supervisor container isolation", () => {
484496 }
485497 } ) ;
486498
499+ it ( "keeps a launch running while its container is still starting" , async ( ) => {
500+ const fixture = containerFixture ( ) ;
501+ const input = testWorkerLaunchInput ( fixture . workspaceDir , "container-startup-poll" ) ;
502+ const startMarker = path . join ( fixture . engineRoot , "hold-start" ) ;
503+ fs . writeFileSync ( startMarker , "hold" ) ;
504+
505+ try {
506+ const running = await fixture . supervisor . launch ( input , endpoint ) ;
507+
508+ // The fake engine keeps the container created until this poll inspects it,
509+ // so the supervisor must not read startup as an exited worker.
510+ expect ( await fixture . supervisor . status ( input . launchId ) ) . toMatchObject ( {
511+ state : "running" ,
512+ container : running . container ,
513+ } ) ;
514+ expect ( await waitForTerminal ( fixture . supervisor , input . launchId ) ) . toMatchObject ( {
515+ state : "completed" ,
516+ } ) ;
517+ } finally {
518+ if ( fs . existsSync ( startMarker ) ) {
519+ fs . unlinkSync ( startMarker ) ;
520+ }
521+ await fixture . supervisor . close ( ) ;
522+ }
523+ } ) ;
524+
487525 it ( "uses the documented Node 22 image when no override is configured" , async ( ) => {
488526 const fixture = containerFixture ( ) ;
489527 const input = testWorkerLaunchInput ( fixture . workspaceDir , "container-default-image" ) ;
@@ -667,7 +705,7 @@ describe("node worker supervisor container isolation", () => {
667705 it ( "interrupts a stale running journal after verifying its dead container identity" , async ( ) => {
668706 const fixture = containerFixture ( ) ;
669707 const launchId = "container-dead-recovery" ;
670- const container = fixture . seed ( { id : "c" . repeat ( 64 ) , launchId, running : false } ) ;
708+ const container = fixture . seed ( { id : "c" . repeat ( 64 ) , launchId, status : "exited" } ) ;
671709 claimFixtureLaunch ( fixture , launchId , container . id ) ;
672710
673711 try {
0 commit comments