@adhdev/daemon-standalone 0.9.82-rc.388 → 0.9.82-rc.389

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
@@ -30108,10 +30108,10 @@ var require_dist3 = __commonJS({
30108
30108
  }
30109
30109
  function getDaemonBuildInfo() {
30110
30110
  if (cached2) return cached2;
30111
- const commit = readInjected(true ? "9a3033a1679a8f914b9b40753006af02a09bc1b5" : void 0) ?? "unknown";
30112
- const commitShort = readInjected(true ? "9a3033a1" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30113
- const version2 = readInjected(true ? "0.9.82-rc.388" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30114
- const builtAt = readInjected(true ? "2026-06-26T03:26:41.986Z" : void 0);
30111
+ const commit = readInjected(true ? "f82b4b4cdb13171d2666cc959054b788af4f2ea5" : void 0) ?? "unknown";
30112
+ const commitShort = readInjected(true ? "f82b4b4c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30113
+ const version2 = readInjected(true ? "0.9.82-rc.389" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30114
+ const builtAt = readInjected(true ? "2026-06-26T06:17:46.237Z" : void 0);
30115
30115
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30116
30116
  return cached2;
30117
30117
  }
@@ -34323,9 +34323,16 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34323
34323
  }
34324
34324
  return false;
34325
34325
  }
34326
+ function isGluedToLetterSuffix(text, matchStart, matchEnd) {
34327
+ const letterOrMark = /[\p{L}\p{M}]/u;
34328
+ const next = matchEnd < text.length ? text[matchEnd] : "";
34329
+ const prev = matchStart > 0 ? text[matchStart - 1] : "";
34330
+ return letterOrMark.test(next) || letterOrMark.test(prev);
34331
+ }
34326
34332
  function isRealMutationMatch(text, matchStart, matchEnd) {
34327
34333
  if (hasNegationBefore(text, matchStart)) return false;
34328
34334
  if (hasTrailingNegation(text, matchEnd)) return false;
34335
+ if (isGluedToLetterSuffix(text, matchStart, matchEnd)) return false;
34329
34336
  if (isInsidePathSegment(text, matchStart, matchEnd)) return false;
34330
34337
  if (isInsideQuotedSpan(text, matchStart, matchEnd)) return false;
34331
34338
  return isMutationKeywordInCommandContext(text, matchStart, matchEnd);
@@ -35044,10 +35051,20 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35044
35051
  CREATE INDEX IF NOT EXISTS idx_mesh_queue_assignment
35045
35052
  ON mesh_queue(mesh_id, assigned_node_id, assigned_session_id, status);
35046
35053
 
35054
+ -- mesh_id is DB-level isolation (defense-in-depth). The fingerprint STRING
35055
+ -- also carries meshId as its first '::'-joined segment (see
35056
+ -- buildMeshCompletionFingerprint) \u2014 that string-prefix defense is kept; this
35057
+ -- column makes cross-mesh suppression impossible even if the string format
35058
+ -- drifts or two meshes ever collide on a fingerprint body.
35047
35059
  CREATE TABLE IF NOT EXISTS mesh_completion_fingerprints (
35048
35060
  fingerprint TEXT PRIMARY KEY,
35049
- expires_at INTEGER NOT NULL
35061
+ expires_at INTEGER NOT NULL,
35062
+ mesh_id TEXT NOT NULL DEFAULT ''
35050
35063
  );
35064
+ -- NOTE: the (mesh_id, fingerprint) index is created in migrateMeshIsolationColumns,
35065
+ -- NOT here. A pre-isolation DB still has the legacy table (CREATE IF NOT EXISTS is a
35066
+ -- no-op), so referencing mesh_id in an index before the ALTER ADD COLUMN runs would
35067
+ -- fail with "no such column". The migration adds the column then the index.
35051
35068
 
35052
35069
  CREATE TABLE IF NOT EXISTS mesh_direct_dispatches (
35053
35070
  task_id TEXT PRIMARY KEY,
@@ -35067,13 +35084,18 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35067
35084
  CREATE INDEX IF NOT EXISTS idx_direct_dispatches_mesh_session
35068
35085
  ON mesh_direct_dispatches(mesh_id, session_id, status);
35069
35086
 
35087
+ -- MESH-ISOLATION-LEAK: mesh_id is part of the PK so a nodeId shared across two
35088
+ -- meshes (same machine in multiple repos) keeps a separate idle-session row per
35089
+ -- mesh, and getRemoteIdleSessions(meshId) can never surface another mesh's
35090
+ -- session for a queue claim.
35070
35091
  CREATE TABLE IF NOT EXISTS remote_idle_sessions (
35092
+ mesh_id TEXT NOT NULL,
35071
35093
  node_id TEXT NOT NULL,
35072
35094
  session_id TEXT NOT NULL,
35073
35095
  provider_type TEXT NOT NULL,
35074
35096
  expires_at INTEGER NOT NULL,
35075
35097
  metadata TEXT,
35076
- PRIMARY KEY (node_id, session_id)
35098
+ PRIMARY KEY (mesh_id, node_id, session_id)
35077
35099
  );
35078
35100
 
35079
35101
  CREATE TABLE IF NOT EXISTS mesh_session_delivery (
@@ -35197,19 +35219,67 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35197
35219
  cursor INTEGER NOT NULL DEFAULT 0
35198
35220
  );
35199
35221
  `);
35222
+ this.migrateMeshIsolationColumns();
35223
+ }
35224
+ tableColumns(table) {
35225
+ const rows = this.db.prepare(`PRAGMA table_info(${table})`).all();
35226
+ return new Set(rows.map((r) => r.name));
35227
+ }
35228
+ /**
35229
+ * MESH-ISOLATION-LEAK migration. Two tables historically lacked a `mesh_id` column,
35230
+ * letting one machine that belongs to multiple meshes (multiple repos) leak rows
35231
+ * across meshes. Both migrations are idempotent and run on every boot — the column
35232
+ * check short-circuits once the new schema is in place.
35233
+ */
35234
+ migrateMeshIsolationColumns() {
35235
+ try {
35236
+ const fpCols = this.tableColumns("mesh_completion_fingerprints");
35237
+ if (!fpCols.has("mesh_id")) {
35238
+ this.db.exec(`ALTER TABLE mesh_completion_fingerprints ADD COLUMN mesh_id TEXT NOT NULL DEFAULT ''`);
35239
+ this.db.exec(`
35240
+ UPDATE mesh_completion_fingerprints
35241
+ SET mesh_id = substr(fingerprint, 1, instr(fingerprint, '::') - 1)
35242
+ WHERE instr(fingerprint, '::') > 0 AND mesh_id = ''
35243
+ `);
35244
+ }
35245
+ this.db.exec(`
35246
+ CREATE INDEX IF NOT EXISTS idx_mesh_completion_fingerprints_mesh
35247
+ ON mesh_completion_fingerprints(mesh_id, fingerprint)
35248
+ `);
35249
+ const idleCols = this.tableColumns("remote_idle_sessions");
35250
+ if (!idleCols.has("mesh_id")) {
35251
+ this.db.exec(`
35252
+ DROP TABLE IF EXISTS remote_idle_sessions;
35253
+ CREATE TABLE remote_idle_sessions (
35254
+ mesh_id TEXT NOT NULL,
35255
+ node_id TEXT NOT NULL,
35256
+ session_id TEXT NOT NULL,
35257
+ provider_type TEXT NOT NULL,
35258
+ expires_at INTEGER NOT NULL,
35259
+ metadata TEXT,
35260
+ PRIMARY KEY (mesh_id, node_id, session_id)
35261
+ );
35262
+ `);
35263
+ }
35264
+ } catch (err) {
35265
+ if (!loggedMigrationFailure) {
35266
+ loggedMigrationFailure = true;
35267
+ LOG2.warn("MeshRuntimeStore", `mesh-isolation column migration failed: ${err?.message || err}`);
35268
+ }
35269
+ }
35200
35270
  }
35201
- hasCompletionFingerprint(fingerprint) {
35271
+ hasCompletionFingerprint(meshId, fingerprint) {
35202
35272
  const now = Date.now();
35203
- const row = this.db.prepare("SELECT 1 FROM mesh_completion_fingerprints WHERE fingerprint = ? AND expires_at > ?").get(fingerprint, now);
35273
+ const row = this.db.prepare("SELECT 1 FROM mesh_completion_fingerprints WHERE mesh_id = ? AND fingerprint = ? AND expires_at > ?").get(meshId, fingerprint, now);
35204
35274
  if (++this.fingerprintSweepCounter >= 100) {
35205
35275
  this.fingerprintSweepCounter = 0;
35206
35276
  this.sweepExpiredFingerprints();
35207
35277
  }
35208
35278
  return row !== void 0;
35209
35279
  }
35210
- recordCompletionFingerprint(fingerprint, ttlMs) {
35280
+ recordCompletionFingerprint(meshId, fingerprint, ttlMs) {
35211
35281
  const expiresAt = Date.now() + ttlMs;
35212
- this.db.prepare("INSERT OR REPLACE INTO mesh_completion_fingerprints (fingerprint, expires_at) VALUES (?, ?)").run(fingerprint, expiresAt);
35282
+ this.db.prepare("INSERT OR REPLACE INTO mesh_completion_fingerprints (fingerprint, expires_at, mesh_id) VALUES (?, ?, ?)").run(fingerprint, expiresAt, meshId);
35213
35283
  this.maybeCheckpointWal();
35214
35284
  }
35215
35285
  sweepExpiredFingerprints() {
@@ -35718,14 +35788,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35718
35788
  `).run(now, meshId, cutoff);
35719
35789
  }
35720
35790
  // ── Remote Idle Sessions ─────────────────────────────────────────────────
35721
- setRemoteIdleSession(nodeId, sessionId, providerType, expiresAt, metadata) {
35791
+ setRemoteIdleSession(meshId, nodeId, sessionId, providerType, expiresAt, metadata) {
35722
35792
  this.db.prepare(`
35723
- INSERT OR REPLACE INTO remote_idle_sessions (node_id, session_id, provider_type, expires_at, metadata)
35724
- VALUES (?, ?, ?, ?, ?)
35725
- `).run(nodeId, sessionId, providerType, expiresAt, metadata ? JSON.stringify(metadata) : null);
35793
+ INSERT OR REPLACE INTO remote_idle_sessions (mesh_id, node_id, session_id, provider_type, expires_at, metadata)
35794
+ VALUES (?, ?, ?, ?, ?, ?)
35795
+ `).run(meshId, nodeId, sessionId, providerType, expiresAt, metadata ? JSON.stringify(metadata) : null);
35726
35796
  }
35727
- getRemoteIdleSessions() {
35728
- const rows = this.db.prepare("SELECT node_id, session_id, provider_type, expires_at, metadata FROM remote_idle_sessions").all();
35797
+ getRemoteIdleSessions(meshId) {
35798
+ const rows = this.db.prepare("SELECT node_id, session_id, provider_type, expires_at, metadata FROM remote_idle_sessions WHERE mesh_id = ?").all(meshId);
35729
35799
  return rows.map((r) => ({
35730
35800
  nodeId: r.node_id,
35731
35801
  sessionId: r.session_id,
@@ -35734,8 +35804,8 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35734
35804
  metadata: r.metadata ? JSON.parse(r.metadata) : void 0
35735
35805
  }));
35736
35806
  }
35737
- deleteRemoteIdleSession(nodeId, sessionId) {
35738
- this.db.prepare("DELETE FROM remote_idle_sessions WHERE node_id = ? AND session_id = ?").run(nodeId, sessionId);
35807
+ deleteRemoteIdleSession(meshId, nodeId, sessionId) {
35808
+ this.db.prepare("DELETE FROM remote_idle_sessions WHERE mesh_id = ? AND node_id = ? AND session_id = ?").run(meshId, nodeId, sessionId);
35739
35809
  }
35740
35810
  pruneExpiredRemoteIdleSessions() {
35741
35811
  this.db.prepare("DELETE FROM remote_idle_sessions WHERE expires_at <= ?").run(Date.now());
@@ -41110,7 +41180,7 @@ Next step: ${nextStep}`;
41110
41180
  }
41111
41181
  let remoteSessions = [];
41112
41182
  try {
41113
- remoteSessions = MeshRuntimeStore.getInstance().getRemoteIdleSessions();
41183
+ remoteSessions = MeshRuntimeStore.getInstance().getRemoteIdleSessions(meshId);
41114
41184
  } catch {
41115
41185
  }
41116
41186
  const remoteCandidates = [];
@@ -41125,7 +41195,7 @@ Next step: ${nextStep}`;
41125
41195
  const assigned = tryAssignQueueTask(components, meshId, candidate.nodeId, candidate.sessionId, candidate.providerType);
41126
41196
  if (assigned && candidate.origin === "remote") {
41127
41197
  try {
41128
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(candidate.nodeId, candidate.sessionId);
41198
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(meshId, candidate.nodeId, candidate.sessionId);
41129
41199
  } catch {
41130
41200
  }
41131
41201
  }
@@ -43900,17 +43970,17 @@ ${cleanBody}`;
43900
43970
  if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
43901
43971
  return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
43902
43972
  }
43903
- function hasFingerprintSeen(fingerprint) {
43973
+ function hasFingerprintSeen(meshId, fingerprint) {
43904
43974
  try {
43905
- return MeshRuntimeStore.getInstance().hasCompletionFingerprint(fingerprint);
43975
+ return MeshRuntimeStore.getInstance().hasCompletionFingerprint(meshId, fingerprint);
43906
43976
  } catch {
43907
43977
  return false;
43908
43978
  }
43909
43979
  }
43910
- function recordFingerprintSeen(fingerprint) {
43980
+ function recordFingerprintSeen(meshId, fingerprint) {
43911
43981
  try {
43912
43982
  const db = MeshRuntimeStore.getInstance();
43913
- db.recordCompletionFingerprint(fingerprint, RECENT_COMPLETION_FINGERPRINT_TTL_MS);
43983
+ db.recordCompletionFingerprint(meshId, fingerprint, RECENT_COMPLETION_FINGERPRINT_TTL_MS);
43914
43984
  db.sweepExpiredFingerprints();
43915
43985
  } catch {
43916
43986
  }
@@ -43940,7 +44010,7 @@ ${cleanBody}`;
43940
44010
  function isDuplicateMeshCompletionEvent(args) {
43941
44011
  const fingerprint = buildMeshCompletionFingerprint(args);
43942
44012
  if (!fingerprint) return false;
43943
- if (hasFingerprintSeen(fingerprint)) {
44013
+ if (hasFingerprintSeen(args.meshId, fingerprint)) {
43944
44014
  if (args.taskId) {
43945
44015
  recordCompletionConflict({
43946
44016
  meshId: args.meshId,
@@ -43952,7 +44022,7 @@ ${cleanBody}`;
43952
44022
  }
43953
44023
  return true;
43954
44024
  }
43955
- recordFingerprintSeen(fingerprint);
44025
+ recordFingerprintSeen(args.meshId, fingerprint);
43956
44026
  return false;
43957
44027
  }
43958
44028
  function isDuplicateMeshApprovalEvent(args) {
@@ -43966,16 +44036,16 @@ ${cleanBody}`;
43966
44036
  args.providerType || "",
43967
44037
  approvalIdentity
43968
44038
  ].join("::");
43969
- if (hasFingerprintSeen(fingerprint)) return true;
43970
- recordFingerprintSeen(fingerprint);
44039
+ if (hasFingerprintSeen(args.meshId, fingerprint)) return true;
44040
+ recordFingerprintSeen(args.meshId, fingerprint);
43971
44041
  return false;
43972
44042
  }
43973
44043
  function isDuplicateRefineTerminalEvent(meshId, eventName, metadataEvent) {
43974
44044
  const jobId = readRefineJobId({ metadataEvent });
43975
44045
  const fingerprint = jobId && (/* @__PURE__ */ new Set(["refine:completed", "refine:failed"])).has(eventName) ? `${meshId}::${eventName}::${jobId}` : "";
43976
44046
  if (!fingerprint) return false;
43977
- if (hasFingerprintSeen(fingerprint)) return true;
43978
- recordFingerprintSeen(fingerprint);
44047
+ if (hasFingerprintSeen(meshId, fingerprint)) return true;
44048
+ recordFingerprintSeen(meshId, fingerprint);
43979
44049
  return false;
43980
44050
  }
43981
44051
  function isSynthesizedReconciledTerminal(terminalPayload) {
@@ -44029,7 +44099,7 @@ ${cleanBody}`;
44029
44099
  if (intentionalCleanupStop) {
44030
44100
  if (eventSessionId && eventNodeId) {
44031
44101
  try {
44032
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(eventNodeId, eventSessionId);
44102
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, eventNodeId, eventSessionId);
44033
44103
  } catch {
44034
44104
  }
44035
44105
  }
@@ -44102,7 +44172,7 @@ ${cleanBody}`;
44102
44172
  terminalTaskId,
44103
44173
  eventTaskId
44104
44174
  });
44105
- const supersedesSynthesizedTerminal = isSynthesizedReconciledTerminal(terminal.payload) && isRealProviderCompletionEvent(args.metadataEvent) && isGenuineCompletionEvidence(args.metadataEvent);
44175
+ const supersedesSynthesizedTerminal = isSynthesizedReconciledTerminal(terminal.payload) && isRealProviderCompletionEvent(args.metadataEvent) && !isFalseIdleCompletion(args.metadataEvent);
44106
44176
  if (!newDispatchAfterTerminal && !supersedesWeakTerminal && !distinctTaskCompletion && !supersedesTruncatedTerminal && !supersedesSynthesizedTerminal) {
44107
44177
  const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
44108
44178
  const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
@@ -44245,7 +44315,25 @@ ${cleanBody}`;
44245
44315
  const isFalseIdle = isFalseIdleCompletion(args.metadataEvent);
44246
44316
  completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp, { tentativeIfDirect: isFalseIdle });
44247
44317
  if (nodeId && providerType) {
44248
- runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
44318
+ if (!isFalseIdle) {
44319
+ sweepExpiredRemoteIdleSessions();
44320
+ try {
44321
+ MeshRuntimeStore.getInstance().setRemoteIdleSession(args.meshId, nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
44322
+ } catch {
44323
+ }
44324
+ setImmediate(() => {
44325
+ maybeAutoFastForwardIdleNode(components, { meshId: args.meshId, nodeId, sessionId, providerType }).finally(() => {
44326
+ try {
44327
+ const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
44328
+ if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
44329
+ } catch (e) {
44330
+ LOG2.warn("MeshQueue", `Failed to assign idle queue task after completion for ${nodeId}: ${e?.message || e}`);
44331
+ }
44332
+ });
44333
+ });
44334
+ } else {
44335
+ runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
44336
+ }
44249
44337
  }
44250
44338
  const completedTaskId = completedTaskForLedger?.id;
44251
44339
  if (completedTaskId && hasPendingDependents(args.meshId, completedTaskId)) {
@@ -44300,14 +44388,14 @@ ${cleanBody}`;
44300
44388
  if (sessionId && nodeId && providerType) {
44301
44389
  sweepExpiredRemoteIdleSessions();
44302
44390
  try {
44303
- MeshRuntimeStore.getInstance().setRemoteIdleSession(nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
44391
+ MeshRuntimeStore.getInstance().setRemoteIdleSession(args.meshId, nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
44304
44392
  } catch {
44305
44393
  }
44306
44394
  setImmediate(() => {
44307
44395
  maybeAutoFastForwardIdleNode(components, { meshId: args.meshId, nodeId, sessionId, providerType }).finally(() => {
44308
44396
  try {
44309
44397
  const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
44310
- if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
44398
+ if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
44311
44399
  } catch (e) {
44312
44400
  LOG2.warn("MeshQueue", `Failed to assign idle queue task after maintenance for ${nodeId}: ${e?.message || e}`);
44313
44401
  }
@@ -44319,7 +44407,7 @@ ${cleanBody}`;
44319
44407
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
44320
44408
  if (sessionId && nodeId) {
44321
44409
  try {
44322
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
44410
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
44323
44411
  } catch {
44324
44412
  }
44325
44413
  }
@@ -44356,7 +44444,7 @@ ${cleanBody}`;
44356
44444
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
44357
44445
  if (sessionId && nodeId) {
44358
44446
  try {
44359
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
44447
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
44360
44448
  } catch {
44361
44449
  }
44362
44450
  }
@@ -44836,6 +44924,9 @@ ${cleanBody}`;
44836
44924
  }
44837
44925
  return DEFAULT_RECONCILE_INTERVAL_MS;
44838
44926
  }
44927
+ function inFlightSynthKey(meshId, taskId) {
44928
+ return `${meshId}::${taskId}`;
44929
+ }
44839
44930
  function resolveCoordinatorDaemonIds(components) {
44840
44931
  const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
44841
44932
  const machineId = readNonEmptyString2(loadConfig2().machineId);
@@ -45400,6 +45491,14 @@ ${cleanBody}`;
45400
45491
  async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId) {
45401
45492
  const dispatches = getActiveDirectDispatches(mesh.id);
45402
45493
  if (dispatches.length === 0) return;
45494
+ const activeTaskKeys = new Set(
45495
+ dispatches.map((d) => readNonEmptyString2(d.taskId)).filter(Boolean).map((taskId) => inFlightSynthKey(mesh.id, taskId))
45496
+ );
45497
+ for (const key of inFlightIdleObservationCounts.keys()) {
45498
+ if (key.startsWith(`${mesh.id}::`) && !activeTaskKeys.has(key)) {
45499
+ inFlightIdleObservationCounts.delete(key);
45500
+ }
45501
+ }
45403
45502
  const dispatchMeshCommand = components.dispatchMeshCommand;
45404
45503
  const nodeById = new Map(mesh.nodes.map((n) => [n.id, n]));
45405
45504
  for (const dispatch of dispatches) {
@@ -45435,7 +45534,19 @@ ${cleanBody}`;
45435
45534
  continue;
45436
45535
  }
45437
45536
  if (!payload) continue;
45438
- if (readChatPayloadStatus(payload) !== "idle") continue;
45537
+ const synthKey = inFlightSynthKey(mesh.id, taskId);
45538
+ if (readChatPayloadStatus(payload) !== "idle") {
45539
+ inFlightIdleObservationCounts.delete(synthKey);
45540
+ continue;
45541
+ }
45542
+ if (dispatch.status === "acked") {
45543
+ const idleStreak = (inFlightIdleObservationCounts.get(synthKey) ?? 0) + 1;
45544
+ inFlightIdleObservationCounts.set(synthKey, idleStreak);
45545
+ if (idleStreak < REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH) {
45546
+ 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)`);
45547
+ continue;
45548
+ }
45549
+ }
45439
45550
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
45440
45551
  const evidence = extractFinalAssistantSummaryEvidence(messages);
45441
45552
  if (!evidence.finalSummary) continue;
@@ -45592,6 +45703,8 @@ ${cleanBody}`;
45592
45703
  }
45593
45704
  var DEFAULT_RECONCILE_INTERVAL_MS;
45594
45705
  var DEFAULT_AUTO_PRUNE_MIN_AGE_MS;
45706
+ var REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH;
45707
+ var inFlightIdleObservationCounts;
45595
45708
  var coordinatorModalParkState;
45596
45709
  var heldEventLedgerRecorded;
45597
45710
  var ASSIGNED_STRANDED_DEADLINE_MS;
@@ -45619,6 +45732,8 @@ ${cleanBody}`;
45619
45732
  init_chat_message_normalization();
45620
45733
  DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
45621
45734
  DEFAULT_AUTO_PRUNE_MIN_AGE_MS = 24 * 60 * 6e4;
45735
+ REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH = 2;
45736
+ inFlightIdleObservationCounts = /* @__PURE__ */ new Map();
45622
45737
  coordinatorModalParkState = /* @__PURE__ */ new Map();
45623
45738
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
45624
45739
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;