@adhdev/daemon-standalone 0.9.82-rc.405 → 0.9.82-rc.407

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
@@ -30127,10 +30127,10 @@ var require_dist3 = __commonJS({
30127
30127
  }
30128
30128
  function getDaemonBuildInfo() {
30129
30129
  if (cached2) return cached2;
30130
- const commit = readInjected(true ? "4e4b5f468d194f630073a66359898bce97fadf4b" : void 0) ?? "unknown";
30131
- const commitShort = readInjected(true ? "4e4b5f46" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30132
- const version2 = readInjected(true ? "0.9.82-rc.405" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30133
- const builtAt = readInjected(true ? "2026-06-28T03:55:26.092Z" : void 0);
30130
+ const commit = readInjected(true ? "bfd7d9b1d38a7d1f4709fbad2627c56b5a1ae342" : void 0) ?? "unknown";
30131
+ const commitShort = readInjected(true ? "bfd7d9b1" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30132
+ const version2 = readInjected(true ? "0.9.82-rc.407" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30133
+ const builtAt = readInjected(true ? "2026-06-28T06:12:42.391Z" : void 0);
30134
30134
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30135
30135
  return cached2;
30136
30136
  }
@@ -46204,6 +46204,20 @@ ${cleanBody}`;
46204
46204
  }
46205
46205
  return DEFAULT_RECONCILE_INTERVAL_MS;
46206
46206
  }
46207
+ function resolveTunedReconcileMs(envName, def, min, max) {
46208
+ const raw = readNonEmptyString2(process.env[envName]);
46209
+ if (raw) {
46210
+ const parsed = Number.parseInt(raw, 10);
46211
+ if (Number.isFinite(parsed) && parsed >= min && parsed <= max) return parsed;
46212
+ }
46213
+ return def;
46214
+ }
46215
+ function resolveMinIdleSettleMs() {
46216
+ return resolveTunedReconcileMs("MESH_INFLIGHT_MIN_IDLE_SETTLE_MS", 16e3, 0, 12e4);
46217
+ }
46218
+ function resolveAckedTurnSettleMs() {
46219
+ return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TURN_SETTLE_MS", 2e4, 0, 18e4);
46220
+ }
46207
46221
  function inFlightSynthKey(meshId, taskId) {
46208
46222
  return `${meshId}::${taskId}`;
46209
46223
  }
@@ -46780,6 +46794,33 @@ ${cleanBody}`;
46780
46794
  function readChatPayloadStatus(payload) {
46781
46795
  return readNonEmptyString2(payload?.status).toLowerCase();
46782
46796
  }
46797
+ function realTerminalEmitPendingForTask(meshId, taskId) {
46798
+ let pending;
46799
+ try {
46800
+ pending = getPendingMeshCoordinatorEvents(meshId);
46801
+ } catch {
46802
+ return false;
46803
+ }
46804
+ return pending.some((e) => readNonEmptyString2(e.metadataEvent?.taskId) === taskId && (e.event === "agent:generating_completed" || e.event === "agent:stopped"));
46805
+ }
46806
+ async function reprobeWorkerStatus(components, args) {
46807
+ try {
46808
+ if (args.isLocalNode) {
46809
+ const r = await components.commandHandler.handle("read_chat", args.readArgs);
46810
+ if (r && r.success === false) return null;
46811
+ return readChatPayloadStatus(unwrapReadChatPayload(r));
46812
+ }
46813
+ if (components.dispatchMeshCommand) {
46814
+ const r = await components.dispatchMeshCommand(args.nodeDaemonId, "read_chat", args.readArgs);
46815
+ const p = unwrapReadChatPayload(r);
46816
+ if (p && p.success === false) return null;
46817
+ return readChatPayloadStatus(p);
46818
+ }
46819
+ } catch {
46820
+ return null;
46821
+ }
46822
+ return null;
46823
+ }
46783
46824
  async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId) {
46784
46825
  const dispatches = getActiveDirectDispatches(mesh.id);
46785
46826
  if (dispatches.length === 0) return;
@@ -46827,18 +46868,34 @@ ${cleanBody}`;
46827
46868
  }
46828
46869
  if (!payload) continue;
46829
46870
  const synthKey = inFlightSynthKey(mesh.id, taskId);
46871
+ const nowMs = Date.now();
46830
46872
  if (readChatPayloadStatus(payload) !== "idle") {
46831
46873
  inFlightIdleObservationCounts.delete(synthKey);
46832
46874
  continue;
46833
46875
  }
46834
46876
  if (dispatch.status === "acked") {
46835
- const idleStreak = (inFlightIdleObservationCounts.get(synthKey) ?? 0) + 1;
46836
- inFlightIdleObservationCounts.set(synthKey, idleStreak);
46837
- if (idleStreak < REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH) {
46838
- LOG2.info("MeshReconcile", `In-flight synth hold: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) read idle ${idleStreak}/${REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH} consecutive tick(s) after generating_started \u2014 deferring completion synth until the idle settle is confirmed (guards against a mid-turn idle flicker pre-empting the real completion)`);
46877
+ const prior = inFlightIdleObservationCounts.get(synthKey);
46878
+ const firstIdleAtMs = prior?.firstIdleAtMs ?? nowMs;
46879
+ const idleStreak = (prior?.count ?? 0) + 1;
46880
+ inFlightIdleObservationCounts.set(synthKey, { count: idleStreak, firstIdleAtMs });
46881
+ const idleSettleMs = nowMs - firstIdleAtMs;
46882
+ const minIdleSettleMs = resolveMinIdleSettleMs();
46883
+ const ackedTurnSettleMs = resolveAckedTurnSettleMs();
46884
+ const ackedAtMs = Date.parse(readNonEmptyString2(dispatch.updatedAt));
46885
+ const sinceAckMs = Number.isFinite(ackedAtMs) ? nowMs - ackedAtMs : Number.POSITIVE_INFINITY;
46886
+ const tickGuardMet = idleStreak >= REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH;
46887
+ const settleGuardMet = idleSettleMs >= minIdleSettleMs;
46888
+ const ackGuardMet = sinceAckMs >= ackedTurnSettleMs;
46889
+ if (!tickGuardMet || !settleGuardMet || !ackGuardMet) {
46890
+ LOG2.info("MeshReconcile", `In-flight synth hold: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) idle ${idleStreak}/${REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH} tick(s), settle ${Math.round(idleSettleMs / 1e3)}s/${Math.round(minIdleSettleMs / 1e3)}s, since-ack ${Number.isFinite(sinceAckMs) ? Math.round(sinceAckMs / 1e3) + "s" : "\u221E"}/${Math.round(ackedTurnSettleMs / 1e3)}s \u2014 deferring completion synth until the worker's turn genuinely settles (guards against a mid-turn idle window pre-empting the real completion)`);
46839
46891
  continue;
46840
46892
  }
46841
46893
  }
46894
+ if (realTerminalEmitPendingForTask(mesh.id, taskId)) {
46895
+ inFlightIdleObservationCounts.delete(synthKey);
46896
+ LOG2.info("MeshReconcile", `Worker-emit priority: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) has a real terminal completion already queued \u2014 yielding synth to the worker's own emit`);
46897
+ continue;
46898
+ }
46842
46899
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
46843
46900
  const evidence = extractFinalAssistantSummaryEvidence(messages);
46844
46901
  if (!evidence.finalSummary) continue;
@@ -46855,6 +46912,12 @@ ${cleanBody}`;
46855
46912
  }, `transcriptAt=${evidence.transcriptMessageAt} < dispatchedAt=${dispatch.dispatchedAt}`);
46856
46913
  continue;
46857
46914
  }
46915
+ const reprobeStatus = await reprobeWorkerStatus(components, { isLocalNode, nodeDaemonId, readArgs });
46916
+ if (reprobeStatus && reprobeStatus !== "idle") {
46917
+ inFlightIdleObservationCounts.delete(synthKey);
46918
+ LOG2.info("MeshReconcile", `Live re-probe defer: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) read '${reprobeStatus}' at synth-commit time \u2014 worker resumed generating; deferring synth to a later tick`);
46919
+ continue;
46920
+ }
46858
46921
  const providerSessionId = readNonEmptyString2(payload.providerSessionId);
46859
46922
  const coordinatorDaemonId = selfIds.find((id) => !!id);
46860
46923
  try {
@@ -49493,6 +49556,13 @@ ${cont}` : cont;
49493
49556
  // queued in pendingOutbound and only flushed asynchronously after idle), so the
49494
49557
  // completion event carries the correct id instead of the racy session scalar.
49495
49558
  currentTurnTaskId = null;
49559
+ // GENERATING-BOUNDARY (R4d): wall-clock when the most recently STARTED turn began
49560
+ // (set by onTurnStarted, persists past completion until the next turn starts).
49561
+ // The startup-grace idle-stayed synthesis anchors its window on when the FIRST turn
49562
+ // STARTED — not on when it finished — so a turn dispatched a few seconds after the
49563
+ // grace collapse and then running for a non-trivial duration is still attributed to
49564
+ // the startup collapse even though its COMPLETION lands past a now-anchored window.
49565
+ currentTurnStartedAt = 0;
49496
49566
  activeModal = null;
49497
49567
  // ── Approval ─────────────────────────────────────
49498
49568
  lastApprovalResolvedAt = 0;
@@ -49603,6 +49673,7 @@ ${cont}` : cont;
49603
49673
  this.clearIdleFinishCandidate("send_message");
49604
49674
  this.currentTurnScope = turnScope;
49605
49675
  this.currentTurnTaskId = typeof turnScope.taskId === "string" && turnScope.taskId.trim() ? turnScope.taskId : null;
49676
+ this.currentTurnStartedAt = Date.now();
49606
49677
  this.responseEpoch += 1;
49607
49678
  }
49608
49679
  /** Called when PTY exits */
@@ -52080,6 +52151,13 @@ ${lastSnapshot}`;
52080
52151
  get currentTurnTaskId() {
52081
52152
  return this.engine.currentTurnTaskId;
52082
52153
  }
52154
+ // R4d: wall-clock when the most recently started turn began (persists past settle).
52155
+ // The provider instance's startup-grace idle-stayed synthesis anchors its window on
52156
+ // this so a delayed-dispatch first turn whose duration overruns the now-anchored
52157
+ // window is still attributed to the startup collapse.
52158
+ get currentTurnStartedAt() {
52159
+ return this.engine.currentTurnStartedAt;
52160
+ }
52083
52161
  get responseEpoch() {
52084
52162
  return this.engine.responseEpoch;
52085
52163
  }
@@ -71010,7 +71088,11 @@ ${body}
71010
71088
  }
71011
71089
  this.lastStatus = newStatus;
71012
71090
  }
71013
- if (newStatus === "idle" && previousStatus === "idle" && this.startupGraceCollapseAt !== null && now - this.startupGraceCollapseAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS) {
71091
+ const firstTurnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : 0;
71092
+ const collapsedAt = this.startupGraceCollapseAt;
71093
+ const turnStartedWithinCollapseWindow = collapsedAt !== null && firstTurnStartedAt > 0 && firstTurnStartedAt >= collapsedAt && firstTurnStartedAt - collapsedAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS;
71094
+ const nowWithinCollapseWindow = collapsedAt !== null && now - collapsedAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS;
71095
+ if (newStatus === "idle" && previousStatus === "idle" && (turnStartedWithinCollapseWindow || nowWithinCollapseWindow)) {
71014
71096
  this.maybeSynthesizeStartupGraceCollapse(chatTitle, now, "startup_grace_idle_turn_collapse");
71015
71097
  }
71016
71098
  if (newStatus === "idle" && adapterStatus.fsmReadySeen === true && !this.agentReadyEmitted) {