@yu_robotics/remote-cli 1.6.241 → 1.6.242
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/client/MessageHandler.d.ts +5 -2
- package/dist/client/MessageHandler.d.ts.map +1 -1
- package/dist/client/MessageHandler.js +81 -3
- package/dist/client/MessageHandler.js.map +1 -1
- package/dist/maintenance/release-notes.json +1 -1
- package/dist/managed/tools.d.ts +38 -2
- package/dist/managed/tools.d.ts.map +1 -1
- package/dist/scheduling/ScheduleCommand.d.ts +7 -0
- package/dist/scheduling/ScheduleCommand.d.ts.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +11 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduleService.d.ts +50 -0
- package/dist/scheduling/ScheduleService.d.ts.map +1 -1
- package/dist/scheduling/ScheduleService.js +249 -17
- package/dist/scheduling/ScheduleService.js.map +1 -1
- package/dist/scheduling/ScheduleToolScope.d.ts +13 -0
- package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -1
- package/dist/scheduling/ScheduleToolScope.js +33 -0
- package/dist/scheduling/ScheduleToolScope.js.map +1 -1
- package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts +1 -0
- package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts.map +1 -1
- package/dist/scheduling/claude/ClaudeSessionSchedules.js +19 -1
- package/dist/scheduling/claude/ClaudeSessionSchedules.js.map +1 -1
- package/dist/scheduling/toolContract.d.ts +19 -1
- package/dist/scheduling/toolContract.d.ts.map +1 -1
- package/dist/scheduling/toolContract.js +4 -2
- package/dist/scheduling/toolContract.js.map +1 -1
- package/dist/scheduling/types.d.ts +3 -0
- package/dist/scheduling/types.d.ts.map +1 -1
- package/native/prebuilds/darwin-arm64/managed_native.node +0 -0
- package/native/prebuilds/darwin-arm64/manifest.json +1 -1
- package/native/prebuilds/darwin-x64/managed_native.node +0 -0
- package/native/prebuilds/darwin-x64/manifest.json +1 -1
- package/native/prebuilds/win32-arm64/managed_native.node +0 -0
- package/native/prebuilds/win32-arm64/manifest.json +1 -1
- package/native/prebuilds/win32-x64/managed_native.node +0 -0
- package/native/prebuilds/win32-x64/manifest.json +1 -1
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ const ERROR_BYTES = 4096;
|
|
|
51
51
|
const LIVE = new Set(['creating', 'active', 'running']);
|
|
52
52
|
const STATES = new Set([...LIVE, 'completed', 'cancelled', 'interrupted', 'failed']);
|
|
53
53
|
const RESTART_REASON = 'Native schedule interrupted by service restart; not recreated or resumed.';
|
|
54
|
+
const MAX_PURGED_IDS = 10_000;
|
|
54
55
|
function bounded(value, limit) {
|
|
55
56
|
if (Buffer.byteLength(value, 'utf8') <= limit)
|
|
56
57
|
return value;
|
|
@@ -109,6 +110,11 @@ class ScheduleService {
|
|
|
109
110
|
pending = new Map();
|
|
110
111
|
runtimes = new Map();
|
|
111
112
|
retainedCancellations = new Map();
|
|
113
|
+
purged = new Map();
|
|
114
|
+
purges = new Map();
|
|
115
|
+
recordOperations = new Map();
|
|
116
|
+
delivering = new Set();
|
|
117
|
+
refreshes = 0;
|
|
112
118
|
tail = Promise.resolve();
|
|
113
119
|
deliveryTail = Promise.resolve();
|
|
114
120
|
tasks = new Set();
|
|
@@ -209,6 +215,8 @@ class ScheduleService {
|
|
|
209
215
|
if (this.closing || this.fault)
|
|
210
216
|
return;
|
|
211
217
|
const record = this.records.get(id);
|
|
218
|
+
if (!record)
|
|
219
|
+
continue;
|
|
212
220
|
if (record.cancelRequested || !this.current(record)) {
|
|
213
221
|
await this.blockRecovery(record, 'Recovery owner retired or cancellation was requested.');
|
|
214
222
|
continue;
|
|
@@ -381,7 +389,7 @@ class ScheduleService {
|
|
|
381
389
|
});
|
|
382
390
|
}
|
|
383
391
|
create(owner, input) {
|
|
384
|
-
return this.operation(this.createSchedule(owner, input));
|
|
392
|
+
return this.operation(this.recordOperation(input.id, this.createSchedule(owner, input)));
|
|
385
393
|
}
|
|
386
394
|
async createSchedule(owner, input) {
|
|
387
395
|
this.checkReady();
|
|
@@ -415,8 +423,8 @@ class ScheduleService {
|
|
|
415
423
|
this.checkReady();
|
|
416
424
|
if (!this.current(originalOwner))
|
|
417
425
|
throw new Error('Schedule owner is no longer current.');
|
|
418
|
-
if (this.records.has(nativeInput.id))
|
|
419
|
-
throw new Error('Schedule ID already exists.');
|
|
426
|
+
if (this.records.has(nativeInput.id) || this.purged.has(nativeInput.id))
|
|
427
|
+
throw new Error('Schedule ID already exists or was purged.');
|
|
420
428
|
if (this.records.size >= this.maxRecords)
|
|
421
429
|
throw new Error('Schedule catalog is full; history was not pruned.');
|
|
422
430
|
const liveCount = [...this.records.values()].filter(record => LIVE.has(record.state)
|
|
@@ -476,6 +484,9 @@ class ScheduleService {
|
|
|
476
484
|
record.state = 'failed';
|
|
477
485
|
record.error = errorText(error);
|
|
478
486
|
}
|
|
487
|
+
if (error instanceof types_1.NativeScheduleNotAdmittedError && !runtime.handle && !runtime.running.size && !runtime.completed.size) {
|
|
488
|
+
record.creationRefused = true;
|
|
489
|
+
}
|
|
479
490
|
if (!this.fault)
|
|
480
491
|
await this.persist();
|
|
481
492
|
});
|
|
@@ -492,6 +503,176 @@ class ScheduleService {
|
|
|
492
503
|
validateOwner(owner);
|
|
493
504
|
return this.serial(async () => [...this.records.values()].filter(record => sameOwner(record, owner)).map(record => structuredClone(record)));
|
|
494
505
|
}
|
|
506
|
+
/** Cancel first, then erase only verified retired history. No native sweep or
|
|
507
|
+
* recovery admission is implied. Missing/foreign IDs never count as removed. */
|
|
508
|
+
purge(owner, selection) {
|
|
509
|
+
return this.operation(this.purgeSelected(structuredClone(owner), structuredClone(selection)));
|
|
510
|
+
}
|
|
511
|
+
async purgeSelected(owner, selection) {
|
|
512
|
+
this.checkReady();
|
|
513
|
+
validateOwner(owner);
|
|
514
|
+
const selectedIds = await this.serial(async () => {
|
|
515
|
+
if (!this.current(owner))
|
|
516
|
+
throw new Error('Schedule purge owner is no longer current.');
|
|
517
|
+
const value = object(selection, ['ids', 'all']);
|
|
518
|
+
if (value.all !== undefined ? value.all !== true || value.ids !== undefined : !Array.isArray(value.ids)) {
|
|
519
|
+
throw new Error('Select exact schedule IDs or all current-owner schedules.');
|
|
520
|
+
}
|
|
521
|
+
const ids = value.all === true ? [...this.records.values()].filter(record => sameOwner(record, owner)).map(record => record.id)
|
|
522
|
+
: [...value.ids];
|
|
523
|
+
if (ids.length > this.maxRecords || new Set(ids).size !== ids.length)
|
|
524
|
+
throw new Error('Invalid schedule purge selection.');
|
|
525
|
+
ids.forEach(ScheduleCommand_1.validateScheduleId);
|
|
526
|
+
let changed = false;
|
|
527
|
+
for (const id of ids) {
|
|
528
|
+
const record = this.records.get(id);
|
|
529
|
+
if (!record || !sameOwner(record, owner))
|
|
530
|
+
continue;
|
|
531
|
+
record.cancelRequested = true;
|
|
532
|
+
if (record.recovery)
|
|
533
|
+
record.recovery.status = 'blocked';
|
|
534
|
+
this.runtimes.get(id)?.recoveryAbort?.abort();
|
|
535
|
+
changed = true;
|
|
536
|
+
}
|
|
537
|
+
// Persist admission/recovery denial before any external cleanup attempt.
|
|
538
|
+
if (changed)
|
|
539
|
+
await this.persist();
|
|
540
|
+
return ids;
|
|
541
|
+
});
|
|
542
|
+
const result = { selectedIds, removedIds: [], alreadyRemovedIds: [], pending: [], errors: [] };
|
|
543
|
+
for (const id of selectedIds) {
|
|
544
|
+
const previouslyPurged = this.purged.has(id);
|
|
545
|
+
try {
|
|
546
|
+
const record = this.records.get(id);
|
|
547
|
+
const prior = this.purged.get(id);
|
|
548
|
+
if ((!record || !sameOwner(record, owner)) && (!prior || !sameOwner(prior, owner))) {
|
|
549
|
+
throw new Error('Schedule not found for this owner.');
|
|
550
|
+
}
|
|
551
|
+
let task = this.purges.get(id);
|
|
552
|
+
if (!task) {
|
|
553
|
+
task = this.purgeRecord(owner, id);
|
|
554
|
+
this.purges.set(id, task);
|
|
555
|
+
void task.finally(() => { if (this.purges.get(id) === task)
|
|
556
|
+
this.purges.delete(id); }).catch(() => { });
|
|
557
|
+
}
|
|
558
|
+
const outcome = await task;
|
|
559
|
+
if (outcome.status === 'pending')
|
|
560
|
+
result.pending.push({ id, reason: outcome.reason, detail: outcome.detail });
|
|
561
|
+
else
|
|
562
|
+
(outcome.status === 'removed' ? result.removedIds : result.alreadyRemovedIds).push(id);
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
if (!previouslyPurged && this.purged.has(id) && sameOwner(this.purged.get(id), owner))
|
|
566
|
+
result.removedIds.push(id);
|
|
567
|
+
result.errors.push({ id, error: errorText(error) });
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
async purgeRecord(owner, id) {
|
|
573
|
+
const pending = (reason, detail) => ({ status: 'pending', reason, detail });
|
|
574
|
+
this.checkReady();
|
|
575
|
+
if (!this.current(owner))
|
|
576
|
+
throw new Error('Schedule purge owner is no longer current.');
|
|
577
|
+
if (this.purged.has(id))
|
|
578
|
+
return { status: 'alreadyRemoved' };
|
|
579
|
+
const record = this.owned(owner, id);
|
|
580
|
+
const current = () => !this.closing && !this.fault && !this.suspending && this.current(owner)
|
|
581
|
+
&& this.records.get(id) === record && record.cancelRequested === true;
|
|
582
|
+
const busy = () => {
|
|
583
|
+
if (this.recordOperations.has(id) || this.recoveryRun || this.refreshes || this.retainedCancellations.has(id)) {
|
|
584
|
+
return pending('operation_pending', 'Creation, recovery, inspection or cleanup is still pending. Retry these same IDs.');
|
|
585
|
+
}
|
|
586
|
+
if (this.delivering.has(id))
|
|
587
|
+
return pending('delivery_pending', 'An external delivery is already in flight; its outcome cannot be revoked.');
|
|
588
|
+
};
|
|
589
|
+
const active = busy();
|
|
590
|
+
if (active)
|
|
591
|
+
return active;
|
|
592
|
+
if (this.purged.size >= MAX_PURGED_IDS)
|
|
593
|
+
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
594
|
+
const runtime = this.runtimes.get(id);
|
|
595
|
+
// Do not interpret terminal state, an absent handle or a stopped process as
|
|
596
|
+
// native definition absence. Existing cancelRetained owns its stronger proof.
|
|
597
|
+
let retainedVerified = false;
|
|
598
|
+
const clean = !runtime && record.recovery?.handoff === 'clean' && record.recovery.nativeDefinitionAbsent === true;
|
|
599
|
+
if (runtime?.handle && !runtime.stopped) {
|
|
600
|
+
await this.cancel(owner, id);
|
|
601
|
+
}
|
|
602
|
+
else if (!runtime && !record.creationRefused && !clean && record.recovery && this.supportsRetainedCancellation(record)) {
|
|
603
|
+
try {
|
|
604
|
+
await this.recordOperation(id, this.cancelRetained(record));
|
|
605
|
+
retainedVerified = true;
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
// A failed receipt (including error-after-commit) is not absence proof.
|
|
609
|
+
// Exact framework verification may still resolve it without recreating.
|
|
610
|
+
if (!this.options.withPurgeVerification)
|
|
611
|
+
throw error;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (!current())
|
|
615
|
+
throw new Error('Schedule purge context changed during cleanup.');
|
|
616
|
+
const unfinished = busy();
|
|
617
|
+
if (unfinished)
|
|
618
|
+
return unfinished;
|
|
619
|
+
if (runtime?.running.size)
|
|
620
|
+
return pending('occurrence_running', 'Future cancellation does not revoke an already admitted occurrence.');
|
|
621
|
+
if (runtime && (!runtime.stopped || runtime.releaseAdmission))
|
|
622
|
+
return pending('operation_pending', 'Native runtime retirement is unconfirmed.');
|
|
623
|
+
const handleProof = runtime?.removalConfirmed && runtime.handle?.nativeDefinitionAbsent !== false;
|
|
624
|
+
const erase = (evidence) => this.serial(async () => {
|
|
625
|
+
this.checkReady();
|
|
626
|
+
if (!current() || evidence?.status === 'verified' && !evidence.isCurrent())
|
|
627
|
+
throw new Error('Schedule purge evidence expired before persistence.');
|
|
628
|
+
const changed = busy();
|
|
629
|
+
if (changed)
|
|
630
|
+
return changed;
|
|
631
|
+
if (this.purged.size >= MAX_PURGED_IDS)
|
|
632
|
+
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
633
|
+
if (this.runtimes.get(id) !== runtime || runtime?.running.size || runtime && !runtime.stopped
|
|
634
|
+
|| handleProof && runtime?.handle?.nativeDefinitionAbsent === false) {
|
|
635
|
+
return pending('operation_pending', 'Native ownership changed before history removal.');
|
|
636
|
+
}
|
|
637
|
+
// The ID-only owner fence prevents delayed CREATE retries from resurrecting
|
|
638
|
+
// deleted history. Prompts, results and recovery identities are not retained.
|
|
639
|
+
const outputs = [...this.pending].filter(([, entry]) => entry.scheduleId === id);
|
|
640
|
+
this.purged.set(id, ownerOf(record));
|
|
641
|
+
this.records.delete(id);
|
|
642
|
+
this.dropPending(id);
|
|
643
|
+
try {
|
|
644
|
+
await this.persist();
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
this.records.set(id, record);
|
|
648
|
+
this.purged.delete(id);
|
|
649
|
+
for (const [key, entry] of outputs)
|
|
650
|
+
this.pending.set(key, entry);
|
|
651
|
+
throw error;
|
|
652
|
+
}
|
|
653
|
+
this.runtimes.delete(id);
|
|
654
|
+
return { status: 'removed' };
|
|
655
|
+
});
|
|
656
|
+
if (record.creationRefused || clean || retainedVerified || handleProof)
|
|
657
|
+
return erase();
|
|
658
|
+
if (!this.options.withPurgeVerification)
|
|
659
|
+
return pending('native_absence_unknown', 'Native absence and execution retirement require exact provider verification; terminal state and current-session absence alone are insufficient.');
|
|
660
|
+
let accepted = false;
|
|
661
|
+
// The framework keeps its native scope/lease open until accept() finishes
|
|
662
|
+
// persisting removal. A receipt returned after closing that lease is unsafe.
|
|
663
|
+
return this.options.withPurgeVerification(structuredClone(record), { isCurrent: current }, async (evidence) => {
|
|
664
|
+
if (accepted)
|
|
665
|
+
throw new Error('Purge verification was already consumed.');
|
|
666
|
+
accepted = true;
|
|
667
|
+
if (!current())
|
|
668
|
+
throw new Error('Schedule purge context changed during verification.');
|
|
669
|
+
if (evidence.status === 'unresolved')
|
|
670
|
+
return pending(evidence.reason, bounded(evidence.detail, ERROR_BYTES));
|
|
671
|
+
if (evidence.status !== 'verified' || typeof evidence.isCurrent !== 'function')
|
|
672
|
+
throw new Error('Invalid native purge verification.');
|
|
673
|
+
return erase(evidence);
|
|
674
|
+
});
|
|
675
|
+
}
|
|
495
676
|
/** Includes terminal jobs whose native process exit is still unconfirmed. */
|
|
496
677
|
hasActiveSchedules(threadId) {
|
|
497
678
|
return [...this.records.values()].some(record => (!threadId || record.threadId === threadId)
|
|
@@ -545,7 +726,8 @@ class ScheduleService {
|
|
|
545
726
|
}
|
|
546
727
|
/** User-requested native reconciliation only; no background polling is installed. */
|
|
547
728
|
refresh(owner) {
|
|
548
|
-
|
|
729
|
+
this.refreshes++;
|
|
730
|
+
return this.operation(this.refreshNative(owner).finally(() => { this.refreshes--; }));
|
|
549
731
|
}
|
|
550
732
|
async refreshNative(owner) {
|
|
551
733
|
this.checkReady();
|
|
@@ -588,7 +770,7 @@ class ScheduleService {
|
|
|
588
770
|
}
|
|
589
771
|
}
|
|
590
772
|
cancel(owner, id) {
|
|
591
|
-
return this.operation(this.cancelSchedule(owner, id));
|
|
773
|
+
return this.operation(this.recordOperation(id, this.cancelSchedule(owner, id)));
|
|
592
774
|
}
|
|
593
775
|
async cancelSchedule(owner, id) {
|
|
594
776
|
this.checkReady();
|
|
@@ -930,8 +1112,10 @@ class ScheduleService {
|
|
|
930
1112
|
try {
|
|
931
1113
|
const handle = await runtime.ready;
|
|
932
1114
|
if (handle && !runtime.stopped) {
|
|
933
|
-
if (LIVE.has(this.records.get(id).state) || handle.cancellationKeepsRunning)
|
|
1115
|
+
if (LIVE.has(this.records.get(id).state) || handle.cancellationKeepsRunning) {
|
|
934
1116
|
await handle.cancel();
|
|
1117
|
+
runtime.removalConfirmed = true;
|
|
1118
|
+
}
|
|
935
1119
|
else
|
|
936
1120
|
await this.stop(id, runtime);
|
|
937
1121
|
}
|
|
@@ -978,6 +1162,8 @@ class ScheduleService {
|
|
|
978
1162
|
let cleanup = false;
|
|
979
1163
|
const runtime = this.runtimes.get(id);
|
|
980
1164
|
await this.serial(async () => {
|
|
1165
|
+
if (!runtime || this.runtimes.get(id) !== runtime || !this.records.has(id))
|
|
1166
|
+
return;
|
|
981
1167
|
if (this.fault)
|
|
982
1168
|
throw this.fault;
|
|
983
1169
|
const record = this.records.get(id);
|
|
@@ -1111,6 +1297,8 @@ class ScheduleService {
|
|
|
1111
1297
|
const pending = this.pending.get(id);
|
|
1112
1298
|
if (!pending)
|
|
1113
1299
|
return;
|
|
1300
|
+
if (this.purges.has(pending.scheduleId))
|
|
1301
|
+
return;
|
|
1114
1302
|
const record = this.records.get(pending.scheduleId);
|
|
1115
1303
|
if (!this.current(record) || record.state === 'cancelled' && !pending.afterCancellation) {
|
|
1116
1304
|
this.pending.delete(id);
|
|
@@ -1127,7 +1315,8 @@ class ScheduleService {
|
|
|
1127
1315
|
success: pending.success, ...(pending.output !== undefined && { output: pending.output }),
|
|
1128
1316
|
...(pending.error !== undefined && { error: pending.error }) };
|
|
1129
1317
|
});
|
|
1130
|
-
if (!delivery || this.closing || !this.current(delivery.schedule) || !this.pending.has(id)
|
|
1318
|
+
if (!delivery || this.closing || !this.current(delivery.schedule) || !this.pending.has(id)
|
|
1319
|
+
|| this.purges.has(delivery.schedule.id))
|
|
1131
1320
|
continue;
|
|
1132
1321
|
const runtime = this.runtimes.get(delivery.schedule.id);
|
|
1133
1322
|
if (runtime?.cancelling) {
|
|
@@ -1135,12 +1324,16 @@ class ScheduleService {
|
|
|
1135
1324
|
runtime.heldDeliveries.add(id);
|
|
1136
1325
|
continue;
|
|
1137
1326
|
}
|
|
1327
|
+
this.delivering.add(delivery.schedule.id);
|
|
1138
1328
|
try {
|
|
1139
1329
|
await this.options.deliver(delivery);
|
|
1140
1330
|
}
|
|
1141
1331
|
catch {
|
|
1142
1332
|
continue;
|
|
1143
1333
|
} // Keep the persisted outbox; only explicit reconnect retries it.
|
|
1334
|
+
finally {
|
|
1335
|
+
this.delivering.delete(delivery.schedule.id);
|
|
1336
|
+
}
|
|
1144
1337
|
await this.serial(async () => { this.pending.delete(id); await this.persist(); });
|
|
1145
1338
|
}
|
|
1146
1339
|
});
|
|
@@ -1148,6 +1341,8 @@ class ScheduleService {
|
|
|
1148
1341
|
return run;
|
|
1149
1342
|
}
|
|
1150
1343
|
stop(id, runtime) {
|
|
1344
|
+
if (this.runtimes.get(id) !== runtime)
|
|
1345
|
+
return Promise.resolve();
|
|
1151
1346
|
if (runtime.stopped)
|
|
1152
1347
|
return Promise.resolve();
|
|
1153
1348
|
if (runtime.stopPromise)
|
|
@@ -1158,8 +1353,12 @@ class ScheduleService {
|
|
|
1158
1353
|
throw new Error('Recovery receipt is unresolved; native ownership retained.');
|
|
1159
1354
|
}
|
|
1160
1355
|
const handle = await runtime.ready;
|
|
1161
|
-
if (handle && !runtime.stopped)
|
|
1356
|
+
if (handle && !runtime.stopped) {
|
|
1162
1357
|
await handle.stop();
|
|
1358
|
+
// Process/job retirement is not itself proof that persisted timing was deleted.
|
|
1359
|
+
if (handle.nativeDefinitionAbsent === true)
|
|
1360
|
+
runtime.removalConfirmed = true;
|
|
1361
|
+
}
|
|
1163
1362
|
// A shared session can delete future firings while an occurrence still
|
|
1164
1363
|
// finishes. Keep ownership until its terminal stopped notification.
|
|
1165
1364
|
if (!handle?.cancellationKeepsRunning || !runtime.running.size)
|
|
@@ -1178,10 +1377,11 @@ class ScheduleService {
|
|
|
1178
1377
|
throw error;
|
|
1179
1378
|
}
|
|
1180
1379
|
})();
|
|
1181
|
-
|
|
1380
|
+
const tracked = this.recordOperation(id, operation);
|
|
1381
|
+
runtime.stopPromise = tracked;
|
|
1182
1382
|
void operation.finally(() => { if (!runtime.stopped)
|
|
1183
1383
|
runtime.stopPromise = undefined; }).catch(() => { });
|
|
1184
|
-
return runtime.recoveryAbort ? this.boundRecovery(
|
|
1384
|
+
return runtime.recoveryAbort ? this.boundRecovery(tracked, 'Native cleanup remains unresolved; ownership retained.') : tracked;
|
|
1185
1385
|
}
|
|
1186
1386
|
async boundRecovery(operation, message) {
|
|
1187
1387
|
let timer;
|
|
@@ -1220,6 +1420,16 @@ class ScheduleService {
|
|
|
1220
1420
|
void task.finally(() => this.operations.delete(task)).catch(() => { });
|
|
1221
1421
|
return task;
|
|
1222
1422
|
}
|
|
1423
|
+
recordOperation(id, task) {
|
|
1424
|
+
this.recordOperations.set(id, (this.recordOperations.get(id) ?? 0) + 1);
|
|
1425
|
+
return task.finally(() => {
|
|
1426
|
+
const remaining = this.recordOperations.get(id) - 1;
|
|
1427
|
+
if (remaining)
|
|
1428
|
+
this.recordOperations.set(id, remaining);
|
|
1429
|
+
else
|
|
1430
|
+
this.recordOperations.delete(id);
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1223
1433
|
current(owner) {
|
|
1224
1434
|
try {
|
|
1225
1435
|
return this.options.isOwnerCurrent(ownerOf(owner)) === true;
|
|
@@ -1266,7 +1476,7 @@ class ScheduleService {
|
|
|
1266
1476
|
try {
|
|
1267
1477
|
// JSON can expand one control byte to six bytes (for example, "\\u0001").
|
|
1268
1478
|
const maxBytes = (this.maxRecords + this.maxPending) * (160 * 1024)
|
|
1269
|
-
+ this.maxRecords * this.maxOccurrences * 515 + 4096;
|
|
1479
|
+
+ this.maxRecords * this.maxOccurrences * 515 + MAX_PURGED_IDS * 2048 + 4096;
|
|
1270
1480
|
const size = (await handle.stat()).size;
|
|
1271
1481
|
if (size > maxBytes)
|
|
1272
1482
|
throw new Error('Schedule catalog exceeds its size limit.');
|
|
@@ -1291,14 +1501,14 @@ class ScheduleService {
|
|
|
1291
1501
|
}
|
|
1292
1502
|
}
|
|
1293
1503
|
load(data) {
|
|
1294
|
-
const catalog = object(data, ['version', 'records', 'pending']);
|
|
1295
|
-
if (![1, 2].includes(catalog.version) || !Array.isArray(catalog.records) || catalog.records.length > this.maxRecords
|
|
1504
|
+
const catalog = object(data, ['version', 'records', 'pending', 'purged']);
|
|
1505
|
+
if (![1, 2, 3].includes(catalog.version) || !Array.isArray(catalog.records) || catalog.records.length > this.maxRecords
|
|
1296
1506
|
|| !Array.isArray(catalog.pending) || catalog.pending.length > this.maxPending)
|
|
1297
1507
|
throw new Error('Invalid schedule catalog envelope.');
|
|
1298
1508
|
const records = new Map();
|
|
1299
1509
|
const pending = new Map();
|
|
1300
1510
|
for (const value of catalog.records) {
|
|
1301
|
-
const record = object(value, ['id', 'backend', 'cwd', 'prompt', 'rule', 'createdAt', 'nativeId', 'state', 'error', 'threadId', 'openId', 'generation', 'execution', 'cancelRequested', 'recovery', 'completedOccurrences', 'skippedOccurrences']);
|
|
1511
|
+
const record = object(value, ['id', 'backend', 'cwd', 'prompt', 'rule', 'createdAt', 'nativeId', 'state', 'error', 'threadId', 'openId', 'generation', 'execution', 'cancelRequested', 'creationRefused', 'recovery', 'completedOccurrences', 'skippedOccurrences']);
|
|
1302
1512
|
(0, ScheduleCommand_1.validateScheduleId)(record.id);
|
|
1303
1513
|
validateOwner(record);
|
|
1304
1514
|
(0, ScheduleCommand_1.validateSchedulePrompt)(record.prompt);
|
|
@@ -1313,6 +1523,10 @@ class ScheduleService {
|
|
|
1313
1523
|
throw new Error('Invalid schedule error.');
|
|
1314
1524
|
if (record.cancelRequested !== undefined && record.cancelRequested !== true)
|
|
1315
1525
|
throw new Error('Invalid cancellation intent.');
|
|
1526
|
+
if (record.creationRefused !== undefined && (catalog.version !== 3 || record.creationRefused !== true || record.nativeId !== undefined
|
|
1527
|
+
|| !['failed', 'cancelled', 'interrupted'].includes(record.state)
|
|
1528
|
+
|| record.completedOccurrences !== undefined))
|
|
1529
|
+
throw new Error('Invalid native admission refusal.');
|
|
1316
1530
|
if (record.execution !== undefined) {
|
|
1317
1531
|
const execution = object(record.execution, ['command', 'model', 'effort']);
|
|
1318
1532
|
for (const value of Object.values(execution))
|
|
@@ -1320,8 +1534,8 @@ class ScheduleService {
|
|
|
1320
1534
|
text(value, 4096);
|
|
1321
1535
|
}
|
|
1322
1536
|
if (record.recovery !== undefined) {
|
|
1323
|
-
if (catalog.version
|
|
1324
|
-
throw new Error('Recovery requires catalog version 2.');
|
|
1537
|
+
if (catalog.version === 1)
|
|
1538
|
+
throw new Error('Recovery requires catalog version 2 or newer.');
|
|
1325
1539
|
const recovery = object(record.recovery, ['version', 'provider', 'strategy', 'identity', 'status', 'orderlyOnly', 'futureOnly', 'handoff', 'nativeDefinitionAbsent', 'handoffPolicy']);
|
|
1326
1540
|
this.validateCheckpoint(recovery);
|
|
1327
1541
|
if (!['eligible', 'pending', 'blocked'].includes(recovery.status))
|
|
@@ -1363,8 +1577,24 @@ class ScheduleService {
|
|
|
1363
1577
|
throw new Error('Invalid cancellation delivery flag.');
|
|
1364
1578
|
pending.set(item.id, structuredClone(item));
|
|
1365
1579
|
}
|
|
1580
|
+
const purged = new Map();
|
|
1581
|
+
if (catalog.version === 3) {
|
|
1582
|
+
if (!Array.isArray(catalog.purged) || catalog.purged.length > MAX_PURGED_IDS)
|
|
1583
|
+
throw new Error('Invalid purge fences.');
|
|
1584
|
+
for (const value of catalog.purged) {
|
|
1585
|
+
const fence = object(value, ['id', 'threadId', 'openId', 'generation']);
|
|
1586
|
+
(0, ScheduleCommand_1.validateScheduleId)(fence.id);
|
|
1587
|
+
validateOwner(fence);
|
|
1588
|
+
if (records.has(fence.id) || purged.has(fence.id))
|
|
1589
|
+
throw new Error('Conflicting purge fence.');
|
|
1590
|
+
purged.set(fence.id, ownerOf(fence));
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
else if (catalog.purged !== undefined)
|
|
1594
|
+
throw new Error('Purge fences require catalog version 3.');
|
|
1366
1595
|
this.records = records;
|
|
1367
1596
|
this.pending = pending;
|
|
1597
|
+
this.purged = purged;
|
|
1368
1598
|
}
|
|
1369
1599
|
async persist() {
|
|
1370
1600
|
if (!this.catalogGate)
|
|
@@ -1385,7 +1615,9 @@ class ScheduleService {
|
|
|
1385
1615
|
}
|
|
1386
1616
|
const handle = await fs.open(temporary, 'wx', 0o600);
|
|
1387
1617
|
try {
|
|
1388
|
-
|
|
1618
|
+
const upgraded = this.purged.size > 0 || [...this.records.values()].some(record => record.creationRefused);
|
|
1619
|
+
await handle.writeFile(JSON.stringify({ version: upgraded ? 3 : 2, records: [...this.records.values()], pending: [...this.pending.values()],
|
|
1620
|
+
...(upgraded ? { purged: [...this.purged].map(([id, owner]) => ({ id, ...owner })) } : {}) }), 'utf8');
|
|
1389
1621
|
await handle.sync();
|
|
1390
1622
|
}
|
|
1391
1623
|
finally {
|