@adhdev/daemon-core 0.9.82-rc.487 → 0.9.82-rc.489

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/index.mjs CHANGED
@@ -409,10 +409,10 @@ function readInjected(value) {
409
409
  }
410
410
  function getDaemonBuildInfo() {
411
411
  if (cached) return cached;
412
- const commit = readInjected(true ? "ef3ded0f5df148982ed222411ea08c6ab0fdb39b" : void 0) ?? "unknown";
413
- const commitShort = readInjected(true ? "ef3ded0f" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
- const version = readInjected(true ? "0.9.82-rc.487" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
- const builtAt = readInjected(true ? "2026-07-10T01:53:17.254Z" : void 0);
412
+ const commit = readInjected(true ? "b268e41ee8422d976c6774101d93809b131860e9" : void 0) ?? "unknown";
413
+ const commitShort = readInjected(true ? "b268e41e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
+ const version = readInjected(true ? "0.9.82-rc.489" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
+ const builtAt = readInjected(true ? "2026-07-10T04:37:55.985Z" : void 0);
416
416
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
417
417
  return cached;
418
418
  }
@@ -6169,6 +6169,7 @@ function reclaimStrandedAssignedTask(meshId, taskId, opts) {
6169
6169
  delete entry.assignedSessionId;
6170
6170
  delete entry.assignedProviderType;
6171
6171
  delete entry.dispatchTimestamp;
6172
+ entry.dispatchNonce = (entry.dispatchNonce || 0) + 1;
6172
6173
  entry.strandedReclaimCount = reclaims;
6173
6174
  entry.updatedAt = now;
6174
6175
  endTaskDispatchInFlight(meshId, taskId);
@@ -7192,6 +7193,7 @@ var init_mesh_runtime_store = __esm({
7192
7193
  entry.assignedSessionId = sessionId;
7193
7194
  if (providerType) entry.assignedProviderType = providerType;
7194
7195
  entry.dispatchTimestamp = now;
7196
+ entry.dispatchNonce = (entry.dispatchNonce || 0) + 1;
7195
7197
  entry.updatedAt = now;
7196
7198
  this.db.prepare(`
7197
7199
  UPDATE mesh_queue SET
@@ -15660,6 +15662,10 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
15660
15662
  meshId,
15661
15663
  nodeId,
15662
15664
  taskId: task.id,
15665
+ // REDRIVE-DUP: carry the current dispatch nonce so the worker can echo it
15666
+ // back on generating_started; a reclaim bumps this row's nonce, making an
15667
+ // already-in-flight stale inject rejectable on arrival.
15668
+ ...typeof task.dispatchNonce === "number" ? { dispatchNonce: task.dispatchNonce } : {},
15663
15669
  ...localDaemonIdForDispatch ? { coordinatorDaemonId: localDaemonIdForDispatch } : {},
15664
15670
  ...sourceCoordinatorSessionId ? { coordinatorSessionId: sourceCoordinatorSessionId } : {}
15665
15671
  }
@@ -15718,6 +15724,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
15718
15724
  meshId,
15719
15725
  nodeId,
15720
15726
  taskId: task.id,
15727
+ // REDRIVE-DUP: carry the current dispatch nonce (see remote branch above).
15728
+ ...typeof task.dispatchNonce === "number" ? { dispatchNonce: task.dispatchNonce } : {},
15721
15729
  ...localCoordinatorDaemonId() ? { coordinatorDaemonId: localCoordinatorDaemonId() } : {},
15722
15730
  ...readNonEmptyString2(task.sourceCoordinatorSessionId) ? { coordinatorSessionId: readNonEmptyString2(task.sourceCoordinatorSessionId) } : {}
15723
15731
  }
@@ -19700,6 +19708,42 @@ function sourceWorkerAutoApproves(components, sessionId) {
19700
19708
  return false;
19701
19709
  }
19702
19710
  }
19711
+ function stopStaleMeshWorker(components, args) {
19712
+ const { meshId, sessionId, providerType } = args;
19713
+ const stopArgs = {
19714
+ targetSessionId: sessionId,
19715
+ ...providerType ? { cliType: providerType } : {},
19716
+ mode: "hard",
19717
+ reason: "stale_mesh_dispatch_reclaimed"
19718
+ };
19719
+ try {
19720
+ const isLocal = components.cliManager?.adapters?.has?.(sessionId) === true;
19721
+ if (isLocal) {
19722
+ if (!stopArgs.cliType) {
19723
+ const localType = components.cliManager?.adapters?.get?.(sessionId)?.cliType;
19724
+ if (localType) stopArgs.cliType = localType;
19725
+ }
19726
+ Promise.resolve(components.cliManager?.handleCliCommand?.("stop_cli", stopArgs)).catch((e) => LOG.warn("MeshQueue", `Local stop of stale worker ${sessionId} failed: ${e?.message || e}`));
19727
+ return;
19728
+ }
19729
+ let daemonId = args.daemonId;
19730
+ if (!daemonId && args.nodeId) {
19731
+ try {
19732
+ const mesh = getMeshWithCache(components, meshId);
19733
+ const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.nodeId));
19734
+ daemonId = node ? readMeshNodeDaemonId(node) || void 0 : void 0;
19735
+ } catch {
19736
+ }
19737
+ }
19738
+ if (daemonId && components.dispatchMeshCommand) {
19739
+ Promise.resolve(components.dispatchMeshCommand(daemonId, "stop_cli", stopArgs)).catch((e) => LOG.warn("MeshQueue", `Remote stop of stale worker ${sessionId} on daemon ${daemonId} failed: ${e?.message || e}`));
19740
+ } else {
19741
+ LOG.warn("MeshQueue", `Cannot stop stale worker ${sessionId}: no local adapter and no resolvable remote daemon id (node ${args.nodeId ?? "?"}). Ack already rejected \u2014 task will re-strand-and-fail if the worker completes.`);
19742
+ }
19743
+ } catch (e) {
19744
+ LOG.warn("MeshQueue", `stopStaleMeshWorker error for ${sessionId}: ${e?.message || e}`);
19745
+ }
19746
+ }
19703
19747
  function injectMeshSystemMessage(components, args) {
19704
19748
  const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
19705
19749
  const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
@@ -19939,6 +19983,35 @@ function injectMeshSystemMessage(components, args) {
19939
19983
  }
19940
19984
  if (sessionId) {
19941
19985
  const startedTaskId = readNonEmptyString2(args.metadataEvent.taskId) || void 0;
19986
+ const startedNonce = typeof args.metadataEvent.dispatchNonce === "number" ? args.metadataEvent.dispatchNonce : void 0;
19987
+ if (startedTaskId && startedNonce !== void 0) {
19988
+ const currentRow = (() => {
19989
+ try {
19990
+ return MeshRuntimeStore.getInstance().findQueueEntryById(args.meshId, startedTaskId);
19991
+ } catch {
19992
+ return null;
19993
+ }
19994
+ })();
19995
+ const currentNonce = typeof currentRow?.dispatchNonce === "number" ? currentRow.dispatchNonce : void 0;
19996
+ if (currentNonce !== void 0 && startedNonce < currentNonce) {
19997
+ LOG.warn("MeshQueue", `Rejecting stale mesh dispatch: task ${startedTaskId} generating_started from session ${sessionId} (node ${nodeId ?? "?"}) carries dispatchNonce ${startedNonce} < current ${currentNonce} \u2014 the task was reclaimed and re-dispatched; stopping this worker to prevent duplicate execution.`);
19998
+ traceMeshEventDrop("stale_dispatch_nonce_rejected", {
19999
+ taskId: startedTaskId,
20000
+ sessionId,
20001
+ nodeId,
20002
+ meshId: args.meshId,
20003
+ event: "agent:generating_started"
20004
+ }, `nonce ${startedNonce} < ${currentNonce}`);
20005
+ stopStaleMeshWorker(components, {
20006
+ meshId: args.meshId,
20007
+ sessionId,
20008
+ nodeId,
20009
+ providerType: readNonEmptyString2(args.metadataEvent.providerType) || readNonEmptyString2(args.metadataEvent.cliType),
20010
+ daemonId: readNonEmptyString2(args.metadataEvent.sourceDaemonId) || readNonEmptyString2(args.metadataEvent.daemonId)
20011
+ });
20012
+ return { success: true, forwarded: 0, suppressed: true, staleDispatchRejected: true };
20013
+ }
20014
+ }
19942
20015
  if (startedTaskId) {
19943
20016
  updateDirectDispatchStatus(args.meshId, sessionId, "acked", startedTaskId);
19944
20017
  } else if (sessionHasActiveAssignment(args.meshId, sessionId)) {
@@ -20475,6 +20548,7 @@ var init_mesh_event_forwarding = __esm({
20475
20548
  init_dist();
20476
20549
  init_mesh_events_stale();
20477
20550
  init_mesh_task_inflight();
20551
+ init_mesh_node_identity();
20478
20552
  init_mesh_events_utils();
20479
20553
  init_mesh_event_classify();
20480
20554
  init_mesh_queue_assignment();
@@ -45089,13 +45163,18 @@ var CliProviderInstance = class _CliProviderInstance {
45089
45163
  * INVARIANT (do not regress): must be STRICTLY GREATER than
45090
45164
  * AUTO_APPROVE_FLAP_CONTINUITY_MS + max_busy_phase + AUTO_APPROVE_SETTLE_MS so
45091
45165
  * that during a flap the settle clock (which FLAP_CONTINUITY keeps alive across
45092
- * each ~4.3–4.5s busy phase) gets to accrue its 600ms on the RETURNING approval
45093
- * frame before this stall bound can trip. Observed geometry: approval ~1.5s,
45094
- * busy ~4.3–4.5s. 9000ms CONTINUITY(6000) + busy(~4.5s) + SETTLE(600) headroom;
45166
+ * each busy phase) gets to accrue its 600ms on the RETURNING approval frame
45167
+ * before this stall bound can trip. Observed geometry — worker: approval ~1.5s,
45168
+ * busy ~4.3–4.5s; coordinator self-session: approval ~1.5s, busy ~2.85s. Both
45169
+ * now use the extended window (isAutonomousMeshSession covers worker +
45170
+ * meshCoordinatorFor). Worst case: CONTINUITY(6000) + busy(~4.5s) + SETTLE(600)
45171
+ * = ~11100ms, so the stall bound must exceed that. 10500ms satisfies the invariant
45172
+ * for coordinator (6000 + 2850 + 600 = 9450 < 10500) and was previously 9000ms
45173
+ * (which failed for a worker busy phase of 4.5s: 6000+4500+600=11100 > 9000).
45095
45174
  * the old 4500ms tripped inside the very first busy phase (while modal=none, so
45096
45175
  * the nudge was NOT deferred) and leaked to the coordinator.
45097
45176
  */
45098
- static AUTO_APPROVE_MASK_STALL_MS = 9e3;
45177
+ static AUTO_APPROVE_MASK_STALL_MS = 10500;
45099
45178
  adapter;
45100
45179
  context = null;
45101
45180
  events = [];
@@ -45557,6 +45636,10 @@ var CliProviderInstance = class _CliProviderInstance {
45557
45636
  // shares this daemon. See isMeshOwnedDelegateSession's post-detach gate.
45558
45637
  ...assignment.nodeId ? { meshNodeId: assignment.nodeId, meshLastNodeId: assignment.nodeId } : {},
45559
45638
  ...assignment.taskId ? { meshActiveTaskId: assignment.taskId } : {},
45639
+ // REDRIVE-DUP: task-level dispatch nonce, echoed on generating_started so the
45640
+ // coordinator can reject a stale (reclaimed) dispatch. Cleared with meshActiveTaskId
45641
+ // on detach so a subsequent unrelated turn never re-echoes a prior task's nonce.
45642
+ ...typeof assignment.dispatchNonce === "number" ? { meshActiveDispatchNonce: assignment.dispatchNonce } : {},
45560
45643
  ...assignment.coordinatorDaemonId ? { meshCoordinatorDaemonId: assignment.coordinatorDaemonId } : {},
45561
45644
  // Session-level routing anchor: the originating coordinator session, so this
45562
45645
  // worker's completion events route back to the exact session that dispatched it.
@@ -45592,15 +45675,17 @@ var CliProviderInstance = class _CliProviderInstance {
45592
45675
  if (!this.settings.meshNodeFor && !this.settings.meshActiveTaskId && !this.settings.meshNodeId) return;
45593
45676
  if (this.settings.launchedByCoordinator === true) {
45594
45677
  if (!this.settings.meshActiveTaskId) return;
45595
- const { meshActiveTaskId: meshActiveTaskId2, ...rest2 } = this.settings;
45678
+ const { meshActiveTaskId: meshActiveTaskId2, meshActiveDispatchNonce: meshActiveDispatchNonce2, ...rest2 } = this.settings;
45596
45679
  void meshActiveTaskId2;
45680
+ void meshActiveDispatchNonce2;
45597
45681
  this.settings = rest2;
45598
45682
  this.adapter.updateRuntimeSettings?.(this.settings);
45599
45683
  return;
45600
45684
  }
45601
- const { meshNodeFor, meshNodeId, meshActiveTaskId, ...rest } = this.settings;
45685
+ const { meshNodeFor, meshNodeId, meshActiveTaskId, meshActiveDispatchNonce, ...rest } = this.settings;
45602
45686
  void meshNodeFor;
45603
45687
  void meshActiveTaskId;
45688
+ void meshActiveDispatchNonce;
45604
45689
  const lastNodeId = typeof meshNodeId === "string" && meshNodeId.trim() ? meshNodeId.trim() : typeof rest.meshLastNodeId === "string" && rest.meshLastNodeId.trim() ? rest.meshLastNodeId.trim() : void 0;
45605
45690
  this.settings = lastNodeId ? { ...rest, meshLastNodeId: lastNodeId } : rest;
45606
45691
  this.adapter.updateRuntimeSettings?.(this.settings);
@@ -46250,7 +46335,7 @@ var CliProviderInstance = class _CliProviderInstance {
46250
46335
  * genuine resolution frees the gate promptly.
46251
46336
  */
46252
46337
  autoApproveContinuityWindowMs() {
46253
- return this.autoApproveMaskSince > 0 && this.isMeshWorkerSession() ? _CliProviderInstance.AUTO_APPROVE_FLAP_CONTINUITY_MS : _CliProviderInstance.AUTO_APPROVE_GATE_HYSTERESIS_MS;
46338
+ return this.autoApproveMaskSince > 0 && this.isAutonomousMeshSession() ? _CliProviderInstance.AUTO_APPROVE_FLAP_CONTINUITY_MS : _CliProviderInstance.AUTO_APPROVE_GATE_HYSTERESIS_MS;
46254
46339
  }
46255
46340
  /**
46256
46341
  * The settle-gate identity signature for a raw activeModal, or null when the
@@ -47089,6 +47174,9 @@ var CliProviderInstance = class _CliProviderInstance {
47089
47174
  const resolved = this.completingTurnTaskId();
47090
47175
  if (resolved) enrichedEvent.taskId = resolved;
47091
47176
  }
47177
+ if (enrichedEvent.dispatchNonce === void 0 && typeof this.settings.meshActiveDispatchNonce === "number") {
47178
+ enrichedEvent.dispatchNonce = this.settings.meshActiveDispatchNonce;
47179
+ }
47092
47180
  }
47093
47181
  if (this.context?.emitProviderEvent) {
47094
47182
  this.context.emitProviderEvent(enrichedEvent);
@@ -49980,6 +50068,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
49980
50068
  meshId: meshContext.meshId,
49981
50069
  ...typeof meshContext.nodeId === "string" && meshContext.nodeId ? { nodeId: meshContext.nodeId } : {},
49982
50070
  ...typeof meshContext.taskId === "string" && meshContext.taskId ? { taskId: meshContext.taskId } : {},
50071
+ // REDRIVE-DUP: carry the dispatch nonce onto the worker session so
50072
+ // its generating_started event echoes it back for the coordinator's
50073
+ // stale-nonce guard.
50074
+ ...typeof meshContext.dispatchNonce === "number" ? { dispatchNonce: meshContext.dispatchNonce } : {},
49983
50075
  ...typeof meshContext.coordinatorDaemonId === "string" && meshContext.coordinatorDaemonId ? { coordinatorDaemonId: meshContext.coordinatorDaemonId } : {}
49984
50076
  });
49985
50077
  } catch {
@@ -58914,7 +59006,50 @@ function buildRefineJobHandle(self, args) {
58914
59006
  }
58915
59007
  };
58916
59008
  }
59009
+ function slimRefineEventResult(result) {
59010
+ const slim = {};
59011
+ for (const key2 of [
59012
+ "success",
59013
+ "code",
59014
+ "error",
59015
+ "convergenceStatus",
59016
+ "blockedReason",
59017
+ "branch",
59018
+ "into",
59019
+ "terminalKind",
59020
+ "nextStep",
59021
+ "finalBranchConvergenceState"
59022
+ ]) {
59023
+ if (result[key2] !== void 0) slim[key2] = result[key2];
59024
+ }
59025
+ if (Array.isArray(result.unreachableSubmoduleCommits)) {
59026
+ slim.unreachableSubmoduleCommits = result.unreachableSubmoduleCommits.map((e) => ({ path: e?.path, autoPublishAllowed: e?.autoPublishAllowed }));
59027
+ }
59028
+ if (result.validationSummary && typeof result.validationSummary === "object") {
59029
+ const vs = result.validationSummary;
59030
+ slim.validationSummary = {
59031
+ status: vs.status,
59032
+ failureCode: vs.failureCode,
59033
+ configSource: vs.configSource,
59034
+ configSourceType: vs.configSourceType,
59035
+ commandsRunCount: Array.isArray(vs.commandsRun) ? vs.commandsRun.length : void 0
59036
+ };
59037
+ }
59038
+ if (result.patchEquivalence && typeof result.patchEquivalence === "object") {
59039
+ const pe = result.patchEquivalence;
59040
+ slim.patchEquivalence = { status: pe.status, equivalent: pe.equivalent };
59041
+ }
59042
+ if (result.submoduleReachability && typeof result.submoduleReachability === "object") {
59043
+ const sr = result.submoduleReachability;
59044
+ slim.submoduleReachability = {
59045
+ checked: Array.isArray(sr.entries) ? sr.entries.length : void 0,
59046
+ unreachable: Array.isArray(sr.unreachable) ? sr.unreachable.length : void 0
59047
+ };
59048
+ }
59049
+ return slim;
59050
+ }
58917
59051
  function queueRefineJobEvent(self, event, handle, result) {
59052
+ const slimResult = result ? slimRefineEventResult(result) : void 0;
58918
59053
  const metadataEvent = {
58919
59054
  source: "refine_mesh_node_async_job",
58920
59055
  jobId: handle.jobId,
@@ -58927,7 +59062,7 @@ function queueRefineJobEvent(self, event, handle, result) {
58927
59062
  startedAt: handle.startedAt,
58928
59063
  completedAt: handle.completedAt,
58929
59064
  retryOfJobId: handle.retryOfJobId,
58930
- ...result ? { result } : {}
59065
+ ...slimResult ? { result: slimResult } : {}
58931
59066
  };
58932
59067
  const eventPayload = {
58933
59068
  event,
@@ -58954,7 +59089,7 @@ function queueRefineJobEvent(self, event, handle, result) {
58954
59089
  startedAt: handle.startedAt,
58955
59090
  completedAt: handle.completedAt,
58956
59091
  retryOfJobId: handle.retryOfJobId,
58957
- ...result ? { result } : {}
59092
+ ...slimResult ? { result: slimResult } : {}
58958
59093
  }
58959
59094
  );
58960
59095
  if (forwarded?.success === true) return;