@adhdev/daemon-core 0.9.82-rc.387 → 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
@@ -383,10 +383,10 @@ function readInjected(value) {
383
383
  }
384
384
  function getDaemonBuildInfo() {
385
385
  if (cached) return cached;
386
- const commit = readInjected(true ? "057d5def5d55af124dfe910ee9accdf244576c14" : void 0) ?? "unknown";
387
- const commitShort = readInjected(true ? "057d5def" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
388
- const version = readInjected(true ? "0.9.82-rc.387" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
389
- const builtAt = readInjected(true ? "2026-06-26T02:21:27.575Z" : void 0);
386
+ const commit = readInjected(true ? "f82b4b4cdb13171d2666cc959054b788af4f2ea5" : void 0) ?? "unknown";
387
+ const commitShort = readInjected(true ? "f82b4b4c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
388
+ const version = readInjected(true ? "0.9.82-rc.389" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
389
+ const builtAt = readInjected(true ? "2026-06-26T06:17:18.789Z" : void 0);
390
390
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
391
391
  return cached;
392
392
  }
@@ -4555,9 +4555,16 @@ function isInsideQuotedSpan(text, matchStart, matchEnd) {
4555
4555
  }
4556
4556
  return false;
4557
4557
  }
4558
+ function isGluedToLetterSuffix(text, matchStart, matchEnd) {
4559
+ const letterOrMark = /[\p{L}\p{M}]/u;
4560
+ const next = matchEnd < text.length ? text[matchEnd] : "";
4561
+ const prev = matchStart > 0 ? text[matchStart - 1] : "";
4562
+ return letterOrMark.test(next) || letterOrMark.test(prev);
4563
+ }
4558
4564
  function isRealMutationMatch(text, matchStart, matchEnd) {
4559
4565
  if (hasNegationBefore(text, matchStart)) return false;
4560
4566
  if (hasTrailingNegation(text, matchEnd)) return false;
4567
+ if (isGluedToLetterSuffix(text, matchStart, matchEnd)) return false;
4561
4568
  if (isInsidePathSegment(text, matchStart, matchEnd)) return false;
4562
4569
  if (isInsideQuotedSpan(text, matchStart, matchEnd)) return false;
4563
4570
  return isMutationKeywordInCommandContext(text, matchStart, matchEnd);
@@ -5264,10 +5271,20 @@ var init_mesh_runtime_store = __esm({
5264
5271
  CREATE INDEX IF NOT EXISTS idx_mesh_queue_assignment
5265
5272
  ON mesh_queue(mesh_id, assigned_node_id, assigned_session_id, status);
5266
5273
 
5274
+ -- mesh_id is DB-level isolation (defense-in-depth). The fingerprint STRING
5275
+ -- also carries meshId as its first '::'-joined segment (see
5276
+ -- buildMeshCompletionFingerprint) \u2014 that string-prefix defense is kept; this
5277
+ -- column makes cross-mesh suppression impossible even if the string format
5278
+ -- drifts or two meshes ever collide on a fingerprint body.
5267
5279
  CREATE TABLE IF NOT EXISTS mesh_completion_fingerprints (
5268
5280
  fingerprint TEXT PRIMARY KEY,
5269
- expires_at INTEGER NOT NULL
5281
+ expires_at INTEGER NOT NULL,
5282
+ mesh_id TEXT NOT NULL DEFAULT ''
5270
5283
  );
5284
+ -- NOTE: the (mesh_id, fingerprint) index is created in migrateMeshIsolationColumns,
5285
+ -- NOT here. A pre-isolation DB still has the legacy table (CREATE IF NOT EXISTS is a
5286
+ -- no-op), so referencing mesh_id in an index before the ALTER ADD COLUMN runs would
5287
+ -- fail with "no such column". The migration adds the column then the index.
5271
5288
 
5272
5289
  CREATE TABLE IF NOT EXISTS mesh_direct_dispatches (
5273
5290
  task_id TEXT PRIMARY KEY,
@@ -5287,13 +5304,18 @@ var init_mesh_runtime_store = __esm({
5287
5304
  CREATE INDEX IF NOT EXISTS idx_direct_dispatches_mesh_session
5288
5305
  ON mesh_direct_dispatches(mesh_id, session_id, status);
5289
5306
 
5307
+ -- MESH-ISOLATION-LEAK: mesh_id is part of the PK so a nodeId shared across two
5308
+ -- meshes (same machine in multiple repos) keeps a separate idle-session row per
5309
+ -- mesh, and getRemoteIdleSessions(meshId) can never surface another mesh's
5310
+ -- session for a queue claim.
5290
5311
  CREATE TABLE IF NOT EXISTS remote_idle_sessions (
5312
+ mesh_id TEXT NOT NULL,
5291
5313
  node_id TEXT NOT NULL,
5292
5314
  session_id TEXT NOT NULL,
5293
5315
  provider_type TEXT NOT NULL,
5294
5316
  expires_at INTEGER NOT NULL,
5295
5317
  metadata TEXT,
5296
- PRIMARY KEY (node_id, session_id)
5318
+ PRIMARY KEY (mesh_id, node_id, session_id)
5297
5319
  );
5298
5320
 
5299
5321
  CREATE TABLE IF NOT EXISTS mesh_session_delivery (
@@ -5417,19 +5439,67 @@ var init_mesh_runtime_store = __esm({
5417
5439
  cursor INTEGER NOT NULL DEFAULT 0
5418
5440
  );
5419
5441
  `);
5442
+ this.migrateMeshIsolationColumns();
5420
5443
  }
5421
- hasCompletionFingerprint(fingerprint) {
5444
+ tableColumns(table) {
5445
+ const rows = this.db.prepare(`PRAGMA table_info(${table})`).all();
5446
+ return new Set(rows.map((r) => r.name));
5447
+ }
5448
+ /**
5449
+ * MESH-ISOLATION-LEAK migration. Two tables historically lacked a `mesh_id` column,
5450
+ * letting one machine that belongs to multiple meshes (multiple repos) leak rows
5451
+ * across meshes. Both migrations are idempotent and run on every boot — the column
5452
+ * check short-circuits once the new schema is in place.
5453
+ */
5454
+ migrateMeshIsolationColumns() {
5455
+ try {
5456
+ const fpCols = this.tableColumns("mesh_completion_fingerprints");
5457
+ if (!fpCols.has("mesh_id")) {
5458
+ this.db.exec(`ALTER TABLE mesh_completion_fingerprints ADD COLUMN mesh_id TEXT NOT NULL DEFAULT ''`);
5459
+ this.db.exec(`
5460
+ UPDATE mesh_completion_fingerprints
5461
+ SET mesh_id = substr(fingerprint, 1, instr(fingerprint, '::') - 1)
5462
+ WHERE instr(fingerprint, '::') > 0 AND mesh_id = ''
5463
+ `);
5464
+ }
5465
+ this.db.exec(`
5466
+ CREATE INDEX IF NOT EXISTS idx_mesh_completion_fingerprints_mesh
5467
+ ON mesh_completion_fingerprints(mesh_id, fingerprint)
5468
+ `);
5469
+ const idleCols = this.tableColumns("remote_idle_sessions");
5470
+ if (!idleCols.has("mesh_id")) {
5471
+ this.db.exec(`
5472
+ DROP TABLE IF EXISTS remote_idle_sessions;
5473
+ CREATE TABLE remote_idle_sessions (
5474
+ mesh_id TEXT NOT NULL,
5475
+ node_id TEXT NOT NULL,
5476
+ session_id TEXT NOT NULL,
5477
+ provider_type TEXT NOT NULL,
5478
+ expires_at INTEGER NOT NULL,
5479
+ metadata TEXT,
5480
+ PRIMARY KEY (mesh_id, node_id, session_id)
5481
+ );
5482
+ `);
5483
+ }
5484
+ } catch (err) {
5485
+ if (!loggedMigrationFailure) {
5486
+ loggedMigrationFailure = true;
5487
+ LOG.warn("MeshRuntimeStore", `mesh-isolation column migration failed: ${err?.message || err}`);
5488
+ }
5489
+ }
5490
+ }
5491
+ hasCompletionFingerprint(meshId, fingerprint) {
5422
5492
  const now = Date.now();
5423
- const row = this.db.prepare("SELECT 1 FROM mesh_completion_fingerprints WHERE fingerprint = ? AND expires_at > ?").get(fingerprint, now);
5493
+ const row = this.db.prepare("SELECT 1 FROM mesh_completion_fingerprints WHERE mesh_id = ? AND fingerprint = ? AND expires_at > ?").get(meshId, fingerprint, now);
5424
5494
  if (++this.fingerprintSweepCounter >= 100) {
5425
5495
  this.fingerprintSweepCounter = 0;
5426
5496
  this.sweepExpiredFingerprints();
5427
5497
  }
5428
5498
  return row !== void 0;
5429
5499
  }
5430
- recordCompletionFingerprint(fingerprint, ttlMs) {
5500
+ recordCompletionFingerprint(meshId, fingerprint, ttlMs) {
5431
5501
  const expiresAt = Date.now() + ttlMs;
5432
- this.db.prepare("INSERT OR REPLACE INTO mesh_completion_fingerprints (fingerprint, expires_at) VALUES (?, ?)").run(fingerprint, expiresAt);
5502
+ this.db.prepare("INSERT OR REPLACE INTO mesh_completion_fingerprints (fingerprint, expires_at, mesh_id) VALUES (?, ?, ?)").run(fingerprint, expiresAt, meshId);
5433
5503
  this.maybeCheckpointWal();
5434
5504
  }
5435
5505
  sweepExpiredFingerprints() {
@@ -5938,14 +6008,14 @@ var init_mesh_runtime_store = __esm({
5938
6008
  `).run(now, meshId, cutoff);
5939
6009
  }
5940
6010
  // ── Remote Idle Sessions ─────────────────────────────────────────────────
5941
- setRemoteIdleSession(nodeId, sessionId, providerType, expiresAt, metadata) {
6011
+ setRemoteIdleSession(meshId, nodeId, sessionId, providerType, expiresAt, metadata) {
5942
6012
  this.db.prepare(`
5943
- INSERT OR REPLACE INTO remote_idle_sessions (node_id, session_id, provider_type, expires_at, metadata)
5944
- VALUES (?, ?, ?, ?, ?)
5945
- `).run(nodeId, sessionId, providerType, expiresAt, metadata ? JSON.stringify(metadata) : null);
6013
+ INSERT OR REPLACE INTO remote_idle_sessions (mesh_id, node_id, session_id, provider_type, expires_at, metadata)
6014
+ VALUES (?, ?, ?, ?, ?, ?)
6015
+ `).run(meshId, nodeId, sessionId, providerType, expiresAt, metadata ? JSON.stringify(metadata) : null);
5946
6016
  }
5947
- getRemoteIdleSessions() {
5948
- const rows = this.db.prepare("SELECT node_id, session_id, provider_type, expires_at, metadata FROM remote_idle_sessions").all();
6017
+ getRemoteIdleSessions(meshId) {
6018
+ const rows = this.db.prepare("SELECT node_id, session_id, provider_type, expires_at, metadata FROM remote_idle_sessions WHERE mesh_id = ?").all(meshId);
5949
6019
  return rows.map((r) => ({
5950
6020
  nodeId: r.node_id,
5951
6021
  sessionId: r.session_id,
@@ -5954,8 +6024,8 @@ var init_mesh_runtime_store = __esm({
5954
6024
  metadata: r.metadata ? JSON.parse(r.metadata) : void 0
5955
6025
  }));
5956
6026
  }
5957
- deleteRemoteIdleSession(nodeId, sessionId) {
5958
- this.db.prepare("DELETE FROM remote_idle_sessions WHERE node_id = ? AND session_id = ?").run(nodeId, sessionId);
6027
+ deleteRemoteIdleSession(meshId, nodeId, sessionId) {
6028
+ this.db.prepare("DELETE FROM remote_idle_sessions WHERE mesh_id = ? AND node_id = ? AND session_id = ?").run(meshId, nodeId, sessionId);
5959
6029
  }
5960
6030
  pruneExpiredRemoteIdleSessions() {
5961
6031
  this.db.prepare("DELETE FROM remote_idle_sessions WHERE expires_at <= ?").run(Date.now());
@@ -11323,7 +11393,7 @@ async function triggerMeshQueue(components, meshId) {
11323
11393
  }
11324
11394
  let remoteSessions = [];
11325
11395
  try {
11326
- remoteSessions = MeshRuntimeStore.getInstance().getRemoteIdleSessions();
11396
+ remoteSessions = MeshRuntimeStore.getInstance().getRemoteIdleSessions(meshId);
11327
11397
  } catch {
11328
11398
  }
11329
11399
  const remoteCandidates = [];
@@ -11338,7 +11408,7 @@ async function triggerMeshQueue(components, meshId) {
11338
11408
  const assigned = tryAssignQueueTask(components, meshId, candidate.nodeId, candidate.sessionId, candidate.providerType);
11339
11409
  if (assigned && candidate.origin === "remote") {
11340
11410
  try {
11341
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(candidate.nodeId, candidate.sessionId);
11411
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(meshId, candidate.nodeId, candidate.sessionId);
11342
11412
  } catch {
11343
11413
  }
11344
11414
  }
@@ -14093,17 +14163,17 @@ function shouldSuppressIntentionalCleanupStop(args) {
14093
14163
  if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
14094
14164
  return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
14095
14165
  }
14096
- function hasFingerprintSeen(fingerprint) {
14166
+ function hasFingerprintSeen(meshId, fingerprint) {
14097
14167
  try {
14098
- return MeshRuntimeStore.getInstance().hasCompletionFingerprint(fingerprint);
14168
+ return MeshRuntimeStore.getInstance().hasCompletionFingerprint(meshId, fingerprint);
14099
14169
  } catch {
14100
14170
  return false;
14101
14171
  }
14102
14172
  }
14103
- function recordFingerprintSeen(fingerprint) {
14173
+ function recordFingerprintSeen(meshId, fingerprint) {
14104
14174
  try {
14105
14175
  const db = MeshRuntimeStore.getInstance();
14106
- db.recordCompletionFingerprint(fingerprint, RECENT_COMPLETION_FINGERPRINT_TTL_MS);
14176
+ db.recordCompletionFingerprint(meshId, fingerprint, RECENT_COMPLETION_FINGERPRINT_TTL_MS);
14107
14177
  db.sweepExpiredFingerprints();
14108
14178
  } catch {
14109
14179
  }
@@ -14133,7 +14203,7 @@ function buildMeshCompletionFingerprint(args) {
14133
14203
  function isDuplicateMeshCompletionEvent(args) {
14134
14204
  const fingerprint = buildMeshCompletionFingerprint(args);
14135
14205
  if (!fingerprint) return false;
14136
- if (hasFingerprintSeen(fingerprint)) {
14206
+ if (hasFingerprintSeen(args.meshId, fingerprint)) {
14137
14207
  if (args.taskId) {
14138
14208
  recordCompletionConflict({
14139
14209
  meshId: args.meshId,
@@ -14145,7 +14215,7 @@ function isDuplicateMeshCompletionEvent(args) {
14145
14215
  }
14146
14216
  return true;
14147
14217
  }
14148
- recordFingerprintSeen(fingerprint);
14218
+ recordFingerprintSeen(args.meshId, fingerprint);
14149
14219
  return false;
14150
14220
  }
14151
14221
  function isDuplicateMeshApprovalEvent(args) {
@@ -14159,16 +14229,16 @@ function isDuplicateMeshApprovalEvent(args) {
14159
14229
  args.providerType || "",
14160
14230
  approvalIdentity
14161
14231
  ].join("::");
14162
- if (hasFingerprintSeen(fingerprint)) return true;
14163
- recordFingerprintSeen(fingerprint);
14232
+ if (hasFingerprintSeen(args.meshId, fingerprint)) return true;
14233
+ recordFingerprintSeen(args.meshId, fingerprint);
14164
14234
  return false;
14165
14235
  }
14166
14236
  function isDuplicateRefineTerminalEvent(meshId, eventName, metadataEvent) {
14167
14237
  const jobId = readRefineJobId({ metadataEvent });
14168
14238
  const fingerprint = jobId && (/* @__PURE__ */ new Set(["refine:completed", "refine:failed"])).has(eventName) ? `${meshId}::${eventName}::${jobId}` : "";
14169
14239
  if (!fingerprint) return false;
14170
- if (hasFingerprintSeen(fingerprint)) return true;
14171
- recordFingerprintSeen(fingerprint);
14240
+ if (hasFingerprintSeen(meshId, fingerprint)) return true;
14241
+ recordFingerprintSeen(meshId, fingerprint);
14172
14242
  return false;
14173
14243
  }
14174
14244
  function isSynthesizedReconciledTerminal(terminalPayload) {
@@ -14222,7 +14292,7 @@ function evaluateMeshEventSuppression(args, ctx) {
14222
14292
  if (intentionalCleanupStop) {
14223
14293
  if (eventSessionId && eventNodeId) {
14224
14294
  try {
14225
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(eventNodeId, eventSessionId);
14295
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, eventNodeId, eventSessionId);
14226
14296
  } catch {
14227
14297
  }
14228
14298
  }
@@ -14295,7 +14365,7 @@ function evaluateMeshEventSuppression(args, ctx) {
14295
14365
  terminalTaskId,
14296
14366
  eventTaskId
14297
14367
  });
14298
- const supersedesSynthesizedTerminal = isSynthesizedReconciledTerminal(terminal.payload) && isRealProviderCompletionEvent(args.metadataEvent) && isGenuineCompletionEvidence(args.metadataEvent);
14368
+ const supersedesSynthesizedTerminal = isSynthesizedReconciledTerminal(terminal.payload) && isRealProviderCompletionEvent(args.metadataEvent) && !isFalseIdleCompletion(args.metadataEvent);
14299
14369
  if (!newDispatchAfterTerminal && !supersedesWeakTerminal && !distinctTaskCompletion && !supersedesTruncatedTerminal && !supersedesSynthesizedTerminal) {
14300
14370
  const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
14301
14371
  const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
@@ -14438,7 +14508,25 @@ function injectMeshSystemMessage(components, args) {
14438
14508
  const isFalseIdle = isFalseIdleCompletion(args.metadataEvent);
14439
14509
  completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp, { tentativeIfDirect: isFalseIdle });
14440
14510
  if (nodeId && providerType) {
14441
- runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
14511
+ if (!isFalseIdle) {
14512
+ sweepExpiredRemoteIdleSessions();
14513
+ try {
14514
+ MeshRuntimeStore.getInstance().setRemoteIdleSession(args.meshId, nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
14515
+ } catch {
14516
+ }
14517
+ setImmediate(() => {
14518
+ maybeAutoFastForwardIdleNode(components, { meshId: args.meshId, nodeId, sessionId, providerType }).finally(() => {
14519
+ try {
14520
+ const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
14521
+ if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
14522
+ } catch (e) {
14523
+ LOG.warn("MeshQueue", `Failed to assign idle queue task after completion for ${nodeId}: ${e?.message || e}`);
14524
+ }
14525
+ });
14526
+ });
14527
+ } else {
14528
+ runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
14529
+ }
14442
14530
  }
14443
14531
  const completedTaskId = completedTaskForLedger?.id;
14444
14532
  if (completedTaskId && hasPendingDependents(args.meshId, completedTaskId)) {
@@ -14493,14 +14581,14 @@ function injectMeshSystemMessage(components, args) {
14493
14581
  if (sessionId && nodeId && providerType) {
14494
14582
  sweepExpiredRemoteIdleSessions();
14495
14583
  try {
14496
- MeshRuntimeStore.getInstance().setRemoteIdleSession(nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
14584
+ MeshRuntimeStore.getInstance().setRemoteIdleSession(args.meshId, nodeId, sessionId, providerType, Date.now() + REMOTE_IDLE_SESSION_TTL_MS);
14497
14585
  } catch {
14498
14586
  }
14499
14587
  setImmediate(() => {
14500
14588
  maybeAutoFastForwardIdleNode(components, { meshId: args.meshId, nodeId, sessionId, providerType }).finally(() => {
14501
14589
  try {
14502
14590
  const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
14503
- if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
14591
+ if (assigned) MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
14504
14592
  } catch (e) {
14505
14593
  LOG.warn("MeshQueue", `Failed to assign idle queue task after maintenance for ${nodeId}: ${e?.message || e}`);
14506
14594
  }
@@ -14512,7 +14600,7 @@ function injectMeshSystemMessage(components, args) {
14512
14600
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
14513
14601
  if (sessionId && nodeId) {
14514
14602
  try {
14515
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
14603
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
14516
14604
  } catch {
14517
14605
  }
14518
14606
  }
@@ -14549,7 +14637,7 @@ function injectMeshSystemMessage(components, args) {
14549
14637
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
14550
14638
  if (sessionId && nodeId) {
14551
14639
  try {
14552
- MeshRuntimeStore.getInstance().deleteRemoteIdleSession(nodeId, sessionId);
14640
+ MeshRuntimeStore.getInstance().deleteRemoteIdleSession(args.meshId, nodeId, sessionId);
14553
14641
  } catch {
14554
14642
  }
14555
14643
  }
@@ -15027,6 +15115,9 @@ function resolveReconcileIntervalMs() {
15027
15115
  }
15028
15116
  return DEFAULT_RECONCILE_INTERVAL_MS;
15029
15117
  }
15118
+ function inFlightSynthKey(meshId, taskId) {
15119
+ return `${meshId}::${taskId}`;
15120
+ }
15030
15121
  function resolveCoordinatorDaemonIds(components) {
15031
15122
  const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
15032
15123
  const machineId = readNonEmptyString2(loadConfig().machineId);
@@ -15591,6 +15682,14 @@ function readChatPayloadStatus(payload) {
15591
15682
  async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId) {
15592
15683
  const dispatches = getActiveDirectDispatches(mesh.id);
15593
15684
  if (dispatches.length === 0) return;
15685
+ const activeTaskKeys = new Set(
15686
+ dispatches.map((d) => readNonEmptyString2(d.taskId)).filter(Boolean).map((taskId) => inFlightSynthKey(mesh.id, taskId))
15687
+ );
15688
+ for (const key of inFlightIdleObservationCounts.keys()) {
15689
+ if (key.startsWith(`${mesh.id}::`) && !activeTaskKeys.has(key)) {
15690
+ inFlightIdleObservationCounts.delete(key);
15691
+ }
15692
+ }
15594
15693
  const dispatchMeshCommand = components.dispatchMeshCommand;
15595
15694
  const nodeById = new Map(mesh.nodes.map((n) => [n.id, n]));
15596
15695
  for (const dispatch of dispatches) {
@@ -15626,7 +15725,19 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
15626
15725
  continue;
15627
15726
  }
15628
15727
  if (!payload) continue;
15629
- if (readChatPayloadStatus(payload) !== "idle") continue;
15728
+ const synthKey = inFlightSynthKey(mesh.id, taskId);
15729
+ if (readChatPayloadStatus(payload) !== "idle") {
15730
+ inFlightIdleObservationCounts.delete(synthKey);
15731
+ continue;
15732
+ }
15733
+ if (dispatch.status === "acked") {
15734
+ const idleStreak = (inFlightIdleObservationCounts.get(synthKey) ?? 0) + 1;
15735
+ inFlightIdleObservationCounts.set(synthKey, idleStreak);
15736
+ if (idleStreak < REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH) {
15737
+ 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)`);
15738
+ continue;
15739
+ }
15740
+ }
15630
15741
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
15631
15742
  const evidence = extractFinalAssistantSummaryEvidence(messages);
15632
15743
  if (!evidence.finalSummary) continue;
@@ -15781,7 +15892,7 @@ function setupMeshReconcileLoop(components) {
15781
15892
  }
15782
15893
  };
15783
15894
  }
15784
- var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
15895
+ var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH, inFlightIdleObservationCounts, coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
15785
15896
  var init_mesh_reconcile_loop = __esm({
15786
15897
  "src/mesh/mesh-reconcile-loop.ts"() {
15787
15898
  "use strict";
@@ -15803,6 +15914,8 @@ var init_mesh_reconcile_loop = __esm({
15803
15914
  init_chat_message_normalization();
15804
15915
  DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
15805
15916
  DEFAULT_AUTO_PRUNE_MIN_AGE_MS = 24 * 60 * 6e4;
15917
+ REQUIRED_CONSECUTIVE_IDLE_TICKS_FOR_INFLIGHT_SYNTH = 2;
15918
+ inFlightIdleObservationCounts = /* @__PURE__ */ new Map();
15806
15919
  coordinatorModalParkState = /* @__PURE__ */ new Map();
15807
15920
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
15808
15921
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;