@bakers-build/conductor 0.19.1-next.2 → 0.19.1-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -402,10 +402,23 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
402
402
  // A watched file changed after this instant was not loaded: the watcher restarts on it.
403
403
  // A self-restart hands over when its watcher stopped looking, so a write during its drain counts.
404
404
  const loadedAt = Number(process.env.BAKERS_RESTART_SINCE) || Date.now();
405
- delete process.env.BAKERS_RESTART_SINCE;
406
405
  const config = await resolveConfig(deps, undefined, true);
407
406
  const checkoutRoot = await checkoutRootOf(config);
408
407
  const logger = loggerFor(checkoutRoot, log);
408
+ const execve = deps.execve ?? process.execve?.bind(process);
409
+ const reExec = (env) => execve?.(process.execPath, [process.execPath, ...process.execArgv, ...process.argv.slice(1)], env);
410
+ // Run cleanup SIGTERMs every process whose environ holds the run's marker.
411
+ const runUuid = process.env.BAKERS_RUN_UUID;
412
+ if (runUuid) {
413
+ logger.warn({ run: runUuid }, `started from run ${runUuid}; dropping the run marker`);
414
+ const { BAKERS_RUN_UUID: _marker, ...env } = process.env;
415
+ // Only a new image clears /proc/<pid>/environ; same pid and log.
416
+ if (execve)
417
+ return reExec(env);
418
+ delete process.env.BAKERS_RUN_UUID;
419
+ logger.warn({ node: process.version }, 'without process.execve (Node >= 22.15) the run cleanup can still end this conductor');
420
+ }
421
+ delete process.env.BAKERS_RESTART_SINCE;
409
422
  // Every start path ends here: detached child, self-restart and update re-exec.
410
423
  const secrets = loadSecretsOrFail(logger);
411
424
  if (!secrets)
@@ -437,14 +450,17 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
437
450
  await conductor.startTools(join(homeBbDir(), 'conductors', `${conductor.id}.json`));
438
451
  const controller = new AbortController();
439
452
  let restart = false;
453
+ let reason = 'serve ended';
440
454
  // A stop wins over a restart already decided: `oven stop` must stay a stop.
441
- const onSignal = () => {
455
+ const onSignal = (signal) => {
442
456
  restart = false;
457
+ reason = signal;
458
+ logger.info({ signal }, `stopping on ${signal}`);
443
459
  controller.abort();
444
460
  };
445
- process.once('SIGINT', onSignal);
446
- process.once('SIGTERM', onSignal);
447
- const execve = deps.execve ?? process.execve?.bind(process);
461
+ const signalHandlers = ['SIGINT', 'SIGTERM', 'SIGHUP'].map((signal) => [signal, () => onSignal(signal)]);
462
+ for (const [signal, handler] of signalHandlers)
463
+ process.once(signal, handler);
448
464
  let watcher;
449
465
  const check = deps.checkConfig ?? defaultCheckConfig;
450
466
  // The restart re-runs loadSecretsOrFail, which exits on a bad file: check first.
@@ -462,6 +478,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
462
478
  const heldBack = new Set();
463
479
  const restartNow = (since = Date.now()) => {
464
480
  restart = true;
481
+ reason = 'restart';
465
482
  process.env.BAKERS_RESTART_SINCE = String(since);
466
483
  watcher?.close();
467
484
  clearInterval(versionTimer);
@@ -626,12 +643,17 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
626
643
  try {
627
644
  await conductor.serve(controller.signal);
628
645
  }
646
+ catch (err) {
647
+ reason = 'error';
648
+ logger.error({ err: String(err) }, `conductor failed: ${err}`);
649
+ throw err;
650
+ }
629
651
  finally {
630
652
  watcher?.close();
631
653
  clearInterval(versionTimer);
632
654
  await conductor.stopTools();
633
- process.removeListener('SIGINT', onSignal);
634
- process.removeListener('SIGTERM', onSignal);
655
+ for (const [signal, handler] of signalHandlers)
656
+ process.removeListener(signal, handler);
635
657
  // The exiting process writes its own `offline`. It has to be this process:
636
658
  // a heartbeat sets `online` unconditionally (ConductorRegistrar), so an
637
659
  // offline written by anyone else is erased by the next tick — the status
@@ -647,10 +669,11 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
647
669
  logger.warn({ conductorId: conductor.id, err: String(err) }, 'could not write offline status on shutdown; the lease reaper will');
648
670
  }
649
671
  }
672
+ logger.info({ reason }, 'conductor stopped');
650
673
  }
651
674
  // Same pid and log.
652
- if (restart && execve)
653
- execve(process.execPath, [process.execPath, ...process.execArgv, ...process.argv.slice(1)], process.env);
675
+ if (restart)
676
+ reExec(process.env);
654
677
  }
655
678
  async function defaultAskUpdate(question) {
656
679
  const rl = createInterface({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/conductor",
3
- "version": "0.19.1-next.2",
3
+ "version": "0.19.1-next.3",
4
4
  "description": "bakers.build conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,14 +32,14 @@
32
32
  "dependencies": {
33
33
  "@dropsh/plugin-jsonapi-schema": "^0.8.2",
34
34
  "@dropsh/plugin-oauth2": "^0.8.2",
35
- "@bakers-build/core": "^0.19.1-next.2",
36
- "@bakers-build/message": "^0.19.1-next.2",
35
+ "@bakers-build/core": "^0.19.1-next.3",
36
+ "@bakers-build/message": "^0.19.1-next.3",
37
37
  "@modelcontextprotocol/sdk": "1.32.1",
38
38
  "commander": "^12.1.0",
39
39
  "dropsh": "^0.8.2"
40
40
  },
41
41
  "bakersBuild": {
42
- "commit": "e30620a66141c1a790cc993de7cdc7379bcc6720",
42
+ "commit": "81f2970d26d8cf6b4367eb513b68032c8aabe616",
43
43
  "channel": "next"
44
44
  }
45
45
  }