@adhdev/daemon-standalone 1.0.58-rc.46 → 1.0.58-rc.48
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 +173 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -36911,10 +36911,10 @@ var require_dist3 = __commonJS({
|
|
|
36911
36911
|
}
|
|
36912
36912
|
function getDaemonBuildInfo() {
|
|
36913
36913
|
if (cached2) return cached2;
|
|
36914
|
-
const commit = readInjected(true ? "
|
|
36915
|
-
const commitShort = readInjected(true ? "
|
|
36916
|
-
const version2 = readInjected(true ? "1.0.58-rc.
|
|
36917
|
-
const builtAt = readInjected(true ? "2026-08-
|
|
36914
|
+
const commit = readInjected(true ? "5b9c8b942cc6dec286f5257470292e03f12c53e7" : void 0) ?? "unknown";
|
|
36915
|
+
const commitShort = readInjected(true ? "5b9c8b94" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
36916
|
+
const version2 = readInjected(true ? "1.0.58-rc.48" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
36917
|
+
const builtAt = readInjected(true ? "2026-08-30T09:40:02.587Z" : void 0);
|
|
36918
36918
|
cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
|
|
36919
36919
|
return cached2;
|
|
36920
36920
|
}
|
|
@@ -68137,6 +68137,35 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
68137
68137
|
ledgerReadCache.set(meshId, { entries, cachedAt: Date.now() });
|
|
68138
68138
|
return entries;
|
|
68139
68139
|
}
|
|
68140
|
+
function filteredLedgerCacheKey(opts) {
|
|
68141
|
+
const kinds = opts.kinds ? [...new Set(opts.kinds)].sort() : [];
|
|
68142
|
+
return JSON.stringify([opts.since ?? null, kinds]);
|
|
68143
|
+
}
|
|
68144
|
+
function getCachedFilteredRawEntries(meshId, opts) {
|
|
68145
|
+
const key2 = filteredLedgerCacheKey(opts);
|
|
68146
|
+
let meshCache = filteredLedgerReadCache.get(meshId);
|
|
68147
|
+
if (meshCache) {
|
|
68148
|
+
const now = Date.now();
|
|
68149
|
+
for (const [cachedKey, entry] of meshCache) {
|
|
68150
|
+
if (now - entry.cachedAt >= LEDGER_CACHE_TTL_MS) meshCache.delete(cachedKey);
|
|
68151
|
+
}
|
|
68152
|
+
if (meshCache.size === 0) {
|
|
68153
|
+
filteredLedgerReadCache.delete(meshId);
|
|
68154
|
+
meshCache = void 0;
|
|
68155
|
+
}
|
|
68156
|
+
}
|
|
68157
|
+
const cached5 = meshCache?.get(key2);
|
|
68158
|
+
if (cached5) return cached5.entries;
|
|
68159
|
+
const entries = readLedgerFromStore(meshId, opts);
|
|
68160
|
+
recordLedgerPushdownScan(entries.length);
|
|
68161
|
+
const targetCache = meshCache ?? /* @__PURE__ */ new Map();
|
|
68162
|
+
targetCache.set(key2, { entries, cachedAt: Date.now() });
|
|
68163
|
+
if (!meshCache) filteredLedgerReadCache.set(meshId, targetCache);
|
|
68164
|
+
return entries;
|
|
68165
|
+
}
|
|
68166
|
+
function invalidateFilteredLedgerCache(meshId) {
|
|
68167
|
+
filteredLedgerReadCache.delete(meshId);
|
|
68168
|
+
}
|
|
68140
68169
|
function entryTimeValue(entry) {
|
|
68141
68170
|
const t = new Date(entry.timestamp).getTime();
|
|
68142
68171
|
return Number.isNaN(t) ? NaN : t;
|
|
@@ -68156,19 +68185,24 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
68156
68185
|
return true;
|
|
68157
68186
|
}
|
|
68158
68187
|
function recordLedgerAppend(meshId, newEntries) {
|
|
68188
|
+
invalidateFilteredLedgerCache(meshId);
|
|
68159
68189
|
if (!appendToLedgerCache(meshId, newEntries)) invalidateLedgerCache(meshId);
|
|
68160
68190
|
}
|
|
68161
68191
|
function invalidateLedgerCache(meshId) {
|
|
68162
68192
|
ledgerReadCache.delete(meshId);
|
|
68193
|
+
invalidateFilteredLedgerCache(meshId);
|
|
68163
68194
|
}
|
|
68164
68195
|
function clearLedgerImportFlag(meshId) {
|
|
68165
68196
|
ledgerImportDone.delete(meshId);
|
|
68197
|
+
invalidateFilteredLedgerCache(meshId);
|
|
68166
68198
|
}
|
|
68167
68199
|
function invalidateAllLedgerCaches() {
|
|
68168
68200
|
ledgerReadCache.clear();
|
|
68201
|
+
filteredLedgerReadCache.clear();
|
|
68169
68202
|
}
|
|
68170
68203
|
var import_fs12;
|
|
68171
68204
|
var ledgerReadCache;
|
|
68205
|
+
var filteredLedgerReadCache;
|
|
68172
68206
|
var LEDGER_CACHE_TTL_MS;
|
|
68173
68207
|
var ledgerImportStoreRef;
|
|
68174
68208
|
var ledgerImportDone;
|
|
@@ -68183,6 +68217,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
68183
68217
|
init_logger();
|
|
68184
68218
|
init_mesh_ledger_paths();
|
|
68185
68219
|
ledgerReadCache = /* @__PURE__ */ new Map();
|
|
68220
|
+
filteredLedgerReadCache = /* @__PURE__ */ new Map();
|
|
68186
68221
|
LEDGER_CACHE_TTL_MS = 3e4;
|
|
68187
68222
|
ledgerImportDone = /* @__PURE__ */ new Set();
|
|
68188
68223
|
ledgerScanStats = {
|
|
@@ -68791,12 +68826,10 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
68791
68826
|
const kinds = opts?.kind?.length ? opts.kind : void 0;
|
|
68792
68827
|
if (!hasSince && !kinds) return getCachedRawEntries(meshId);
|
|
68793
68828
|
try {
|
|
68794
|
-
|
|
68829
|
+
return getCachedFilteredRawEntries(meshId, {
|
|
68795
68830
|
...hasSince ? { since: opts.since } : {},
|
|
68796
68831
|
...kinds ? { kinds } : {}
|
|
68797
68832
|
});
|
|
68798
|
-
recordLedgerPushdownScan(entries.length);
|
|
68799
|
-
return entries;
|
|
68800
68833
|
} catch {
|
|
68801
68834
|
return getCachedRawEntries(meshId);
|
|
68802
68835
|
}
|
|
@@ -74031,6 +74064,96 @@ ${rendered}`, "utf-8");
|
|
|
74031
74064
|
return { status: "failed", attemptId: presentation.attemptId, stage };
|
|
74032
74065
|
}
|
|
74033
74066
|
}
|
|
74067
|
+
function pushTerminalBucket(buckets, key2, terminal) {
|
|
74068
|
+
if (!key2) return;
|
|
74069
|
+
let bucket2 = buckets.get(key2);
|
|
74070
|
+
if (!bucket2) {
|
|
74071
|
+
bucket2 = { real: [], approval: [] };
|
|
74072
|
+
buckets.set(key2, bucket2);
|
|
74073
|
+
}
|
|
74074
|
+
(terminal.entry.kind === "task_approval_needed" ? bucket2.approval : bucket2.real).push(terminal);
|
|
74075
|
+
}
|
|
74076
|
+
function pushTerminalQuery(queries, key2, query) {
|
|
74077
|
+
if (!key2) return;
|
|
74078
|
+
const existing = queries.get(key2);
|
|
74079
|
+
if (existing) existing.push(query);
|
|
74080
|
+
else queries.set(key2, [query]);
|
|
74081
|
+
}
|
|
74082
|
+
function earlierTerminal(a, b) {
|
|
74083
|
+
if (!a) return b;
|
|
74084
|
+
if (!b) return a;
|
|
74085
|
+
return a.order <= b.order ? a : b;
|
|
74086
|
+
}
|
|
74087
|
+
function buildMeshActiveWorkLedgerSnapshot(ledgerEntries, options = {}) {
|
|
74088
|
+
const timestampByEntry = /* @__PURE__ */ new Map();
|
|
74089
|
+
for (const entry of ledgerEntries) timestampByEntry.set(entry, new Date(entry.timestamp).getTime());
|
|
74090
|
+
const entries = ledgerEntries.slice().sort((a, b) => timestampByEntry.get(a) - timestampByEntry.get(b));
|
|
74091
|
+
const taskBuckets = /* @__PURE__ */ new Map();
|
|
74092
|
+
const sessionBuckets = /* @__PURE__ */ new Map();
|
|
74093
|
+
const nodeBuckets = /* @__PURE__ */ new Map();
|
|
74094
|
+
let order = 0;
|
|
74095
|
+
for (const entry of entries) {
|
|
74096
|
+
if (!TERMINAL_LEDGER_KINDS.has(entry.kind) && entry.kind !== "task_approval_needed") continue;
|
|
74097
|
+
const timestampMs = timestampByEntry.get(entry);
|
|
74098
|
+
if (!Number.isFinite(timestampMs)) continue;
|
|
74099
|
+
const indexed = { entry, timestampMs, order: order++ };
|
|
74100
|
+
const taskId = readString7(entry.payload?.taskId);
|
|
74101
|
+
if (taskId) {
|
|
74102
|
+
pushTerminalBucket(taskBuckets, taskId, indexed);
|
|
74103
|
+
} else {
|
|
74104
|
+
pushTerminalBucket(sessionBuckets, readString7(entry.sessionId), indexed);
|
|
74105
|
+
pushTerminalBucket(nodeBuckets, machineCoreFromDaemonId(entry.nodeId), indexed);
|
|
74106
|
+
}
|
|
74107
|
+
}
|
|
74108
|
+
return {
|
|
74109
|
+
entries,
|
|
74110
|
+
matchDirectDispatchTerminals(dispatches) {
|
|
74111
|
+
const sortedDispatches = dispatches.slice().sort((a, b) => timestampByEntry.get(a) - timestampByEntry.get(b));
|
|
74112
|
+
const taskQueries = /* @__PURE__ */ new Map();
|
|
74113
|
+
const sessionQueries = /* @__PURE__ */ new Map();
|
|
74114
|
+
const nodeQueries = /* @__PURE__ */ new Map();
|
|
74115
|
+
for (const dispatch of sortedDispatches) {
|
|
74116
|
+
const timestampMs = timestampByEntry.get(dispatch) ?? new Date(dispatch.timestamp).getTime();
|
|
74117
|
+
if (!Number.isFinite(timestampMs)) continue;
|
|
74118
|
+
const query = { dispatch, timestampMs };
|
|
74119
|
+
pushTerminalQuery(taskQueries, directDispatchTaskId(dispatch), query);
|
|
74120
|
+
const sessionId = readString7(dispatch.sessionId);
|
|
74121
|
+
if (dispatch.sessionId) pushTerminalQuery(sessionQueries, sessionId, query);
|
|
74122
|
+
else pushTerminalQuery(nodeQueries, machineCoreFromDaemonId(dispatch.nodeId), query);
|
|
74123
|
+
}
|
|
74124
|
+
const realByDispatch = /* @__PURE__ */ new Map();
|
|
74125
|
+
const approvalByDispatch = /* @__PURE__ */ new Map();
|
|
74126
|
+
const resolve32 = (queries, buckets, bucketKind, output) => {
|
|
74127
|
+
for (const [key2, bucketQueries] of queries) {
|
|
74128
|
+
const terminals = buckets.get(key2)?.[bucketKind];
|
|
74129
|
+
if (!terminals?.length) continue;
|
|
74130
|
+
let cursor = 0;
|
|
74131
|
+
for (const query of bucketQueries) {
|
|
74132
|
+
while (cursor < terminals.length) {
|
|
74133
|
+
options.onTerminalProbe?.();
|
|
74134
|
+
if (terminals[cursor].timestampMs >= query.timestampMs) break;
|
|
74135
|
+
cursor += 1;
|
|
74136
|
+
}
|
|
74137
|
+
const candidate = terminals[cursor];
|
|
74138
|
+
if (candidate) output.set(query.dispatch, earlierTerminal(output.get(query.dispatch), candidate));
|
|
74139
|
+
}
|
|
74140
|
+
}
|
|
74141
|
+
};
|
|
74142
|
+
resolve32(taskQueries, taskBuckets, "real", realByDispatch);
|
|
74143
|
+
resolve32(sessionQueries, sessionBuckets, "real", realByDispatch);
|
|
74144
|
+
resolve32(nodeQueries, nodeBuckets, "real", realByDispatch);
|
|
74145
|
+
resolve32(taskQueries, taskBuckets, "approval", approvalByDispatch);
|
|
74146
|
+
resolve32(sessionQueries, sessionBuckets, "approval", approvalByDispatch);
|
|
74147
|
+
resolve32(nodeQueries, nodeBuckets, "approval", approvalByDispatch);
|
|
74148
|
+
const result = /* @__PURE__ */ new Map();
|
|
74149
|
+
for (const dispatch of sortedDispatches) {
|
|
74150
|
+
const selected = realByDispatch.get(dispatch) || approvalByDispatch.get(dispatch);
|
|
74151
|
+
if (selected) result.set(dispatch, selected.entry);
|
|
74152
|
+
}
|
|
74153
|
+
return result;
|
|
74154
|
+
}
|
|
74155
|
+
};
|
|
74156
|
+
}
|
|
74034
74157
|
function readString7(value) {
|
|
74035
74158
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
74036
74159
|
}
|
|
@@ -74102,13 +74225,6 @@ ${rendered}`, "utf-8");
|
|
|
74102
74225
|
function directDispatchTaskId(entry) {
|
|
74103
74226
|
return readString7(entry.payload?.taskId) || entry.id;
|
|
74104
74227
|
}
|
|
74105
|
-
function terminalMatchesDispatch(terminal, dispatch, taskId) {
|
|
74106
|
-
const terminalTaskId = readString7(terminal.payload?.taskId);
|
|
74107
|
-
if (terminalTaskId && terminalTaskId === taskId) return true;
|
|
74108
|
-
if (terminalTaskId && terminalTaskId !== taskId) return false;
|
|
74109
|
-
if (dispatch.sessionId && sessionIdsEquivalent(terminal.sessionId, dispatch.sessionId)) return true;
|
|
74110
|
-
return Boolean(dispatch.nodeId && daemonIdsEquivalent(terminal.nodeId, dispatch.nodeId) && !dispatch.sessionId);
|
|
74111
|
-
}
|
|
74112
74228
|
function statusFromTerminal(entry) {
|
|
74113
74229
|
if (entry.kind === "task_approval_needed") return "awaiting_approval";
|
|
74114
74230
|
if (entry.kind === "task_question_pending") return "awaiting_choice";
|
|
@@ -74125,8 +74241,7 @@ ${rendered}`, "utf-8");
|
|
|
74125
74241
|
}
|
|
74126
74242
|
function buildLedgerDirectDispatchRecord(dispatch, ctx) {
|
|
74127
74243
|
const taskId = directDispatchTaskId(dispatch);
|
|
74128
|
-
const
|
|
74129
|
-
const terminal = matching.find((entry) => entry.kind !== "task_approval_needed") || matching[0];
|
|
74244
|
+
const terminal = ctx.terminal;
|
|
74130
74245
|
const terminalStatus = terminal ? statusFromTerminal(terminal) : void 0;
|
|
74131
74246
|
const live = sessionStatusFromNodes(ctx.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
74132
74247
|
const status = terminalStatus || live.status || "assigned";
|
|
@@ -74227,6 +74342,8 @@ ${rendered}`, "utf-8");
|
|
|
74227
74342
|
}
|
|
74228
74343
|
function buildMeshActiveWork(opts) {
|
|
74229
74344
|
const now = opts.now ?? Date.now();
|
|
74345
|
+
const ledgerSnapshot = opts.ledgerSnapshot ?? buildMeshActiveWorkLedgerSnapshot(opts.ledgerEntries || []);
|
|
74346
|
+
const ledgerEntries = ledgerSnapshot.entries;
|
|
74230
74347
|
const records = [];
|
|
74231
74348
|
const staleDirectWork = [];
|
|
74232
74349
|
const terminalDirectWork = [];
|
|
@@ -74237,7 +74354,7 @@ ${rendered}`, "utf-8");
|
|
|
74237
74354
|
const queueNodeId = task.assignedNodeId || task.targetNodeId;
|
|
74238
74355
|
const queueSessionId = task.assignedSessionId || task.targetSessionId;
|
|
74239
74356
|
const queueLive = task.status === "assigned" ? sessionStatusFromNodes(opts.nodes, queueNodeId ?? void 0, queueSessionId ?? void 0) : {};
|
|
74240
|
-
const queueTerminalAuthority = task.status === "assigned" && hasTerminalLedgerAuthorityForTask(
|
|
74357
|
+
const queueTerminalAuthority = task.status === "assigned" && hasTerminalLedgerAuthorityForTask(ledgerEntries, task.id);
|
|
74241
74358
|
let queueStatus = !queueTerminalAuthority && (queueLive.status === "awaiting_approval" || queueLive.status === "awaiting_choice" || queueLive.status === "generating") ? queueLive.status : task.status;
|
|
74242
74359
|
const turnOverlay = task.status === "assigned" ? turnProjectionActiveWorkStatus(opts.meshId, task.id) : null;
|
|
74243
74360
|
if (turnOverlay) queueStatus = turnOverlay.status;
|
|
@@ -74267,7 +74384,7 @@ ${rendered}`, "utf-8");
|
|
|
74267
74384
|
const dbStatus = dispatch.status;
|
|
74268
74385
|
const isTerminal = dbStatus === "completed" || dbStatus === "failed" || dbStatus === "stale";
|
|
74269
74386
|
const turnOverlay = isTerminal ? null : turnProjectionActiveWorkStatus(opts.meshId, dispatch.taskId);
|
|
74270
|
-
const directTerminalAuthority = !isTerminal && hasTerminalLedgerAuthorityForTask(
|
|
74387
|
+
const directTerminalAuthority = !isTerminal && hasTerminalLedgerAuthorityForTask(ledgerEntries, dispatch.taskId);
|
|
74271
74388
|
const liveStatus = directTerminalAuthority ? void 0 : live.status;
|
|
74272
74389
|
const status = isTerminal ? dbStatus === "completed" ? "idle" : "failed" : turnOverlay?.status || liveStatus || (dbStatus === "acked" ? "generating" : "assigned");
|
|
74273
74390
|
const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
|
|
@@ -74311,12 +74428,12 @@ ${rendered}`, "utf-8");
|
|
|
74311
74428
|
}
|
|
74312
74429
|
records.push(record2);
|
|
74313
74430
|
}
|
|
74314
|
-
const
|
|
74315
|
-
const
|
|
74316
|
-
for (const dispatch of
|
|
74431
|
+
const ledgerDispatches = ledgerEntries.filter(isDirectDispatch);
|
|
74432
|
+
const terminalByDispatch = ledgerSnapshot.matchDirectDispatchTerminals(ledgerDispatches);
|
|
74433
|
+
for (const dispatch of ledgerDispatches) {
|
|
74317
74434
|
if (dbTaskIds.has(directDispatchTaskId(dispatch))) continue;
|
|
74318
74435
|
if (queueTaskIds.has(directDispatchTaskId(dispatch))) continue;
|
|
74319
|
-
const { record: record2, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, {
|
|
74436
|
+
const { record: record2, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, { terminal: terminalByDispatch.get(dispatch), nodes: opts.nodes, now });
|
|
74320
74437
|
if (terminalRow) {
|
|
74321
74438
|
terminalDirectWork.push(record2);
|
|
74322
74439
|
if (opts.includeTerminalDirect !== true) continue;
|
|
@@ -74328,11 +74445,11 @@ ${rendered}`, "utf-8");
|
|
|
74328
74445
|
records.push(record2);
|
|
74329
74446
|
}
|
|
74330
74447
|
} else {
|
|
74331
|
-
const
|
|
74332
|
-
const
|
|
74333
|
-
for (const dispatch of
|
|
74448
|
+
const ledgerDispatches = ledgerEntries.filter(isDirectDispatch);
|
|
74449
|
+
const terminalByDispatch = ledgerSnapshot.matchDirectDispatchTerminals(ledgerDispatches);
|
|
74450
|
+
for (const dispatch of ledgerDispatches) {
|
|
74334
74451
|
if (queueTaskIds.has(directDispatchTaskId(dispatch))) continue;
|
|
74335
|
-
const { record: record2, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, {
|
|
74452
|
+
const { record: record2, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, { terminal: terminalByDispatch.get(dispatch), nodes: opts.nodes, now });
|
|
74336
74453
|
if (terminalRow) {
|
|
74337
74454
|
terminalDirectWork.push(record2);
|
|
74338
74455
|
if (opts.includeTerminalDirect !== true) continue;
|
|
@@ -74374,6 +74491,7 @@ ${rendered}`, "utf-8");
|
|
|
74374
74491
|
meshId: opts.meshId,
|
|
74375
74492
|
queue: opts.queue,
|
|
74376
74493
|
ledgerEntries: opts.ledgerEntries,
|
|
74494
|
+
ledgerSnapshot: opts.ledgerSnapshot,
|
|
74377
74495
|
directDispatches: opts.directDispatches,
|
|
74378
74496
|
nodes: opts.nodes,
|
|
74379
74497
|
now,
|
|
@@ -74526,13 +74644,13 @@ ${rendered}`, "utf-8");
|
|
|
74526
74644
|
${lines.join("\n")}
|
|
74527
74645
|
The mesh has no work in flight. For each mission, decide its outcome: continue it (enqueue/dispatch the remaining work) or close it with mesh_mission_upsert(mission_id, status: "completed" | "abandoned"). Do not leave a finished mission in 'active'. This is a one-time reminder.`;
|
|
74528
74646
|
}
|
|
74529
|
-
function maybeInjectIdleActiveMissionReminder(meshId, coordinator, policy, now = Date.now(), instanceManager) {
|
|
74647
|
+
function maybeInjectIdleActiveMissionReminder(meshId, coordinator, policy, now = Date.now(), instanceManager, sharedLedgerSnapshot) {
|
|
74530
74648
|
try {
|
|
74531
74649
|
if (!coordinator) return false;
|
|
74532
74650
|
if (policy?.idleActiveMissionReminder === false) return false;
|
|
74533
74651
|
const activeMissions = getMeshMissions(meshId, ["active"]);
|
|
74534
74652
|
if (activeMissions.length === 0) return false;
|
|
74535
|
-
const ledgerEntries = readLedgerEntriesByKind(meshId, [
|
|
74653
|
+
const ledgerEntries = sharedLedgerSnapshot?.entries ?? readLedgerEntriesByKind(meshId, [
|
|
74536
74654
|
"task_dispatched",
|
|
74537
74655
|
"task_completed",
|
|
74538
74656
|
"task_failed",
|
|
@@ -74545,6 +74663,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
74545
74663
|
queue: getQueue(meshId),
|
|
74546
74664
|
directDispatches: getActiveDirectDispatches(meshId),
|
|
74547
74665
|
ledgerEntries,
|
|
74666
|
+
ledgerSnapshot: sharedLedgerSnapshot,
|
|
74548
74667
|
now
|
|
74549
74668
|
}).summary;
|
|
74550
74669
|
if (summary.totalActiveCount !== 0 || summary.generatingCount !== 0) return false;
|
|
@@ -87051,6 +87170,7 @@ ${cleanBody}`;
|
|
|
87051
87170
|
}
|
|
87052
87171
|
var DEFAULT_RECONCILE_INTERVAL_MS;
|
|
87053
87172
|
var DEFAULT_AUTO_PRUNE_MIN_AGE_MS;
|
|
87173
|
+
var DEFAULT_AUTO_PRUNE_INTERVAL_MS;
|
|
87054
87174
|
var DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS;
|
|
87055
87175
|
var init_mesh_reconcile_config = __esm2({
|
|
87056
87176
|
"src/mesh/mesh-reconcile-config.ts"() {
|
|
@@ -87059,6 +87179,7 @@ ${cleanBody}`;
|
|
|
87059
87179
|
init_mesh_reconcile_acked_hold();
|
|
87060
87180
|
DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
|
|
87061
87181
|
DEFAULT_AUTO_PRUNE_MIN_AGE_MS = 24 * 60 * 6e4;
|
|
87182
|
+
DEFAULT_AUTO_PRUNE_INTERVAL_MS = 6e4;
|
|
87062
87183
|
DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS = 12e3;
|
|
87063
87184
|
}
|
|
87064
87185
|
});
|
|
@@ -89784,10 +89905,18 @@ ${cleanBody}`;
|
|
|
89784
89905
|
}
|
|
89785
89906
|
}
|
|
89786
89907
|
}
|
|
89787
|
-
async function autoPruneStaleDirectDispatches(components, mesh, selfIds, localDaemonId, minAgeMs) {
|
|
89908
|
+
async function autoPruneStaleDirectDispatches(components, mesh, selfIds, localDaemonId, minAgeMs, sharedLedgerSnapshot) {
|
|
89788
89909
|
const directDispatches = getActiveDirectDispatches(mesh.id);
|
|
89789
|
-
if (directDispatches.length === 0) return;
|
|
89910
|
+
if (directDispatches.length === 0) return void 0;
|
|
89790
89911
|
const liveNodes = await collectLiveNodesWithSessions(components, mesh, selfIds, localDaemonId);
|
|
89912
|
+
const ledgerSnapshot = sharedLedgerSnapshot ?? buildMeshActiveWorkLedgerSnapshot(readLedgerEntriesByKind(mesh.id, [
|
|
89913
|
+
"task_dispatched",
|
|
89914
|
+
"task_completed",
|
|
89915
|
+
"task_failed",
|
|
89916
|
+
"task_stalled",
|
|
89917
|
+
"task_approval_needed",
|
|
89918
|
+
"task_question_pending"
|
|
89919
|
+
]));
|
|
89791
89920
|
const result = pruneStaleDirectDispatches({
|
|
89792
89921
|
meshId: mesh.id,
|
|
89793
89922
|
queue: getQueue(mesh.id),
|
|
@@ -89796,14 +89925,8 @@ ${cleanBody}`;
|
|
|
89796
89925
|
// tail:500 window can be crowded out by unrelated mesh traffic while a still-active
|
|
89797
89926
|
// dispatch's ledger evidence falls out of the window, risking a live dispatch being
|
|
89798
89927
|
// misclassified as an orphan and pruned.
|
|
89799
|
-
ledgerEntries:
|
|
89800
|
-
|
|
89801
|
-
"task_completed",
|
|
89802
|
-
"task_failed",
|
|
89803
|
-
"task_stalled",
|
|
89804
|
-
"task_approval_needed",
|
|
89805
|
-
"task_question_pending"
|
|
89806
|
-
]),
|
|
89928
|
+
ledgerEntries: ledgerSnapshot.entries,
|
|
89929
|
+
ledgerSnapshot,
|
|
89807
89930
|
directDispatches,
|
|
89808
89931
|
nodes: liveNodes,
|
|
89809
89932
|
execute: true,
|
|
@@ -89813,6 +89936,7 @@ ${cleanBody}`;
|
|
|
89813
89936
|
if (result.prunedCount > 0) {
|
|
89814
89937
|
LOG2.info("MeshReconcile", `Auto-pruned ${result.prunedCount} orphaned direct dispatch record(s) for mesh ${mesh.id}`);
|
|
89815
89938
|
}
|
|
89939
|
+
return ledgerSnapshot;
|
|
89816
89940
|
}
|
|
89817
89941
|
async function fetchAssignedTaskChatTail(components, mesh, row, tailLimit = 10) {
|
|
89818
89942
|
const sessionId = readNonEmptyString(row.assignedSessionId);
|
|
@@ -91671,6 +91795,7 @@ ${cleanBody}`;
|
|
|
91671
91795
|
return void 0;
|
|
91672
91796
|
}
|
|
91673
91797
|
})();
|
|
91798
|
+
const activeWorkLedgerSnapshots = /* @__PURE__ */ new Map();
|
|
91674
91799
|
if (dispatchMeshCommand) {
|
|
91675
91800
|
try {
|
|
91676
91801
|
await retryUnresolvedDelegateForwards(components);
|
|
@@ -91828,11 +91953,16 @@ ${cleanBody}`;
|
|
|
91828
91953
|
}
|
|
91829
91954
|
{
|
|
91830
91955
|
const minAgeMs = resolveAutoPruneMinAgeMs();
|
|
91956
|
+
const nowMs = Date.now();
|
|
91831
91957
|
for (const mesh of listMeshes()) {
|
|
91832
91958
|
const selfIds = resolveCoordinatorSelfIds(mesh, drainDaemonIds);
|
|
91833
91959
|
if (!daemonHostsMesh(mesh, selfIds)) continue;
|
|
91960
|
+
const lastRunAt = lastAutoPruneRunAtByMesh.get(mesh.id);
|
|
91961
|
+
if (lastRunAt !== void 0 && nowMs - lastRunAt < DEFAULT_AUTO_PRUNE_INTERVAL_MS) continue;
|
|
91962
|
+
lastAutoPruneRunAtByMesh.set(mesh.id, nowMs);
|
|
91834
91963
|
try {
|
|
91835
|
-
await autoPruneStaleDirectDispatches(components, mesh, selfIds, localDaemonId, minAgeMs);
|
|
91964
|
+
const snapshot = await autoPruneStaleDirectDispatches(components, mesh, selfIds, localDaemonId, minAgeMs);
|
|
91965
|
+
if (snapshot) activeWorkLedgerSnapshots.set(mesh.id, snapshot);
|
|
91836
91966
|
} catch (e) {
|
|
91837
91967
|
LOG2.warn("MeshReconcile", `Auto-prune stale direct failed for mesh ${mesh.id}: ${e?.message || e}`);
|
|
91838
91968
|
}
|
|
@@ -92059,7 +92189,8 @@ ${cleanBody}`;
|
|
|
92059
92189
|
targetCoordinators[0].instance,
|
|
92060
92190
|
getMesh(meshId)?.policy,
|
|
92061
92191
|
void 0,
|
|
92062
|
-
components.instanceManager
|
|
92192
|
+
components.instanceManager,
|
|
92193
|
+
activeWorkLedgerSnapshots.get(meshId)
|
|
92063
92194
|
);
|
|
92064
92195
|
continue;
|
|
92065
92196
|
}
|
|
@@ -92126,6 +92257,7 @@ ${cleanBody}`;
|
|
|
92126
92257
|
var lastDiskRetentionRunAt;
|
|
92127
92258
|
var IDLE_SESSION_REAP_INTERVAL_MS;
|
|
92128
92259
|
var lastIdleSessionReapRunAt;
|
|
92260
|
+
var lastAutoPruneRunAtByMesh;
|
|
92129
92261
|
var init_mesh_reconcile_loop = __esm2({
|
|
92130
92262
|
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
92131
92263
|
"use strict";
|
|
@@ -92164,6 +92296,7 @@ ${cleanBody}`;
|
|
|
92164
92296
|
init_mesh_reconcile_unresolved_forward();
|
|
92165
92297
|
DISK_RETENTION_INTERVAL_MS2 = 60 * 60 * 1e3;
|
|
92166
92298
|
IDLE_SESSION_REAP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
92299
|
+
lastAutoPruneRunAtByMesh = /* @__PURE__ */ new Map();
|
|
92167
92300
|
}
|
|
92168
92301
|
});
|
|
92169
92302
|
var mesh_events_exports = {};
|