@adhdev/daemon-core 0.9.82-rc.487 → 0.9.82-rc.488
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/commands/router-refine.d.ts +14 -0
- package/dist/index.js +138 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -8
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-event-forwarding.d.ts +9 -0
- package/dist/mesh/mesh-work-queue.d.ts +11 -0
- package/dist/providers/cli-provider-instance.d.ts +1 -0
- package/dist/providers/provider-instance-manager.d.ts +1 -0
- package/dist/providers/provider-instance.d.ts +1 -0
- package/package.json +3 -3
- package/src/commands/cli-manager.ts +4 -0
- package/src/commands/router-refine.ts +60 -2
- package/src/mesh/mesh-event-forwarding.ts +92 -0
- package/src/mesh/mesh-queue-assignment.ts +6 -0
- package/src/mesh/mesh-runtime-store.ts +5 -0
- package/src/mesh/mesh-work-queue.ts +18 -0
- package/src/providers/cli-provider-instance.ts +17 -6
- package/src/providers/provider-instance-manager.ts +1 -1
- package/src/providers/provider-instance.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -409,10 +409,10 @@ function readInjected(value) {
|
|
|
409
409
|
}
|
|
410
410
|
function getDaemonBuildInfo() {
|
|
411
411
|
if (cached) return cached;
|
|
412
|
-
const commit = readInjected(true ? "
|
|
413
|
-
const commitShort = readInjected(true ? "
|
|
414
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
415
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
412
|
+
const commit = readInjected(true ? "a659fcbbe9641240de42b95804a16b8852c5b4eb" : void 0) ?? "unknown";
|
|
413
|
+
const commitShort = readInjected(true ? "a659fcbb" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
414
|
+
const version = readInjected(true ? "0.9.82-rc.488" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
415
|
+
const builtAt = readInjected(true ? "2026-07-10T03:46:52.780Z" : void 0);
|
|
416
416
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
417
417
|
return cached;
|
|
418
418
|
}
|
|
@@ -6169,6 +6169,7 @@ function reclaimStrandedAssignedTask(meshId, taskId, opts) {
|
|
|
6169
6169
|
delete entry.assignedSessionId;
|
|
6170
6170
|
delete entry.assignedProviderType;
|
|
6171
6171
|
delete entry.dispatchTimestamp;
|
|
6172
|
+
entry.dispatchNonce = (entry.dispatchNonce || 0) + 1;
|
|
6172
6173
|
entry.strandedReclaimCount = reclaims;
|
|
6173
6174
|
entry.updatedAt = now;
|
|
6174
6175
|
endTaskDispatchInFlight(meshId, taskId);
|
|
@@ -7192,6 +7193,7 @@ var init_mesh_runtime_store = __esm({
|
|
|
7192
7193
|
entry.assignedSessionId = sessionId;
|
|
7193
7194
|
if (providerType) entry.assignedProviderType = providerType;
|
|
7194
7195
|
entry.dispatchTimestamp = now;
|
|
7196
|
+
entry.dispatchNonce = (entry.dispatchNonce || 0) + 1;
|
|
7195
7197
|
entry.updatedAt = now;
|
|
7196
7198
|
this.db.prepare(`
|
|
7197
7199
|
UPDATE mesh_queue SET
|
|
@@ -15660,6 +15662,10 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
15660
15662
|
meshId,
|
|
15661
15663
|
nodeId,
|
|
15662
15664
|
taskId: task.id,
|
|
15665
|
+
// REDRIVE-DUP: carry the current dispatch nonce so the worker can echo it
|
|
15666
|
+
// back on generating_started; a reclaim bumps this row's nonce, making an
|
|
15667
|
+
// already-in-flight stale inject rejectable on arrival.
|
|
15668
|
+
...typeof task.dispatchNonce === "number" ? { dispatchNonce: task.dispatchNonce } : {},
|
|
15663
15669
|
...localDaemonIdForDispatch ? { coordinatorDaemonId: localDaemonIdForDispatch } : {},
|
|
15664
15670
|
...sourceCoordinatorSessionId ? { coordinatorSessionId: sourceCoordinatorSessionId } : {}
|
|
15665
15671
|
}
|
|
@@ -15718,6 +15724,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
15718
15724
|
meshId,
|
|
15719
15725
|
nodeId,
|
|
15720
15726
|
taskId: task.id,
|
|
15727
|
+
// REDRIVE-DUP: carry the current dispatch nonce (see remote branch above).
|
|
15728
|
+
...typeof task.dispatchNonce === "number" ? { dispatchNonce: task.dispatchNonce } : {},
|
|
15721
15729
|
...localCoordinatorDaemonId() ? { coordinatorDaemonId: localCoordinatorDaemonId() } : {},
|
|
15722
15730
|
...readNonEmptyString2(task.sourceCoordinatorSessionId) ? { coordinatorSessionId: readNonEmptyString2(task.sourceCoordinatorSessionId) } : {}
|
|
15723
15731
|
}
|
|
@@ -19700,6 +19708,42 @@ function sourceWorkerAutoApproves(components, sessionId) {
|
|
|
19700
19708
|
return false;
|
|
19701
19709
|
}
|
|
19702
19710
|
}
|
|
19711
|
+
function stopStaleMeshWorker(components, args) {
|
|
19712
|
+
const { meshId, sessionId, providerType } = args;
|
|
19713
|
+
const stopArgs = {
|
|
19714
|
+
targetSessionId: sessionId,
|
|
19715
|
+
...providerType ? { cliType: providerType } : {},
|
|
19716
|
+
mode: "hard",
|
|
19717
|
+
reason: "stale_mesh_dispatch_reclaimed"
|
|
19718
|
+
};
|
|
19719
|
+
try {
|
|
19720
|
+
const isLocal = components.cliManager?.adapters?.has?.(sessionId) === true;
|
|
19721
|
+
if (isLocal) {
|
|
19722
|
+
if (!stopArgs.cliType) {
|
|
19723
|
+
const localType = components.cliManager?.adapters?.get?.(sessionId)?.cliType;
|
|
19724
|
+
if (localType) stopArgs.cliType = localType;
|
|
19725
|
+
}
|
|
19726
|
+
Promise.resolve(components.cliManager?.handleCliCommand?.("stop_cli", stopArgs)).catch((e) => LOG.warn("MeshQueue", `Local stop of stale worker ${sessionId} failed: ${e?.message || e}`));
|
|
19727
|
+
return;
|
|
19728
|
+
}
|
|
19729
|
+
let daemonId = args.daemonId;
|
|
19730
|
+
if (!daemonId && args.nodeId) {
|
|
19731
|
+
try {
|
|
19732
|
+
const mesh = getMeshWithCache(components, meshId);
|
|
19733
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.nodeId));
|
|
19734
|
+
daemonId = node ? readMeshNodeDaemonId(node) || void 0 : void 0;
|
|
19735
|
+
} catch {
|
|
19736
|
+
}
|
|
19737
|
+
}
|
|
19738
|
+
if (daemonId && components.dispatchMeshCommand) {
|
|
19739
|
+
Promise.resolve(components.dispatchMeshCommand(daemonId, "stop_cli", stopArgs)).catch((e) => LOG.warn("MeshQueue", `Remote stop of stale worker ${sessionId} on daemon ${daemonId} failed: ${e?.message || e}`));
|
|
19740
|
+
} else {
|
|
19741
|
+
LOG.warn("MeshQueue", `Cannot stop stale worker ${sessionId}: no local adapter and no resolvable remote daemon id (node ${args.nodeId ?? "?"}). Ack already rejected \u2014 task will re-strand-and-fail if the worker completes.`);
|
|
19742
|
+
}
|
|
19743
|
+
} catch (e) {
|
|
19744
|
+
LOG.warn("MeshQueue", `stopStaleMeshWorker error for ${sessionId}: ${e?.message || e}`);
|
|
19745
|
+
}
|
|
19746
|
+
}
|
|
19703
19747
|
function injectMeshSystemMessage(components, args) {
|
|
19704
19748
|
const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
19705
19749
|
const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
@@ -19939,6 +19983,35 @@ function injectMeshSystemMessage(components, args) {
|
|
|
19939
19983
|
}
|
|
19940
19984
|
if (sessionId) {
|
|
19941
19985
|
const startedTaskId = readNonEmptyString2(args.metadataEvent.taskId) || void 0;
|
|
19986
|
+
const startedNonce = typeof args.metadataEvent.dispatchNonce === "number" ? args.metadataEvent.dispatchNonce : void 0;
|
|
19987
|
+
if (startedTaskId && startedNonce !== void 0) {
|
|
19988
|
+
const currentRow = (() => {
|
|
19989
|
+
try {
|
|
19990
|
+
return MeshRuntimeStore.getInstance().findQueueEntryById(args.meshId, startedTaskId);
|
|
19991
|
+
} catch {
|
|
19992
|
+
return null;
|
|
19993
|
+
}
|
|
19994
|
+
})();
|
|
19995
|
+
const currentNonce = typeof currentRow?.dispatchNonce === "number" ? currentRow.dispatchNonce : void 0;
|
|
19996
|
+
if (currentNonce !== void 0 && startedNonce < currentNonce) {
|
|
19997
|
+
LOG.warn("MeshQueue", `Rejecting stale mesh dispatch: task ${startedTaskId} generating_started from session ${sessionId} (node ${nodeId ?? "?"}) carries dispatchNonce ${startedNonce} < current ${currentNonce} \u2014 the task was reclaimed and re-dispatched; stopping this worker to prevent duplicate execution.`);
|
|
19998
|
+
traceMeshEventDrop("stale_dispatch_nonce_rejected", {
|
|
19999
|
+
taskId: startedTaskId,
|
|
20000
|
+
sessionId,
|
|
20001
|
+
nodeId,
|
|
20002
|
+
meshId: args.meshId,
|
|
20003
|
+
event: "agent:generating_started"
|
|
20004
|
+
}, `nonce ${startedNonce} < ${currentNonce}`);
|
|
20005
|
+
stopStaleMeshWorker(components, {
|
|
20006
|
+
meshId: args.meshId,
|
|
20007
|
+
sessionId,
|
|
20008
|
+
nodeId,
|
|
20009
|
+
providerType: readNonEmptyString2(args.metadataEvent.providerType) || readNonEmptyString2(args.metadataEvent.cliType),
|
|
20010
|
+
daemonId: readNonEmptyString2(args.metadataEvent.sourceDaemonId) || readNonEmptyString2(args.metadataEvent.daemonId)
|
|
20011
|
+
});
|
|
20012
|
+
return { success: true, forwarded: 0, suppressed: true, staleDispatchRejected: true };
|
|
20013
|
+
}
|
|
20014
|
+
}
|
|
19942
20015
|
if (startedTaskId) {
|
|
19943
20016
|
updateDirectDispatchStatus(args.meshId, sessionId, "acked", startedTaskId);
|
|
19944
20017
|
} else if (sessionHasActiveAssignment(args.meshId, sessionId)) {
|
|
@@ -20475,6 +20548,7 @@ var init_mesh_event_forwarding = __esm({
|
|
|
20475
20548
|
init_dist();
|
|
20476
20549
|
init_mesh_events_stale();
|
|
20477
20550
|
init_mesh_task_inflight();
|
|
20551
|
+
init_mesh_node_identity();
|
|
20478
20552
|
init_mesh_events_utils();
|
|
20479
20553
|
init_mesh_event_classify();
|
|
20480
20554
|
init_mesh_queue_assignment();
|
|
@@ -45557,6 +45631,10 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
45557
45631
|
// shares this daemon. See isMeshOwnedDelegateSession's post-detach gate.
|
|
45558
45632
|
...assignment.nodeId ? { meshNodeId: assignment.nodeId, meshLastNodeId: assignment.nodeId } : {},
|
|
45559
45633
|
...assignment.taskId ? { meshActiveTaskId: assignment.taskId } : {},
|
|
45634
|
+
// REDRIVE-DUP: task-level dispatch nonce, echoed on generating_started so the
|
|
45635
|
+
// coordinator can reject a stale (reclaimed) dispatch. Cleared with meshActiveTaskId
|
|
45636
|
+
// on detach so a subsequent unrelated turn never re-echoes a prior task's nonce.
|
|
45637
|
+
...typeof assignment.dispatchNonce === "number" ? { meshActiveDispatchNonce: assignment.dispatchNonce } : {},
|
|
45560
45638
|
...assignment.coordinatorDaemonId ? { meshCoordinatorDaemonId: assignment.coordinatorDaemonId } : {},
|
|
45561
45639
|
// Session-level routing anchor: the originating coordinator session, so this
|
|
45562
45640
|
// worker's completion events route back to the exact session that dispatched it.
|
|
@@ -45592,15 +45670,17 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
45592
45670
|
if (!this.settings.meshNodeFor && !this.settings.meshActiveTaskId && !this.settings.meshNodeId) return;
|
|
45593
45671
|
if (this.settings.launchedByCoordinator === true) {
|
|
45594
45672
|
if (!this.settings.meshActiveTaskId) return;
|
|
45595
|
-
const { meshActiveTaskId: meshActiveTaskId2, ...rest2 } = this.settings;
|
|
45673
|
+
const { meshActiveTaskId: meshActiveTaskId2, meshActiveDispatchNonce: meshActiveDispatchNonce2, ...rest2 } = this.settings;
|
|
45596
45674
|
void meshActiveTaskId2;
|
|
45675
|
+
void meshActiveDispatchNonce2;
|
|
45597
45676
|
this.settings = rest2;
|
|
45598
45677
|
this.adapter.updateRuntimeSettings?.(this.settings);
|
|
45599
45678
|
return;
|
|
45600
45679
|
}
|
|
45601
|
-
const { meshNodeFor, meshNodeId, meshActiveTaskId, ...rest } = this.settings;
|
|
45680
|
+
const { meshNodeFor, meshNodeId, meshActiveTaskId, meshActiveDispatchNonce, ...rest } = this.settings;
|
|
45602
45681
|
void meshNodeFor;
|
|
45603
45682
|
void meshActiveTaskId;
|
|
45683
|
+
void meshActiveDispatchNonce;
|
|
45604
45684
|
const lastNodeId = typeof meshNodeId === "string" && meshNodeId.trim() ? meshNodeId.trim() : typeof rest.meshLastNodeId === "string" && rest.meshLastNodeId.trim() ? rest.meshLastNodeId.trim() : void 0;
|
|
45605
45685
|
this.settings = lastNodeId ? { ...rest, meshLastNodeId: lastNodeId } : rest;
|
|
45606
45686
|
this.adapter.updateRuntimeSettings?.(this.settings);
|
|
@@ -47089,6 +47169,9 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47089
47169
|
const resolved = this.completingTurnTaskId();
|
|
47090
47170
|
if (resolved) enrichedEvent.taskId = resolved;
|
|
47091
47171
|
}
|
|
47172
|
+
if (enrichedEvent.dispatchNonce === void 0 && typeof this.settings.meshActiveDispatchNonce === "number") {
|
|
47173
|
+
enrichedEvent.dispatchNonce = this.settings.meshActiveDispatchNonce;
|
|
47174
|
+
}
|
|
47092
47175
|
}
|
|
47093
47176
|
if (this.context?.emitProviderEvent) {
|
|
47094
47177
|
this.context.emitProviderEvent(enrichedEvent);
|
|
@@ -49980,6 +50063,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49980
50063
|
meshId: meshContext.meshId,
|
|
49981
50064
|
...typeof meshContext.nodeId === "string" && meshContext.nodeId ? { nodeId: meshContext.nodeId } : {},
|
|
49982
50065
|
...typeof meshContext.taskId === "string" && meshContext.taskId ? { taskId: meshContext.taskId } : {},
|
|
50066
|
+
// REDRIVE-DUP: carry the dispatch nonce onto the worker session so
|
|
50067
|
+
// its generating_started event echoes it back for the coordinator's
|
|
50068
|
+
// stale-nonce guard.
|
|
50069
|
+
...typeof meshContext.dispatchNonce === "number" ? { dispatchNonce: meshContext.dispatchNonce } : {},
|
|
49983
50070
|
...typeof meshContext.coordinatorDaemonId === "string" && meshContext.coordinatorDaemonId ? { coordinatorDaemonId: meshContext.coordinatorDaemonId } : {}
|
|
49984
50071
|
});
|
|
49985
50072
|
} catch {
|
|
@@ -58914,7 +59001,50 @@ function buildRefineJobHandle(self, args) {
|
|
|
58914
59001
|
}
|
|
58915
59002
|
};
|
|
58916
59003
|
}
|
|
59004
|
+
function slimRefineEventResult(result) {
|
|
59005
|
+
const slim = {};
|
|
59006
|
+
for (const key2 of [
|
|
59007
|
+
"success",
|
|
59008
|
+
"code",
|
|
59009
|
+
"error",
|
|
59010
|
+
"convergenceStatus",
|
|
59011
|
+
"blockedReason",
|
|
59012
|
+
"branch",
|
|
59013
|
+
"into",
|
|
59014
|
+
"terminalKind",
|
|
59015
|
+
"nextStep",
|
|
59016
|
+
"finalBranchConvergenceState"
|
|
59017
|
+
]) {
|
|
59018
|
+
if (result[key2] !== void 0) slim[key2] = result[key2];
|
|
59019
|
+
}
|
|
59020
|
+
if (Array.isArray(result.unreachableSubmoduleCommits)) {
|
|
59021
|
+
slim.unreachableSubmoduleCommits = result.unreachableSubmoduleCommits.map((e) => ({ path: e?.path, autoPublishAllowed: e?.autoPublishAllowed }));
|
|
59022
|
+
}
|
|
59023
|
+
if (result.validationSummary && typeof result.validationSummary === "object") {
|
|
59024
|
+
const vs = result.validationSummary;
|
|
59025
|
+
slim.validationSummary = {
|
|
59026
|
+
status: vs.status,
|
|
59027
|
+
failureCode: vs.failureCode,
|
|
59028
|
+
configSource: vs.configSource,
|
|
59029
|
+
configSourceType: vs.configSourceType,
|
|
59030
|
+
commandsRunCount: Array.isArray(vs.commandsRun) ? vs.commandsRun.length : void 0
|
|
59031
|
+
};
|
|
59032
|
+
}
|
|
59033
|
+
if (result.patchEquivalence && typeof result.patchEquivalence === "object") {
|
|
59034
|
+
const pe = result.patchEquivalence;
|
|
59035
|
+
slim.patchEquivalence = { status: pe.status, equivalent: pe.equivalent };
|
|
59036
|
+
}
|
|
59037
|
+
if (result.submoduleReachability && typeof result.submoduleReachability === "object") {
|
|
59038
|
+
const sr = result.submoduleReachability;
|
|
59039
|
+
slim.submoduleReachability = {
|
|
59040
|
+
checked: Array.isArray(sr.entries) ? sr.entries.length : void 0,
|
|
59041
|
+
unreachable: Array.isArray(sr.unreachable) ? sr.unreachable.length : void 0
|
|
59042
|
+
};
|
|
59043
|
+
}
|
|
59044
|
+
return slim;
|
|
59045
|
+
}
|
|
58917
59046
|
function queueRefineJobEvent(self, event, handle, result) {
|
|
59047
|
+
const slimResult = result ? slimRefineEventResult(result) : void 0;
|
|
58918
59048
|
const metadataEvent = {
|
|
58919
59049
|
source: "refine_mesh_node_async_job",
|
|
58920
59050
|
jobId: handle.jobId,
|
|
@@ -58927,7 +59057,7 @@ function queueRefineJobEvent(self, event, handle, result) {
|
|
|
58927
59057
|
startedAt: handle.startedAt,
|
|
58928
59058
|
completedAt: handle.completedAt,
|
|
58929
59059
|
retryOfJobId: handle.retryOfJobId,
|
|
58930
|
-
...
|
|
59060
|
+
...slimResult ? { result: slimResult } : {}
|
|
58931
59061
|
};
|
|
58932
59062
|
const eventPayload = {
|
|
58933
59063
|
event,
|
|
@@ -58954,7 +59084,7 @@ function queueRefineJobEvent(self, event, handle, result) {
|
|
|
58954
59084
|
startedAt: handle.startedAt,
|
|
58955
59085
|
completedAt: handle.completedAt,
|
|
58956
59086
|
retryOfJobId: handle.retryOfJobId,
|
|
58957
|
-
...
|
|
59087
|
+
...slimResult ? { result: slimResult } : {}
|
|
58958
59088
|
}
|
|
58959
59089
|
);
|
|
58960
59090
|
if (forwarded?.success === true) return;
|