@adhdev/daemon-core 1.0.28-rc.7 → 1.0.28-rc.8

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.d.ts CHANGED
@@ -53,7 +53,7 @@ export { MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS, MESH_WORKTREE_BOOTSTRAP_CONFI
53
53
  export type { MeshRefineValidationCategory, MeshRefineValidationCommandPlan, MeshRefineValidationPlan, RepoMeshRefineConfig, RepoMeshRefineValidationCommandConfig, } from './mesh/refine-config.js';
54
54
  export { loadRepoSettings } from './config/repo-settings.js';
55
55
  export type { RepoSettings, LoadRepoSettingsOptions } from './config/repo-settings.js';
56
- export { appendLedgerEntry, appendRemoteLedgerEntries, buildTaskCompletionEvidence, normalizeMeshWorkerResult, readLedgerEntries, readLedgerSlice, readLedgerSliceFromStore, getLedgerSummary, getLedgerDir, getSessionRecoveryContext, MAX_LEDGER_SLICE_LIMIT, tombstoneOperatingNote, readOperatingNotes, pruneOperatingNotes, isOperatingNoteTombstoned, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST } from './mesh/mesh-ledger.js';
56
+ export { appendLedgerEntry, appendRemoteLedgerEntries, buildTaskCompletionEvidence, normalizeMeshWorkerResult, readLedgerEntries, readLedgerSlice, readLedgerSliceFromStore, getLedgerSummary, getLedgerDir, getSessionRecoveryContext, ledgerEntryTaskId, MAX_LEDGER_SLICE_LIMIT, tombstoneOperatingNote, readOperatingNotes, pruneOperatingNotes, isOperatingNoteTombstoned, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST } from './mesh/mesh-ledger.js';
57
57
  export type { AppendRemoteLedgerResult, MeshLedgerEntry, MeshLedgerKind, MeshLedgerSlice, MeshLedgerSummary, ReadLedgerOptions, ReadLedgerSliceOptions, SessionRecoveryContext, MeshTaskCompletionEvidence, MeshWorkerResultArtifact, MeshProcessArtifact, MeshValidationResultArtifact } from './mesh/mesh-ledger.js';
58
58
  export { fastForwardMeshNode } from './mesh/mesh-fast-forward.js';
59
59
  export type { MeshFastForwardNodeArgs, MeshFastForwardPlannedStep, MeshFastForwardResult } from './mesh/mesh-fast-forward.js';
package/dist/index.js CHANGED
@@ -791,10 +791,10 @@ function readInjected(value) {
791
791
  }
792
792
  function getDaemonBuildInfo() {
793
793
  if (cached) return cached;
794
- const commit = readInjected(true ? "4d3d797d7472b72daaa82b9460f599e819ffee72" : void 0) ?? "unknown";
795
- const commitShort = readInjected(true ? "4d3d797d" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
796
- const version = readInjected(true ? "1.0.28-rc.7" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
797
- const builtAt = readInjected(true ? "2026-07-25T10:44:41.655Z" : void 0);
794
+ const commit = readInjected(true ? "cb5f0a4f64296587a261176e08731f2f3ed78766" : void 0) ?? "unknown";
795
+ const commitShort = readInjected(true ? "cb5f0a4f" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
796
+ const version = readInjected(true ? "1.0.28-rc.8" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
797
+ const builtAt = readInjected(true ? "2026-07-25T12:20:55.839Z" : void 0);
798
798
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
799
799
  return cached;
800
800
  }
@@ -7731,6 +7731,10 @@ var init_mesh_runtime_store = __esm({
7731
7731
  node_id TEXT,
7732
7732
  session_id TEXT,
7733
7733
  provider_type TEXT,
7734
+ -- LEDGER-TASK-TRACEABILITY (B): the task a lifecycle entry pertains to,
7735
+ -- promoted from payload.taskId so kind+task_id joins are index-backed
7736
+ -- (legacy DBs get this column via migrateMeshIsolationColumns' ALTER).
7737
+ task_id TEXT,
7734
7738
  payload TEXT NOT NULL DEFAULT '{}'
7735
7739
  );
7736
7740
 
@@ -7902,6 +7906,15 @@ var init_mesh_runtime_store = __esm({
7902
7906
  `);
7903
7907
  this.db.exec(`DROP TABLE IF EXISTS mesh_direct_delivered_events`);
7904
7908
  this.db.exec(`DROP TABLE IF EXISTS mesh_completion_conflicts`);
7909
+ const ledgerCols = this.tableColumns("mesh_event_ledger");
7910
+ if (!ledgerCols.has("task_id")) {
7911
+ this.db.exec(`ALTER TABLE mesh_event_ledger ADD COLUMN task_id TEXT`);
7912
+ }
7913
+ this.db.exec(`
7914
+ CREATE INDEX IF NOT EXISTS idx_mesh_event_ledger_task
7915
+ ON mesh_event_ledger(mesh_id, task_id, timestamp)
7916
+ WHERE task_id IS NOT NULL
7917
+ `);
7905
7918
  } catch (err) {
7906
7919
  if (!loggedMigrationFailure) {
7907
7920
  loggedMigrationFailure = true;
@@ -8853,8 +8866,8 @@ var init_mesh_runtime_store = __esm({
8853
8866
  }
8854
8867
  this.db.prepare(
8855
8868
  `INSERT OR IGNORE INTO mesh_event_ledger
8856
- (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, payload)
8857
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
8869
+ (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, task_id, payload)
8870
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
8858
8871
  ).run(
8859
8872
  entry.id,
8860
8873
  entry.meshId,
@@ -8863,6 +8876,7 @@ var init_mesh_runtime_store = __esm({
8863
8876
  entry.nodeId ?? null,
8864
8877
  entry.sessionId ?? null,
8865
8878
  entry.providerType ?? null,
8879
+ entry.taskId ?? null,
8866
8880
  JSON.stringify(entry.payload ?? {})
8867
8881
  );
8868
8882
  this.maybeCheckpointWal();
@@ -8893,6 +8907,7 @@ var init_mesh_runtime_store = __esm({
8893
8907
  nodeId: r.node_id,
8894
8908
  sessionId: r.session_id,
8895
8909
  providerType: r.provider_type,
8910
+ taskId: r.task_id ?? null,
8896
8911
  payload: (() => {
8897
8912
  try {
8898
8913
  return JSON.parse(r.payload);
@@ -8939,6 +8954,7 @@ var init_mesh_runtime_store = __esm({
8939
8954
  nodeId: r.node_id,
8940
8955
  sessionId: r.session_id,
8941
8956
  providerType: r.provider_type,
8957
+ taskId: r.task_id ?? null,
8942
8958
  payload: (() => {
8943
8959
  try {
8944
8960
  return JSON.parse(r.payload);
@@ -8980,8 +8996,8 @@ var init_mesh_runtime_store = __esm({
8980
8996
  let imported = 0;
8981
8997
  const stmt = this.db.prepare(
8982
8998
  `INSERT OR IGNORE INTO mesh_event_ledger
8983
- (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, payload)
8984
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
8999
+ (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, task_id, payload)
9000
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
8985
9001
  );
8986
9002
  this.db.transaction(() => {
8987
9003
  for (const e of entries) {
@@ -8994,6 +9010,7 @@ var init_mesh_runtime_store = __esm({
8994
9010
  e.nodeId ?? null,
8995
9011
  e.sessionId ?? null,
8996
9012
  e.providerType ?? null,
9013
+ e.taskId ?? null,
8997
9014
  JSON.stringify(e.payload ?? {})
8998
9015
  );
8999
9016
  if (result.changes > 0) imported++;
@@ -9373,6 +9390,7 @@ __export(mesh_ledger_exports, {
9373
9390
  isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
9374
9391
  isNoteExpired: () => isNoteExpired,
9375
9392
  isOperatingNoteTombstoned: () => isOperatingNoteTombstoned,
9393
+ ledgerEntryTaskId: () => ledgerEntryTaskId,
9376
9394
  meshLedgerEvents: () => meshLedgerEvents,
9377
9395
  normalizeMeshWorkerResult: () => normalizeMeshWorkerResult,
9378
9396
  pruneOperatingNotes: () => pruneOperatingNotes,
@@ -9382,6 +9400,11 @@ __export(mesh_ledger_exports, {
9382
9400
  readOperatingNotes: () => readOperatingNotes,
9383
9401
  tombstoneOperatingNote: () => tombstoneOperatingNote
9384
9402
  });
9403
+ function ledgerEntryTaskId(entry) {
9404
+ if (typeof entry.taskId === "string" && entry.taskId.trim()) return entry.taskId.trim();
9405
+ const fromPayload = entry.payload && typeof entry.payload === "object" ? entry.payload.taskId : void 0;
9406
+ return typeof fromPayload === "string" && fromPayload.trim() ? fromPayload.trim() : void 0;
9407
+ }
9385
9408
  function isIntentionalCleanupStopEntry(entry) {
9386
9409
  if (entry.kind !== "session_stopped" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") return false;
9387
9410
  const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
@@ -9690,6 +9713,10 @@ function appendLedgerEntry(meshId, partial) {
9690
9713
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9691
9714
  ...partial
9692
9715
  };
9716
+ if (!entry.taskId && TASK_LIFECYCLE_LEDGER_KINDS.has(entry.kind)) {
9717
+ const derived = ledgerEntryTaskId(entry);
9718
+ if (derived) entry.taskId = derived;
9719
+ }
9693
9720
  const filePath = getLedgerPath(meshId);
9694
9721
  if ((0, import_fs7.existsSync)(filePath)) {
9695
9722
  try {
@@ -9711,6 +9738,7 @@ function appendLedgerEntry(meshId, partial) {
9711
9738
  nodeId: entry.nodeId ?? null,
9712
9739
  sessionId: entry.sessionId ?? null,
9713
9740
  providerType: entry.providerType ?? null,
9741
+ taskId: entry.taskId ?? null,
9714
9742
  payload: entry.payload
9715
9743
  });
9716
9744
  } catch {
@@ -9891,7 +9919,13 @@ function readLedgerFile(meshId) {
9891
9919
  if (!line.trim()) continue;
9892
9920
  try {
9893
9921
  const entry = JSON.parse(line);
9894
- if (entry.id && entry.kind) entries.push(entry);
9922
+ if (entry.id && entry.kind) {
9923
+ if (!entry.taskId) {
9924
+ const derived = ledgerEntryTaskId(entry);
9925
+ if (derived) entry.taskId = derived;
9926
+ }
9927
+ entries.push(entry);
9928
+ }
9895
9929
  } catch {
9896
9930
  }
9897
9931
  }
@@ -9915,6 +9949,7 @@ function ensureLedgerImported(store, meshId) {
9915
9949
  nodeId: e.nodeId ?? null,
9916
9950
  sessionId: e.sessionId ?? null,
9917
9951
  providerType: e.providerType ?? null,
9952
+ taskId: ledgerEntryTaskId(e) ?? null,
9918
9953
  payload: e.payload ?? {}
9919
9954
  })));
9920
9955
  } catch {
@@ -9923,16 +9958,21 @@ function ensureLedgerImported(store, meshId) {
9923
9958
  function readLedgerFromStore(meshId) {
9924
9959
  const store = MeshRuntimeStore.getInstance();
9925
9960
  ensureLedgerImported(store, meshId);
9926
- return store.readLedgerEntriesOrdered(meshId).map((r) => ({
9927
- id: r.id,
9928
- meshId: r.meshId,
9929
- timestamp: r.timestamp,
9930
- kind: r.kind,
9931
- ...r.nodeId ? { nodeId: r.nodeId } : {},
9932
- ...r.sessionId ? { sessionId: r.sessionId } : {},
9933
- ...r.providerType ? { providerType: r.providerType } : {},
9934
- payload: r.payload && typeof r.payload === "object" ? r.payload : {}
9935
- }));
9961
+ return store.readLedgerEntriesOrdered(meshId).map((r) => {
9962
+ const payload = r.payload && typeof r.payload === "object" ? r.payload : {};
9963
+ const taskId = ledgerEntryTaskId({ taskId: r.taskId ?? void 0, payload });
9964
+ return {
9965
+ id: r.id,
9966
+ meshId: r.meshId,
9967
+ timestamp: r.timestamp,
9968
+ kind: r.kind,
9969
+ ...r.nodeId ? { nodeId: r.nodeId } : {},
9970
+ ...r.sessionId ? { sessionId: r.sessionId } : {},
9971
+ ...r.providerType ? { providerType: r.providerType } : {},
9972
+ ...taskId ? { taskId } : {},
9973
+ payload
9974
+ };
9975
+ });
9936
9976
  }
9937
9977
  function getCachedRawEntries(meshId) {
9938
9978
  const now = Date.now();
@@ -10159,7 +10199,7 @@ function rotateLedgerFile(meshId, currentPath) {
10159
10199
  `);
10160
10200
  }
10161
10201
  }
10162
- var import_fs7, import_path7, import_crypto8, import_events, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, COMPACT_THRESHOLD_BYTES, ARCHIVE_TERMINAL_OLDER_THAN_MS, RECENT_FAILURE_WINDOW_MS, ARCHIVABLE_KINDS, DEFAULT_LEDGER_SLICE_LIMIT, MAX_LEDGER_SLICE_LIMIT, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST, OPERATING_NOTE_CATEGORY_TTL_DAYS, MS_PER_DAY, meshLedgerEvents, ledgerReadCache, LEDGER_CACHE_TTL_MS, ledgerImportStoreRef, ledgerImportDone;
10202
+ var import_fs7, import_path7, import_crypto8, import_events, TASK_LIFECYCLE_LEDGER_KINDS, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, COMPACT_THRESHOLD_BYTES, ARCHIVE_TERMINAL_OLDER_THAN_MS, RECENT_FAILURE_WINDOW_MS, ARCHIVABLE_KINDS, DEFAULT_LEDGER_SLICE_LIMIT, MAX_LEDGER_SLICE_LIMIT, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST, OPERATING_NOTE_CATEGORY_TTL_DAYS, MS_PER_DAY, meshLedgerEvents, ledgerReadCache, LEDGER_CACHE_TTL_MS, ledgerImportStoreRef, ledgerImportDone;
10163
10203
  var init_mesh_ledger = __esm({
10164
10204
  "src/mesh/mesh-ledger.ts"() {
10165
10205
  "use strict";
@@ -10171,6 +10211,17 @@ var init_mesh_ledger = __esm({
10171
10211
  import_events = require("events");
10172
10212
  init_mesh_runtime_store();
10173
10213
  init_contracts();
10214
+ TASK_LIFECYCLE_LEDGER_KINDS = /* @__PURE__ */ new Set([
10215
+ "task_dispatched",
10216
+ "task_claimed",
10217
+ "task_completed",
10218
+ "task_failed",
10219
+ "task_stalled",
10220
+ "task_reclaimed",
10221
+ "task_approval_needed",
10222
+ "task_question_pending",
10223
+ "p2p_dispatch_failed"
10224
+ ]);
10174
10225
  LEDGER_DIR_NAME = "mesh-ledger";
10175
10226
  MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024;
10176
10227
  COMPACT_THRESHOLD_BYTES = 2 * 1024 * 1024;
@@ -19156,6 +19207,43 @@ async function waitForLocalSessionReady(components, sessionId) {
19156
19207
  }
19157
19208
  LOG.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
19158
19209
  }
19210
+ function recordTaskDispatchedLedger(ctx, deliveryId) {
19211
+ const task = ctx.task;
19212
+ const routing = ctx.routingDecision;
19213
+ const routingDecision = {
19214
+ source: routing?.source ?? "queue",
19215
+ selectedNodeId: ctx.nodeId,
19216
+ ...localCoordinatorDaemonId() ? { daemonId: localCoordinatorDaemonId() } : {},
19217
+ transport: ctx.transport,
19218
+ // D: resolved execution profile — prefer the caller's resolved values, fall back
19219
+ // to what the claimed task row carries (queue/idle drains carry it on the task).
19220
+ resolvedProviderType: routing?.resolvedProviderType ?? ctx.providerType,
19221
+ ...routing?.resolvedModel ?? task.model ? { resolvedModel: routing?.resolvedModel ?? task.model } : {},
19222
+ ...routing?.resolvedThinkingLevel ?? task.thinkingLevel ? { resolvedThinkingLevel: routing?.resolvedThinkingLevel ?? task.thinkingLevel } : {},
19223
+ ...routing?.resolvedDifficulty ?? task.difficulty ? { resolvedDifficulty: routing?.resolvedDifficulty ?? task.difficulty } : {},
19224
+ ...typeof routing?.fitnessScore === "number" ? { fitnessScore: routing.fitnessScore } : {},
19225
+ ...routing?.skippedCandidates?.length ? { skippedCandidates: routing.skippedCandidates } : {},
19226
+ ...routing?.requiredTagsResult ? { requiredTagsResult: routing.requiredTagsResult } : {},
19227
+ ...routing?.reason ? { reason: routing.reason } : {}
19228
+ };
19229
+ appendLedgerEntry(ctx.meshId, {
19230
+ kind: "task_dispatched",
19231
+ nodeId: ctx.nodeId,
19232
+ sessionId: ctx.sessionId,
19233
+ providerType: ctx.providerType,
19234
+ taskId: task.id,
19235
+ payload: {
19236
+ taskId: task.id,
19237
+ ...task.missionId ? { missionId: task.missionId } : {},
19238
+ deliveryId,
19239
+ transport: ctx.transport,
19240
+ ...ctx.sourceCoordinatorSessionId ? { coordinatorSessionId: ctx.sourceCoordinatorSessionId } : {},
19241
+ ...ctx.sourceCoordinatorDaemonId ? { coordinatorDaemonId: ctx.sourceCoordinatorDaemonId } : {},
19242
+ ...Array.isArray(task.requiredTags) && task.requiredTags.length ? { requiredTags: task.requiredTags } : {},
19243
+ routingDecision
19244
+ }
19245
+ });
19246
+ }
19159
19247
  function deliverTaskToSession(dispatchThunk, ctx, warmup) {
19160
19248
  const delivery = createSessionDelivery({
19161
19249
  meshId: ctx.meshId,
@@ -19169,6 +19257,10 @@ function deliverTaskToSession(dispatchThunk, ctx, warmup) {
19169
19257
  ...ctx.sourceCoordinatorSessionId ? { sourceCoordinatorSessionId: ctx.sourceCoordinatorSessionId } : {},
19170
19258
  ...ctx.sourceCoordinatorDaemonId ? { sourceCoordinatorDaemonId: ctx.sourceCoordinatorDaemonId } : {}
19171
19259
  });
19260
+ try {
19261
+ recordTaskDispatchedLedger(ctx, delivery.id);
19262
+ } catch {
19263
+ }
19172
19264
  let dispatchPromise;
19173
19265
  try {
19174
19266
  dispatchPromise = Promise.resolve(dispatchThunk());
@@ -19232,7 +19324,7 @@ function resolveClaimingSessionTranscriptProfile(components, sessionId) {
19232
19324
  return void 0;
19233
19325
  }
19234
19326
  }
19235
- function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
19327
+ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType, routingDecision) {
19236
19328
  const mesh = getMeshWithCache(components, meshId);
19237
19329
  const node = mesh?.nodes.find((n) => meshNodeIdMatches(n, nodeId));
19238
19330
  if (isWorkspaceAutoFastForwardInFlight(readNonEmptyString(node?.workspace))) {
@@ -19309,6 +19401,24 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19309
19401
  return false;
19310
19402
  }
19311
19403
  LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
19404
+ try {
19405
+ appendLedgerEntry(meshId, {
19406
+ kind: "task_claimed",
19407
+ nodeId,
19408
+ sessionId,
19409
+ providerType,
19410
+ taskId: task.id,
19411
+ payload: {
19412
+ taskId: task.id,
19413
+ ...task.missionId ? { missionId: task.missionId } : {},
19414
+ nodeId,
19415
+ sessionId,
19416
+ providerType,
19417
+ claimedAt: (/* @__PURE__ */ new Date()).toISOString()
19418
+ }
19419
+ });
19420
+ } catch {
19421
+ }
19312
19422
  retractActionableSkipIfPreviouslyNotified(meshId, task.id);
19313
19423
  beginTaskDispatchInFlight(meshId, task.id);
19314
19424
  const silentIdlePushOnDispatch = resolveCoordinatorIdlePushPolicy(mesh?.policy) === "auto_silent_on_dispatch";
@@ -19346,7 +19456,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19346
19456
  task,
19347
19457
  transport: "remote",
19348
19458
  ...sourceCoordinatorSessionId ? { sourceCoordinatorSessionId } : {},
19349
- ...localDaemonIdForDispatch ? { sourceCoordinatorDaemonId: localDaemonIdForDispatch } : {}
19459
+ ...localDaemonIdForDispatch ? { sourceCoordinatorDaemonId: localDaemonIdForDispatch } : {},
19460
+ ...routingDecision ? { routingDecision } : {}
19350
19461
  },
19351
19462
  // Warmup-aware deadline: this dispatch can be the FIRST command to a
19352
19463
  // peer whose mesh DataChannel is still opening — charge the cold-open
@@ -19413,7 +19524,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19413
19524
  task,
19414
19525
  transport: "local",
19415
19526
  ...readNonEmptyString(task.sourceCoordinatorSessionId) ? { sourceCoordinatorSessionId: readNonEmptyString(task.sourceCoordinatorSessionId) } : {},
19416
- ...localCoordinatorDaemonId() ? { sourceCoordinatorDaemonId: localCoordinatorDaemonId() } : {}
19527
+ ...localCoordinatorDaemonId() ? { sourceCoordinatorDaemonId: localCoordinatorDaemonId() } : {},
19528
+ ...routingDecision ? { routingDecision } : {}
19417
19529
  }
19418
19530
  );
19419
19531
  return true;
@@ -19851,11 +19963,16 @@ function recordAutoLaunchEvent(meshId, args) {
19851
19963
  nodeId: args.nodeId,
19852
19964
  sessionId: args.sessionId,
19853
19965
  providerType: args.providerType,
19966
+ // (B) promote taskId so this entry joins the task lifecycle timeline.
19967
+ ...args.taskId ? { taskId: args.taskId } : {},
19854
19968
  payload: {
19855
19969
  phase: args.phase,
19856
19970
  taskId: args.taskId,
19857
19971
  reason: args.reason,
19858
- error: args.error
19972
+ error: args.error,
19973
+ // (D) resolved execution profile for the spawned worker.
19974
+ ...args.model ? { resolvedModel: args.model } : {},
19975
+ ...args.thinkingLevel ? { resolvedThinkingLevel: args.thinkingLevel } : {}
19859
19976
  }
19860
19977
  });
19861
19978
  } catch (e) {
@@ -19877,7 +19994,9 @@ function markAutoLaunch(meshId, taskId, args) {
19877
19994
  providerType: args.providerType,
19878
19995
  sessionId: args.sessionId,
19879
19996
  reason: args.reason,
19880
- error: args.error
19997
+ error: args.error,
19998
+ ...args.model ? { model: args.model } : {},
19999
+ ...args.thinkingLevel ? { thinkingLevel: args.thinkingLevel } : {}
19881
20000
  });
19882
20001
  if (args.status === "skipped") {
19883
20002
  if (isActionableSkipReason(args.reason)) {
@@ -20077,6 +20196,14 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20077
20196
  // pass it through for the 'fitness' strategy's task→slot ranking.
20078
20197
  { bumpCursor: true, task: { difficulty: task.difficulty, requiredTags: task.requiredTags } }
20079
20198
  ).map((c) => c.node);
20199
+ const skippedCandidates = [];
20200
+ const SKIPPED_CANDIDATES_MAX = 12;
20201
+ const markSkip = (nodeIdForSkip, reason, extra) => {
20202
+ markAutoLaunch(meshId, task.id, { status: "skipped", reason, nodeId: nodeIdForSkip, ...extra || {} });
20203
+ if (nodeIdForSkip && skippedCandidates.length < SKIPPED_CANDIDATES_MAX) {
20204
+ skippedCandidates.push({ nodeId: nodeIdForSkip, reason });
20205
+ }
20206
+ };
20080
20207
  for (const node of orderedCandidateNodes) {
20081
20208
  const nodeId = readMeshNodeId(node);
20082
20209
  if (!nodeId) continue;
@@ -20085,50 +20212,50 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20085
20212
  const cooldownUntil = autoLaunchCooldownUntil.get(launchKey) || 0;
20086
20213
  if (cooldownUntil > 0 && now >= cooldownUntil) autoLaunchCooldownUntil.delete(launchKey);
20087
20214
  if (autoLaunchInProgress.has(launchKey)) {
20088
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "auto_launch_in_progress", nodeId });
20215
+ markSkip(nodeId, "auto_launch_in_progress");
20089
20216
  continue;
20090
20217
  }
20091
20218
  if (now < cooldownUntil) {
20092
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "auto_launch_cooldown", nodeId });
20219
+ markSkip(nodeId, "auto_launch_cooldown");
20093
20220
  continue;
20094
20221
  }
20095
20222
  if (isDirtyNode(node)) {
20096
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "dirty_workspace", nodeId });
20223
+ markSkip(nodeId, "dirty_workspace");
20097
20224
  continue;
20098
20225
  }
20099
20226
  if (!isLaunchableNode(node)) {
20100
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_not_launch_ready", nodeId });
20227
+ markSkip(nodeId, "node_not_launch_ready");
20101
20228
  continue;
20102
20229
  }
20103
20230
  if (!isMeshNodeFreshEnoughToLaunch(node, freshnessGate)) {
20104
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_stale_behind_upstream", nodeId });
20231
+ markSkip(nodeId, "node_stale_behind_upstream");
20105
20232
  continue;
20106
20233
  }
20107
20234
  const launchTarget = resolveAutoLaunchTarget(components, node);
20108
20235
  if (launchTarget.mode === "skip") {
20109
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: launchTarget.reason || "auto_launch_unavailable", nodeId });
20236
+ markSkip(nodeId, launchTarget.reason || "auto_launch_unavailable");
20110
20237
  autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
20111
20238
  sweepExpiredCooldowns();
20112
20239
  continue;
20113
20240
  }
20114
20241
  if (nodeHasLiveSessionPendingClaim(components, meshId, nodeId, task, node)) {
20115
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_has_live_session_pending_claim", nodeId });
20242
+ markSkip(nodeId, "node_has_live_session_pending_claim");
20116
20243
  continue;
20117
20244
  }
20118
20245
  if (!isTaskReadonly(task) && nodeHasActiveAssignment(meshId, nodeId)) {
20119
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_has_active_assignment", nodeId });
20246
+ markSkip(nodeId, "node_has_active_assignment");
20120
20247
  continue;
20121
20248
  }
20122
20249
  const maxConcurrentSessions = Number(node?.policy?.maxConcurrentSessions);
20123
20250
  if (Number.isFinite(maxConcurrentSessions) && maxConcurrentSessions >= 0 && liveSessionCountForNode(components, meshId, nodeId) >= maxConcurrentSessions) {
20124
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "max_concurrent_sessions_reached", nodeId });
20251
+ markSkip(nodeId, "max_concurrent_sessions_reached");
20125
20252
  continue;
20126
20253
  }
20127
20254
  autoLaunchInProgress.add(launchKey);
20128
20255
  try {
20129
20256
  const resolved = await resolveUsableProvider(components, nodeId, node, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags });
20130
20257
  if (!resolved.providerType) {
20131
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: resolved.reason || "provider_unusable", nodeId });
20258
+ markSkip(nodeId, resolved.reason || "provider_unusable");
20132
20259
  continue;
20133
20260
  }
20134
20261
  const rawEffectiveModel = typeof task.model === "string" && task.model.trim() ? task.model.trim() : resolved.model;
@@ -20139,7 +20266,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20139
20266
  }
20140
20267
  const providerCap = resolveProviderMaxParallel(resolveNodeCapabilitySlots(node), resolved.providerType);
20141
20268
  if (providerCap !== void 0 && activeProviderAssignedCount(meshId, nodeId, resolved.providerType) >= providerCap) {
20142
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "max_provider_parallel_reached", nodeId, providerType: resolved.providerType });
20269
+ markSkip(nodeId, "max_provider_parallel_reached", { providerType: resolved.providerType });
20143
20270
  continue;
20144
20271
  }
20145
20272
  const launchSettings = {
@@ -20167,7 +20294,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20167
20294
  meshCoordinatorDaemonId: launchTarget.coordinatorDaemonId,
20168
20295
  meshCoordinatorNodeId: nodeId
20169
20296
  };
20170
- markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType });
20297
+ markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20171
20298
  let launchResult2;
20172
20299
  try {
20173
20300
  launchResult2 = await components.dispatchMeshCommand(launchTarget.daemonId, "launch_cli", withStatusProbeMarker({
@@ -20196,12 +20323,12 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20196
20323
  return false;
20197
20324
  }
20198
20325
  const remoteSessionId = readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.id) || readNonEmptyString(payload.runtimeSessionId);
20199
- markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId: remoteSessionId || void 0 });
20326
+ markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId: remoteSessionId || void 0, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20200
20327
  autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
20201
20328
  sweepExpiredCooldowns();
20202
20329
  return true;
20203
20330
  }
20204
- markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType });
20331
+ markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20205
20332
  const launchResult = await components.cliManager.handleCliCommand("launch_cli", {
20206
20333
  cliType: resolved.providerType,
20207
20334
  dir: node.workspace,
@@ -20226,9 +20353,25 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20226
20353
  sweepExpiredCooldowns();
20227
20354
  return false;
20228
20355
  }
20229
- markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId });
20356
+ markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20230
20357
  await waitForLocalSessionReady(components, sessionId);
20231
- tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType);
20358
+ const requiredTags = Array.isArray(task.requiredTags) ? task.requiredTags.filter((t) => !!t) : [];
20359
+ const routingDecision = {
20360
+ source: "autoLaunch",
20361
+ fitnessScore: nodeFitnessForTask(node, { difficulty: task.difficulty, requiredTags: task.requiredTags }),
20362
+ ...skippedCandidates.length ? { skippedCandidates } : {},
20363
+ requiredTagsResult: {
20364
+ required: requiredTags,
20365
+ satisfied: !requiredTags.length || nodeSatisfiesRequiredTags(requiredTags, buildMeshNodeCapabilityTags(node, resolved.providerType)),
20366
+ missing: requiredTags.filter((t) => !buildMeshNodeCapabilityTags(node, resolved.providerType).includes(t))
20367
+ },
20368
+ resolvedProviderType: resolved.providerType,
20369
+ ...effectiveModel ? { resolvedModel: effectiveModel } : {},
20370
+ ...effectiveThinkingLevel ? { resolvedThinkingLevel: effectiveThinkingLevel } : {},
20371
+ ...task.difficulty ? { resolvedDifficulty: String(task.difficulty) } : {},
20372
+ ...resolved.reason ? { reason: resolved.reason } : {}
20373
+ };
20374
+ tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType, routingDecision);
20232
20375
  return true;
20233
20376
  } catch (e) {
20234
20377
  markAutoLaunch(meshId, task.id, { status: "failed", error: e?.message || String(e), nodeId });
@@ -32701,6 +32844,7 @@ __export(index_exports, {
32701
32844
  killIdeProcess: () => killIdeProcess,
32702
32845
  launchIDE: () => launchIDE,
32703
32846
  launchWithCdp: () => launchWithCdp,
32847
+ ledgerEntryTaskId: () => ledgerEntryTaskId,
32704
32848
  listCoordinatorsForWorkspace: () => listCoordinatorsForWorkspace,
32705
32849
  listHostedCliRuntimes: () => listHostedCliRuntimes,
32706
32850
  listMagiKindPanels: () => listMagiKindPanels,
@@ -77915,6 +78059,7 @@ var V1_CONTRACT_VERSION = "1.0.0";
77915
78059
  killIdeProcess,
77916
78060
  launchIDE,
77917
78061
  launchWithCdp,
78062
+ ledgerEntryTaskId,
77918
78063
  listCoordinatorsForWorkspace,
77919
78064
  listHostedCliRuntimes,
77920
78065
  listMagiKindPanels,