@adhdev/daemon-core 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.mjs CHANGED
@@ -394,10 +394,10 @@ function readInjected(value) {
394
394
  }
395
395
  function getDaemonBuildInfo() {
396
396
  if (cached) return cached;
397
- const commit = readInjected(true ? "4e4b5f468d194f630073a66359898bce97fadf4b" : void 0) ?? "unknown";
398
- const commitShort = readInjected(true ? "4e4b5f46" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
399
- const version = readInjected(true ? "0.9.82-rc.405" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
400
- const builtAt = readInjected(true ? "2026-06-28T03:54:34.483Z" : void 0);
397
+ const commit = readInjected(true ? "bfd7d9b1d38a7d1f4709fbad2627c56b5a1ae342" : void 0) ?? "unknown";
398
+ const commitShort = readInjected(true ? "bfd7d9b1" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
399
+ const version = readInjected(true ? "0.9.82-rc.407" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
400
+ const builtAt = readInjected(true ? "2026-06-28T06:12:15.473Z" : void 0);
401
401
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
402
402
  return cached;
403
403
  }
@@ -16366,6 +16366,20 @@ function resolveReconcileIntervalMs() {
16366
16366
  }
16367
16367
  return DEFAULT_RECONCILE_INTERVAL_MS;
16368
16368
  }
16369
+ function resolveTunedReconcileMs(envName, def, min, max) {
16370
+ const raw = readNonEmptyString2(process.env[envName]);
16371
+ if (raw) {
16372
+ const parsed = Number.parseInt(raw, 10);
16373
+ if (Number.isFinite(parsed) && parsed >= min && parsed <= max) return parsed;
16374
+ }
16375
+ return def;
16376
+ }
16377
+ function resolveMinIdleSettleMs() {
16378
+ return resolveTunedReconcileMs("MESH_INFLIGHT_MIN_IDLE_SETTLE_MS", 16e3, 0, 12e4);
16379
+ }
16380
+ function resolveAckedTurnSettleMs() {
16381
+ return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TURN_SETTLE_MS", 2e4, 0, 18e4);
16382
+ }
16369
16383
  function inFlightSynthKey(meshId, taskId) {
16370
16384
  return `${meshId}::${taskId}`;
16371
16385
  }
@@ -16942,6 +16956,33 @@ function unwrapReadChatPayload(raw) {
16942
16956
  function readChatPayloadStatus(payload) {
16943
16957
  return readNonEmptyString2(payload?.status).toLowerCase();
16944
16958
  }
16959
+ function realTerminalEmitPendingForTask(meshId, taskId) {
16960
+ let pending;
16961
+ try {
16962
+ pending = getPendingMeshCoordinatorEvents(meshId);
16963
+ } catch {
16964
+ return false;
16965
+ }
16966
+ return pending.some((e) => readNonEmptyString2(e.metadataEvent?.taskId) === taskId && (e.event === "agent:generating_completed" || e.event === "agent:stopped"));
16967
+ }
16968
+ async function reprobeWorkerStatus(components, args) {
16969
+ try {
16970
+ if (args.isLocalNode) {
16971
+ const r = await components.commandHandler.handle("read_chat", args.readArgs);
16972
+ if (r && r.success === false) return null;
16973
+ return readChatPayloadStatus(unwrapReadChatPayload(r));
16974
+ }
16975
+ if (components.dispatchMeshCommand) {
16976
+ const r = await components.dispatchMeshCommand(args.nodeDaemonId, "read_chat", args.readArgs);
16977
+ const p = unwrapReadChatPayload(r);
16978
+ if (p && p.success === false) return null;
16979
+ return readChatPayloadStatus(p);
16980
+ }
16981
+ } catch {
16982
+ return null;
16983
+ }
16984
+ return null;
16985
+ }
16945
16986
  async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId) {
16946
16987
  const dispatches = getActiveDirectDispatches(mesh.id);
16947
16988
  if (dispatches.length === 0) return;
@@ -16989,18 +17030,34 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
16989
17030
  }
16990
17031
  if (!payload) continue;
16991
17032
  const synthKey = inFlightSynthKey(mesh.id, taskId);
17033
+ const nowMs = Date.now();
16992
17034
  if (readChatPayloadStatus(payload) !== "idle") {
16993
17035
  inFlightIdleObservationCounts.delete(synthKey);
16994
17036
  continue;
16995
17037
  }
16996
17038
  if (dispatch.status === "acked") {
16997
- const idleStreak = (inFlightIdleObservationCounts.get(synthKey) ?? 0) + 1;
16998
- inFlightIdleObservationCounts.set(synthKey, idleStreak);
16999
- if (idleStreak < REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH) {
17000
- LOG.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)`);
17039
+ const prior = inFlightIdleObservationCounts.get(synthKey);
17040
+ const firstIdleAtMs = prior?.firstIdleAtMs ?? nowMs;
17041
+ const idleStreak = (prior?.count ?? 0) + 1;
17042
+ inFlightIdleObservationCounts.set(synthKey, { count: idleStreak, firstIdleAtMs });
17043
+ const idleSettleMs = nowMs - firstIdleAtMs;
17044
+ const minIdleSettleMs = resolveMinIdleSettleMs();
17045
+ const ackedTurnSettleMs = resolveAckedTurnSettleMs();
17046
+ const ackedAtMs = Date.parse(readNonEmptyString2(dispatch.updatedAt));
17047
+ const sinceAckMs = Number.isFinite(ackedAtMs) ? nowMs - ackedAtMs : Number.POSITIVE_INFINITY;
17048
+ const tickGuardMet = idleStreak >= REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH;
17049
+ const settleGuardMet = idleSettleMs >= minIdleSettleMs;
17050
+ const ackGuardMet = sinceAckMs >= ackedTurnSettleMs;
17051
+ if (!tickGuardMet || !settleGuardMet || !ackGuardMet) {
17052
+ LOG.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)`);
17001
17053
  continue;
17002
17054
  }
17003
17055
  }
17056
+ if (realTerminalEmitPendingForTask(mesh.id, taskId)) {
17057
+ inFlightIdleObservationCounts.delete(synthKey);
17058
+ LOG.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`);
17059
+ continue;
17060
+ }
17004
17061
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
17005
17062
  const evidence = extractFinalAssistantSummaryEvidence(messages);
17006
17063
  if (!evidence.finalSummary) continue;
@@ -17017,6 +17074,12 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
17017
17074
  }, `transcriptAt=${evidence.transcriptMessageAt} < dispatchedAt=${dispatch.dispatchedAt}`);
17018
17075
  continue;
17019
17076
  }
17077
+ const reprobeStatus = await reprobeWorkerStatus(components, { isLocalNode, nodeDaemonId, readArgs });
17078
+ if (reprobeStatus && reprobeStatus !== "idle") {
17079
+ inFlightIdleObservationCounts.delete(synthKey);
17080
+ LOG.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`);
17081
+ continue;
17082
+ }
17020
17083
  const providerSessionId = readNonEmptyString2(payload.providerSessionId);
17021
17084
  const coordinatorDaemonId = selfIds.find((id) => !!id);
17022
17085
  try {
@@ -19658,6 +19721,13 @@ var init_cli_state_engine = __esm({
19658
19721
  // queued in pendingOutbound and only flushed asynchronously after idle), so the
19659
19722
  // completion event carries the correct id instead of the racy session scalar.
19660
19723
  currentTurnTaskId = null;
19724
+ // GENERATING-BOUNDARY (R4d): wall-clock when the most recently STARTED turn began
19725
+ // (set by onTurnStarted, persists past completion until the next turn starts).
19726
+ // The startup-grace idle-stayed synthesis anchors its window on when the FIRST turn
19727
+ // STARTED — not on when it finished — so a turn dispatched a few seconds after the
19728
+ // grace collapse and then running for a non-trivial duration is still attributed to
19729
+ // the startup collapse even though its COMPLETION lands past a now-anchored window.
19730
+ currentTurnStartedAt = 0;
19661
19731
  activeModal = null;
19662
19732
  // ── Approval ─────────────────────────────────────
19663
19733
  lastApprovalResolvedAt = 0;
@@ -19768,6 +19838,7 @@ var init_cli_state_engine = __esm({
19768
19838
  this.clearIdleFinishCandidate("send_message");
19769
19839
  this.currentTurnScope = turnScope;
19770
19840
  this.currentTurnTaskId = typeof turnScope.taskId === "string" && turnScope.taskId.trim() ? turnScope.taskId : null;
19841
+ this.currentTurnStartedAt = Date.now();
19771
19842
  this.responseEpoch += 1;
19772
19843
  }
19773
19844
  /** Called when PTY exits */
@@ -22245,6 +22316,13 @@ ${lastSnapshot}`;
22245
22316
  get currentTurnTaskId() {
22246
22317
  return this.engine.currentTurnTaskId;
22247
22318
  }
22319
+ // R4d: wall-clock when the most recently started turn began (persists past settle).
22320
+ // The provider instance's startup-grace idle-stayed synthesis anchors its window on
22321
+ // this so a delayed-dispatch first turn whose duration overruns the now-anchored
22322
+ // window is still attributed to the startup collapse.
22323
+ get currentTurnStartedAt() {
22324
+ return this.engine.currentTurnStartedAt;
22325
+ }
22248
22326
  get responseEpoch() {
22249
22327
  return this.engine.responseEpoch;
22250
22328
  }
@@ -40984,7 +41062,11 @@ var CliProviderInstance = class _CliProviderInstance {
40984
41062
  }
40985
41063
  this.lastStatus = newStatus;
40986
41064
  }
40987
- if (newStatus === "idle" && previousStatus === "idle" && this.startupGraceCollapseAt !== null && now - this.startupGraceCollapseAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS) {
41065
+ const firstTurnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : 0;
41066
+ const collapsedAt = this.startupGraceCollapseAt;
41067
+ const turnStartedWithinCollapseWindow = collapsedAt !== null && firstTurnStartedAt > 0 && firstTurnStartedAt >= collapsedAt && firstTurnStartedAt - collapsedAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS;
41068
+ const nowWithinCollapseWindow = collapsedAt !== null && now - collapsedAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS;
41069
+ if (newStatus === "idle" && previousStatus === "idle" && (turnStartedWithinCollapseWindow || nowWithinCollapseWindow)) {
40988
41070
  this.maybeSynthesizeStartupGraceCollapse(chatTitle, now, "startup_grace_idle_turn_collapse");
40989
41071
  }
40990
41072
  if (newStatus === "idle" && adapterStatus.fsmReadySeen === true && !this.agentReadyEmitted) {