@adhdev/daemon-standalone 0.9.82-rc.24 → 0.9.82-rc.25

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
@@ -23644,18 +23644,20 @@ Follow these recovery rules:
23644
23644
  return entry;
23645
23645
  });
23646
23646
  }
23647
- function updateSessionTaskStatus(meshId, sessionId, status) {
23647
+ function updateSessionTaskStatus(meshId, sessionId, status, opts) {
23648
23648
  return withQueueLock(meshId, () => {
23649
23649
  const queue = readQueue(meshId);
23650
+ const occurredAtTime = opts?.occurredAt ? new Date(opts.occurredAt).getTime() : Number.NaN;
23651
+ const hasOccurredAt = Number.isFinite(occurredAtTime);
23650
23652
  let bestIdx = -1;
23651
23653
  let bestTime = 0;
23652
23654
  for (let i = queue.length - 1; i >= 0; i--) {
23653
- if (queue[i].assignedSessionId === sessionId && queue[i].status === "assigned") {
23654
- const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
23655
- if (time3 > bestTime) {
23656
- bestTime = time3;
23657
- bestIdx = i;
23658
- }
23655
+ if (queue[i].assignedSessionId !== sessionId || queue[i].status !== "assigned") continue;
23656
+ const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
23657
+ if (hasOccurredAt && Number.isFinite(time3) && time3 > occurredAtTime) continue;
23658
+ if (time3 > bestTime) {
23659
+ bestTime = time3;
23660
+ bestIdx = i;
23659
23661
  }
23660
23662
  }
23661
23663
  if (bestIdx === -1) return null;
@@ -24201,6 +24203,38 @@ Follow these recovery rules:
24201
24203
  if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
24202
24204
  return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
24203
24205
  }
24206
+ function readEventTimestamp(value) {
24207
+ if (typeof value === "number" && Number.isFinite(value)) return value;
24208
+ if (typeof value === "string" && value.trim()) {
24209
+ const numeric = Number(value);
24210
+ if (Number.isFinite(numeric)) return numeric;
24211
+ const parsed = Date.parse(value);
24212
+ if (Number.isFinite(parsed)) return parsed;
24213
+ }
24214
+ return null;
24215
+ }
24216
+ function buildMeshCompletionFingerprint(args) {
24217
+ const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) : readNonEmptyString(args.finalSummary).slice(0, 200);
24218
+ return [
24219
+ args.meshId,
24220
+ args.event,
24221
+ args.sessionId,
24222
+ args.providerType || "",
24223
+ args.providerSessionId || "",
24224
+ timestampPart
24225
+ ].join("::");
24226
+ }
24227
+ function isDuplicateMeshCompletionEvent(args) {
24228
+ const fingerprint = buildMeshCompletionFingerprint(args);
24229
+ if (!fingerprint) return false;
24230
+ const now = Date.now();
24231
+ for (const [key, seenAt] of recentCompletionFingerprints.entries()) {
24232
+ if (now - seenAt > RECENT_COMPLETION_FINGERPRINT_TTL_MS) recentCompletionFingerprints.delete(key);
24233
+ }
24234
+ if (recentCompletionFingerprints.has(fingerprint)) return true;
24235
+ recentCompletionFingerprints.set(fingerprint, now);
24236
+ return false;
24237
+ }
24204
24238
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
24205
24239
  const task = claimNextTask(meshId, nodeId, sessionId);
24206
24240
  if (!task) {
@@ -24562,13 +24596,31 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
24562
24596
  LOG2.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
24563
24597
  return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
24564
24598
  }
24599
+ const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
24600
+ if (args.event === "agent:generating_completed" && eventSessionId) {
24601
+ const duplicateCompletion = isDuplicateMeshCompletionEvent({
24602
+ meshId: args.meshId,
24603
+ event: args.event,
24604
+ sessionId: eventSessionId,
24605
+ providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
24606
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
24607
+ timestamp: eventTimestamp,
24608
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
24609
+ });
24610
+ if (duplicateCompletion) {
24611
+ LOG2.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
24612
+ return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true };
24613
+ }
24614
+ }
24565
24615
  let completedTaskForLedger = null;
24566
24616
  if (args.event === "agent:generating_completed") {
24567
24617
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
24568
24618
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
24569
24619
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
24570
24620
  if (sessionId) {
24571
- const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed");
24621
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed", {
24622
+ occurredAt: eventTimestamp !== null ? new Date(eventTimestamp).toISOString() : void 0
24623
+ });
24572
24624
  completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
24573
24625
  if (nodeId && providerType) {
24574
24626
  setImmediate(() => {
@@ -24782,6 +24834,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
24782
24834
  providerType: readNonEmptyString(payload.providerType),
24783
24835
  providerSessionId: readNonEmptyString(payload.providerSessionId),
24784
24836
  finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
24837
+ ...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
24785
24838
  intentional: payload.intentional === true,
24786
24839
  intentionalStop: payload.intentionalStop === true,
24787
24840
  operatorCleanup: payload.operatorCleanup === true,
@@ -24831,6 +24884,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
24831
24884
  var MESH_COORDINATOR_EVENTS;
24832
24885
  var EVENT_TO_LEDGER_KIND;
24833
24886
  var INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS;
24887
+ var RECENT_COMPLETION_FINGERPRINT_TTL_MS;
24888
+ var recentCompletionFingerprints;
24834
24889
  var autoLaunchInProgress;
24835
24890
  var autoLaunchCooldownUntil;
24836
24891
  var AUTO_LAUNCH_COOLDOWN_MS;
@@ -24862,6 +24917,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
24862
24917
  "monitor:long_generating": "task_stalled"
24863
24918
  };
24864
24919
  INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
24920
+ RECENT_COMPLETION_FINGERPRINT_TTL_MS = 10 * 60 * 1e3;
24921
+ recentCompletionFingerprints = /* @__PURE__ */ new Map();
24865
24922
  autoLaunchInProgress = /* @__PURE__ */ new Set();
24866
24923
  autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
24867
24924
  AUTO_LAUNCH_COOLDOWN_MS = 5e3;