@yu_robotics/remote-cli 1.6.265 → 1.6.267
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 +1 -0
- package/dist/client/MessageHandler.d.ts.map +1 -1
- package/dist/client/MessageHandler.js +86 -58
- package/dist/client/MessageHandler.js.map +1 -1
- package/dist/executor/AgyExecutor.d.ts +0 -2
- package/dist/executor/AgyExecutor.d.ts.map +1 -1
- package/dist/executor/AgyExecutor.js +0 -19
- package/dist/executor/AgyExecutor.js.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.d.ts +1 -4
- package/dist/executor/ClaudePersistentExecutor.d.ts.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.js +0 -59
- package/dist/executor/ClaudePersistentExecutor.js.map +1 -1
- package/dist/executor/DshExecutor.d.ts +1 -5
- package/dist/executor/DshExecutor.d.ts.map +1 -1
- package/dist/executor/DshExecutor.js +0 -35
- package/dist/executor/DshExecutor.js.map +1 -1
- package/dist/executor/IExecutor.d.ts +0 -4
- package/dist/executor/IExecutor.d.ts.map +1 -1
- package/dist/executor/acp/AcpClient.d.ts +0 -1
- package/dist/executor/acp/AcpClient.d.ts.map +1 -1
- package/dist/executor/acp/AcpClient.js.map +1 -1
- package/dist/executor/agy/AgyAcpRuntime.d.ts +0 -3
- package/dist/executor/agy/AgyAcpRuntime.d.ts.map +1 -1
- package/dist/executor/agy/AgyAcpRuntime.js +1 -30
- package/dist/executor/agy/AgyAcpRuntime.js.map +1 -1
- package/dist/executor/dsh/DshAcpClient.d.ts +1 -10
- package/dist/executor/dsh/DshAcpClient.d.ts.map +1 -1
- package/dist/executor/dsh/DshAcpClient.js +12 -75
- package/dist/executor/dsh/DshAcpClient.js.map +1 -1
- package/dist/executor/dsh/DshPrivacy.d.ts +1 -1
- package/dist/executor/dsh/DshPrivacy.d.ts.map +1 -1
- package/dist/executor/dsh/DshPrivacy.js +2 -2
- package/dist/executor/dsh/DshPrivacy.js.map +1 -1
- package/dist/maintenance/release-notes.json +1 -1
- package/dist/scheduling/ScheduleCapabilities.d.ts +0 -42
- package/dist/scheduling/ScheduleCapabilities.d.ts.map +1 -1
- package/dist/scheduling/ScheduleCapabilities.js +3 -4
- package/dist/scheduling/ScheduleCapabilities.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +3 -3
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduleService.d.ts +10 -19
- package/dist/scheduling/ScheduleService.d.ts.map +1 -1
- package/dist/scheduling/ScheduleService.js +103 -577
- package/dist/scheduling/ScheduleService.js.map +1 -1
- package/dist/scheduling/ScheduleToolScope.d.ts +2 -2
- package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -1
- package/dist/scheduling/ScheduleToolScope.js +1 -1
- package/dist/scheduling/ScheduleToolScope.js.map +1 -1
- package/dist/scheduling/agy/AgyScheduleHost.d.ts +1 -3
- package/dist/scheduling/agy/AgyScheduleHost.d.ts.map +1 -1
- package/dist/scheduling/agy/AgyScheduleHost.js +0 -3
- package/dist/scheduling/agy/AgyScheduleHost.js.map +1 -1
- package/dist/scheduling/agy/AgySessionSchedules.d.ts +3 -2
- package/dist/scheduling/agy/AgySessionSchedules.d.ts.map +1 -1
- package/dist/scheduling/agy/AgySessionSchedules.js +3 -0
- package/dist/scheduling/agy/AgySessionSchedules.js.map +1 -1
- package/dist/scheduling/dsh/NativeScheduleToolGuard.d.ts +14 -0
- package/dist/scheduling/dsh/NativeScheduleToolGuard.d.ts.map +1 -0
- package/dist/scheduling/dsh/NativeScheduleToolGuard.js +12 -0
- package/dist/scheduling/dsh/NativeScheduleToolGuard.js.map +1 -0
- package/dist/scheduling/dsh/ScheduledSessionGuard.d.ts +0 -1
- package/dist/scheduling/dsh/ScheduledSessionGuard.d.ts.map +1 -1
- package/dist/scheduling/dsh/ScheduledSessionGuard.js +0 -27
- package/dist/scheduling/dsh/ScheduledSessionGuard.js.map +1 -1
- package/dist/scheduling/types.d.ts +3 -8
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scheduling/types.js.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
- package/dist/scheduling/ClaudeNativeScheduleProvider.d.ts +0 -19
- package/dist/scheduling/ClaudeNativeScheduleProvider.d.ts.map +0 -1
- package/dist/scheduling/ClaudeNativeScheduleProvider.js +0 -570
- package/dist/scheduling/ClaudeNativeScheduleProvider.js.map +0 -1
- package/dist/scheduling/DshNativeScheduleProvider.d.ts +0 -19
- package/dist/scheduling/DshNativeScheduleProvider.d.ts.map +0 -1
- package/dist/scheduling/DshNativeScheduleProvider.js +0 -470
- package/dist/scheduling/DshNativeScheduleProvider.js.map +0 -1
- package/dist/scheduling/dsh/HostBridge.d.ts +0 -96
- package/dist/scheduling/dsh/HostBridge.d.ts.map +0 -1
- package/dist/scheduling/dsh/HostBridge.js +0 -364
- package/dist/scheduling/dsh/HostBridge.js.map +0 -1
- package/dist/scheduling/dsh/ScopePlugin.d.ts +0 -9
- package/dist/scheduling/dsh/ScopePlugin.d.ts.map +0 -1
- package/dist/scheduling/dsh/ScopePlugin.js +0 -13
- package/dist/scheduling/dsh/ScopePlugin.js.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleBridge.d.ts +0 -35
- package/dist/scheduling/dsh/SessionScheduleBridge.d.ts.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleBridge.js +0 -296
- package/dist/scheduling/dsh/SessionScheduleBridge.js.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleClient.d.ts +0 -15
- package/dist/scheduling/dsh/SessionScheduleClient.d.ts.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleClient.js +0 -184
- package/dist/scheduling/dsh/SessionScheduleClient.js.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleStorage.d.ts +0 -8
- package/dist/scheduling/dsh/SessionScheduleStorage.d.ts.map +0 -1
- package/dist/scheduling/dsh/SessionScheduleStorage.js +0 -34
- package/dist/scheduling/dsh/SessionScheduleStorage.js.map +0 -1
- package/dist/scheduling/dsh/launch.d.ts +0 -13
- package/dist/scheduling/dsh/launch.d.ts.map +0 -1
- package/dist/scheduling/dsh/launch.js +0 -58
- package/dist/scheduling/dsh/launch.js.map +0 -1
- package/dist/scheduling/dsh/protocol.d.ts +0 -28
- package/dist/scheduling/dsh/protocol.d.ts.map +0 -1
- package/dist/scheduling/dsh/protocol.js +0 -142
- package/dist/scheduling/dsh/protocol.js.map +0 -1
- package/dist/scheduling/dsh/sessionLaunch.d.ts +0 -3
- package/dist/scheduling/dsh/sessionLaunch.d.ts.map +0 -1
- package/dist/scheduling/dsh/sessionLaunch.js +0 -22
- package/dist/scheduling/dsh/sessionLaunch.js.map +0 -1
- package/dist/scheduling/dsh/sessionProtocol.d.ts +0 -4
- package/dist/scheduling/dsh/sessionProtocol.d.ts.map +0 -1
- package/dist/scheduling/dsh/sessionProtocol.js +0 -7
- package/dist/scheduling/dsh/sessionProtocol.js.map +0 -1
|
@@ -44,7 +44,6 @@ const fs = __importStar(require("node:fs/promises"));
|
|
|
44
44
|
const node_path_1 = __importDefault(require("node:path"));
|
|
45
45
|
const node_crypto_1 = require("node:crypto");
|
|
46
46
|
const ScheduleCommand_1 = require("./ScheduleCommand");
|
|
47
|
-
const types_1 = require("./types");
|
|
48
47
|
const ScheduleCapabilities_1 = require("./ScheduleCapabilities");
|
|
49
48
|
const HostScheduleRule_1 = require("./host/HostScheduleRule");
|
|
50
49
|
exports.SCHEDULE_CATALOG_FILE = 'schedule-catalog.json';
|
|
@@ -128,7 +127,6 @@ class ScheduleService {
|
|
|
128
127
|
now;
|
|
129
128
|
records = new Map();
|
|
130
129
|
pending = new Map();
|
|
131
|
-
runtimes = new Map();
|
|
132
130
|
retainedCancellations = new Map();
|
|
133
131
|
purged = new Map();
|
|
134
132
|
cleanup = new Map();
|
|
@@ -136,7 +134,6 @@ class ScheduleService {
|
|
|
136
134
|
purges = new Map();
|
|
137
135
|
recordOperations = new Map();
|
|
138
136
|
delivering = new Set();
|
|
139
|
-
refreshes = 0;
|
|
140
137
|
tail = Promise.resolve();
|
|
141
138
|
deliveryTail = Promise.resolve();
|
|
142
139
|
tasks = new Set();
|
|
@@ -145,7 +142,6 @@ class ScheduleService {
|
|
|
145
142
|
initialized = false;
|
|
146
143
|
closing = false;
|
|
147
144
|
destruction;
|
|
148
|
-
pendingCreates = 0;
|
|
149
145
|
fault;
|
|
150
146
|
catalogPath = '';
|
|
151
147
|
hostCatalogPath = '';
|
|
@@ -268,40 +264,14 @@ class ScheduleService {
|
|
|
268
264
|
text(value.identity, 8192);
|
|
269
265
|
}
|
|
270
266
|
create(owner, input) {
|
|
271
|
-
this.
|
|
272
|
-
const creation = this.recordOperation(input.id, this.createSchedule(owner, input).finally(async () => {
|
|
273
|
-
this.pendingCreates--;
|
|
274
|
-
if (this.closing && !this.pendingCreates) {
|
|
275
|
-
await this.tail;
|
|
276
|
-
this.catalogGate?.close();
|
|
277
|
-
this.catalogGate = undefined;
|
|
278
|
-
}
|
|
279
|
-
}));
|
|
280
|
-
return this.operation(creation.catch(async (error) => {
|
|
281
|
-
if (error instanceof types_1.NativeScheduleNotAdmittedError) {
|
|
282
|
-
// The create operation has settled. Concurrent cancel/purge operations
|
|
283
|
-
// retain their own record lease and must finish before any compaction.
|
|
284
|
-
await this.serial(async () => {
|
|
285
|
-
const record = this.records.get(input.id);
|
|
286
|
-
if (record && sameOwner(record, owner))
|
|
287
|
-
await this.compactRefusedCreation(record);
|
|
288
|
-
}).catch(() => { }); // Keep the original failure receipt; persistence faults remain fenced.
|
|
289
|
-
}
|
|
290
|
-
throw error;
|
|
291
|
-
}));
|
|
267
|
+
return this.operation(this.recordOperation(input.id, this.createSchedule(owner, input)));
|
|
292
268
|
}
|
|
293
269
|
async createSchedule(owner, input) {
|
|
294
270
|
this.checkReady();
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
(0, ScheduleCapabilities_1.assertHostScheduleBackend)(backend);
|
|
300
|
-
else {
|
|
301
|
-
(0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
|
|
302
|
-
if (this.legacyUnavailable)
|
|
303
|
-
throw new Error('Legacy native catalog is unavailable.');
|
|
304
|
-
}
|
|
271
|
+
if (input.engine !== 'host')
|
|
272
|
+
throw new Error('Schedule creation requires the host engine.');
|
|
273
|
+
const { backend } = input;
|
|
274
|
+
(0, ScheduleCapabilities_1.assertHostScheduleBackend)(backend);
|
|
305
275
|
const createdAt = this.now();
|
|
306
276
|
if (!Number.isSafeInteger(createdAt) || createdAt < 0)
|
|
307
277
|
throw new Error('Invalid schedule clock.');
|
|
@@ -309,173 +279,53 @@ class ScheduleService {
|
|
|
309
279
|
(0, ScheduleCommand_1.validateScheduleId)(input.id);
|
|
310
280
|
(0, ScheduleCommand_1.validateSchedulePrompt)(input.prompt);
|
|
311
281
|
(0, ScheduleCommand_1.validateScheduleRule)(input.rule, createdAt);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
text(input.sessionId);
|
|
318
|
-
}
|
|
319
|
-
const host = input.engine === 'host';
|
|
320
|
-
if (host) {
|
|
321
|
-
text(input.bindingEpoch);
|
|
322
|
-
if (owner.bindingEpoch !== undefined && owner.bindingEpoch !== input.bindingEpoch)
|
|
323
|
-
throw new Error('Host schedule binding epoch changed.');
|
|
324
|
-
}
|
|
325
|
-
else if (input.bindingEpoch !== undefined)
|
|
326
|
-
throw new Error('Unexpected native schedule binding epoch.');
|
|
327
|
-
if (host && !this.options.hostDispatch)
|
|
282
|
+
text(input.sessionId);
|
|
283
|
+
text(input.bindingEpoch);
|
|
284
|
+
if (owner.bindingEpoch !== undefined && owner.bindingEpoch !== input.bindingEpoch)
|
|
285
|
+
throw new Error('Host schedule binding epoch changed.');
|
|
286
|
+
if (!this.options.hostDispatch)
|
|
328
287
|
throw new Error('Host schedule dispatch is unavailable.');
|
|
329
|
-
const nextDueAt =
|
|
288
|
+
const nextDueAt = this.hostDue(input.rule, createdAt);
|
|
330
289
|
text(input.cwd, 4096);
|
|
331
290
|
if (!node_path_1.default.isAbsolute(input.cwd))
|
|
332
291
|
throw new Error('Schedule working directory must be absolute.');
|
|
333
|
-
const originalOwner = ownerOf({ ...owner, bindingEpoch: host ? input.bindingEpoch : undefined });
|
|
334
|
-
const definition = { ...structuredClone(input), backend, threadId: owner.threadId };
|
|
335
|
-
const nativeInput = !host && (0, ScheduleCapabilities_1.isNativeScheduleBackend)(backend)
|
|
336
|
-
? { ...definition, backend } : undefined;
|
|
337
|
-
// Never trust a caller-supplied provider checkpoint.
|
|
338
|
-
if (nativeInput)
|
|
339
|
-
delete nativeInput.recovery;
|
|
340
292
|
for (const value of [input.command, input.model, input.effort])
|
|
341
293
|
if (value !== undefined)
|
|
342
294
|
text(value, 4096);
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
const runtime = host ? undefined : this.newRuntime();
|
|
350
|
-
await this.serial(async () => {
|
|
295
|
+
const record = { ...ownerOf(owner), bindingEpoch: input.bindingEpoch,
|
|
296
|
+
id: input.id, engine: 'host', backend, sessionId: input.sessionId, cwd: input.cwd,
|
|
297
|
+
prompt: input.prompt, rule: structuredClone(input.rule), createdAt, state: 'active', nextDueAt,
|
|
298
|
+
execution: { command: input.command, model: input.model, effort: input.effort } };
|
|
299
|
+
return this.serial(async () => {
|
|
351
300
|
this.checkReady();
|
|
352
|
-
if (!this.current(
|
|
301
|
+
if (!this.current(record))
|
|
353
302
|
throw new Error('Schedule owner is no longer current.');
|
|
354
|
-
if (this.records.has(
|
|
303
|
+
if (this.records.has(record.id) || this.purged.has(record.id) || this.unavailableLegacyIds.has(record.id)) {
|
|
355
304
|
throw new Error('Schedule ID already exists or was purged.');
|
|
356
305
|
}
|
|
357
|
-
if (
|
|
306
|
+
if (this.retireStaleHosts()) {
|
|
358
307
|
await this.persist();
|
|
359
|
-
if (!this.current(
|
|
308
|
+
if (!this.current(record))
|
|
360
309
|
throw new Error('Schedule owner changed during creation.');
|
|
361
310
|
}
|
|
362
|
-
const records = [...this.records.values()];
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
311
|
+
const records = [...this.records.values()].filter(row => row.engine === 'host');
|
|
312
|
+
if (records.filter(row => LIVE.has(row.state) || row.inFlightDueAt !== undefined).length >= this.maxLive) {
|
|
313
|
+
throw new Error('Live host schedule limit reached.');
|
|
314
|
+
}
|
|
315
|
+
if (records.filter(row => this.hostCatalogIds.has(row.id)).length >= this.maxRecords) {
|
|
316
|
+
const stale = records.find(row => this.hostCatalogIds.has(row.id) && row.state === 'interrupted'
|
|
317
|
+
&& this.hostOwnerStatus(row) === false && !this.hostAttempts.has(row.id) && !this.delivering.has(row.id)
|
|
318
|
+
&& !this.recordOperations.has(row.id) && !this.purges.has(row.id));
|
|
369
319
|
if (!stale || this.purgeFencesFull(stale.id))
|
|
370
320
|
throw new Error('Schedule catalog is full; history was not pruned.');
|
|
371
|
-
}
|
|
372
|
-
const liveCount = records.filter(record => (record.engine === 'host') === host && (LIVE.has(record.state)
|
|
373
|
-
|| record.inFlightDueAt !== undefined || this.hasRetainedCleanupRoute(record)
|
|
374
|
-
|| (this.runtimes.has(record.id) && !this.runtimes.get(record.id).stopped))).length;
|
|
375
|
-
if (liveCount >= this.maxLive)
|
|
376
|
-
throw new Error(host ? 'Live host schedule limit reached.' : 'Live native schedule limit reached.');
|
|
377
|
-
if (stale) {
|
|
378
321
|
this.purged.set(stale.id, ownerOf(stale));
|
|
379
322
|
this.records.delete(stale.id);
|
|
380
323
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.records.set(definition.id, { ...originalOwner, id: definition.id, backend,
|
|
384
|
-
cwd: definition.cwd, prompt: definition.prompt, rule: structuredClone(definition.rule),
|
|
385
|
-
createdAt, state: host ? 'active' : 'creating', execution: { command: definition.command, model: definition.model, effort: definition.effort },
|
|
386
|
-
...(host && { engine: 'host', sessionId: definition.sessionId, nextDueAt }),
|
|
387
|
-
...(nativeInput?.recovery && { recovery: { ...nativeInput.recovery, status: 'blocked' } }) });
|
|
324
|
+
this.hostCatalogIds.add(record.id);
|
|
325
|
+
this.records.set(record.id, record);
|
|
388
326
|
await this.persist();
|
|
389
|
-
|
|
390
|
-
this.runtimes.set(definition.id, runtime);
|
|
327
|
+
return structuredClone(record);
|
|
391
328
|
});
|
|
392
|
-
if (!runtime || !nativeInput)
|
|
393
|
-
return structuredClone(this.records.get(definition.id));
|
|
394
|
-
try {
|
|
395
|
-
const handle = await this.options.provider.create(structuredClone(nativeInput), event => {
|
|
396
|
-
if (this.runtimes.get(nativeInput.id) !== runtime) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (event.type === 'started' || event.type === 'completed')
|
|
400
|
-
runtime.observedOccurrence = true;
|
|
401
|
-
const task = this.onEvent(nativeInput.id, structuredClone(event));
|
|
402
|
-
// A rejected pre-CREATE attribution is an admission refusal, not a
|
|
403
|
-
// runtime event fault. persist() still fences actual storage failures.
|
|
404
|
-
if (event.type !== 'attributed')
|
|
405
|
-
this.track(task);
|
|
406
|
-
return task;
|
|
407
|
-
}, () => this.canAdmitOccurrence(nativeInput.id, runtime));
|
|
408
|
-
runtime.handle = handle;
|
|
409
|
-
runtime.resolveReady(handle);
|
|
410
|
-
text(handle.nativeId);
|
|
411
|
-
await this.serial(async () => {
|
|
412
|
-
const record = this.records.get(nativeInput.id);
|
|
413
|
-
record.nativeId = handle.nativeId;
|
|
414
|
-
if (record.recovery && handle.cleanupIdentity) {
|
|
415
|
-
text(handle.cleanupIdentity, 8192);
|
|
416
|
-
record.recovery.identity = handle.cleanupIdentity;
|
|
417
|
-
}
|
|
418
|
-
const ownerCurrent = this.current(originalOwner);
|
|
419
|
-
if (this.closing) {
|
|
420
|
-
await this.persist();
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
if (!ownerCurrent) {
|
|
424
|
-
if (LIVE.has(record.state)) {
|
|
425
|
-
record.state = 'interrupted';
|
|
426
|
-
record.error = 'Schedule owner or service retired during creation.';
|
|
427
|
-
}
|
|
428
|
-
if (!ownerCurrent)
|
|
429
|
-
this.dropPending(record.id);
|
|
430
|
-
}
|
|
431
|
-
else if (record.state === 'creating')
|
|
432
|
-
record.state = 'active';
|
|
433
|
-
await this.persist();
|
|
434
|
-
});
|
|
435
|
-
const record = this.records.get(nativeInput.id);
|
|
436
|
-
if (!LIVE.has(record.state) && !runtime.cancelling)
|
|
437
|
-
await this.stop(nativeInput.id, runtime);
|
|
438
|
-
return structuredClone(this.records.get(nativeInput.id));
|
|
439
|
-
}
|
|
440
|
-
catch (error) {
|
|
441
|
-
if (error instanceof types_1.NativeScheduleCleanupError)
|
|
442
|
-
runtime.handle = error.handle;
|
|
443
|
-
runtime.resolveReady(runtime.handle);
|
|
444
|
-
await this.serial(async () => {
|
|
445
|
-
const record = this.records.get(nativeInput.id);
|
|
446
|
-
if (error instanceof types_1.NativeScheduleCleanupError) {
|
|
447
|
-
if (error.handle.nativeId) {
|
|
448
|
-
text(error.handle.nativeId);
|
|
449
|
-
record.nativeId = error.handle.nativeId;
|
|
450
|
-
}
|
|
451
|
-
if (record.recovery && error.handle.cleanupIdentity) {
|
|
452
|
-
text(error.handle.cleanupIdentity, 8192);
|
|
453
|
-
record.recovery.identity = error.handle.cleanupIdentity;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if (this.closing) {
|
|
457
|
-
if (!this.fault)
|
|
458
|
-
await this.persist();
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
if (LIVE.has(record.state)) {
|
|
462
|
-
record.state = 'failed';
|
|
463
|
-
record.error = errorText(error);
|
|
464
|
-
}
|
|
465
|
-
if (error instanceof types_1.NativeScheduleNotAdmittedError && !runtime.handle && !runtime.observedOccurrence
|
|
466
|
-
&& !record.nativeId && !runtime.running.size && !runtime.completed.size
|
|
467
|
-
&& !record.completedOccurrences?.length && !record.skippedOccurrences?.length) {
|
|
468
|
-
record.creationRefused = true;
|
|
469
|
-
}
|
|
470
|
-
if (!this.fault)
|
|
471
|
-
await this.persist();
|
|
472
|
-
});
|
|
473
|
-
if (runtime.handle)
|
|
474
|
-
await this.stop(nativeInput.id, runtime).catch(() => { });
|
|
475
|
-
else
|
|
476
|
-
runtime.stopped = true;
|
|
477
|
-
throw error;
|
|
478
|
-
}
|
|
479
329
|
}
|
|
480
330
|
hostDue(rule, after) {
|
|
481
331
|
const due = (0, HostScheduleRule_1.nextHostDue)(rule, after);
|
|
@@ -498,6 +348,7 @@ class ScheduleService {
|
|
|
498
348
|
finishHost(record, due, result) {
|
|
499
349
|
const occurrenceId = `host-${due}`;
|
|
500
350
|
const id = deliveryId(record.id, occurrenceId);
|
|
351
|
+
const interruptedCron = result.abortedByUser && record.inFlightDueAt === due && record.rule.kind === 'cron';
|
|
501
352
|
delete record.inFlightDueAt;
|
|
502
353
|
delete record.nextDueAt;
|
|
503
354
|
// Host slots advance monotonically. The persisted next/in-flight slot
|
|
@@ -509,7 +360,7 @@ class ScheduleService {
|
|
|
509
360
|
...(result.error !== undefined && { error: bounded(result.error, ERROR_BYTES) }) });
|
|
510
361
|
if (record.cancelRequested)
|
|
511
362
|
record.state = 'cancelled';
|
|
512
|
-
else if (!result.success) {
|
|
363
|
+
else if (!result.success && !interruptedCron) {
|
|
513
364
|
record.state = 'failed';
|
|
514
365
|
record.error = bounded(result.error ?? 'Host schedule execution failed.', ERROR_BYTES);
|
|
515
366
|
}
|
|
@@ -717,16 +568,14 @@ class ScheduleService {
|
|
|
717
568
|
/** Called under the catalog serial queue, never through output-erasing purge.
|
|
718
569
|
* A refusal is proof about this fresh attempt, not historical native absence. */
|
|
719
570
|
async compactRefusedCreation(record) {
|
|
720
|
-
const id = record.id
|
|
571
|
+
const id = record.id;
|
|
721
572
|
if (record.state !== 'failed' || record.creationRefused !== true || record.nativeId !== undefined
|
|
722
573
|
|| record.cancelRequested || record.cleanupConfirmed || record.completedOccurrences?.length || record.skippedOccurrences?.length
|
|
723
574
|
|| this.records.get(id) !== record || this.cleanup.has(id) || this.purged.has(id)
|
|
724
|
-
|| this.fault || this.closing
|
|
575
|
+
|| this.fault || this.closing
|
|
725
576
|
|| this.recordOperations.has(id) || this.retainedCancellations.has(id) || this.purges.has(id)
|
|
726
577
|
|| this.delivering.has(id) || [...this.pending.values()].some(item => item.scheduleId === id)
|
|
727
578
|
|| this.options.isNativeMutationPending?.(ownerOf(record))
|
|
728
|
-
|| runtime && (!runtime.stopped || runtime.handle || runtime.observedOccurrence || runtime.running.size || runtime.completed.size
|
|
729
|
-
|| runtime.heldDeliveries.size || runtime.cancelling || runtime.cancelPromise || runtime.stopPromise)
|
|
730
579
|
|| this.purgeFencesFull(id))
|
|
731
580
|
return;
|
|
732
581
|
this.purged.set(id, ownerOf(record));
|
|
@@ -739,8 +588,6 @@ class ScheduleService {
|
|
|
739
588
|
this.purged.delete(id);
|
|
740
589
|
throw error;
|
|
741
590
|
}
|
|
742
|
-
if (runtime)
|
|
743
|
-
this.runtimes.delete(id);
|
|
744
591
|
}
|
|
745
592
|
/** Catalog lookup only; this does not probe or recreate native jobs. */
|
|
746
593
|
async list(owner) {
|
|
@@ -748,6 +595,46 @@ class ScheduleService {
|
|
|
748
595
|
validateOwner(owner);
|
|
749
596
|
return this.serial(async () => [...this.records.values()].filter(record => sameOwner(record, owner)).map(record => structuredClone(record)));
|
|
750
597
|
}
|
|
598
|
+
/** Commit context erasure before reset advances its generation. Late host results
|
|
599
|
+
* require their original record object and cannot recreate a removed definition. */
|
|
600
|
+
clearHostContext(threadId, authorize, allowNativeRecovery) {
|
|
601
|
+
return this.operation(this.serial(async () => {
|
|
602
|
+
this.checkReady();
|
|
603
|
+
const thread = [...this.records.values()].filter(row => row.threadId === threadId);
|
|
604
|
+
if (!allowNativeRecovery && thread.some(row => row.engine !== 'host' && this.isActiveSchedule(row))) {
|
|
605
|
+
throw new Error('Cancel this thread\'s native schedules with /schedule cancel <id> before resetting its conversation.');
|
|
606
|
+
}
|
|
607
|
+
const hosts = thread.filter(row => row.engine === 'host');
|
|
608
|
+
if (!hosts.length)
|
|
609
|
+
return 0;
|
|
610
|
+
const owner = authorize();
|
|
611
|
+
if (owner && (!owner.bindingEpoch || owner.threadId !== threadId || !this.current(owner))) {
|
|
612
|
+
throw new Error('The schedule binding changed before conversation reset.');
|
|
613
|
+
}
|
|
614
|
+
const selected = hosts.filter(row => owner && sameOwner(row, owner));
|
|
615
|
+
const pendingSchedules = new Set([...this.pending.values()].map(delivery => delivery.scheduleId));
|
|
616
|
+
if (hosts.some(row => (!owner || !sameOwner(row, owner)) && (this.isActiveSchedule(row)
|
|
617
|
+
|| pendingSchedules.has(row.id) || this.delivering.has(row.id) || this.hostAttempts.has(row.id)))) {
|
|
618
|
+
throw new Error('A host schedule still owns a different binding or conversation context.');
|
|
619
|
+
}
|
|
620
|
+
if (!selected.length)
|
|
621
|
+
return 0;
|
|
622
|
+
if (selected.some(row => this.delivering.has(row.id) || this.purges.has(row.id) || this.recordOperations.has(row.id))) {
|
|
623
|
+
throw new Error('Schedule delivery or management is in progress. Retry the conversation reset after it settles.');
|
|
624
|
+
}
|
|
625
|
+
if ([...this.purged.keys()].filter(id => this.hostCatalogIds.has(id)).length + selected.length > MAX_PURGED_IDS) {
|
|
626
|
+
throw new Error('Host schedule replay fence capacity reached. Conversation reset was refused.');
|
|
627
|
+
}
|
|
628
|
+
for (const row of selected) {
|
|
629
|
+
this.purged.set(row.id, ownerOf(row));
|
|
630
|
+
this.records.delete(row.id);
|
|
631
|
+
this.dropPending(row.id);
|
|
632
|
+
this.hostRetryAt.delete(row.id);
|
|
633
|
+
}
|
|
634
|
+
await this.persist();
|
|
635
|
+
return selected.length;
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
751
638
|
/** Operational deletion ledger, separate from user history and never recoverable. */
|
|
752
639
|
async listCleanup(owner) {
|
|
753
640
|
this.checkReady();
|
|
@@ -912,7 +799,7 @@ class ScheduleService {
|
|
|
912
799
|
if (!prior || !sameCleanupOwner(prior, owner) || this.records.has(id))
|
|
913
800
|
throw new Error('Purge owned history before forgetting unresolved cleanup tracking.');
|
|
914
801
|
if (this.options.isNativeMutationPending?.(owner) || this.recordOperations.has(id)
|
|
915
|
-
|| this.
|
|
802
|
+
|| this.retainedCancellations.has(id))
|
|
916
803
|
return { status: 'pending', reason: 'operation_pending', detail: 'Native work or cleanup is still pending; tracking was not forgotten.' };
|
|
917
804
|
if (this.delivering.has(id))
|
|
918
805
|
return { status: 'pending', reason: 'delivery_pending', detail: 'An external delivery is already in flight; tracking was not forgotten.' };
|
|
@@ -996,7 +883,7 @@ class ScheduleService {
|
|
|
996
883
|
if (this.hostAttempts.has(id))
|
|
997
884
|
return pending('operation_pending', 'Host dispatch is reserving the thread.');
|
|
998
885
|
if ((record.engine !== 'host' && this.options.isNativeMutationPending?.(owner)) || this.recordOperations.has(id)
|
|
999
|
-
|| this.
|
|
886
|
+
|| this.retainedCancellations.has(id)) {
|
|
1000
887
|
return pending('operation_pending', 'Creation, inspection or cleanup is still pending. Retry these same IDs.');
|
|
1001
888
|
}
|
|
1002
889
|
if (this.delivering.has(id))
|
|
@@ -1007,15 +894,11 @@ class ScheduleService {
|
|
|
1007
894
|
return active;
|
|
1008
895
|
if (this.purgeFencesFull(id))
|
|
1009
896
|
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
1010
|
-
const runtime = this.runtimes.get(id);
|
|
1011
897
|
// Do not interpret terminal state, an absent handle or a stopped process as
|
|
1012
898
|
// native definition absence. Existing cancelRetained owns its stronger proof.
|
|
1013
899
|
let retainedVerified = false;
|
|
1014
|
-
const clean = record.engine === 'host' ||
|
|
1015
|
-
if (
|
|
1016
|
-
await this.cancel(owner, id);
|
|
1017
|
-
}
|
|
1018
|
-
else if (!runtime && !record.creationRefused && !clean && record.recovery && this.supportsRetainedCancellation(record)) {
|
|
900
|
+
const clean = record.engine === 'host' || record.cleanupConfirmed === true;
|
|
901
|
+
if (!record.creationRefused && !clean && record.recovery && this.supportsRetainedCancellation(record)) {
|
|
1019
902
|
try {
|
|
1020
903
|
await this.recordOperation(id, this.cancelRetained(record));
|
|
1021
904
|
retainedVerified = true;
|
|
@@ -1032,11 +915,6 @@ class ScheduleService {
|
|
|
1032
915
|
const unfinished = busy();
|
|
1033
916
|
if (unfinished)
|
|
1034
917
|
return unfinished;
|
|
1035
|
-
if (runtime?.running.size)
|
|
1036
|
-
return pending('occurrence_running', 'Future cancellation does not revoke an already admitted occurrence.');
|
|
1037
|
-
if (runtime && (!runtime.stopped))
|
|
1038
|
-
return pending('operation_pending', 'Native runtime retirement is unconfirmed.');
|
|
1039
|
-
const handleProof = runtime?.removalConfirmed && runtime.handle?.nativeDefinitionAbsent !== false;
|
|
1040
918
|
const erase = (evidence, unresolved) => this.serial(async () => {
|
|
1041
919
|
this.checkReady();
|
|
1042
920
|
if (!current() || evidence?.status === 'verified' && !evidence.isCurrent())
|
|
@@ -1046,10 +924,6 @@ class ScheduleService {
|
|
|
1046
924
|
return changed;
|
|
1047
925
|
if (this.purgeFencesFull(id))
|
|
1048
926
|
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
1049
|
-
if (this.runtimes.get(id) !== runtime || runtime?.running.size || runtime && !runtime.stopped
|
|
1050
|
-
|| handleProof && runtime?.handle?.nativeDefinitionAbsent === false) {
|
|
1051
|
-
return pending('operation_pending', 'Native ownership changed before history removal.');
|
|
1052
|
-
}
|
|
1053
927
|
if (unresolved && this.cleanup.size >= MAX_CLEANUP_RECORDS)
|
|
1054
928
|
return pending('fence_capacity', 'Native cleanup ledger capacity reached (1000); resolve existing cleanup before removing more history.');
|
|
1055
929
|
// Commit history/output deletion, minimal operational selector and replay
|
|
@@ -1071,10 +945,9 @@ class ScheduleService {
|
|
|
1071
945
|
this.pending.set(key, entry);
|
|
1072
946
|
throw error;
|
|
1073
947
|
}
|
|
1074
|
-
this.runtimes.delete(id);
|
|
1075
948
|
return { status: 'removed' };
|
|
1076
949
|
});
|
|
1077
|
-
if (record.creationRefused || clean || retainedVerified
|
|
950
|
+
if (record.creationRefused || clean || retainedVerified)
|
|
1078
951
|
return erase();
|
|
1079
952
|
if (!this.options.withPurgeVerification)
|
|
1080
953
|
return erase(undefined, 'native_absence_unknown');
|
|
@@ -1099,26 +972,17 @@ class ScheduleService {
|
|
|
1099
972
|
hasPendingResults() { return this.pending.size > 0; }
|
|
1100
973
|
/** Includes terminal jobs whose native process exit is still unconfirmed. */
|
|
1101
974
|
hasActiveSchedules(threadId) {
|
|
1102
|
-
return [...this.records.values()].some(record => (!threadId || record.threadId === threadId)
|
|
1103
|
-
&& (LIVE.has(record.state) || record.inFlightDueAt !== undefined || this.hasRetainedCleanupRoute(record) || (this.runtimes.has(record.id) && !this.runtimes.get(record.id).stopped)));
|
|
975
|
+
return [...this.records.values()].some(record => (!threadId || record.threadId === threadId) && this.isActiveSchedule(record));
|
|
1104
976
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
this.checkReady();
|
|
1108
|
-
this.owned(owner, id);
|
|
1109
|
-
const runtime = this.runtimes.get(id);
|
|
1110
|
-
// Cancellation can hide the card while its native runtime still needs retirement.
|
|
1111
|
-
return !!runtime?.handle && !runtime.stopped;
|
|
977
|
+
isActiveSchedule(record) {
|
|
978
|
+
return LIVE.has(record.state) || record.inFlightDueAt !== undefined || this.hasRetainedCleanupRoute(record);
|
|
1112
979
|
}
|
|
1113
980
|
/** Card eligibility includes retryable cleanup even for a terminal catalog record. */
|
|
1114
981
|
canCancel(owner, id) {
|
|
1115
982
|
this.checkReady();
|
|
1116
983
|
const record = this.owned(owner, id);
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
return false;
|
|
1120
|
-
return LIVE.has(record.state) || this.hasRetainedCleanupRoute(record) || ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record)
|
|
1121
|
-
|| Boolean(runtime && !runtime.stopped);
|
|
984
|
+
return LIVE.has(record.state) || this.hasRetainedCleanupRoute(record)
|
|
985
|
+
|| ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record);
|
|
1122
986
|
}
|
|
1123
987
|
/** Newly observed cleanup facts never supply historical recovery proof. The optional
|
|
1124
988
|
* retirement callback is framework-owned and checked under the native cleanup lease. */
|
|
@@ -1143,9 +1007,8 @@ class ScheduleService {
|
|
|
1143
1007
|
record.state = 'interrupted';
|
|
1144
1008
|
record.error = absent ? 'Owner-reviewed native definition absent on current host; predecessor work remains unknown.'
|
|
1145
1009
|
: 'Owner-reviewed native deletion requested; absence and predecessor work remain unconfirmed.';
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
&& !this.recordOperations.has(id) && !this.refreshes && !this.retainedCancellations.has(id)) {
|
|
1010
|
+
if (absent && retirementConfirmed?.(record) === true
|
|
1011
|
+
&& !this.recordOperations.has(id) && !this.retainedCancellations.has(id)) {
|
|
1149
1012
|
record.state = 'cancelled';
|
|
1150
1013
|
record.cleanupConfirmed = true;
|
|
1151
1014
|
delete record.error;
|
|
@@ -1168,67 +1031,10 @@ class ScheduleService {
|
|
|
1168
1031
|
const record = this.owned(owner, id);
|
|
1169
1032
|
if (record.engine === 'host')
|
|
1170
1033
|
return;
|
|
1171
|
-
if (this.runtimes.get(id)?.stopped)
|
|
1172
|
-
return;
|
|
1173
1034
|
record.error = errorText(error);
|
|
1174
1035
|
await this.persist();
|
|
1175
1036
|
});
|
|
1176
1037
|
}
|
|
1177
|
-
/** Observe native inventory without deleting definitions or retiring native work. */
|
|
1178
|
-
refresh(owner) {
|
|
1179
|
-
this.refreshes++;
|
|
1180
|
-
return this.operation(this.refreshNative(structuredClone(owner)).finally(() => { this.refreshes--; }));
|
|
1181
|
-
}
|
|
1182
|
-
async refreshNative(owner) {
|
|
1183
|
-
this.checkReady();
|
|
1184
|
-
validateOwner(owner);
|
|
1185
|
-
const candidates = await this.serial(async () => [...this.records.values()]
|
|
1186
|
-
.filter(record => sameOwner(record, owner)).map(record => record.id));
|
|
1187
|
-
let failure;
|
|
1188
|
-
for (const id of candidates) {
|
|
1189
|
-
const record = this.records.get(id);
|
|
1190
|
-
const runtime = this.runtimes.get(id);
|
|
1191
|
-
const handle = runtime?.handle;
|
|
1192
|
-
if (!record || !runtime || !handle)
|
|
1193
|
-
continue;
|
|
1194
|
-
const nativeId = record.nativeId;
|
|
1195
|
-
const completed = runtime.completed.size;
|
|
1196
|
-
// Recheck after every read: cancellation or execution may have
|
|
1197
|
-
// advanced while inventory was awaiting its native receipt.
|
|
1198
|
-
const readable = () => !this.closing && !this.fault && this.current(owner)
|
|
1199
|
-
&& this.records.get(id) === record && record.nativeId === nativeId && record.state === 'active' && !record.cancelRequested
|
|
1200
|
-
&& this.runtimes.get(id) === runtime && runtime.handle === handle && !runtime.stopped && !runtime.cancelling
|
|
1201
|
-
&& !runtime.running.size && runtime.completed.size === completed && !runtime.stopPromise
|
|
1202
|
-
&& !this.recordOperations.has(id) && !this.retainedCancellations.has(id);
|
|
1203
|
-
if (!readable())
|
|
1204
|
-
continue;
|
|
1205
|
-
let present;
|
|
1206
|
-
try {
|
|
1207
|
-
present = await handle.list();
|
|
1208
|
-
if (typeof present !== 'boolean')
|
|
1209
|
-
throw new Error('Native inventory returned no verified presence or absence.');
|
|
1210
|
-
}
|
|
1211
|
-
catch (error) {
|
|
1212
|
-
// Read uncertainty is not absence or cancellation authority. Leave the
|
|
1213
|
-
// durable record, recovery fences and future occurrence admission intact.
|
|
1214
|
-
if (readable())
|
|
1215
|
-
failure ??= new Error(`Native inventory could not be verified for ${id}: ${errorText(error)}`);
|
|
1216
|
-
continue;
|
|
1217
|
-
}
|
|
1218
|
-
if (present)
|
|
1219
|
-
continue;
|
|
1220
|
-
await this.serial(async () => {
|
|
1221
|
-
if (!readable())
|
|
1222
|
-
return;
|
|
1223
|
-
record.state = 'interrupted';
|
|
1224
|
-
const detail = 'Native schedule is no longer listed; execution completion and cleanup are not confirmed.';
|
|
1225
|
-
record.error = record.error ? `${bounded(record.error, ERROR_BYTES - Buffer.byteLength(detail) - 1)}\n${detail}` : detail;
|
|
1226
|
-
await this.persist();
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
if (failure)
|
|
1230
|
-
throw failure;
|
|
1231
|
-
}
|
|
1232
1038
|
cancel(owner, id) {
|
|
1233
1039
|
return this.operation(this.recordOperation(id, this.cancelSchedule(owner, id)));
|
|
1234
1040
|
}
|
|
@@ -1236,7 +1042,6 @@ class ScheduleService {
|
|
|
1236
1042
|
this.checkReady();
|
|
1237
1043
|
validateOwner(owner);
|
|
1238
1044
|
(0, ScheduleCommand_1.validateScheduleId)(id);
|
|
1239
|
-
let runtime;
|
|
1240
1045
|
let existing;
|
|
1241
1046
|
let operation;
|
|
1242
1047
|
await this.serial(async () => {
|
|
@@ -1252,41 +1057,24 @@ class ScheduleService {
|
|
|
1252
1057
|
existing = this.retainedCancellations.get(id);
|
|
1253
1058
|
if (existing)
|
|
1254
1059
|
return;
|
|
1255
|
-
runtime = this.runtimes.get(id);
|
|
1256
1060
|
record.cancelRequested = true;
|
|
1257
1061
|
if (record.recovery)
|
|
1258
1062
|
record.recovery.status = 'blocked';
|
|
1259
1063
|
await this.persist();
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|| ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record))) {
|
|
1064
|
+
if (unsettledNativeWork(record) || record.state === 'failed' && !!record.recovery
|
|
1065
|
+
|| ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record)) {
|
|
1263
1066
|
operation = Promise.resolve().then(() => this.cancelRetained(record));
|
|
1264
1067
|
this.retainedCancellations.set(id, operation);
|
|
1265
1068
|
return;
|
|
1266
1069
|
}
|
|
1267
|
-
if (
|
|
1268
|
-
existing = runtime.cancelPromise;
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
if (!LIVE.has(record.state) && !runtime?.cancelling && (!runtime || runtime.stopped)) {
|
|
1272
|
-
if (record.recovery && runtime?.stopped) {
|
|
1273
|
-
record.state = 'cancelled';
|
|
1274
|
-
delete record.error;
|
|
1275
|
-
}
|
|
1276
|
-
for (const [key, pending] of this.pending) {
|
|
1277
|
-
if (pending.scheduleId === id && !pending.afterCancellation)
|
|
1278
|
-
this.pending.delete(key);
|
|
1279
|
-
}
|
|
1280
|
-
await this.persist();
|
|
1281
|
-
operation = Promise.resolve(structuredClone(record));
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
if (!runtime)
|
|
1070
|
+
if (LIVE.has(record.state))
|
|
1285
1071
|
throw new Error('Native schedule handle is unavailable.');
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1072
|
+
for (const [key, pending] of this.pending) {
|
|
1073
|
+
if (pending.scheduleId === id && !pending.afterCancellation)
|
|
1074
|
+
this.pending.delete(key);
|
|
1075
|
+
}
|
|
1076
|
+
await this.persist();
|
|
1077
|
+
operation = Promise.resolve(structuredClone(record));
|
|
1290
1078
|
});
|
|
1291
1079
|
return (existing ?? operation);
|
|
1292
1080
|
}
|
|
@@ -1298,7 +1086,7 @@ class ScheduleService {
|
|
|
1298
1086
|
supportsRetainedCancellation(record) {
|
|
1299
1087
|
if (record.engine === 'host' || !(0, ScheduleCapabilities_1.isNativeScheduleBackend)(record.backend))
|
|
1300
1088
|
return false;
|
|
1301
|
-
const cleanup = this.options.
|
|
1089
|
+
const cleanup = this.options.cleanupFor?.({ ...record, backend: record.backend, ...record.execution });
|
|
1302
1090
|
return !!record.recovery && !!cleanup?.cancelRetained && cleanup.provider === record.recovery.provider
|
|
1303
1091
|
&& cleanup.strategy === record.recovery.strategy;
|
|
1304
1092
|
}
|
|
@@ -1308,7 +1096,7 @@ class ScheduleService {
|
|
|
1308
1096
|
const ownership = record.recovery;
|
|
1309
1097
|
if (record.engine === 'host' || !(0, ScheduleCapabilities_1.isNativeScheduleBackend)(record.backend))
|
|
1310
1098
|
throw new Error('Native cleanup requires a legacy schedule.');
|
|
1311
|
-
const provider = this.options.
|
|
1099
|
+
const provider = this.options.cleanupFor?.({ id: record.id, threadId: record.threadId,
|
|
1312
1100
|
backend: record.backend, cwd: record.cwd, prompt: record.prompt, rule: record.rule,
|
|
1313
1101
|
...record.execution, recovery: ownership });
|
|
1314
1102
|
if (!ownership || !provider?.cancelRetained || provider.provider !== ownership.provider || provider.strategy !== ownership.strategy) {
|
|
@@ -1360,9 +1148,8 @@ class ScheduleService {
|
|
|
1360
1148
|
/** Idle future definitions do not block updates. Active work and durable deliveries still do. */
|
|
1361
1149
|
canRestartWithoutActiveWork() {
|
|
1362
1150
|
return this.initialized && !this.closing && !this.fault && !this.operations.size
|
|
1363
|
-
&& !this.hostAttempts.size && !
|
|
1364
|
-
&& !
|
|
1365
|
-
!runtime.running.size && !runtime.cancelling) && ![...this.records.values()].some(record => record.state === 'creating');
|
|
1151
|
+
&& !this.hostAttempts.size && !this.pending.size && !this.delivering.size
|
|
1152
|
+
&& ![...this.records.values()].some(record => record.inFlightDueAt !== undefined || record.state === 'creating');
|
|
1366
1153
|
}
|
|
1367
1154
|
/** Shutdown revokes admission only. It never invokes native schedule RPCs or waits for result ACKs. */
|
|
1368
1155
|
destroy() {
|
|
@@ -1375,192 +1162,11 @@ class ScheduleService {
|
|
|
1375
1162
|
// Complete only writes already in this process's serial filesystem queue.
|
|
1376
1163
|
// Native requests, results and delivery are independently durable or remain unknown after exit.
|
|
1377
1164
|
await this.tail;
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
// work here. Process exit releases the kernel gate even if it never returns.
|
|
1381
|
-
if (!this.pendingCreates) {
|
|
1382
|
-
this.catalogGate?.close();
|
|
1383
|
-
this.catalogGate = undefined;
|
|
1384
|
-
}
|
|
1165
|
+
this.catalogGate?.close();
|
|
1166
|
+
this.catalogGate = undefined;
|
|
1385
1167
|
})();
|
|
1386
1168
|
}
|
|
1387
|
-
|
|
1388
|
-
try {
|
|
1389
|
-
const handle = await runtime.ready;
|
|
1390
|
-
if (handle && !runtime.stopped) {
|
|
1391
|
-
if (LIVE.has(this.records.get(id).state) || handle.cancellationKeepsRunning) {
|
|
1392
|
-
await handle.cancel();
|
|
1393
|
-
runtime.removalConfirmed = true;
|
|
1394
|
-
}
|
|
1395
|
-
else
|
|
1396
|
-
await this.stop(id, runtime);
|
|
1397
|
-
}
|
|
1398
|
-
await this.serial(async () => {
|
|
1399
|
-
const record = this.records.get(id);
|
|
1400
|
-
record.state = 'cancelled';
|
|
1401
|
-
delete record.error;
|
|
1402
|
-
if (handle?.cancellationKeepsRunning) {
|
|
1403
|
-
for (const pending of this.pending.values())
|
|
1404
|
-
if (pending.scheduleId === id)
|
|
1405
|
-
pending.afterCancellation = true;
|
|
1406
|
-
}
|
|
1407
|
-
else
|
|
1408
|
-
this.dropPending(id);
|
|
1409
|
-
await this.persist();
|
|
1410
|
-
});
|
|
1411
|
-
runtime.cancelling = false;
|
|
1412
|
-
runtime.heldDeliveries.clear();
|
|
1413
|
-
await this.stop(id, runtime);
|
|
1414
|
-
if (handle?.cancellationKeepsRunning)
|
|
1415
|
-
await this.attemptDeliveries([...this.pending.keys()]);
|
|
1416
|
-
return structuredClone(this.records.get(id));
|
|
1417
|
-
}
|
|
1418
|
-
catch (error) {
|
|
1419
|
-
runtime.cancelling = false;
|
|
1420
|
-
await this.serial(async () => {
|
|
1421
|
-
this.records.get(id).error = errorText(error);
|
|
1422
|
-
if (!this.fault)
|
|
1423
|
-
await this.persist();
|
|
1424
|
-
});
|
|
1425
|
-
if (!LIVE.has(this.records.get(id).state))
|
|
1426
|
-
await this.stop(id, runtime).catch(() => { });
|
|
1427
|
-
const ids = [...runtime.heldDeliveries];
|
|
1428
|
-
runtime.heldDeliveries.clear();
|
|
1429
|
-
await this.attemptDeliveries(ids, true);
|
|
1430
|
-
throw error;
|
|
1431
|
-
}
|
|
1432
|
-
finally {
|
|
1433
|
-
runtime.cancelPromise = undefined;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
async onEvent(id, event) {
|
|
1437
|
-
let delivery;
|
|
1438
|
-
let cleanup = false;
|
|
1439
|
-
const runtime = this.runtimes.get(id);
|
|
1440
|
-
await this.serial(async () => {
|
|
1441
|
-
if (!runtime || this.runtimes.get(id) !== runtime || !this.records.has(id)) {
|
|
1442
|
-
return;
|
|
1443
|
-
}
|
|
1444
|
-
if (this.fault)
|
|
1445
|
-
throw this.fault;
|
|
1446
|
-
if (this.closing) {
|
|
1447
|
-
if (event.type === 'attributed')
|
|
1448
|
-
throw new Error('Schedule service closed before native creation attribution.');
|
|
1449
|
-
return;
|
|
1450
|
-
}
|
|
1451
|
-
const record = this.records.get(id);
|
|
1452
|
-
if (event.type === 'attributed') {
|
|
1453
|
-
if (!record.recovery || record.state !== 'creating' || !this.current(record) || record.cancelRequested) {
|
|
1454
|
-
throw new Error('Native creation attribution is no longer admissible.');
|
|
1455
|
-
}
|
|
1456
|
-
text(event.cleanupIdentity, 8192);
|
|
1457
|
-
record.recovery.identity = event.cleanupIdentity;
|
|
1458
|
-
await this.persist();
|
|
1459
|
-
return;
|
|
1460
|
-
}
|
|
1461
|
-
// Process exit evidence is independent of task state, including late exit
|
|
1462
|
-
// after a failed cancellation cleanup. Never downgrade confirmed exit.
|
|
1463
|
-
if (event.type === 'stopped' && event.exitConfirmed !== false) {
|
|
1464
|
-
runtime.stopped = true;
|
|
1465
|
-
if (record.error?.startsWith('Native process exit unconfirmed:')) {
|
|
1466
|
-
delete record.error;
|
|
1467
|
-
await this.persist();
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
const ownerCurrent = this.current(record);
|
|
1471
|
-
if (this.closing)
|
|
1472
|
-
return;
|
|
1473
|
-
if (!ownerCurrent) {
|
|
1474
|
-
if (record.recovery && (!ownerCurrent || event.type !== 'stopped' || event.exitConfirmed === false))
|
|
1475
|
-
record.recovery.status = 'blocked';
|
|
1476
|
-
if (LIVE.has(record.state)) {
|
|
1477
|
-
record.state = 'interrupted';
|
|
1478
|
-
record.error = 'Schedule owner or service is no longer current.';
|
|
1479
|
-
}
|
|
1480
|
-
// Native stop notifications during shutdown must preserve completed outbox
|
|
1481
|
-
// entries for restart. Only actual ownership invalidation discards them.
|
|
1482
|
-
if (!ownerCurrent)
|
|
1483
|
-
this.dropPending(id);
|
|
1484
|
-
cleanup = true;
|
|
1485
|
-
await this.persist();
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
const finishingFailed = record.state === 'failed' && event.type === 'completed' && runtime.running.has(event.occurrenceId);
|
|
1489
|
-
const finishingCancelled = record.state === 'cancelled' && runtime.handle?.cancellationKeepsRunning
|
|
1490
|
-
&& event.type === 'completed' && runtime.running.has(event.occurrenceId);
|
|
1491
|
-
if ((!finishingCancelled && record.state === 'cancelled') || record.state === 'failed' && !finishingFailed || record.state === 'completed')
|
|
1492
|
-
return;
|
|
1493
|
-
if (event.type === 'stopped') {
|
|
1494
|
-
if (record.recovery)
|
|
1495
|
-
record.recovery.status = 'blocked';
|
|
1496
|
-
if (LIVE.has(record.state)) {
|
|
1497
|
-
record.state = 'interrupted';
|
|
1498
|
-
record.error = bounded(event.reason, ERROR_BYTES);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
else {
|
|
1502
|
-
text(event.occurrenceId);
|
|
1503
|
-
if (runtime.completed.has(event.occurrenceId))
|
|
1504
|
-
return;
|
|
1505
|
-
if (record.state === 'interrupted' && (event.type !== 'completed' || !runtime.running.has(event.occurrenceId)))
|
|
1506
|
-
return;
|
|
1507
|
-
if (runtime.completed.size + runtime.running.size >= this.maxOccurrences && !runtime.running.has(event.occurrenceId)) {
|
|
1508
|
-
record.state = 'interrupted';
|
|
1509
|
-
record.error = 'Occurrence tracking limit reached; native schedule stopped.';
|
|
1510
|
-
cleanup = true;
|
|
1511
|
-
}
|
|
1512
|
-
else if (event.type === 'started') {
|
|
1513
|
-
runtime.running.add(event.occurrenceId);
|
|
1514
|
-
record.state = 'running';
|
|
1515
|
-
if (record.recovery)
|
|
1516
|
-
record.recovery.status = 'blocked';
|
|
1517
|
-
}
|
|
1518
|
-
else if (event.type === 'completed') {
|
|
1519
|
-
if (typeof event.success !== 'boolean')
|
|
1520
|
-
throw new Error('Invalid native completion event.');
|
|
1521
|
-
runtime.running.delete(event.occurrenceId);
|
|
1522
|
-
runtime.completed.add(event.occurrenceId);
|
|
1523
|
-
record.completedOccurrences = [...runtime.completed];
|
|
1524
|
-
if (this.outboxFull(id)) {
|
|
1525
|
-
record.state = 'interrupted';
|
|
1526
|
-
record.error = 'Delivery outbox is full; latest result could not be retained. Native schedule stopped.';
|
|
1527
|
-
cleanup = true;
|
|
1528
|
-
}
|
|
1529
|
-
else {
|
|
1530
|
-
delivery = deliveryId(id, event.occurrenceId);
|
|
1531
|
-
this.pending.set(delivery, { id: delivery, scheduleId: id, occurrenceId: event.occurrenceId,
|
|
1532
|
-
success: event.success, ...(finishingCancelled ? { afterCancellation: true } : {}), ...(event.output !== undefined && { output: bounded(event.output, OUTPUT_BYTES) }),
|
|
1533
|
-
...(event.error !== undefined && { error: bounded(event.error, ERROR_BYTES) }) });
|
|
1534
|
-
if (finishingCancelled) {
|
|
1535
|
-
cleanup = true;
|
|
1536
|
-
}
|
|
1537
|
-
else if (record.rule.kind === 'once') {
|
|
1538
|
-
record.state = 'completed';
|
|
1539
|
-
cleanup = true;
|
|
1540
|
-
}
|
|
1541
|
-
else if (record.state !== 'interrupted' && record.state !== 'failed') {
|
|
1542
|
-
record.state = runtime.running.size ? 'running' : 'active';
|
|
1543
|
-
if (record.recovery && !runtime.running.size)
|
|
1544
|
-
record.recovery.status = 'blocked';
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
else
|
|
1549
|
-
throw new Error('Invalid native schedule event.');
|
|
1550
|
-
}
|
|
1551
|
-
await this.persist();
|
|
1552
|
-
});
|
|
1553
|
-
// Do not wait for a create handle before recording or delivering an early result.
|
|
1554
|
-
// stop() records retryable exit failures itself. A cleanup timeout must not
|
|
1555
|
-
// fault the entire service or prevent a later explicit cancellation retry.
|
|
1556
|
-
// Persistence failures still set the service fault inside persist().
|
|
1557
|
-
if (cleanup && !this.closing && !runtime.cancelling)
|
|
1558
|
-
this.track(this.stop(id, runtime).catch(() => { }));
|
|
1559
|
-
if (delivery) {
|
|
1560
|
-
await this.attemptDeliveries([delivery], true);
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
attemptDeliveries(ids, firstAttempt = false) {
|
|
1169
|
+
attemptDeliveries(ids) {
|
|
1564
1170
|
const run = this.deliveryTail.then(async () => {
|
|
1565
1171
|
for (const id of ids) {
|
|
1566
1172
|
let delivery;
|
|
@@ -1588,12 +1194,6 @@ class ScheduleService {
|
|
|
1588
1194
|
await this.persist();
|
|
1589
1195
|
return;
|
|
1590
1196
|
}
|
|
1591
|
-
const runtime = this.runtimes.get(record.id);
|
|
1592
|
-
if (runtime?.cancelling) {
|
|
1593
|
-
if (firstAttempt)
|
|
1594
|
-
runtime.heldDeliveries.add(id);
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
1197
|
delivery = { id, schedule: structuredClone(record), occurrenceId: pending.occurrenceId,
|
|
1598
1198
|
success: pending.success, ...(pending.output !== undefined && { output: pending.output }),
|
|
1599
1199
|
...(pending.error !== undefined && { error: pending.error }) };
|
|
@@ -1601,12 +1201,6 @@ class ScheduleService {
|
|
|
1601
1201
|
if (!delivery || this.closing || !this.current(delivery.schedule) || !this.pending.has(id)
|
|
1602
1202
|
|| this.purges.has(delivery.schedule.id))
|
|
1603
1203
|
continue;
|
|
1604
|
-
const runtime = this.runtimes.get(delivery.schedule.id);
|
|
1605
|
-
if (runtime?.cancelling) {
|
|
1606
|
-
if (firstAttempt)
|
|
1607
|
-
runtime.heldDeliveries.add(id);
|
|
1608
|
-
continue;
|
|
1609
|
-
}
|
|
1610
1204
|
this.delivering.add(delivery.schedule.id);
|
|
1611
1205
|
try {
|
|
1612
1206
|
await this.options.deliver(delivery);
|
|
@@ -1628,76 +1222,10 @@ class ScheduleService {
|
|
|
1628
1222
|
this.deliveryTail = run.catch(() => { });
|
|
1629
1223
|
return run;
|
|
1630
1224
|
}
|
|
1631
|
-
stop(id, runtime) {
|
|
1632
|
-
if (this.closing || this.runtimes.get(id) !== runtime)
|
|
1633
|
-
return Promise.resolve();
|
|
1634
|
-
if (runtime.stopped)
|
|
1635
|
-
return this.rememberCleanup(id, runtime);
|
|
1636
|
-
if (runtime.stopPromise)
|
|
1637
|
-
return runtime.stopPromise;
|
|
1638
|
-
const operation = (async () => {
|
|
1639
|
-
try {
|
|
1640
|
-
const handle = await runtime.ready;
|
|
1641
|
-
if (this.closing)
|
|
1642
|
-
return;
|
|
1643
|
-
if (handle && !runtime.stopped) {
|
|
1644
|
-
await handle.stop();
|
|
1645
|
-
// Process/job retirement is not itself proof that persisted timing was deleted.
|
|
1646
|
-
if (handle.nativeDefinitionAbsent === true)
|
|
1647
|
-
runtime.removalConfirmed = true;
|
|
1648
|
-
}
|
|
1649
|
-
// A shared session can delete future firings while an occurrence still
|
|
1650
|
-
// finishes. Keep ownership until its terminal stopped notification.
|
|
1651
|
-
if (handle?.retirementConfirmed !== false && (!handle?.cancellationKeepsRunning || !runtime.running.size))
|
|
1652
|
-
runtime.stopped = true;
|
|
1653
|
-
if (runtime.stopped) {
|
|
1654
|
-
await this.rememberCleanup(id, runtime);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
catch (error) {
|
|
1658
|
-
await this.serial(async () => {
|
|
1659
|
-
this.records.get(id).error = `Native process exit unconfirmed: ${errorText(error)}`.slice(0, ERROR_BYTES / 4);
|
|
1660
|
-
if (!this.fault)
|
|
1661
|
-
await this.persist();
|
|
1662
|
-
});
|
|
1663
|
-
throw error;
|
|
1664
|
-
}
|
|
1665
|
-
})();
|
|
1666
|
-
const tracked = this.recordOperation(id, operation);
|
|
1667
|
-
runtime.stopPromise = tracked;
|
|
1668
|
-
void operation.finally(() => { if (!runtime.stopped)
|
|
1669
|
-
runtime.stopPromise = undefined; }).catch(() => { });
|
|
1670
|
-
return tracked;
|
|
1671
|
-
}
|
|
1672
|
-
rememberCleanup(id, runtime) {
|
|
1673
|
-
return this.serial(async () => {
|
|
1674
|
-
const record = this.records.get(id);
|
|
1675
|
-
if (this.runtimes.get(id) === runtime && runtime.stopped && !runtime.running.size
|
|
1676
|
-
&& runtime.removalConfirmed && runtime.handle?.nativeDefinitionAbsent === true
|
|
1677
|
-
&& record?.cancelRequested && record.state === 'cancelled' && !record.cleanupConfirmed) {
|
|
1678
|
-
record.cleanupConfirmed = true;
|
|
1679
|
-
await this.persist();
|
|
1680
|
-
}
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
canAdmitOccurrence(id, runtime) {
|
|
1684
|
-
const record = this.records.get(id);
|
|
1685
|
-
return !!record && this.runtimes.get(id) === runtime && !this.closing && !this.fault
|
|
1686
|
-
&& !runtime.stopped && !runtime.cancelling && !record.cancelRequested
|
|
1687
|
-
&& LIVE.has(record.state) && this.current(record);
|
|
1688
|
-
}
|
|
1689
|
-
newRuntime() {
|
|
1690
|
-
let resolveReady;
|
|
1691
|
-
const ready = new Promise(resolve => { resolveReady = resolve; });
|
|
1692
|
-
return { ready, resolveReady, running: new Set(), completed: new Set(), heldDeliveries: new Set(), cancelling: false, stopped: false };
|
|
1693
|
-
}
|
|
1694
1225
|
track(task) {
|
|
1695
1226
|
this.tasks.add(task);
|
|
1696
1227
|
void task.catch(error => {
|
|
1697
|
-
// Persistence/protocol failures fail closed and stop native producers.
|
|
1698
1228
|
this.fault ??= error instanceof Error ? error : new Error('Schedule service failed.');
|
|
1699
|
-
for (const [id, runtime] of this.runtimes)
|
|
1700
|
-
void this.stop(id, runtime).catch(() => { });
|
|
1701
1229
|
}).finally(() => this.tasks.delete(task));
|
|
1702
1230
|
}
|
|
1703
1231
|
operation(task) {
|
|
@@ -2001,8 +1529,6 @@ class ScheduleService {
|
|
|
2001
1529
|
}
|
|
2002
1530
|
catch (error) {
|
|
2003
1531
|
this.fault = error instanceof Error ? error : new Error('Schedule catalog write failed.');
|
|
2004
|
-
for (const [id, runtime] of this.runtimes)
|
|
2005
|
-
void this.stop(id, runtime).catch(() => { });
|
|
2006
1532
|
throw this.fault;
|
|
2007
1533
|
}
|
|
2008
1534
|
}
|