@miraland-labs/conduit-bridge 0.16.188 → 0.16.189

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.
package/dist/cli.js CHANGED
@@ -20,7 +20,7 @@ import { BOOTSTRAP_RESULTS, buildSovereignExecutionFacts, workspaceIsClean } fro
20
20
  import { ensureCheckout } from "./checkout.js";
21
21
  import { buildOnShiftIntentProof, managedWorkspacePath, maybeApplyOnShiftIntent } from "./on-shift-apply.js";
22
22
  import { expandOpsValue, loadOpsEnv, OPS_VERBS, runOps } from "./ops.js";
23
- import { pumpExecutionSlots, renewLeases } from "./execution.js";
23
+ import { assignmentsPending, pumpExecutionSlots, renewLeases } from "./execution.js";
24
24
  import { createRehearsalWorktree, rehearsalWorktreePath, removeAttemptWorktree } from "./attempt-worktree.js";
25
25
  import { applyRunnerToolPath, installRunnerService, uninstallRunnerService } from "./service.js";
26
26
  import { BRIDGE_PROTOCOL_VERSION, cachedBridgePreflight, gateRehearsalLockHeld, planGateRehearsals, PREFLIGHT_CACHE_TTL_MS, runGateRehearsal, unavailableWorkspacePreflight } from "./preflight.js";
@@ -667,9 +667,17 @@ async function runner() {
667
667
  await heartbeat(client, config, workspace, currentBrief, preflight, intentProof, bootstrapResult);
668
668
  }
669
669
  await renewLeases(client, config);
670
+ // Dispatched work outranks a rehearsal already running. Stop it with nothing recorded, release
671
+ // the lock, and claim on this same cycle. The rehearsal stays due.
672
+ if (gateRehearsalRunning && await assignmentsPending(client)) {
673
+ gateRehearsalAbort?.abort();
674
+ await gateRehearsalDone;
675
+ }
670
676
  // Another runner on this computer rehearsing its gate: claim as usual, rehearse on a later cycle.
677
+ // An assignment already waiting is claimed below; this cycle does not start a rehearsal.
671
678
  if (workspace && onlineDriverIds(config).length && !gateRehearsalRunning && rehearsalPlan?.due
672
- && running.size === 0 && Object.keys(config.activeAttempts).length === 0 && !gateRehearsalLockHeld()) {
679
+ && running.size === 0 && Object.keys(config.activeAttempts).length === 0 && !gateRehearsalLockHeld()
680
+ && !await assignmentsPending(client)) {
673
681
  startGateRehearsal(rehearsalPlan.due.workspace, rehearsalPlan.due.plan);
674
682
  }
675
683
  // No claim while the gate rehearses: the rehearsal measures the gate alone, never beside an attempt.
@@ -729,8 +737,10 @@ async function runner() {
729
737
  await new Promise((resolveSleep) => setTimeout(resolveSleep, intervalMs));
730
738
  }
731
739
  }
732
- /** True while the gate rehearsal runs in the background; the loop keeps beating but claims nothing. */
740
+ /** True while the gate rehearsal runs in the background. A dispatched assignment aborts it, then this cycle claims. */
733
741
  let gateRehearsalRunning = false;
742
+ let gateRehearsalAbort = null;
743
+ let gateRehearsalDone = Promise.resolve();
734
744
  /** An observation fingerprints the source checkout; a fast-forward under it reads as the observer writing. */
735
745
  let investigationRunning = false;
736
746
  /** The rehearsals the heartbeat reports, one per on-shift repository; empty reports no field. */
@@ -777,21 +787,30 @@ async function rehearsalCheckouts(workspace, brief, refresh) {
777
787
  */
778
788
  function startGateRehearsal(workspace, plan) {
779
789
  gateRehearsalRunning = true;
790
+ const abort = new AbortController();
791
+ gateRehearsalAbort = abort;
780
792
  const rehearsalPath = rehearsalWorktreePath(workspace);
781
793
  console.log(`Rehearsing the gate in ${workspace}: ${plan.commands.join(", ")}`);
782
- void createRehearsalWorktree(workspace, plan.commit)
794
+ gateRehearsalDone = createRehearsalWorktree(workspace, plan.commit)
783
795
  .then((path) => runGateRehearsal(path, plan, {
796
+ signal: abort.signal,
784
797
  freshWorkspace: (warmUpSeconds) => {
785
798
  console.log(`Gate warm-up took ${warmUpSeconds} s; measuring again in a fresh worktree`);
786
799
  return createRehearsalWorktree(workspace, plan.commit);
787
800
  },
788
801
  }))
789
- .then((rehearsal) => { if (rehearsal === "busy")
790
- console.log("Gate rehearsal deferred: another runner on this computer is rehearsing"); })
802
+ .then((rehearsal) => {
803
+ if (rehearsal === "busy")
804
+ console.log("Gate rehearsal deferred: another runner on this computer is rehearsing");
805
+ else if (abort.signal.aborted)
806
+ console.log("Gate rehearsal stopped: an assignment is waiting");
807
+ })
791
808
  .catch((error) => console.error(`Gate rehearsal failed: ${redactSecrets(error instanceof Error ? error.message : "unknown error")}`))
792
809
  .finally(async () => {
793
810
  await removeAttemptWorktree(workspace, rehearsalPath);
794
811
  gateRehearsalRunning = false;
812
+ if (gateRehearsalAbort === abort)
813
+ gateRehearsalAbort = null;
795
814
  });
796
815
  }
797
816
  /** Last state announced, so a workspace that stays diverged does not print on every cycle. */
package/dist/execution.js CHANGED
@@ -832,6 +832,21 @@ export async function pumpExecutionSlots(client, config, workspace, brief, timeo
832
832
  }
833
833
  return progressed;
834
834
  }
835
+ /**
836
+ * True when `/runner/v1/assignments` lists work for this machine. A failed poll is not waiting
837
+ * work: the caller keeps the current cycle. The claim path still parses and claims.
838
+ */
839
+ export async function assignmentsPending(client) {
840
+ try {
841
+ const data = await client.request("/runner/v1/assignments");
842
+ if (!data || typeof data !== "object" || !("assignments" in data))
843
+ return false;
844
+ return Array.isArray(data.assignments) && data.assignments.length > 0;
845
+ }
846
+ catch {
847
+ return false;
848
+ }
849
+ }
835
850
  /** Claim one assignment when under capacity; does not start the agent (multi-slot pump does). */
836
851
  export async function claimNextAssignment(client, config, workspace, brief, driverId, processOnlineIds, options = {}) {
837
852
  if (Object.keys(config.activeAttempts).length >= config.leaseCapacity)
package/dist/preflight.js CHANGED
@@ -10,7 +10,7 @@ import { bridgeConfigDirectory } from "./config.js";
10
10
  import { runBoundedVerificationCommand, VERIFICATION_TIMEOUT_MS, verificationEvidenceCommands } from "./ensure-test-evidence.js";
11
11
  import { lockfileDigest } from "./execution-facts.js";
12
12
  import { resolveAgentTimeout, resolveMaxTurns } from "./execution-budget.js";
13
- import { hasAntigravityLogin, hasClaudeLogin, hasGrokLogin, hasOpenAiLogin, hasOpenCodeLogin, driverExecutable, readSignInStatus, } from "./driver.js";
13
+ import { hasAntigravityLogin, hasClaudeLogin, hasGrokLogin, hasOpenAiLogin, hasOpenCodeLogin, driverExecutable, readSignInStatus, stopTrackedProcessGroups, } from "./driver.js";
14
14
  import { laneQuota, laneTierBindings, localFuelOnlyDriver, onlineDriverIds, resolveDriverFuel, supportsReadOnlyDiagnosis } from "./drivers.js";
15
15
  /** Protocol 3: read-only diagnosis can reuse a retained failed-attempt worktree. */
16
16
  // 4: each driver snapshot reports diagnosis_read_only, so the control plane can require a
@@ -421,23 +421,70 @@ async function acquireGateRehearsalLock(lockPath) {
421
421
  await unlink(claim).catch(() => undefined);
422
422
  }
423
423
  }
424
+ /** Resolve when `work` settles, or with "aborted" when `signal` aborts first. */
425
+ function untilAbort(work, signal) {
426
+ if (!signal)
427
+ return work;
428
+ if (signal.aborted)
429
+ return Promise.resolve("aborted");
430
+ return new Promise((resolve, reject) => {
431
+ const onAbort = () => resolve("aborted");
432
+ signal.addEventListener("abort", onAbort, { once: true });
433
+ work.then((value) => {
434
+ signal.removeEventListener("abort", onAbort);
435
+ resolve(signal.aborted ? "aborted" : value);
436
+ }, (error) => {
437
+ signal.removeEventListener("abort", onAbort);
438
+ if (signal.aborted)
439
+ resolve("aborted");
440
+ else
441
+ reject(error);
442
+ });
443
+ });
444
+ }
445
+ /** Call `stop` if `signal` aborts after this returns. An already-aborted signal has no command yet. */
446
+ function stopWhenAborted(signal, stop) {
447
+ if (!signal || signal.aborted)
448
+ return () => undefined;
449
+ signal.addEventListener("abort", stop, { once: true });
450
+ return () => signal.removeEventListener("abort", stop);
451
+ }
452
+ async function runRehearsalCommand(run, command, cwd, timeoutMs, signal) {
453
+ if (signal?.aborted)
454
+ return "aborted";
455
+ const work = (signal ? run(command, cwd, timeoutMs, signal) : run(command, cwd, timeoutMs)).catch(() => null);
456
+ const result = await untilAbort(work, signal);
457
+ if (result === "aborted" || signal?.aborted)
458
+ return "aborted";
459
+ return result;
460
+ }
424
461
  /**
425
- * Run the planned gate once and remember it for the day. Null when no command could start.
426
- * "busy" when another rehearsal on this computer holds the lock: nothing is run or remembered, so
427
- * the gate is still due and the next cycle tries again.
462
+ * Run the planned gate once and remember it for the day. Null when no command could start, or when
463
+ * `signal` aborts: the command is stopped, nothing is remembered, and the lock is released, so the
464
+ * gate stays due. "busy" when another rehearsal on this computer holds the lock: nothing is run or
465
+ * remembered, so the gate is still due and the next cycle tries again.
428
466
  */
429
467
  export async function runGateRehearsal(workspace, plan, options = {}) {
468
+ if (options.signal?.aborted)
469
+ return null;
430
470
  const lockPath = options.lockPath ?? gateRehearsalLockPath();
431
471
  if (!await acquireGateRehearsalLock(lockPath))
432
472
  return "busy";
473
+ const releaseAbort = stopWhenAborted(options.signal, stopTrackedProcessGroups);
433
474
  try {
475
+ if (options.signal?.aborted)
476
+ return null;
434
477
  return await rehearseGate(workspace, plan, options);
435
478
  }
436
479
  finally {
480
+ releaseAbort();
437
481
  await unlink(lockPath).catch(() => undefined);
438
482
  }
439
483
  }
440
484
  async function rehearseGate(workspace, plan, options) {
485
+ const signal = options.signal;
486
+ if (signal?.aborted)
487
+ return null;
441
488
  const now = options.now ?? Date.now;
442
489
  const run = options.runCommand ?? runBoundedVerificationCommand;
443
490
  const commands = [];
@@ -445,7 +492,10 @@ async function rehearseGate(workspace, plan, options) {
445
492
  for (const command of plan.commands) {
446
493
  const started = now();
447
494
  // A command that cannot start measured nothing; the dry run skips it the same way.
448
- const result = await run(command, cwd, REHEARSAL_TIMEOUT_MS).catch(() => null);
495
+ // An abort measures nothing either: the gate stays due for the next quiet cycle.
496
+ const result = await runRehearsalCommand(run, command, cwd, REHEARSAL_TIMEOUT_MS, signal);
497
+ if (result === "aborted")
498
+ return null;
449
499
  if (!result)
450
500
  continue;
451
501
  const elapsed = now() - started;
@@ -456,10 +506,16 @@ async function rehearseGate(workspace, plan, options) {
456
506
  }
457
507
  // The pass fit only the rehearsal's limit: it was a warm-up. Measure once more, in a fresh
458
508
  // checkout with the attempt's limit, so the report shows what an attempt will see.
459
- if (options.freshWorkspace)
460
- cwd = await options.freshWorkspace(seconds);
509
+ if (options.freshWorkspace) {
510
+ const fresh = await untilAbort(options.freshWorkspace(seconds), signal);
511
+ if (fresh === "aborted")
512
+ return null;
513
+ cwd = fresh;
514
+ }
461
515
  const again = now();
462
- const second = await run(command, cwd, VERIFICATION_TIMEOUT_MS).catch(() => null);
516
+ const second = await runRehearsalCommand(run, command, cwd, VERIFICATION_TIMEOUT_MS, signal);
517
+ if (second === "aborted")
518
+ return null;
463
519
  if (!second) {
464
520
  commands.push({ command, seconds, exit_code: result.code, timed_out: false });
465
521
  continue;
@@ -472,6 +528,8 @@ async function rehearseGate(workspace, plan, options) {
472
528
  warm_up_seconds: seconds,
473
529
  });
474
530
  }
531
+ if (signal?.aborted)
532
+ return null;
475
533
  const at = now();
476
534
  const rehearsal = commands.length
477
535
  ? { repository: plan.repository, commit: plan.commit, rehearsed_at: new Date(at).toISOString(), commands }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miraland-labs/conduit-bridge",
3
- "version": "0.16.188",
3
+ "version": "0.16.189",
4
4
  "description": "Conduit Bridge CLI — join, connect, disconnect, multi-driver lanes, and run Claude Code / Codex / Cursor / OpenCode / Pi / Kiro / Antigravity / Grok Build agents for a Conduit organization",
5
5
  "type": "module",
6
6
  "bin": {