@adhdev/daemon-standalone 0.9.82-rc.533 → 0.9.82-rc.535

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.js CHANGED
@@ -30208,10 +30208,10 @@ var require_dist3 = __commonJS({
30208
30208
  }
30209
30209
  function getDaemonBuildInfo() {
30210
30210
  if (cached2) return cached2;
30211
- const commit = readInjected(true ? "4bcba3bd84cc9f4cd08a3d93965f10f43fcf5dad" : void 0) ?? "unknown";
30212
- const commitShort = readInjected(true ? "4bcba3bd" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30213
- const version2 = readInjected(true ? "0.9.82-rc.533" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30214
- const builtAt = readInjected(true ? "2026-07-15T07:46:12.141Z" : void 0);
30211
+ const commit = readInjected(true ? "207830c90b06f2f738a85f74079a2460d53767c8" : void 0) ?? "unknown";
30212
+ const commitShort = readInjected(true ? "207830c9" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30213
+ const version2 = readInjected(true ? "0.9.82-rc.535" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30214
+ const builtAt = readInjected(true ? "2026-07-15T10:23:33.822Z" : void 0);
30215
30215
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30216
30216
  return cached2;
30217
30217
  }
@@ -35486,12 +35486,16 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35486
35486
  return [];
35487
35487
  }
35488
35488
  }
35489
+ function consumeSessionDelivery(meshId, sessionId, status, taskId) {
35490
+ try {
35491
+ return MeshRuntimeStore.getInstance().consumeSessionDelivery(meshId, sessionId, status, taskId);
35492
+ } catch {
35493
+ return 0;
35494
+ }
35495
+ }
35489
35496
  function markSessionDeliveriesTerminal(meshId, sessionId, terminalStatus) {
35490
35497
  try {
35491
- const active = MeshRuntimeStore.getInstance().getActiveSessionDeliveries(meshId, sessionId);
35492
- for (const delivery of active) {
35493
- MeshRuntimeStore.getInstance().updateSessionDeliveryStatus(delivery.id, terminalStatus);
35494
- }
35498
+ MeshRuntimeStore.getInstance().markOpenSessionDeliveriesTerminal(meshId, sessionId, terminalStatus);
35495
35499
  } catch {
35496
35500
  }
35497
35501
  }
@@ -37556,6 +37560,25 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
37556
37560
  });
37557
37561
  this.maybeCheckpointWal();
37558
37562
  }
37563
+ // DELIVERED-NOT-CONSUMED-REDRIVE monotonic FSM: the forward-progress lifecycle of a
37564
+ // delivery is a strictly increasing rank — a status may only advance, never regress.
37565
+ // The redrive bug was a NON-monotonic FSM: the transport-confirm callback
37566
+ // (mesh-queue-assignment :384) writes 'delivered' unconditionally by PK, so when the
37567
+ // worker's agent:generating_started raced AHEAD of the confirm and already flipped the
37568
+ // row 'delivering'→'acked', the late confirm CLOBBERED 'acked' back to 'delivered'.
37569
+ // taskDeliveryConsumed() (which keys on 'acked'/'completed') then read false forever,
37570
+ // and the short-grace re-drive re-opened an already-consumed task. Enforcing the rank
37571
+ // ordering here makes the two event orders converge on the same monotone terminal state
37572
+ // regardless of arrival order, so a late confirm can never demote a consumed delivery.
37573
+ // 'failed'/'expired'/'cancelled' are absorbing OUTCOMES, not progress ranks — they are
37574
+ // always allowed (a genuine dispatch failure must be recordable even from 'acked').
37575
+ static DELIVERY_PROGRESS_RANK = {
37576
+ queued: 0,
37577
+ delivering: 1,
37578
+ delivered: 2,
37579
+ acked: 3,
37580
+ completed: 4
37581
+ };
37559
37582
  updateSessionDeliveryStatus(id, status, opts) {
37560
37583
  const now = (/* @__PURE__ */ new Date()).toISOString();
37561
37584
  if (opts?.incrementAttempt) {
@@ -37564,13 +37587,75 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
37564
37587
  SET status = @status, last_error = @lastError, attempt_count = attempt_count + 1, updated_at = @updatedAt
37565
37588
  WHERE id = @id
37566
37589
  `).run({ id, status, lastError: opts?.lastError ?? null, updatedAt: now });
37567
- } else {
37590
+ return;
37591
+ }
37592
+ const targetRank = _MeshRuntimeStore.DELIVERY_PROGRESS_RANK[status];
37593
+ if (targetRank === void 0) {
37568
37594
  this.db.prepare(`
37569
37595
  UPDATE mesh_session_delivery
37570
37596
  SET status = @status, last_error = @lastError, updated_at = @updatedAt
37571
37597
  WHERE id = @id
37572
37598
  `).run({ id, status, lastError: opts?.lastError ?? null, updatedAt: now });
37599
+ return;
37600
+ }
37601
+ this.db.prepare(`
37602
+ UPDATE mesh_session_delivery
37603
+ SET status = @status, last_error = @lastError, updated_at = @updatedAt
37604
+ WHERE id = @id AND (@targetRank >= CASE status
37605
+ WHEN 'queued' THEN 0 WHEN 'delivering' THEN 1 WHEN 'delivered' THEN 2
37606
+ WHEN 'acked' THEN 3 WHEN 'completed' THEN 4 ELSE 99 END)
37607
+ `).run({ id, status, lastError: opts?.lastError ?? null, updatedAt: now, targetRank });
37608
+ }
37609
+ /**
37610
+ * DELIVERED-NOT-CONSUMED-REDRIVE consume path. Advance a task's delivery record(s) to a
37611
+ * CONSUMED status ('acked' or 'completed'), matching on mesh + session (+ taskId when the
37612
+ * event names one) and INCLUDING rows already in 'delivered'/'acked'/'delivering'.
37613
+ *
37614
+ * The ack/terminal callers previously routed through getActiveSessionDeliveries(), whose SQL
37615
+ * EXCLUDES 'delivered' — so in the normal event order (transport confirm flips 'delivered'
37616
+ * BEFORE the worker's generating_started fires) the ack matched zero rows and the delivery
37617
+ * was stranded 'delivered', never 'acked'. This finds the row by (mesh, session[, task])
37618
+ * directly and relies on updateSessionDeliveryStatus's monotonic guard to only advance it.
37619
+ * Returns the number of rows advanced.
37620
+ */
37621
+ consumeSessionDelivery(meshId, sessionId, status, taskId) {
37622
+ const rows = this.db.prepare(
37623
+ taskId ? `SELECT id, session_id FROM mesh_session_delivery
37624
+ WHERE mesh_id = ? AND task_id = ?
37625
+ AND status IN ('queued','delivering','delivered','acked')` : `SELECT id, session_id FROM mesh_session_delivery
37626
+ WHERE mesh_id = ? AND session_id = ?
37627
+ AND status IN ('queued','delivering','delivered','acked')`
37628
+ ).all(meshId, taskId ?? sessionId);
37629
+ let advanced = 0;
37630
+ for (const r of rows) {
37631
+ if (!sessionIdsEquivalent(r.session_id ?? void 0, sessionId)) continue;
37632
+ this.updateSessionDeliveryStatus(r.id, status);
37633
+ advanced++;
37634
+ }
37635
+ return advanced;
37636
+ }
37637
+ /**
37638
+ * DELIVERED-NOT-CONSUMED-REDRIVE terminal path. Mark every OPEN delivery for a session
37639
+ * (queued/delivering/delivered/acked) terminal on task completion/failure. The prior
37640
+ * markSessionDeliveriesTerminal() routed through getActiveSessionDeliveries(), whose SQL
37641
+ * EXCLUDES 'delivered'/'completed' — so a 'delivered' row (the common case, since the
37642
+ * transport confirm flips it before the completion event) was never marked terminal and
37643
+ * stayed 'delivered', keeping taskDeliveryConsumed() false and feeding the false re-drive.
37644
+ * We match rows in OPEN states directly here. 'completed' advances monotonically (it is the
37645
+ * top progress rank); 'failed' is an absorbing outcome written unconditionally.
37646
+ */
37647
+ markOpenSessionDeliveriesTerminal(meshId, sessionId, terminalStatus) {
37648
+ const rows = this.db.prepare(
37649
+ `SELECT id, session_id FROM mesh_session_delivery
37650
+ WHERE mesh_id = ? AND status IN ('queued','delivering','delivered','acked')`
37651
+ ).all(meshId);
37652
+ let marked = 0;
37653
+ for (const r of rows) {
37654
+ if (!sessionIdsEquivalent(r.session_id ?? void 0, sessionId)) continue;
37655
+ this.updateSessionDeliveryStatus(r.id, terminalStatus);
37656
+ marked++;
37573
37657
  }
37658
+ return marked;
37574
37659
  }
37575
37660
  getActiveSessionDeliveries(meshId, sessionId) {
37576
37661
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -50570,17 +50655,7 @@ ${cleanBody}`;
50570
50655
  updateDirectDispatchStatus(args.meshId, sessionId, "acked", soleTaskId);
50571
50656
  }
50572
50657
  }
50573
- const activeDeliveries = (() => {
50574
- try {
50575
- return MeshRuntimeStore.getInstance().getActiveSessionDeliveries(args.meshId, sessionId);
50576
- } catch {
50577
- return [];
50578
- }
50579
- })();
50580
- const deliveriesToAck = startedTaskId ? activeDeliveries.filter((d) => d.taskId === startedTaskId) : activeDeliveries;
50581
- for (const d of deliveriesToAck) {
50582
- updateSessionDeliveryStatus(d.id, "acked");
50583
- }
50658
+ consumeSessionDelivery(args.meshId, sessionId, "acked", startedTaskId);
50584
50659
  }
50585
50660
  } else if (args.event === "agent:stopped") {
50586
50661
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
@@ -52015,6 +52090,9 @@ ${cleanBody}`;
52015
52090
  for (const key2 of [...deliveredNoTurnUnknownStreak.keys()]) {
52016
52091
  if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) deliveredNoTurnUnknownStreak.delete(key2);
52017
52092
  }
52093
+ for (const key2 of [...deliveredUnconsumedUnknownStreak.keys()]) {
52094
+ if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) deliveredUnconsumedUnknownStreak.delete(key2);
52095
+ }
52018
52096
  for (const row of assigned) {
52019
52097
  const dispatchedAtMs = Date.parse(row.dispatchTimestamp ?? "");
52020
52098
  if (!Number.isFinite(dispatchedAtMs)) continue;
@@ -52026,13 +52104,33 @@ ${cleanBody}`;
52026
52104
  updateTaskStatus(meshId, row.id, status);
52027
52105
  continue;
52028
52106
  }
52107
+ const shortStreakKey = `${meshId}::${row.id}`;
52029
52108
  const verdict = row.assignedSessionId ? resolveSessionBusyVerdict(components, row.assignedSessionId) : "IDLE_CONFIRMED";
52030
- if (verdict !== "GENERATING") {
52109
+ if (verdict === "GENERATING") {
52110
+ deliveredUnconsumedUnknownStreak.delete(shortStreakKey);
52111
+ } else {
52112
+ if (verdict === "IDLE_CONFIRMED") {
52113
+ deliveredUnconsumedUnknownStreak.delete(shortStreakKey);
52114
+ } else {
52115
+ const streak = (deliveredUnconsumedUnknownStreak.get(shortStreakKey) ?? 0) + 1;
52116
+ deliveredUnconsumedUnknownStreak.set(shortStreakKey, streak);
52117
+ if (streak < RECLAIM_UNKNOWN_GRACE_TICKS) {
52118
+ traceMeshEventDrop("short_redrive_deferred_unknown_verdict", {
52119
+ taskId: row.id,
52120
+ sessionId: row.assignedSessionId,
52121
+ nodeId: row.assignedNodeId,
52122
+ meshId,
52123
+ event: "agent:generating_started"
52124
+ }, `unknown ${streak}/${RECLAIM_UNKNOWN_GRACE_TICKS}`);
52125
+ continue;
52126
+ }
52127
+ }
52031
52128
  const redriven = reclaimStrandedAssignedTask(meshId, row.id, {
52032
52129
  reason: "delivered_not_consumed_redrive",
52033
52130
  ageMs
52034
52131
  });
52035
52132
  if (redriven) {
52133
+ deliveredUnconsumedUnknownStreak.delete(shortStreakKey);
52036
52134
  LOG2.warn("MeshReconcile", `Re-drove delivered-but-unconsumed task ${row.id} on mesh ${meshId} (node=${row.assignedNodeId ?? "?"} session=${row.assignedSessionId ?? "?"}, delivered but no generating_started in ${Math.round(ageMs / 1e3)}s, verdict ${verdict} \u2192 ${redriven.status})`);
52037
52135
  traceMeshEventDrop("assigned_delivered_not_consumed_redrive", {
52038
52136
  taskId: row.id,
@@ -52594,6 +52692,7 @@ ${cleanBody}`;
52594
52692
  var ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS;
52595
52693
  var RECLAIM_UNKNOWN_GRACE_TICKS;
52596
52694
  var deliveredNoTurnUnknownStreak;
52695
+ var deliveredUnconsumedUnknownStreak;
52597
52696
  var ZOMBIE_ASSIGNED_MIN_AGE_MS;
52598
52697
  var STRICT_SESSION_MATCH_TTL_MS;
52599
52698
  var unresolvedForwardRejectionCounts;
@@ -52634,6 +52733,7 @@ ${cleanBody}`;
52634
52733
  ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS = 25e3;
52635
52734
  RECLAIM_UNKNOWN_GRACE_TICKS = 3;
52636
52735
  deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
52736
+ deliveredUnconsumedUnknownStreak = /* @__PURE__ */ new Map();
52637
52737
  ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
52638
52738
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
52639
52739
  unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
@@ -56020,7 +56120,7 @@ ${cont}` : cont;
56020
56120
  if (!this.isWaitingForResponse || this.hasActionableApproval()) return false;
56021
56121
  const snap = this.transport.getSnapshot();
56022
56122
  const detectFn = typeof this.transport.runDetectStatus === "function" ? () => this.transport.runDetectStatus(snap.recentOutputBuffer) : () => this.runDetectStatus(snap);
56023
- const latestStatus = detectFn() || this.currentStatus;
56123
+ const latestStatus = detectFn();
56024
56124
  if (latestStatus === "generating") {
56025
56125
  this.evaluateSettled(snap);
56026
56126
  return true;
@@ -84550,10 +84650,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
84550
84650
  candidates.push(path45.join(providerDir, "specs", "default.json"));
84551
84651
  candidates.push(path45.join(providerDir, "spec.json"));
84552
84652
  const specPath = candidates.find((p) => fs42.existsSync(p));
84653
+ let nh;
84553
84654
  if (specPath) {
84554
84655
  resolved._resolvedSpecPath = specPath;
84555
84656
  let specControls;
84556
- let nh;
84557
84657
  try {
84558
84658
  const rawSpec = JSON.parse(fs42.readFileSync(specPath, "utf8"));
84559
84659
  specControls = rawSpec.control_bar;
@@ -84579,42 +84679,48 @@ Run 'adhdev doctor' for detailed diagnostics.`
84579
84679
  }
84580
84680
  }
84581
84681
  }
84582
- if (nh) {
84583
- let reader = null;
84584
- let format = "spec";
84585
- if (nh.source) {
84586
- format = `spec-${nh.source.kind}`;
84587
- reader = (input) => executeNativeHistory(nh, input);
84588
- } else if (nh.override_path) {
84589
- const overrideFile = path45.resolve(providerDir, nh.override_path);
84590
- if (fs42.existsSync(overrideFile)) {
84591
- try {
84592
- registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
84593
- delete require.cache[require.resolve(overrideFile)];
84594
- const mod = require(overrideFile);
84595
- const fn = typeof mod === "function" ? mod : mod && typeof mod.default === "function" ? mod.default : null;
84596
- if (fn) {
84597
- format = "spec-override";
84598
- reader = (input) => fn(input);
84599
- }
84600
- } catch {
84682
+ }
84683
+ if (!nh) {
84684
+ const inlineNh = base?.nativeHistory || resolved?.nativeHistory;
84685
+ if (inlineNh && (inlineNh.source || inlineNh.override_path || inlineNh.reader)) {
84686
+ nh = inlineNh;
84687
+ }
84688
+ }
84689
+ if (nh) {
84690
+ let reader = null;
84691
+ let format = "spec";
84692
+ if (nh.source) {
84693
+ format = `spec-${nh.source.kind}`;
84694
+ reader = (input) => executeNativeHistory(nh, input);
84695
+ } else if (nh.override_path) {
84696
+ const overrideFile = path45.resolve(providerDir, nh.override_path);
84697
+ if (fs42.existsSync(overrideFile)) {
84698
+ try {
84699
+ registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
84700
+ delete require.cache[require.resolve(overrideFile)];
84701
+ const mod = require(overrideFile);
84702
+ const fn = typeof mod === "function" ? mod : mod && typeof mod.default === "function" ? mod.default : null;
84703
+ if (fn) {
84704
+ format = "spec-override";
84705
+ reader = (input) => fn(input);
84601
84706
  }
84707
+ } catch {
84602
84708
  }
84603
- } else if (nh.reader) {
84604
- const dispatch = createNativeHistoryDispatcher(nh.reader);
84605
- format = nh.reader;
84606
- reader = (input) => dispatch(input);
84607
- }
84608
- if (reader) {
84609
- resolved.scripts = { ...resolved.scripts || {} };
84610
- resolved.scripts.readNativeHistory = reader;
84611
- resolved.nativeHistory = {
84612
- format,
84613
- watchPath: void 0,
84614
- scripts: { readSession: "readNativeHistory" },
84615
- mode: "native-source"
84616
- };
84617
84709
  }
84710
+ } else if (nh.reader) {
84711
+ const dispatch = createNativeHistoryDispatcher(nh.reader);
84712
+ format = nh.reader;
84713
+ reader = (input) => dispatch(input);
84714
+ }
84715
+ if (reader) {
84716
+ resolved.scripts = { ...resolved.scripts || {} };
84717
+ resolved.scripts.readNativeHistory = reader;
84718
+ resolved.nativeHistory = {
84719
+ format,
84720
+ watchPath: void 0,
84721
+ scripts: { readSession: "readNativeHistory" },
84722
+ mode: "native-source"
84723
+ };
84618
84724
  }
84619
84725
  }
84620
84726
  } catch {