@adhdev/daemon-core 0.9.82-rc.298 → 0.9.82-rc.299
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 +44 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -11
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events-coordinator.d.ts +5 -0
- package/dist/mesh/mesh-runtime-store.d.ts +4 -0
- package/package.json +2 -2
- package/src/mesh/mesh-events-coordinator.ts +31 -3
- package/src/mesh/mesh-runtime-store.ts +37 -2
|
@@ -2,6 +2,11 @@ import type { DaemonComponents } from '../boot/daemon-lifecycle.js';
|
|
|
2
2
|
export declare function __resetIdleAutoFastForwardForTests(): void;
|
|
3
3
|
export declare function __resetMeshWorkspaceCacheForTests(): void;
|
|
4
4
|
export declare function tryAssignQueueTask(components: DaemonComponents, meshId: string, nodeId: string, sessionId: string, providerType: string): boolean;
|
|
5
|
+
/** Active assignments that hold the one-active-per-node / global-parallel invariant
|
|
6
|
+
* (everything except read-only diagnoses, which run unbounded by the write cap). */
|
|
7
|
+
export declare function activeWriteAssignedCount(meshId: string): number;
|
|
8
|
+
/** Active read-only (live_debug_readonly) assignments, for the read-only safety cap. */
|
|
9
|
+
export declare function activeReadonlyAssignedCount(meshId: string): number;
|
|
5
10
|
export interface MeshQueueTriggerResult {
|
|
6
11
|
success: true;
|
|
7
12
|
meshId: string;
|
|
@@ -30,6 +30,10 @@ export declare class MeshRuntimeStore {
|
|
|
30
30
|
updateQueueEntry(entry: MeshWorkQueueEntry): void;
|
|
31
31
|
findQueueEntryById(meshId: string, id: string): MeshWorkQueueEntry | null;
|
|
32
32
|
hasActiveAssignment(meshId: string, sessionId: string, nodeId: string): boolean;
|
|
33
|
+
/** A session may only execute one task at a time, regardless of task mode. */
|
|
34
|
+
private hasActiveSessionAssignment;
|
|
35
|
+
/** A node may only execute one write task at a time (worktree isolation). */
|
|
36
|
+
private hasActiveNodeAssignment;
|
|
33
37
|
claimNextQueueTask(meshId: string, nodeId: string, sessionId: string, capabilityTags?: string[]): MeshWorkQueueEntry | null;
|
|
34
38
|
getQueueStatsByStatus(meshId: string): {
|
|
35
39
|
status: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhdev/daemon-core",
|
|
3
|
-
"version": "0.9.82-rc.
|
|
3
|
+
"version": "0.9.82-rc.299",
|
|
4
4
|
"description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"author": "vilmire",
|
|
47
47
|
"license": "AGPL-3.0-or-later",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@adhdev/mesh-shared": "0.9.82-rc.
|
|
49
|
+
"@adhdev/mesh-shared": "0.9.82-rc.299",
|
|
50
50
|
"@adhdev/session-host-core": "*",
|
|
51
51
|
"@agentclientprotocol/sdk": "^0.16.1",
|
|
52
52
|
"ajv": "^8.20.0",
|
|
@@ -474,6 +474,19 @@ function activeAssignedCount(meshId: string): number {
|
|
|
474
474
|
return getQueue(meshId, { status: ['assigned'] as any }).length;
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
+
/** Active assignments that hold the one-active-per-node / global-parallel invariant
|
|
478
|
+
* (everything except read-only diagnoses, which run unbounded by the write cap). */
|
|
479
|
+
export function activeWriteAssignedCount(meshId: string): number {
|
|
480
|
+
return getQueue(meshId, { status: ['assigned'] as any })
|
|
481
|
+
.filter(task => task.taskMode !== 'live_debug_readonly').length;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Active read-only (live_debug_readonly) assignments, for the read-only safety cap. */
|
|
485
|
+
export function activeReadonlyAssignedCount(meshId: string): number {
|
|
486
|
+
return getQueue(meshId, { status: ['assigned'] as any })
|
|
487
|
+
.filter(task => task.taskMode === 'live_debug_readonly').length;
|
|
488
|
+
}
|
|
489
|
+
|
|
477
490
|
function nodeHasActiveAssignment(meshId: string, nodeId: string): boolean {
|
|
478
491
|
return getQueue(meshId, { status: ['assigned'] as any }).some(task => task.assignedNodeId === nodeId);
|
|
479
492
|
}
|
|
@@ -628,10 +641,22 @@ async function maybeAutoLaunchOneQueueSession(components: DaemonComponents, mesh
|
|
|
628
641
|
if (!pending.length) return false;
|
|
629
642
|
|
|
630
643
|
const maxParallelTasks = Math.max(1, Math.floor(Number(mesh?.policy?.maxParallelTasks) || 2));
|
|
644
|
+
// Read-only diagnoses carry no isolation/merge cost, so they are exempt from the
|
|
645
|
+
// write-task parallel cap. To prevent runaway auto-launch they get their own,
|
|
646
|
+
// higher safety cap (2x the write cap).
|
|
647
|
+
const maxReadonlyParallelTasks = Math.max(2, maxParallelTasks * 2);
|
|
631
648
|
for (const task of pending) {
|
|
632
|
-
|
|
649
|
+
const isReadonly = task.taskMode === 'live_debug_readonly';
|
|
650
|
+
if (isReadonly) {
|
|
651
|
+
if (activeReadonlyAssignedCount(meshId) >= maxReadonlyParallelTasks) {
|
|
652
|
+
markAutoLaunch(meshId, task.id, { status: 'skipped', reason: 'max_readonly_parallel_tasks_reached' });
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
} else if (activeWriteAssignedCount(meshId) >= maxParallelTasks) {
|
|
656
|
+
// Write tasks are capped; skip this one but keep scanning so a later
|
|
657
|
+
// read-only task in the queue can still launch under its own cap.
|
|
633
658
|
markAutoLaunch(meshId, task.id, { status: 'skipped', reason: 'max_parallel_tasks_reached' });
|
|
634
|
-
|
|
659
|
+
continue;
|
|
635
660
|
}
|
|
636
661
|
if (task.targetSessionId) {
|
|
637
662
|
markAutoLaunch(meshId, task.id, { status: 'skipped', reason: 'target_session_constraint' });
|
|
@@ -687,7 +712,10 @@ async function maybeAutoLaunchOneQueueSession(components: DaemonComponents, mesh
|
|
|
687
712
|
markAutoLaunch(meshId, task.id, { status: 'skipped', reason: localSkipReason, nodeId });
|
|
688
713
|
continue;
|
|
689
714
|
}
|
|
690
|
-
|
|
715
|
+
// Write tasks keep the one-active-per-node invariant (worktree isolation);
|
|
716
|
+
// read-only (live_debug_readonly) diagnoses may auto-launch onto a node
|
|
717
|
+
// that already has an active assignment.
|
|
718
|
+
if (task.taskMode !== 'live_debug_readonly' && nodeHasActiveAssignment(meshId, nodeId)) {
|
|
691
719
|
markAutoLaunch(meshId, task.id, { status: 'skipped', reason: 'node_has_active_assignment', nodeId });
|
|
692
720
|
continue;
|
|
693
721
|
}
|
|
@@ -459,11 +459,37 @@ export class MeshRuntimeStore {
|
|
|
459
459
|
return row !== undefined;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
+
/** A session may only execute one task at a time, regardless of task mode. */
|
|
463
|
+
private hasActiveSessionAssignment(meshId: string, sessionId: string): boolean {
|
|
464
|
+
const row = this.db.prepare(`
|
|
465
|
+
SELECT 1 FROM mesh_queue
|
|
466
|
+
WHERE mesh_id = ? AND status = 'assigned' AND assigned_session_id = ?
|
|
467
|
+
LIMIT 1
|
|
468
|
+
`).get(meshId, sessionId);
|
|
469
|
+
return row !== undefined;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** A node may only execute one write task at a time (worktree isolation). */
|
|
473
|
+
private hasActiveNodeAssignment(meshId: string, nodeId: string): boolean {
|
|
474
|
+
const row = this.db.prepare(`
|
|
475
|
+
SELECT 1 FROM mesh_queue
|
|
476
|
+
WHERE mesh_id = ? AND status = 'assigned' AND assigned_node_id = ?
|
|
477
|
+
LIMIT 1
|
|
478
|
+
`).get(meshId, nodeId);
|
|
479
|
+
return row !== undefined;
|
|
480
|
+
}
|
|
481
|
+
|
|
462
482
|
// O(1) claim: transaction ensures only one session claims a pending task
|
|
463
483
|
claimNextQueueTask(meshId: string, nodeId: string, sessionId: string, capabilityTags: string[] = []): MeshWorkQueueEntry | null {
|
|
464
484
|
return this.transaction(() => {
|
|
465
485
|
this.ensureLegacyQueueMigrated(meshId);
|
|
466
|
-
|
|
486
|
+
// A session executes one task at a time regardless of mode — block early.
|
|
487
|
+
// The node-level conflict is evaluated per-candidate below so that
|
|
488
|
+
// read-only (live_debug_readonly) tasks can claim concurrently on a node
|
|
489
|
+
// that already has an active assignment, while write tasks keep the
|
|
490
|
+
// one-active-per-node invariant (worktree isolation).
|
|
491
|
+
if (this.hasActiveSessionAssignment(meshId, sessionId)) return null;
|
|
492
|
+
const nodeBusy = this.hasActiveNodeAssignment(meshId, nodeId);
|
|
467
493
|
|
|
468
494
|
// Priority: session-targeted > node-targeted (no session) > unconstrained
|
|
469
495
|
const rows = [
|
|
@@ -508,9 +534,18 @@ export class MeshRuntimeStore {
|
|
|
508
534
|
return deps.every(depId => depStatus.get(depId) === 'completed');
|
|
509
535
|
};
|
|
510
536
|
|
|
537
|
+
// Per-candidate node-conflict gate: write tasks (anything other than
|
|
538
|
+
// live_debug_readonly) require an idle node; read-only tasks bypass the
|
|
539
|
+
// node-busy check so N read-only diagnoses can run on one node at once.
|
|
540
|
+
const nodeConflictAllows = (candidate: MeshWorkQueueEntry): boolean => {
|
|
541
|
+
if (candidate.taskMode === 'live_debug_readonly') return true;
|
|
542
|
+
return !nodeBusy;
|
|
543
|
+
};
|
|
544
|
+
|
|
511
545
|
const entry = candidates.find(candidate =>
|
|
512
546
|
nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags)
|
|
513
|
-
&& dependenciesSatisfied(candidate)
|
|
547
|
+
&& dependenciesSatisfied(candidate)
|
|
548
|
+
&& nodeConflictAllows(candidate));
|
|
514
549
|
if (!entry) return null;
|
|
515
550
|
|
|
516
551
|
const now = new Date().toISOString();
|