@adhdev/daemon-core 0.9.82-rc.365 → 0.9.82-rc.366

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.
@@ -1325,6 +1325,14 @@ export interface MeshQueueTriggerResult {
1325
1325
  status?: string;
1326
1326
  }>;
1327
1327
  autoLaunchStarted: boolean;
1328
+ /**
1329
+ * True when a worker session is already on its way to claim a still-pending task —
1330
+ * either launched this tick (autoLaunchStarted) or launched on a prior tick and still
1331
+ * booting/awaiting-claim. Callers MUST treat this as "wait, do not launch another
1332
+ * session": a second launch double-edits the worktree. Mutually informative with
1333
+ * `noIdleMeshSessionAvailable`, which is suppressed whenever this is true.
1334
+ */
1335
+ autoLaunchPending?: boolean;
1328
1336
  noIdleMeshSessionAvailable?: boolean;
1329
1337
  }
1330
1338
 
@@ -1485,6 +1493,28 @@ export async function triggerMeshQueue(components: DaemonComponents, meshId: str
1485
1493
  nodeId: task.assignedNodeId,
1486
1494
  sessionId: task.assignedSessionId,
1487
1495
  }));
1496
+
1497
+ // An auto-launch is "pending" when the coordinator has already spun a session up
1498
+ // for a still-pending task and is waiting on that session's idle→claim. This covers
1499
+ // two ticks:
1500
+ // - THIS tick fired the launch (autoLaunchStarted), or
1501
+ // - a PRIOR tick launched a session that is still booting/awaiting-claim — the
1502
+ // per-task await-claim guard (maybeAutoLaunchOneQueueSession) deliberately
1503
+ // declines to launch again, so autoLaunchStarted is false even though a session
1504
+ // is on its way to claim this task.
1505
+ // Without this signal, the second tick reports `noIdleMeshSessionAvailable` and the
1506
+ // MCP guidance tells the coordinator to launch ANOTHER worker — producing a duplicate
1507
+ // session that double-edits the worktree. The claim itself is fine; only the wording
1508
+ // was wrong, so we surface `autoLaunchPending` to suppress the bad "launch one more"
1509
+ // advice while the just-launched session converges.
1510
+ const autoLaunchPending = autoLaunchStarted || afterQueue.some(task => {
1511
+ if (task.status !== 'pending') return false;
1512
+ const al = task.autoLaunch;
1513
+ if (!al || (al.status !== 'started' && al.status !== 'completed')) return false;
1514
+ const launchedAtMs = Date.parse(al.updatedAt);
1515
+ return Number.isFinite(launchedAtMs) && Date.now() - launchedAtMs < AUTO_LAUNCH_AWAIT_CLAIM_MS;
1516
+ });
1517
+
1488
1518
  return {
1489
1519
  success: true,
1490
1520
  meshId,
@@ -1498,7 +1528,11 @@ export async function triggerMeshQueue(components: DaemonComponents, meshId: str
1498
1528
  remoteIdleSessionsChecked,
1499
1529
  skippedSessions,
1500
1530
  autoLaunchStarted,
1501
- ...(pendingAfter > 0 && newlyAssignedTasks.length === 0 && localIdleSessionsChecked === 0 && remoteIdleSessionsChecked === 0 && !autoLaunchStarted
1531
+ ...(autoLaunchPending ? { autoLaunchPending: true } : {}),
1532
+ // Only report "no idle session, go launch one" when nothing is already on its way.
1533
+ // A pending auto-launch (this tick or a prior still-converging one) means a session
1534
+ // WILL claim shortly, so it is not a no-session-available situation.
1535
+ ...(pendingAfter > 0 && newlyAssignedTasks.length === 0 && localIdleSessionsChecked === 0 && remoteIdleSessionsChecked === 0 && !autoLaunchPending
1502
1536
  ? { noIdleMeshSessionAvailable: true }
1503
1537
  : {}),
1504
1538
  };