maka-agent 0.2.0-dev.76.20261009 → 0.2.0-dev.77.20261009
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +115 -17
- package/node_modules/@maka/runtime/dist/agent-run.js +11 -0
- package/node_modules/@maka/runtime/dist/computer-use-observation-text.js +22 -0
- package/node_modules/@maka/runtime/dist/conversation-copy-agent-output.js +227 -0
- package/node_modules/@maka/runtime/dist/conversation-copy.js +176 -46
- package/node_modules/@maka/runtime/dist/filesystem-worker/resource-resolver.js +3 -1
- package/node_modules/@maka/runtime/dist/owned-child-process.js +209 -0
- package/node_modules/@maka/runtime/dist/owned-process-main.js +183 -0
- package/node_modules/@maka/runtime/dist/pipe-process-driver.js +19 -25
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +124 -3
- package/node_modules/@maka/runtime/dist/session-manager.js +125 -12
- package/node_modules/@maka/runtime/dist/shell-exec.js +18 -20
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +2 -1
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +279 -8
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +209 -37
- package/node_modules/@maka/runtime/dist/tool-availability.js +37 -6
- package/node_modules/@maka/runtime/dist/tool-runtime.js +2 -1
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +44 -13
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -0
- package/node_modules/@maka/runtime-host/dist/client/wsl-environment.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +46 -9
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +47 -40
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +70 -24
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +5 -1
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +41 -5
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +20 -3
- package/node_modules/@maka/runtime-host/dist/server/session-background-activity.js +71 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +8 -4
- package/node_modules/@maka/runtime-host/dist/server/session-interaction-activity.js +78 -0
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +56 -0
- package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +16 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +3 -1
- package/node_modules/@maka/storage/dist/context-offload-store.js +8 -3
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +54 -19
- package/package.json +2 -2
- /package/node_modules/@maka/runtime/dist/workers/{filesystem-worker.js → filesystem-worker.mjs} +0 -0
|
@@ -22,6 +22,15 @@ import { projectAgentGraphSchedule, } from './stream-graph-supervisor-tools.js';
|
|
|
22
22
|
import { stableHash } from './request-shape.js';
|
|
23
23
|
const MAX_RECONCILIATION_ATTEMPTS = 8;
|
|
24
24
|
const SCHEDULE_INTENT_SCHEMA_VERSION = 1;
|
|
25
|
+
// A failed control pass can park the wave it is stopping, and nothing else may
|
|
26
|
+
// wake it. Retry with a capped backoff while that wave is still running.
|
|
27
|
+
const CONTROL_RETRY_INITIAL_DELAY_MS = 100;
|
|
28
|
+
const CONTROL_RETRY_MAX_DELAY_MS = 5_000;
|
|
29
|
+
// The eighth consecutive failure of a stop or a control read lands about 11 s
|
|
30
|
+
// after the first, once the backoff has reached its cap: a fault that clears
|
|
31
|
+
// during the ramp is never reported as stuck, while a persistent one is
|
|
32
|
+
// surfaced instead of leaving the graph parked behind a single failure record.
|
|
33
|
+
const CONTROL_STUCK_FAILURES = 8;
|
|
25
34
|
/**
|
|
26
35
|
* Applies durable supervisor schedule intent to existing and newly
|
|
27
36
|
* materialized graph operators.
|
|
@@ -35,6 +44,39 @@ export async function reconcileAgentGraphSchedule(input) {
|
|
|
35
44
|
if (!Number.isSafeInteger(input.maxNewActivations) || input.maxNewActivations < 0) {
|
|
36
45
|
throw new Error('Agent graph maxNewActivations must be a non-negative safe integer');
|
|
37
46
|
}
|
|
47
|
+
const wake = createReconciliationWake();
|
|
48
|
+
// Install before reading the durable schedule: a commit during any await
|
|
49
|
+
// remains pending until this reconciliation consumes it.
|
|
50
|
+
const unsubscribe = input.subscribeToScheduleChanges?.(wake.notify);
|
|
51
|
+
try {
|
|
52
|
+
return await reconcileSchedule(input, wake);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
unsubscribe?.();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createReconciliationWake() {
|
|
59
|
+
let pending = false;
|
|
60
|
+
let resolve;
|
|
61
|
+
let next = new Promise((done) => {
|
|
62
|
+
resolve = done;
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
notify() {
|
|
66
|
+
pending = true;
|
|
67
|
+
resolve();
|
|
68
|
+
},
|
|
69
|
+
async wait() {
|
|
70
|
+
if (!pending)
|
|
71
|
+
await next;
|
|
72
|
+
pending = false;
|
|
73
|
+
next = new Promise((done) => {
|
|
74
|
+
resolve = done;
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function reconcileSchedule(input, wake) {
|
|
38
80
|
const processedIntentIds = new Set();
|
|
39
81
|
const dispatches = [];
|
|
40
82
|
const stops = [];
|
|
@@ -43,6 +85,11 @@ export async function reconcileAgentGraphSchedule(input) {
|
|
|
43
85
|
// reconciliation; cache them per source graph so repeated snapshot reads do
|
|
44
86
|
// not replay the full committed projection of a closed epoch.
|
|
45
87
|
const selectedResultCache = new Map();
|
|
88
|
+
// Exact stops that already succeeded in this reconciliation; later passes
|
|
89
|
+
// and wakes do not stop the same activation again.
|
|
90
|
+
const resolvedStops = new Set();
|
|
91
|
+
// Consecutive stop failures per target, reset when the target resolves.
|
|
92
|
+
const stopFailureStreaks = new Map();
|
|
46
93
|
let newActivationCount = 0;
|
|
47
94
|
let observedExistingActivationCount = 0;
|
|
48
95
|
let snapshot = await readScheduleSnapshot(input, selectedResultCache);
|
|
@@ -50,10 +97,8 @@ export async function reconcileAgentGraphSchedule(input) {
|
|
|
50
97
|
if (input.abortSignal?.aborted) {
|
|
51
98
|
return reconciliationResult('cancelled', newActivationCount, observedExistingActivationCount, dispatches, stops, [], failures, snapshot);
|
|
52
99
|
}
|
|
53
|
-
const stopWave = await applyScheduleStops(input, snapshot);
|
|
54
|
-
stops
|
|
55
|
-
for (const failure of stopWave.failures)
|
|
56
|
-
recordReconciliationFailure(input, failures, failure);
|
|
100
|
+
const stopWave = await applyScheduleStops(input, snapshot, resolvedStops);
|
|
101
|
+
recordScheduleStops(input, stops, failures, stopFailureStreaks, stopWave);
|
|
57
102
|
if (failures.length > 0) {
|
|
58
103
|
snapshot = await readScheduleSnapshot(input, selectedResultCache);
|
|
59
104
|
return reconciliationResult(input.abortSignal?.aborted ? 'cancelled' : 'failed', newActivationCount, observedExistingActivationCount, dispatches, stops, [], failures, snapshot);
|
|
@@ -196,13 +241,81 @@ export async function reconcileAgentGraphSchedule(input) {
|
|
|
196
241
|
snapshot = await readScheduleSnapshot(input, selectedResultCache);
|
|
197
242
|
return reconciliationResult('failed', newActivationCount, observedExistingActivationCount, dispatches, stops, deferredWork, failures, snapshot);
|
|
198
243
|
}
|
|
199
|
-
|
|
244
|
+
let waveSettled = false;
|
|
245
|
+
const wave = Promise.all(prepared.map(async (work) => {
|
|
200
246
|
const outcome = await dispatchScheduledWork(input, work, snapshot.schedule.revision);
|
|
201
247
|
if (outcome.status === 'rejected') {
|
|
202
248
|
notifySupervisor(input.supervisor?.onReconciliationFailure, outcome.failure);
|
|
203
249
|
}
|
|
204
250
|
return outcome;
|
|
205
|
-
}))
|
|
251
|
+
})).finally(() => {
|
|
252
|
+
waveSettled = true;
|
|
253
|
+
wake.notify();
|
|
254
|
+
});
|
|
255
|
+
let controlReadFailure;
|
|
256
|
+
let controlReadFailureStreak = 0;
|
|
257
|
+
let retryTimer;
|
|
258
|
+
let retryDelay = CONTROL_RETRY_INITIAL_DELAY_MS;
|
|
259
|
+
try {
|
|
260
|
+
// A driver abort does not end this loop: the wave still owns its
|
|
261
|
+
// dispatches, and a child parked behind a failed stop settles only
|
|
262
|
+
// after a retry succeeds.
|
|
263
|
+
while (!waveSettled) {
|
|
264
|
+
await wake.wait();
|
|
265
|
+
clearTimeout(retryTimer);
|
|
266
|
+
retryTimer = undefined;
|
|
267
|
+
if (waveSettled)
|
|
268
|
+
break;
|
|
269
|
+
let retry;
|
|
270
|
+
try {
|
|
271
|
+
const latest = await readScheduleSnapshot(input, selectedResultCache);
|
|
272
|
+
const controls = await applyScheduleStops(input, latest, resolvedStops);
|
|
273
|
+
recordScheduleStops(input, stops, failures, stopFailureStreaks, controls);
|
|
274
|
+
if (controlReadFailure) {
|
|
275
|
+
failures.splice(failures.indexOf(controlReadFailure), 1);
|
|
276
|
+
controlReadFailure = undefined;
|
|
277
|
+
}
|
|
278
|
+
controlReadFailureStreak = 0;
|
|
279
|
+
retry = controls.failures.length > 0;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (controlReadFailure)
|
|
283
|
+
failures.splice(failures.indexOf(controlReadFailure), 1);
|
|
284
|
+
controlReadFailureStreak += 1;
|
|
285
|
+
// Like a stop, a read failure notifies on its first occurrence and,
|
|
286
|
+
// once, when it has persisted long enough to be stuck.
|
|
287
|
+
controlReadFailure =
|
|
288
|
+
controlReadFailureStreak < CONTROL_STUCK_FAILURES
|
|
289
|
+
? { phase: 'schedule', error }
|
|
290
|
+
: {
|
|
291
|
+
phase: 'schedule',
|
|
292
|
+
error: new Error(`Reading graph schedule controls is stuck after ${controlReadFailureStreak} consecutive failures and is still retrying`, { cause: error }),
|
|
293
|
+
};
|
|
294
|
+
failures.push(controlReadFailure);
|
|
295
|
+
if (controlReadFailureStreak === 1 ||
|
|
296
|
+
controlReadFailureStreak === CONTROL_STUCK_FAILURES) {
|
|
297
|
+
notifySupervisor(input.supervisor?.onReconciliationFailure, controlReadFailure);
|
|
298
|
+
}
|
|
299
|
+
retry = true;
|
|
300
|
+
}
|
|
301
|
+
// A failed stop can keep its child, and so this wave, parked until a
|
|
302
|
+
// retry succeeds. Back off instead of waiting for another commit.
|
|
303
|
+
if (retry) {
|
|
304
|
+
retryTimer = setTimeout(wake.notify, retryDelay);
|
|
305
|
+
retryDelay = Math.min(retryDelay * 2, CONTROL_RETRY_MAX_DELAY_MS);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
retryDelay = CONTROL_RETRY_INITIAL_DELAY_MS;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
clearTimeout(retryTimer);
|
|
314
|
+
// This wave remains the sole owner of all dispatched executions, even
|
|
315
|
+
// if a control-store read fails while processing a schedule wake.
|
|
316
|
+
await wave;
|
|
317
|
+
}
|
|
318
|
+
const outcomes = await wave;
|
|
206
319
|
let stale = false;
|
|
207
320
|
for (const outcome of outcomes) {
|
|
208
321
|
if (outcome.status === 'stale') {
|
|
@@ -259,6 +372,7 @@ async function readScheduleSnapshot(input, selectedResultCache) {
|
|
|
259
372
|
assertGraphObservation(input.topology.graphId, observation);
|
|
260
373
|
notifySupervisor(input.supervisor?.onObservation, observation);
|
|
261
374
|
const schedule = projectAgentGraphSchedule(input.topology.graphId, updates);
|
|
375
|
+
notifySupervisor(input.onScheduleObserved, schedule);
|
|
262
376
|
const selectedInputs = schedule.work
|
|
263
377
|
.filter((work) => work.status === 'requested')
|
|
264
378
|
.flatMap((work) => work.selectedResultInputs ?? []);
|
|
@@ -359,7 +473,43 @@ async function resolveSelectedResultRecords(input, selectedInputs, cache) {
|
|
|
359
473
|
function selectedResultKey(selected) {
|
|
360
474
|
return `${selected.sourceGraphId}\u0000${selected.resultId}`;
|
|
361
475
|
}
|
|
362
|
-
|
|
476
|
+
function recordScheduleStops(input, stops, failures, streaks, controls) {
|
|
477
|
+
stops.push(...controls.stops);
|
|
478
|
+
const resolvedTargets = new Set(controls.stops.map((stop) => stop.targetId));
|
|
479
|
+
for (const targetId of resolvedTargets)
|
|
480
|
+
streaks.delete(targetId);
|
|
481
|
+
for (let index = failures.length - 1; index >= 0; index -= 1) {
|
|
482
|
+
const failure = failures[index];
|
|
483
|
+
if (failure.phase === 'stop' && failure.targetId && resolvedTargets.has(failure.targetId)) {
|
|
484
|
+
failures.splice(index, 1);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
for (const failure of controls.failures) {
|
|
488
|
+
const targetId = failure.targetId ?? '';
|
|
489
|
+
const streak = (streaks.get(targetId) ?? 0) + 1;
|
|
490
|
+
streaks.set(targetId, streak);
|
|
491
|
+
// The stuck state travels in the message: supervisor notifications are
|
|
492
|
+
// structured clones and the durable client failure keeps only the reason.
|
|
493
|
+
const recorded = streak < CONTROL_STUCK_FAILURES
|
|
494
|
+
? failure
|
|
495
|
+
: {
|
|
496
|
+
...failure,
|
|
497
|
+
error: new Error(`Stop for graph target ${targetId} is stuck after ${streak} consecutive failures and is still retrying`, { cause: failure.error }),
|
|
498
|
+
};
|
|
499
|
+
// A retried stop that fails again replaces its earlier failure. The
|
|
500
|
+
// supervisor hears about the first failure and, once, about a stuck stop,
|
|
501
|
+
// not about every backoff attempt.
|
|
502
|
+
const previous = failures.findIndex((existing) => existing.phase === 'stop' && existing.targetId === failure.targetId);
|
|
503
|
+
if (previous >= 0)
|
|
504
|
+
failures[previous] = recorded;
|
|
505
|
+
else
|
|
506
|
+
failures.push(recorded);
|
|
507
|
+
if (streak === 1 || streak === CONTROL_STUCK_FAILURES) {
|
|
508
|
+
notifySupervisor(input.supervisor?.onReconciliationFailure, recorded);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
async function applyScheduleStops(input, snapshot, resolvedStops) {
|
|
363
513
|
const requests = new Map();
|
|
364
514
|
for (const stopped of snapshot.schedule.stoppedTargets) {
|
|
365
515
|
requests.set(stopped.targetId, stopped.reason);
|
|
@@ -375,7 +525,7 @@ async function applyScheduleStops(input, snapshot) {
|
|
|
375
525
|
const claimsByIntent = new Map(snapshot.claims.map((claim) => [claim.intentId, claim]));
|
|
376
526
|
const activationTargets = graphActivationTargets(snapshot.observation);
|
|
377
527
|
const immediate = [];
|
|
378
|
-
const
|
|
528
|
+
const targets = [];
|
|
379
529
|
const failures = [];
|
|
380
530
|
for (const [targetId, reason] of requests) {
|
|
381
531
|
const work = workById.get(targetId);
|
|
@@ -386,13 +536,26 @@ async function applyScheduleStops(input, snapshot) {
|
|
|
386
536
|
? activationTargets.get(claim.targetRunId)
|
|
387
537
|
: activationTargets.get(targetId);
|
|
388
538
|
if (activation && isTerminalActivationStatus(activation.status)) {
|
|
389
|
-
|
|
390
|
-
targetId,
|
|
391
|
-
reason,
|
|
392
|
-
status: 'already_terminal',
|
|
539
|
+
const identity = {
|
|
393
540
|
sessionId: activation.sessionId,
|
|
394
|
-
|
|
395
|
-
|
|
541
|
+
runId: activation.activationId,
|
|
542
|
+
turnId: activation.turnId,
|
|
543
|
+
};
|
|
544
|
+
// A durable terminal does not prove that backend cleanup succeeded.
|
|
545
|
+
// Retry the exact stop only while a failed stop retains cleanup for this
|
|
546
|
+
// Run; a settled historical target resolves without a runtime call.
|
|
547
|
+
if (resolvedStops.has(stopTargetKey(targetId, identity)) ||
|
|
548
|
+
!input.stopController.hasPendingAgentGraphActivationStop?.(identity)) {
|
|
549
|
+
immediate.push({
|
|
550
|
+
targetId,
|
|
551
|
+
reason,
|
|
552
|
+
status: 'already_terminal',
|
|
553
|
+
sessionId: activation.sessionId,
|
|
554
|
+
activationId: activation.activationId,
|
|
555
|
+
});
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
targets.push({ targetId, reason, status: 'already_terminal', identity });
|
|
396
559
|
continue;
|
|
397
560
|
}
|
|
398
561
|
if (work && claim) {
|
|
@@ -424,36 +587,37 @@ async function applyScheduleStops(input, snapshot) {
|
|
|
424
587
|
}
|
|
425
588
|
const sessionId = activation?.sessionId ?? claim.targetSessionId;
|
|
426
589
|
const activationId = activation?.activationId ?? claim.targetRunId;
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
reason,
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
590
|
+
const turnId = activation?.turnId ?? claim.targetTurnId;
|
|
591
|
+
const identity = { sessionId, runId: activationId, turnId };
|
|
592
|
+
if (resolvedStops.has(stopTargetKey(targetId, identity))) {
|
|
593
|
+
immediate.push({ targetId, reason, status: 'stopped', sessionId, activationId });
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
targets.push({ targetId, reason, status: 'stopped', identity });
|
|
434
597
|
}
|
|
435
|
-
const settled = await Promise.allSettled(
|
|
436
|
-
await input.stopController.
|
|
437
|
-
|
|
598
|
+
const settled = await Promise.allSettled(targets.map(async (target) => {
|
|
599
|
+
await input.stopController.stopAgentGraphActivation(target.identity, {
|
|
600
|
+
source: 'graph_supervisor',
|
|
601
|
+
});
|
|
602
|
+
return {
|
|
438
603
|
targetId: target.targetId,
|
|
439
604
|
reason: target.reason,
|
|
440
|
-
status:
|
|
441
|
-
sessionId,
|
|
442
|
-
activationId: target.
|
|
443
|
-
}
|
|
605
|
+
status: target.status,
|
|
606
|
+
sessionId: target.identity.sessionId,
|
|
607
|
+
activationId: target.identity.runId,
|
|
608
|
+
};
|
|
444
609
|
}));
|
|
445
610
|
settled.forEach((result, index) => {
|
|
611
|
+
const target = targets[index];
|
|
446
612
|
if (result.status === 'fulfilled') {
|
|
447
|
-
|
|
613
|
+
resolvedStops.add(stopTargetKey(target.targetId, target.identity));
|
|
614
|
+
immediate.push(result.value);
|
|
448
615
|
return;
|
|
449
616
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
targetId: target.targetId,
|
|
455
|
-
error: new Error(`Failed to stop graph supervisor target ${target.targetId} in ${sessionId}`, { cause: result.reason }),
|
|
456
|
-
});
|
|
617
|
+
failures.push({
|
|
618
|
+
phase: 'stop',
|
|
619
|
+
targetId: target.targetId,
|
|
620
|
+
error: new Error(`Failed to stop graph supervisor target ${target.targetId} in ${target.identity.sessionId}`, { cause: result.reason }),
|
|
457
621
|
});
|
|
458
622
|
});
|
|
459
623
|
return {
|
|
@@ -461,6 +625,9 @@ async function applyScheduleStops(input, snapshot) {
|
|
|
461
625
|
failures,
|
|
462
626
|
};
|
|
463
627
|
}
|
|
628
|
+
function stopTargetKey(targetId, identity) {
|
|
629
|
+
return [targetId, identity.sessionId, identity.runId, identity.turnId].join('\u0000');
|
|
630
|
+
}
|
|
464
631
|
async function dispatchScheduledWork(input, prepared, expectedRevision) {
|
|
465
632
|
let admission;
|
|
466
633
|
try {
|
|
@@ -593,7 +760,7 @@ function scheduledWorkIntent(topology, observation, work, provision) {
|
|
|
593
760
|
],
|
|
594
761
|
};
|
|
595
762
|
}
|
|
596
|
-
function scheduledWorkIntentId(graphId, workId) {
|
|
763
|
+
export function scheduledWorkIntentId(graphId, workId) {
|
|
597
764
|
const hash = stableHash({
|
|
598
765
|
schemaVersion: SCHEDULE_INTENT_SCHEMA_VERSION,
|
|
599
766
|
graphId,
|
|
@@ -712,15 +879,20 @@ function orderedRequestedWork(schedule) {
|
|
|
712
879
|
}
|
|
713
880
|
function graphActivationTargets(observation) {
|
|
714
881
|
const targets = new Map();
|
|
882
|
+
const sourceByActivation = new Map(observation.projection.records.map((record) => [record.activationId, record.source]));
|
|
715
883
|
for (const binding of observation.projection.operators) {
|
|
716
884
|
const state = observation.projection.state.operators[binding.operatorId];
|
|
717
885
|
for (const activation of Object.values(state?.activations ?? {})) {
|
|
718
886
|
if (targets.has(activation.activationId)) {
|
|
719
887
|
throw new Error(`Graph activation ${activation.activationId} belongs to multiple operators`);
|
|
720
888
|
}
|
|
889
|
+
const source = sourceByActivation.get(activation.activationId);
|
|
890
|
+
if (!source)
|
|
891
|
+
throw new Error(`Graph activation ${activation.activationId} has no source`);
|
|
721
892
|
targets.set(activation.activationId, {
|
|
722
893
|
sessionId: binding.sessionId,
|
|
723
894
|
activationId: activation.activationId,
|
|
895
|
+
turnId: source.turnId,
|
|
724
896
|
status: activation.status,
|
|
725
897
|
});
|
|
726
898
|
}
|
|
@@ -289,7 +289,11 @@ export class ToolAvailabilityRuntime {
|
|
|
289
289
|
name: TOOL_SEARCH_NAME,
|
|
290
290
|
description: renderInventory(this.groups),
|
|
291
291
|
parameters: z.object({
|
|
292
|
-
query: z
|
|
292
|
+
query: z
|
|
293
|
+
.string()
|
|
294
|
+
.trim()
|
|
295
|
+
.min(1)
|
|
296
|
+
.describe('Search query describing the needed capability. An exact catalog tool name activates only that tool.'),
|
|
293
297
|
limit: z
|
|
294
298
|
.number()
|
|
295
299
|
.int()
|
|
@@ -300,11 +304,7 @@ export class ToolAvailabilityRuntime {
|
|
|
300
304
|
}),
|
|
301
305
|
impl: ({ query, limit = TOOL_SEARCH_DEFAULT_LIMIT }, context) => {
|
|
302
306
|
const normalizedQuery = query.trim();
|
|
303
|
-
const ranked = this.
|
|
304
|
-
.map((result) => String(result.id))
|
|
305
|
-
.filter((name) => !activeTools.has(name))
|
|
306
|
-
.slice(0, TOOL_SEARCH_MAX_LIMIT)
|
|
307
|
-
.filter((name) => this.searchableNames.has(name));
|
|
307
|
+
const ranked = this.rankDeferredSearchHits(normalizedQuery, activeTools);
|
|
308
308
|
const activated = [];
|
|
309
309
|
let blocked;
|
|
310
310
|
let schemaChars = 0;
|
|
@@ -355,6 +355,37 @@ export class ToolAvailabilityRuntime {
|
|
|
355
355
|
},
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Rank deferred tools for one search. An exact catalog name (case-sensitive,
|
|
360
|
+
* then unique case-insensitive) never expands into MiniSearch neighbors, so
|
|
361
|
+
* naming one tool cannot invalidate the prompt-cache prefix with up to
|
|
362
|
+
* `TOOL_SEARCH_DEFAULT_LIMIT` extra schemas.
|
|
363
|
+
*/
|
|
364
|
+
rankDeferredSearchHits(query, activeTools) {
|
|
365
|
+
const exactName = this.resolveExactCatalogName(query);
|
|
366
|
+
if (exactName !== undefined) {
|
|
367
|
+
return this.searchableNames.has(exactName) && !activeTools.has(exactName) ? [exactName] : [];
|
|
368
|
+
}
|
|
369
|
+
return this.searchIndex.search(query)
|
|
370
|
+
.map((result) => String(result.id))
|
|
371
|
+
.filter((name) => !activeTools.has(name))
|
|
372
|
+
.slice(0, TOOL_SEARCH_MAX_LIMIT)
|
|
373
|
+
.filter((name) => this.searchableNames.has(name));
|
|
374
|
+
}
|
|
375
|
+
resolveExactCatalogName(query) {
|
|
376
|
+
if (this.toolsByName.has(query))
|
|
377
|
+
return query;
|
|
378
|
+
const lowered = query.toLowerCase();
|
|
379
|
+
let match;
|
|
380
|
+
for (const name of this.toolsByName.keys()) {
|
|
381
|
+
if (name.toLowerCase() !== lowered)
|
|
382
|
+
continue;
|
|
383
|
+
if (match !== undefined)
|
|
384
|
+
return undefined;
|
|
385
|
+
match = name;
|
|
386
|
+
}
|
|
387
|
+
return match;
|
|
388
|
+
}
|
|
358
389
|
buildDiagnostic(allTools, active, visibleToolSchemaChars) {
|
|
359
390
|
const activeSet = new Set(active);
|
|
360
391
|
const enabledSourceIds = this.groups
|
|
@@ -2152,7 +2152,8 @@ function racePromiseWithAbort(promise, signal) {
|
|
|
2152
2152
|
*/
|
|
2153
2153
|
export function formatDeferredNotLoadedText(toolName) {
|
|
2154
2154
|
return (`Tool "${toolName}" is available but not loaded yet. ` +
|
|
2155
|
-
`Call tool_search
|
|
2155
|
+
`Call tool_search with query "${toolName}" to activate it first, ` +
|
|
2156
|
+
`then call "${toolName}" on a later step.`);
|
|
2156
2157
|
}
|
|
2157
2158
|
/**
|
|
2158
2159
|
* Canonical key for a tool call's args; order-independent so identical calls
|
|
@@ -63,6 +63,7 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
63
63
|
#closed = false;
|
|
64
64
|
#quiesced = false;
|
|
65
65
|
#terminalError;
|
|
66
|
+
#startTask;
|
|
66
67
|
#reconnectTask;
|
|
67
68
|
#reconnectAbort;
|
|
68
69
|
#discardTask = Promise.resolve();
|
|
@@ -96,10 +97,22 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
96
97
|
get current() {
|
|
97
98
|
return this.#current;
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
start() {
|
|
101
|
+
if (this.#closed)
|
|
102
|
+
return Promise.reject(new Error('Runtime Host reconnect lifecycle is closed'));
|
|
103
|
+
if (this.#startTask)
|
|
104
|
+
return this.#startTask;
|
|
105
|
+
const task = deferredTask();
|
|
106
|
+
this.#startTask = task.promise;
|
|
107
|
+
void this.#start().then(task.resolve, task.reject);
|
|
108
|
+
return task.promise;
|
|
109
|
+
}
|
|
110
|
+
async #start() {
|
|
100
111
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
112
|
+
const initial = this.#initial;
|
|
113
|
+
this.#initial = undefined;
|
|
114
|
+
if (initial) {
|
|
115
|
+
this.#install(initial);
|
|
103
116
|
return;
|
|
104
117
|
}
|
|
105
118
|
this.#initialSignal?.throwIfAborted();
|
|
@@ -109,6 +122,8 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
109
122
|
this.#install(await this.#connect(signal));
|
|
110
123
|
}
|
|
111
124
|
catch (error) {
|
|
125
|
+
if (this.#closed)
|
|
126
|
+
throw error;
|
|
112
127
|
const failure = asError(error);
|
|
113
128
|
if ((typeof this.#retryInitialFailure === 'function'
|
|
114
129
|
? this.#retryInitialFailure(failure)
|
|
@@ -198,8 +213,12 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
198
213
|
return this.#suspension(current);
|
|
199
214
|
}
|
|
200
215
|
close() {
|
|
201
|
-
this.#closeTask
|
|
202
|
-
|
|
216
|
+
if (this.#closeTask)
|
|
217
|
+
return this.#closeTask;
|
|
218
|
+
const task = deferredTask();
|
|
219
|
+
this.#closeTask = task.promise;
|
|
220
|
+
void this.#close().then(task.resolve, task.reject);
|
|
221
|
+
return task.promise;
|
|
203
222
|
}
|
|
204
223
|
async #close() {
|
|
205
224
|
if (this.#closed)
|
|
@@ -210,9 +229,11 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
210
229
|
this.#abort.abort();
|
|
211
230
|
const error = new Error('Runtime Host reconnect lifecycle is closed');
|
|
212
231
|
this.#rejectWaiters(error);
|
|
213
|
-
const current = this.#current;
|
|
232
|
+
const current = this.#current ?? this.#initial;
|
|
233
|
+
this.#initial = undefined;
|
|
214
234
|
this.#setCurrent(undefined);
|
|
215
235
|
await current?.close().catch(() => undefined);
|
|
236
|
+
await this.#startTask?.catch(() => undefined);
|
|
216
237
|
await this.#reconnectTask?.catch(() => undefined);
|
|
217
238
|
await this.#discardTask;
|
|
218
239
|
this.#resolveClosed();
|
|
@@ -248,17 +269,18 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
248
269
|
this.#reconnectTask)
|
|
249
270
|
return;
|
|
250
271
|
const reconnectAbort = new AbortController();
|
|
251
|
-
const task =
|
|
272
|
+
const task = deferredTask();
|
|
252
273
|
this.#reconnectAbort = reconnectAbort;
|
|
253
|
-
this.#reconnectTask = task;
|
|
274
|
+
this.#reconnectTask = task.promise;
|
|
275
|
+
void this.#reconnect(AbortSignal.any([this.#abort.signal, reconnectAbort.signal])).then(task.resolve, task.reject);
|
|
254
276
|
const finalize = () => {
|
|
255
|
-
if (this.#reconnectTask === task) {
|
|
277
|
+
if (this.#reconnectTask === task.promise) {
|
|
256
278
|
this.#reconnectTask = undefined;
|
|
257
279
|
this.#reconnectAbort = undefined;
|
|
258
280
|
}
|
|
259
281
|
this.#scheduleReconnect();
|
|
260
282
|
};
|
|
261
|
-
void task.then(finalize, finalize);
|
|
283
|
+
void task.promise.then(finalize, finalize);
|
|
262
284
|
}
|
|
263
285
|
async #reconnect(signal) {
|
|
264
286
|
let attemptedWakeGeneration = this.#wakeGeneration;
|
|
@@ -348,13 +370,13 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
348
370
|
}
|
|
349
371
|
}
|
|
350
372
|
#failPermanently(error) {
|
|
351
|
-
if (this.#terminalError)
|
|
373
|
+
if (this.#closed || this.#terminalError)
|
|
352
374
|
return;
|
|
353
375
|
this.#terminalError = error;
|
|
354
|
-
this.#abort.abort();
|
|
355
376
|
this.#rejectWaiters(error);
|
|
377
|
+
// Acquisition tasks must settle before close can finish joining them.
|
|
378
|
+
void this.close();
|
|
356
379
|
notifyError(this.#onFatalError, error);
|
|
357
|
-
this.#resolveClosed();
|
|
358
380
|
}
|
|
359
381
|
#rejectWaiters(error) {
|
|
360
382
|
for (const waiter of this.#waiters) {
|
|
@@ -364,6 +386,15 @@ class RuntimeHostReconnectLifecycleImpl {
|
|
|
364
386
|
this.#waiters.clear();
|
|
365
387
|
}
|
|
366
388
|
}
|
|
389
|
+
function deferredTask() {
|
|
390
|
+
let resolve;
|
|
391
|
+
let reject;
|
|
392
|
+
const promise = new Promise((resolveTask, rejectTask) => {
|
|
393
|
+
resolve = resolveTask;
|
|
394
|
+
reject = rejectTask;
|
|
395
|
+
});
|
|
396
|
+
return { promise, resolve, reject };
|
|
397
|
+
}
|
|
367
398
|
function notifyError(listener, error) {
|
|
368
399
|
try {
|
|
369
400
|
listener?.(error);
|
|
@@ -35,6 +35,12 @@ export function projectSessionCatalogSummary(session) {
|
|
|
35
35
|
? {}
|
|
36
36
|
: { lastMessagePreview: session.lastMessagePreview }),
|
|
37
37
|
status: session.status,
|
|
38
|
+
...(session.backgroundActivity === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: { backgroundActivity: session.backgroundActivity }),
|
|
41
|
+
...(session.backgroundActivityVersion === undefined
|
|
42
|
+
? {}
|
|
43
|
+
: { backgroundActivityVersion: session.backgroundActivityVersion }),
|
|
38
44
|
...(session.blockedReason === undefined ? {} : { blockedReason: session.blockedReason }),
|
|
39
45
|
...(session.statusUpdatedAt === undefined ? {} : { statusUpdatedAt: session.statusUpdatedAt }),
|
|
40
46
|
...(session.liveRunState === undefined
|
|
@@ -112,6 +112,10 @@ class WslProcessByteStream {
|
|
|
112
112
|
}
|
|
113
113
|
onError(listener) {
|
|
114
114
|
this.child.once('error', listener);
|
|
115
|
+
// Pipe errors are emitted independently of the write callback and the
|
|
116
|
+
// ChildProcess error event. Route them through the transport failure fence.
|
|
117
|
+
this.child.stdin.on('error', listener);
|
|
118
|
+
this.child.stdout.on('error', listener);
|
|
115
119
|
}
|
|
116
120
|
write(chunk) {
|
|
117
121
|
return new Promise((resolve, reject) => {
|
|
@@ -65,7 +65,10 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
65
65
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
66
66
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
67
67
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
68
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
68
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 212;
|
|
69
|
+
// 212: Session catalogs carry `backgroundActivity` and `backgroundActivityVersion`
|
|
70
|
+
// for Host-owned activity and generation-scoped ordering independent of Session
|
|
71
|
+
// revisions and Turn epochs. Older closed decoders reject these fields.
|
|
69
72
|
// 208: Usage queries filter by model call kind. Epoch-207 peers reject the
|
|
70
73
|
// filter or ignore it.
|
|
71
74
|
// 206: `storage.retention.query` and `storage.retention.set` read and change the
|