@yu_robotics/remote-cli 1.6.266 → 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.map +1 -1
- package/dist/client/MessageHandler.js +10 -51
- 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 +4 -17
- package/dist/scheduling/ScheduleService.d.ts.map +1 -1
- package/dist/scheduling/ScheduleService.js +59 -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);
|
|
@@ -718,16 +568,14 @@ class ScheduleService {
|
|
|
718
568
|
/** Called under the catalog serial queue, never through output-erasing purge.
|
|
719
569
|
* A refusal is proof about this fresh attempt, not historical native absence. */
|
|
720
570
|
async compactRefusedCreation(record) {
|
|
721
|
-
const id = record.id
|
|
571
|
+
const id = record.id;
|
|
722
572
|
if (record.state !== 'failed' || record.creationRefused !== true || record.nativeId !== undefined
|
|
723
573
|
|| record.cancelRequested || record.cleanupConfirmed || record.completedOccurrences?.length || record.skippedOccurrences?.length
|
|
724
574
|
|| this.records.get(id) !== record || this.cleanup.has(id) || this.purged.has(id)
|
|
725
|
-
|| this.fault || this.closing
|
|
575
|
+
|| this.fault || this.closing
|
|
726
576
|
|| this.recordOperations.has(id) || this.retainedCancellations.has(id) || this.purges.has(id)
|
|
727
577
|
|| this.delivering.has(id) || [...this.pending.values()].some(item => item.scheduleId === id)
|
|
728
578
|
|| this.options.isNativeMutationPending?.(ownerOf(record))
|
|
729
|
-
|| runtime && (!runtime.stopped || runtime.handle || runtime.observedOccurrence || runtime.running.size || runtime.completed.size
|
|
730
|
-
|| runtime.heldDeliveries.size || runtime.cancelling || runtime.cancelPromise || runtime.stopPromise)
|
|
731
579
|
|| this.purgeFencesFull(id))
|
|
732
580
|
return;
|
|
733
581
|
this.purged.set(id, ownerOf(record));
|
|
@@ -740,8 +588,6 @@ class ScheduleService {
|
|
|
740
588
|
this.purged.delete(id);
|
|
741
589
|
throw error;
|
|
742
590
|
}
|
|
743
|
-
if (runtime)
|
|
744
|
-
this.runtimes.delete(id);
|
|
745
591
|
}
|
|
746
592
|
/** Catalog lookup only; this does not probe or recreate native jobs. */
|
|
747
593
|
async list(owner) {
|
|
@@ -953,7 +799,7 @@ class ScheduleService {
|
|
|
953
799
|
if (!prior || !sameCleanupOwner(prior, owner) || this.records.has(id))
|
|
954
800
|
throw new Error('Purge owned history before forgetting unresolved cleanup tracking.');
|
|
955
801
|
if (this.options.isNativeMutationPending?.(owner) || this.recordOperations.has(id)
|
|
956
|
-
|| this.
|
|
802
|
+
|| this.retainedCancellations.has(id))
|
|
957
803
|
return { status: 'pending', reason: 'operation_pending', detail: 'Native work or cleanup is still pending; tracking was not forgotten.' };
|
|
958
804
|
if (this.delivering.has(id))
|
|
959
805
|
return { status: 'pending', reason: 'delivery_pending', detail: 'An external delivery is already in flight; tracking was not forgotten.' };
|
|
@@ -1037,7 +883,7 @@ class ScheduleService {
|
|
|
1037
883
|
if (this.hostAttempts.has(id))
|
|
1038
884
|
return pending('operation_pending', 'Host dispatch is reserving the thread.');
|
|
1039
885
|
if ((record.engine !== 'host' && this.options.isNativeMutationPending?.(owner)) || this.recordOperations.has(id)
|
|
1040
|
-
|| this.
|
|
886
|
+
|| this.retainedCancellations.has(id)) {
|
|
1041
887
|
return pending('operation_pending', 'Creation, inspection or cleanup is still pending. Retry these same IDs.');
|
|
1042
888
|
}
|
|
1043
889
|
if (this.delivering.has(id))
|
|
@@ -1048,15 +894,11 @@ class ScheduleService {
|
|
|
1048
894
|
return active;
|
|
1049
895
|
if (this.purgeFencesFull(id))
|
|
1050
896
|
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
1051
|
-
const runtime = this.runtimes.get(id);
|
|
1052
897
|
// Do not interpret terminal state, an absent handle or a stopped process as
|
|
1053
898
|
// native definition absence. Existing cancelRetained owns its stronger proof.
|
|
1054
899
|
let retainedVerified = false;
|
|
1055
|
-
const clean = record.engine === 'host' ||
|
|
1056
|
-
if (
|
|
1057
|
-
await this.cancel(owner, id);
|
|
1058
|
-
}
|
|
1059
|
-
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)) {
|
|
1060
902
|
try {
|
|
1061
903
|
await this.recordOperation(id, this.cancelRetained(record));
|
|
1062
904
|
retainedVerified = true;
|
|
@@ -1073,11 +915,6 @@ class ScheduleService {
|
|
|
1073
915
|
const unfinished = busy();
|
|
1074
916
|
if (unfinished)
|
|
1075
917
|
return unfinished;
|
|
1076
|
-
if (runtime?.running.size)
|
|
1077
|
-
return pending('occurrence_running', 'Future cancellation does not revoke an already admitted occurrence.');
|
|
1078
|
-
if (runtime && (!runtime.stopped))
|
|
1079
|
-
return pending('operation_pending', 'Native runtime retirement is unconfirmed.');
|
|
1080
|
-
const handleProof = runtime?.removalConfirmed && runtime.handle?.nativeDefinitionAbsent !== false;
|
|
1081
918
|
const erase = (evidence, unresolved) => this.serial(async () => {
|
|
1082
919
|
this.checkReady();
|
|
1083
920
|
if (!current() || evidence?.status === 'verified' && !evidence.isCurrent())
|
|
@@ -1087,10 +924,6 @@ class ScheduleService {
|
|
|
1087
924
|
return changed;
|
|
1088
925
|
if (this.purgeFencesFull(id))
|
|
1089
926
|
return pending('fence_capacity', 'Durable purge ID capacity reached; no replay fence was discarded.');
|
|
1090
|
-
if (this.runtimes.get(id) !== runtime || runtime?.running.size || runtime && !runtime.stopped
|
|
1091
|
-
|| handleProof && runtime?.handle?.nativeDefinitionAbsent === false) {
|
|
1092
|
-
return pending('operation_pending', 'Native ownership changed before history removal.');
|
|
1093
|
-
}
|
|
1094
927
|
if (unresolved && this.cleanup.size >= MAX_CLEANUP_RECORDS)
|
|
1095
928
|
return pending('fence_capacity', 'Native cleanup ledger capacity reached (1000); resolve existing cleanup before removing more history.');
|
|
1096
929
|
// Commit history/output deletion, minimal operational selector and replay
|
|
@@ -1112,10 +945,9 @@ class ScheduleService {
|
|
|
1112
945
|
this.pending.set(key, entry);
|
|
1113
946
|
throw error;
|
|
1114
947
|
}
|
|
1115
|
-
this.runtimes.delete(id);
|
|
1116
948
|
return { status: 'removed' };
|
|
1117
949
|
});
|
|
1118
|
-
if (record.creationRefused || clean || retainedVerified
|
|
950
|
+
if (record.creationRefused || clean || retainedVerified)
|
|
1119
951
|
return erase();
|
|
1120
952
|
if (!this.options.withPurgeVerification)
|
|
1121
953
|
return erase(undefined, 'native_absence_unknown');
|
|
@@ -1143,26 +975,14 @@ class ScheduleService {
|
|
|
1143
975
|
return [...this.records.values()].some(record => (!threadId || record.threadId === threadId) && this.isActiveSchedule(record));
|
|
1144
976
|
}
|
|
1145
977
|
isActiveSchedule(record) {
|
|
1146
|
-
return LIVE.has(record.state) || record.inFlightDueAt !== undefined || this.hasRetainedCleanupRoute(record)
|
|
1147
|
-
|| (this.runtimes.has(record.id) && !this.runtimes.get(record.id).stopped);
|
|
1148
|
-
}
|
|
1149
|
-
/** Read-only admission for purge of an owned runtime, including cancelled jobs. */
|
|
1150
|
-
needsNativePurge(owner, id) {
|
|
1151
|
-
this.checkReady();
|
|
1152
|
-
this.owned(owner, id);
|
|
1153
|
-
const runtime = this.runtimes.get(id);
|
|
1154
|
-
// Cancellation can hide the card while its native runtime still needs retirement.
|
|
1155
|
-
return !!runtime?.handle && !runtime.stopped;
|
|
978
|
+
return LIVE.has(record.state) || record.inFlightDueAt !== undefined || this.hasRetainedCleanupRoute(record);
|
|
1156
979
|
}
|
|
1157
980
|
/** Card eligibility includes retryable cleanup even for a terminal catalog record. */
|
|
1158
981
|
canCancel(owner, id) {
|
|
1159
982
|
this.checkReady();
|
|
1160
983
|
const record = this.owned(owner, id);
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
return false;
|
|
1164
|
-
return LIVE.has(record.state) || this.hasRetainedCleanupRoute(record) || ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record)
|
|
1165
|
-
|| Boolean(runtime && !runtime.stopped);
|
|
984
|
+
return LIVE.has(record.state) || this.hasRetainedCleanupRoute(record)
|
|
985
|
+
|| ['interrupted', 'failed'].includes(record.state) && !!record.nativeId && this.supportsRetainedCancellation(record);
|
|
1166
986
|
}
|
|
1167
987
|
/** Newly observed cleanup facts never supply historical recovery proof. The optional
|
|
1168
988
|
* retirement callback is framework-owned and checked under the native cleanup lease. */
|
|
@@ -1187,9 +1007,8 @@ class ScheduleService {
|
|
|
1187
1007
|
record.state = 'interrupted';
|
|
1188
1008
|
record.error = absent ? 'Owner-reviewed native definition absent on current host; predecessor work remains unknown.'
|
|
1189
1009
|
: 'Owner-reviewed native deletion requested; absence and predecessor work remain unconfirmed.';
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
&& !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)) {
|
|
1193
1012
|
record.state = 'cancelled';
|
|
1194
1013
|
record.cleanupConfirmed = true;
|
|
1195
1014
|
delete record.error;
|
|
@@ -1212,67 +1031,10 @@ class ScheduleService {
|
|
|
1212
1031
|
const record = this.owned(owner, id);
|
|
1213
1032
|
if (record.engine === 'host')
|
|
1214
1033
|
return;
|
|
1215
|
-
if (this.runtimes.get(id)?.stopped)
|
|
1216
|
-
return;
|
|
1217
1034
|
record.error = errorText(error);
|
|
1218
1035
|
await this.persist();
|
|
1219
1036
|
});
|
|
1220
1037
|
}
|
|
1221
|
-
/** Observe native inventory without deleting definitions or retiring native work. */
|
|
1222
|
-
refresh(owner) {
|
|
1223
|
-
this.refreshes++;
|
|
1224
|
-
return this.operation(this.refreshNative(structuredClone(owner)).finally(() => { this.refreshes--; }));
|
|
1225
|
-
}
|
|
1226
|
-
async refreshNative(owner) {
|
|
1227
|
-
this.checkReady();
|
|
1228
|
-
validateOwner(owner);
|
|
1229
|
-
const candidates = await this.serial(async () => [...this.records.values()]
|
|
1230
|
-
.filter(record => sameOwner(record, owner)).map(record => record.id));
|
|
1231
|
-
let failure;
|
|
1232
|
-
for (const id of candidates) {
|
|
1233
|
-
const record = this.records.get(id);
|
|
1234
|
-
const runtime = this.runtimes.get(id);
|
|
1235
|
-
const handle = runtime?.handle;
|
|
1236
|
-
if (!record || !runtime || !handle)
|
|
1237
|
-
continue;
|
|
1238
|
-
const nativeId = record.nativeId;
|
|
1239
|
-
const completed = runtime.completed.size;
|
|
1240
|
-
// Recheck after every read: cancellation or execution may have
|
|
1241
|
-
// advanced while inventory was awaiting its native receipt.
|
|
1242
|
-
const readable = () => !this.closing && !this.fault && this.current(owner)
|
|
1243
|
-
&& this.records.get(id) === record && record.nativeId === nativeId && record.state === 'active' && !record.cancelRequested
|
|
1244
|
-
&& this.runtimes.get(id) === runtime && runtime.handle === handle && !runtime.stopped && !runtime.cancelling
|
|
1245
|
-
&& !runtime.running.size && runtime.completed.size === completed && !runtime.stopPromise
|
|
1246
|
-
&& !this.recordOperations.has(id) && !this.retainedCancellations.has(id);
|
|
1247
|
-
if (!readable())
|
|
1248
|
-
continue;
|
|
1249
|
-
let present;
|
|
1250
|
-
try {
|
|
1251
|
-
present = await handle.list();
|
|
1252
|
-
if (typeof present !== 'boolean')
|
|
1253
|
-
throw new Error('Native inventory returned no verified presence or absence.');
|
|
1254
|
-
}
|
|
1255
|
-
catch (error) {
|
|
1256
|
-
// Read uncertainty is not absence or cancellation authority. Leave the
|
|
1257
|
-
// durable record, recovery fences and future occurrence admission intact.
|
|
1258
|
-
if (readable())
|
|
1259
|
-
failure ??= new Error(`Native inventory could not be verified for ${id}: ${errorText(error)}`);
|
|
1260
|
-
continue;
|
|
1261
|
-
}
|
|
1262
|
-
if (present)
|
|
1263
|
-
continue;
|
|
1264
|
-
await this.serial(async () => {
|
|
1265
|
-
if (!readable())
|
|
1266
|
-
return;
|
|
1267
|
-
record.state = 'interrupted';
|
|
1268
|
-
const detail = 'Native schedule is no longer listed; execution completion and cleanup are not confirmed.';
|
|
1269
|
-
record.error = record.error ? `${bounded(record.error, ERROR_BYTES - Buffer.byteLength(detail) - 1)}\n${detail}` : detail;
|
|
1270
|
-
await this.persist();
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
if (failure)
|
|
1274
|
-
throw failure;
|
|
1275
|
-
}
|
|
1276
1038
|
cancel(owner, id) {
|
|
1277
1039
|
return this.operation(this.recordOperation(id, this.cancelSchedule(owner, id)));
|
|
1278
1040
|
}
|
|
@@ -1280,7 +1042,6 @@ class ScheduleService {
|
|
|
1280
1042
|
this.checkReady();
|
|
1281
1043
|
validateOwner(owner);
|
|
1282
1044
|
(0, ScheduleCommand_1.validateScheduleId)(id);
|
|
1283
|
-
let runtime;
|
|
1284
1045
|
let existing;
|
|
1285
1046
|
let operation;
|
|
1286
1047
|
await this.serial(async () => {
|
|
@@ -1296,41 +1057,24 @@ class ScheduleService {
|
|
|
1296
1057
|
existing = this.retainedCancellations.get(id);
|
|
1297
1058
|
if (existing)
|
|
1298
1059
|
return;
|
|
1299
|
-
runtime = this.runtimes.get(id);
|
|
1300
1060
|
record.cancelRequested = true;
|
|
1301
1061
|
if (record.recovery)
|
|
1302
1062
|
record.recovery.status = 'blocked';
|
|
1303
1063
|
await this.persist();
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|| ['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)) {
|
|
1307
1066
|
operation = Promise.resolve().then(() => this.cancelRetained(record));
|
|
1308
1067
|
this.retainedCancellations.set(id, operation);
|
|
1309
1068
|
return;
|
|
1310
1069
|
}
|
|
1311
|
-
if (
|
|
1312
|
-
existing = runtime.cancelPromise;
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
if (!LIVE.has(record.state) && !runtime?.cancelling && (!runtime || runtime.stopped)) {
|
|
1316
|
-
if (record.recovery && runtime?.stopped) {
|
|
1317
|
-
record.state = 'cancelled';
|
|
1318
|
-
delete record.error;
|
|
1319
|
-
}
|
|
1320
|
-
for (const [key, pending] of this.pending) {
|
|
1321
|
-
if (pending.scheduleId === id && !pending.afterCancellation)
|
|
1322
|
-
this.pending.delete(key);
|
|
1323
|
-
}
|
|
1324
|
-
await this.persist();
|
|
1325
|
-
operation = Promise.resolve(structuredClone(record));
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
if (!runtime)
|
|
1070
|
+
if (LIVE.has(record.state))
|
|
1329
1071
|
throw new Error('Native schedule handle is unavailable.');
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
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));
|
|
1334
1078
|
});
|
|
1335
1079
|
return (existing ?? operation);
|
|
1336
1080
|
}
|
|
@@ -1342,7 +1086,7 @@ class ScheduleService {
|
|
|
1342
1086
|
supportsRetainedCancellation(record) {
|
|
1343
1087
|
if (record.engine === 'host' || !(0, ScheduleCapabilities_1.isNativeScheduleBackend)(record.backend))
|
|
1344
1088
|
return false;
|
|
1345
|
-
const cleanup = this.options.
|
|
1089
|
+
const cleanup = this.options.cleanupFor?.({ ...record, backend: record.backend, ...record.execution });
|
|
1346
1090
|
return !!record.recovery && !!cleanup?.cancelRetained && cleanup.provider === record.recovery.provider
|
|
1347
1091
|
&& cleanup.strategy === record.recovery.strategy;
|
|
1348
1092
|
}
|
|
@@ -1352,7 +1096,7 @@ class ScheduleService {
|
|
|
1352
1096
|
const ownership = record.recovery;
|
|
1353
1097
|
if (record.engine === 'host' || !(0, ScheduleCapabilities_1.isNativeScheduleBackend)(record.backend))
|
|
1354
1098
|
throw new Error('Native cleanup requires a legacy schedule.');
|
|
1355
|
-
const provider = this.options.
|
|
1099
|
+
const provider = this.options.cleanupFor?.({ id: record.id, threadId: record.threadId,
|
|
1356
1100
|
backend: record.backend, cwd: record.cwd, prompt: record.prompt, rule: record.rule,
|
|
1357
1101
|
...record.execution, recovery: ownership });
|
|
1358
1102
|
if (!ownership || !provider?.cancelRetained || provider.provider !== ownership.provider || provider.strategy !== ownership.strategy) {
|
|
@@ -1404,9 +1148,8 @@ class ScheduleService {
|
|
|
1404
1148
|
/** Idle future definitions do not block updates. Active work and durable deliveries still do. */
|
|
1405
1149
|
canRestartWithoutActiveWork() {
|
|
1406
1150
|
return this.initialized && !this.closing && !this.fault && !this.operations.size
|
|
1407
|
-
&& !this.hostAttempts.size && !
|
|
1408
|
-
&& !
|
|
1409
|
-
!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');
|
|
1410
1153
|
}
|
|
1411
1154
|
/** Shutdown revokes admission only. It never invokes native schedule RPCs or waits for result ACKs. */
|
|
1412
1155
|
destroy() {
|
|
@@ -1419,192 +1162,11 @@ class ScheduleService {
|
|
|
1419
1162
|
// Complete only writes already in this process's serial filesystem queue.
|
|
1420
1163
|
// Native requests, results and delivery are independently durable or remain unknown after exit.
|
|
1421
1164
|
await this.tail;
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
// work here. Process exit releases the kernel gate even if it never returns.
|
|
1425
|
-
if (!this.pendingCreates) {
|
|
1426
|
-
this.catalogGate?.close();
|
|
1427
|
-
this.catalogGate = undefined;
|
|
1428
|
-
}
|
|
1165
|
+
this.catalogGate?.close();
|
|
1166
|
+
this.catalogGate = undefined;
|
|
1429
1167
|
})();
|
|
1430
1168
|
}
|
|
1431
|
-
|
|
1432
|
-
try {
|
|
1433
|
-
const handle = await runtime.ready;
|
|
1434
|
-
if (handle && !runtime.stopped) {
|
|
1435
|
-
if (LIVE.has(this.records.get(id).state) || handle.cancellationKeepsRunning) {
|
|
1436
|
-
await handle.cancel();
|
|
1437
|
-
runtime.removalConfirmed = true;
|
|
1438
|
-
}
|
|
1439
|
-
else
|
|
1440
|
-
await this.stop(id, runtime);
|
|
1441
|
-
}
|
|
1442
|
-
await this.serial(async () => {
|
|
1443
|
-
const record = this.records.get(id);
|
|
1444
|
-
record.state = 'cancelled';
|
|
1445
|
-
delete record.error;
|
|
1446
|
-
if (handle?.cancellationKeepsRunning) {
|
|
1447
|
-
for (const pending of this.pending.values())
|
|
1448
|
-
if (pending.scheduleId === id)
|
|
1449
|
-
pending.afterCancellation = true;
|
|
1450
|
-
}
|
|
1451
|
-
else
|
|
1452
|
-
this.dropPending(id);
|
|
1453
|
-
await this.persist();
|
|
1454
|
-
});
|
|
1455
|
-
runtime.cancelling = false;
|
|
1456
|
-
runtime.heldDeliveries.clear();
|
|
1457
|
-
await this.stop(id, runtime);
|
|
1458
|
-
if (handle?.cancellationKeepsRunning)
|
|
1459
|
-
await this.attemptDeliveries([...this.pending.keys()]);
|
|
1460
|
-
return structuredClone(this.records.get(id));
|
|
1461
|
-
}
|
|
1462
|
-
catch (error) {
|
|
1463
|
-
runtime.cancelling = false;
|
|
1464
|
-
await this.serial(async () => {
|
|
1465
|
-
this.records.get(id).error = errorText(error);
|
|
1466
|
-
if (!this.fault)
|
|
1467
|
-
await this.persist();
|
|
1468
|
-
});
|
|
1469
|
-
if (!LIVE.has(this.records.get(id).state))
|
|
1470
|
-
await this.stop(id, runtime).catch(() => { });
|
|
1471
|
-
const ids = [...runtime.heldDeliveries];
|
|
1472
|
-
runtime.heldDeliveries.clear();
|
|
1473
|
-
await this.attemptDeliveries(ids, true);
|
|
1474
|
-
throw error;
|
|
1475
|
-
}
|
|
1476
|
-
finally {
|
|
1477
|
-
runtime.cancelPromise = undefined;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
async onEvent(id, event) {
|
|
1481
|
-
let delivery;
|
|
1482
|
-
let cleanup = false;
|
|
1483
|
-
const runtime = this.runtimes.get(id);
|
|
1484
|
-
await this.serial(async () => {
|
|
1485
|
-
if (!runtime || this.runtimes.get(id) !== runtime || !this.records.has(id)) {
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
if (this.fault)
|
|
1489
|
-
throw this.fault;
|
|
1490
|
-
if (this.closing) {
|
|
1491
|
-
if (event.type === 'attributed')
|
|
1492
|
-
throw new Error('Schedule service closed before native creation attribution.');
|
|
1493
|
-
return;
|
|
1494
|
-
}
|
|
1495
|
-
const record = this.records.get(id);
|
|
1496
|
-
if (event.type === 'attributed') {
|
|
1497
|
-
if (!record.recovery || record.state !== 'creating' || !this.current(record) || record.cancelRequested) {
|
|
1498
|
-
throw new Error('Native creation attribution is no longer admissible.');
|
|
1499
|
-
}
|
|
1500
|
-
text(event.cleanupIdentity, 8192);
|
|
1501
|
-
record.recovery.identity = event.cleanupIdentity;
|
|
1502
|
-
await this.persist();
|
|
1503
|
-
return;
|
|
1504
|
-
}
|
|
1505
|
-
// Process exit evidence is independent of task state, including late exit
|
|
1506
|
-
// after a failed cancellation cleanup. Never downgrade confirmed exit.
|
|
1507
|
-
if (event.type === 'stopped' && event.exitConfirmed !== false) {
|
|
1508
|
-
runtime.stopped = true;
|
|
1509
|
-
if (record.error?.startsWith('Native process exit unconfirmed:')) {
|
|
1510
|
-
delete record.error;
|
|
1511
|
-
await this.persist();
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
const ownerCurrent = this.current(record);
|
|
1515
|
-
if (this.closing)
|
|
1516
|
-
return;
|
|
1517
|
-
if (!ownerCurrent) {
|
|
1518
|
-
if (record.recovery && (!ownerCurrent || event.type !== 'stopped' || event.exitConfirmed === false))
|
|
1519
|
-
record.recovery.status = 'blocked';
|
|
1520
|
-
if (LIVE.has(record.state)) {
|
|
1521
|
-
record.state = 'interrupted';
|
|
1522
|
-
record.error = 'Schedule owner or service is no longer current.';
|
|
1523
|
-
}
|
|
1524
|
-
// Native stop notifications during shutdown must preserve completed outbox
|
|
1525
|
-
// entries for restart. Only actual ownership invalidation discards them.
|
|
1526
|
-
if (!ownerCurrent)
|
|
1527
|
-
this.dropPending(id);
|
|
1528
|
-
cleanup = true;
|
|
1529
|
-
await this.persist();
|
|
1530
|
-
return;
|
|
1531
|
-
}
|
|
1532
|
-
const finishingFailed = record.state === 'failed' && event.type === 'completed' && runtime.running.has(event.occurrenceId);
|
|
1533
|
-
const finishingCancelled = record.state === 'cancelled' && runtime.handle?.cancellationKeepsRunning
|
|
1534
|
-
&& event.type === 'completed' && runtime.running.has(event.occurrenceId);
|
|
1535
|
-
if ((!finishingCancelled && record.state === 'cancelled') || record.state === 'failed' && !finishingFailed || record.state === 'completed')
|
|
1536
|
-
return;
|
|
1537
|
-
if (event.type === 'stopped') {
|
|
1538
|
-
if (record.recovery)
|
|
1539
|
-
record.recovery.status = 'blocked';
|
|
1540
|
-
if (LIVE.has(record.state)) {
|
|
1541
|
-
record.state = 'interrupted';
|
|
1542
|
-
record.error = bounded(event.reason, ERROR_BYTES);
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
else {
|
|
1546
|
-
text(event.occurrenceId);
|
|
1547
|
-
if (runtime.completed.has(event.occurrenceId))
|
|
1548
|
-
return;
|
|
1549
|
-
if (record.state === 'interrupted' && (event.type !== 'completed' || !runtime.running.has(event.occurrenceId)))
|
|
1550
|
-
return;
|
|
1551
|
-
if (runtime.completed.size + runtime.running.size >= this.maxOccurrences && !runtime.running.has(event.occurrenceId)) {
|
|
1552
|
-
record.state = 'interrupted';
|
|
1553
|
-
record.error = 'Occurrence tracking limit reached; native schedule stopped.';
|
|
1554
|
-
cleanup = true;
|
|
1555
|
-
}
|
|
1556
|
-
else if (event.type === 'started') {
|
|
1557
|
-
runtime.running.add(event.occurrenceId);
|
|
1558
|
-
record.state = 'running';
|
|
1559
|
-
if (record.recovery)
|
|
1560
|
-
record.recovery.status = 'blocked';
|
|
1561
|
-
}
|
|
1562
|
-
else if (event.type === 'completed') {
|
|
1563
|
-
if (typeof event.success !== 'boolean')
|
|
1564
|
-
throw new Error('Invalid native completion event.');
|
|
1565
|
-
runtime.running.delete(event.occurrenceId);
|
|
1566
|
-
runtime.completed.add(event.occurrenceId);
|
|
1567
|
-
record.completedOccurrences = [...runtime.completed];
|
|
1568
|
-
if (this.outboxFull(id)) {
|
|
1569
|
-
record.state = 'interrupted';
|
|
1570
|
-
record.error = 'Delivery outbox is full; latest result could not be retained. Native schedule stopped.';
|
|
1571
|
-
cleanup = true;
|
|
1572
|
-
}
|
|
1573
|
-
else {
|
|
1574
|
-
delivery = deliveryId(id, event.occurrenceId);
|
|
1575
|
-
this.pending.set(delivery, { id: delivery, scheduleId: id, occurrenceId: event.occurrenceId,
|
|
1576
|
-
success: event.success, ...(finishingCancelled ? { afterCancellation: true } : {}), ...(event.output !== undefined && { output: bounded(event.output, OUTPUT_BYTES) }),
|
|
1577
|
-
...(event.error !== undefined && { error: bounded(event.error, ERROR_BYTES) }) });
|
|
1578
|
-
if (finishingCancelled) {
|
|
1579
|
-
cleanup = true;
|
|
1580
|
-
}
|
|
1581
|
-
else if (record.rule.kind === 'once') {
|
|
1582
|
-
record.state = 'completed';
|
|
1583
|
-
cleanup = true;
|
|
1584
|
-
}
|
|
1585
|
-
else if (record.state !== 'interrupted' && record.state !== 'failed') {
|
|
1586
|
-
record.state = runtime.running.size ? 'running' : 'active';
|
|
1587
|
-
if (record.recovery && !runtime.running.size)
|
|
1588
|
-
record.recovery.status = 'blocked';
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
else
|
|
1593
|
-
throw new Error('Invalid native schedule event.');
|
|
1594
|
-
}
|
|
1595
|
-
await this.persist();
|
|
1596
|
-
});
|
|
1597
|
-
// Do not wait for a create handle before recording or delivering an early result.
|
|
1598
|
-
// stop() records retryable exit failures itself. A cleanup timeout must not
|
|
1599
|
-
// fault the entire service or prevent a later explicit cancellation retry.
|
|
1600
|
-
// Persistence failures still set the service fault inside persist().
|
|
1601
|
-
if (cleanup && !this.closing && !runtime.cancelling)
|
|
1602
|
-
this.track(this.stop(id, runtime).catch(() => { }));
|
|
1603
|
-
if (delivery) {
|
|
1604
|
-
await this.attemptDeliveries([delivery], true);
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
attemptDeliveries(ids, firstAttempt = false) {
|
|
1169
|
+
attemptDeliveries(ids) {
|
|
1608
1170
|
const run = this.deliveryTail.then(async () => {
|
|
1609
1171
|
for (const id of ids) {
|
|
1610
1172
|
let delivery;
|
|
@@ -1632,12 +1194,6 @@ class ScheduleService {
|
|
|
1632
1194
|
await this.persist();
|
|
1633
1195
|
return;
|
|
1634
1196
|
}
|
|
1635
|
-
const runtime = this.runtimes.get(record.id);
|
|
1636
|
-
if (runtime?.cancelling) {
|
|
1637
|
-
if (firstAttempt)
|
|
1638
|
-
runtime.heldDeliveries.add(id);
|
|
1639
|
-
return;
|
|
1640
|
-
}
|
|
1641
1197
|
delivery = { id, schedule: structuredClone(record), occurrenceId: pending.occurrenceId,
|
|
1642
1198
|
success: pending.success, ...(pending.output !== undefined && { output: pending.output }),
|
|
1643
1199
|
...(pending.error !== undefined && { error: pending.error }) };
|
|
@@ -1645,12 +1201,6 @@ class ScheduleService {
|
|
|
1645
1201
|
if (!delivery || this.closing || !this.current(delivery.schedule) || !this.pending.has(id)
|
|
1646
1202
|
|| this.purges.has(delivery.schedule.id))
|
|
1647
1203
|
continue;
|
|
1648
|
-
const runtime = this.runtimes.get(delivery.schedule.id);
|
|
1649
|
-
if (runtime?.cancelling) {
|
|
1650
|
-
if (firstAttempt)
|
|
1651
|
-
runtime.heldDeliveries.add(id);
|
|
1652
|
-
continue;
|
|
1653
|
-
}
|
|
1654
1204
|
this.delivering.add(delivery.schedule.id);
|
|
1655
1205
|
try {
|
|
1656
1206
|
await this.options.deliver(delivery);
|
|
@@ -1672,76 +1222,10 @@ class ScheduleService {
|
|
|
1672
1222
|
this.deliveryTail = run.catch(() => { });
|
|
1673
1223
|
return run;
|
|
1674
1224
|
}
|
|
1675
|
-
stop(id, runtime) {
|
|
1676
|
-
if (this.closing || this.runtimes.get(id) !== runtime)
|
|
1677
|
-
return Promise.resolve();
|
|
1678
|
-
if (runtime.stopped)
|
|
1679
|
-
return this.rememberCleanup(id, runtime);
|
|
1680
|
-
if (runtime.stopPromise)
|
|
1681
|
-
return runtime.stopPromise;
|
|
1682
|
-
const operation = (async () => {
|
|
1683
|
-
try {
|
|
1684
|
-
const handle = await runtime.ready;
|
|
1685
|
-
if (this.closing)
|
|
1686
|
-
return;
|
|
1687
|
-
if (handle && !runtime.stopped) {
|
|
1688
|
-
await handle.stop();
|
|
1689
|
-
// Process/job retirement is not itself proof that persisted timing was deleted.
|
|
1690
|
-
if (handle.nativeDefinitionAbsent === true)
|
|
1691
|
-
runtime.removalConfirmed = true;
|
|
1692
|
-
}
|
|
1693
|
-
// A shared session can delete future firings while an occurrence still
|
|
1694
|
-
// finishes. Keep ownership until its terminal stopped notification.
|
|
1695
|
-
if (handle?.retirementConfirmed !== false && (!handle?.cancellationKeepsRunning || !runtime.running.size))
|
|
1696
|
-
runtime.stopped = true;
|
|
1697
|
-
if (runtime.stopped) {
|
|
1698
|
-
await this.rememberCleanup(id, runtime);
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
catch (error) {
|
|
1702
|
-
await this.serial(async () => {
|
|
1703
|
-
this.records.get(id).error = `Native process exit unconfirmed: ${errorText(error)}`.slice(0, ERROR_BYTES / 4);
|
|
1704
|
-
if (!this.fault)
|
|
1705
|
-
await this.persist();
|
|
1706
|
-
});
|
|
1707
|
-
throw error;
|
|
1708
|
-
}
|
|
1709
|
-
})();
|
|
1710
|
-
const tracked = this.recordOperation(id, operation);
|
|
1711
|
-
runtime.stopPromise = tracked;
|
|
1712
|
-
void operation.finally(() => { if (!runtime.stopped)
|
|
1713
|
-
runtime.stopPromise = undefined; }).catch(() => { });
|
|
1714
|
-
return tracked;
|
|
1715
|
-
}
|
|
1716
|
-
rememberCleanup(id, runtime) {
|
|
1717
|
-
return this.serial(async () => {
|
|
1718
|
-
const record = this.records.get(id);
|
|
1719
|
-
if (this.runtimes.get(id) === runtime && runtime.stopped && !runtime.running.size
|
|
1720
|
-
&& runtime.removalConfirmed && runtime.handle?.nativeDefinitionAbsent === true
|
|
1721
|
-
&& record?.cancelRequested && record.state === 'cancelled' && !record.cleanupConfirmed) {
|
|
1722
|
-
record.cleanupConfirmed = true;
|
|
1723
|
-
await this.persist();
|
|
1724
|
-
}
|
|
1725
|
-
});
|
|
1726
|
-
}
|
|
1727
|
-
canAdmitOccurrence(id, runtime) {
|
|
1728
|
-
const record = this.records.get(id);
|
|
1729
|
-
return !!record && this.runtimes.get(id) === runtime && !this.closing && !this.fault
|
|
1730
|
-
&& !runtime.stopped && !runtime.cancelling && !record.cancelRequested
|
|
1731
|
-
&& LIVE.has(record.state) && this.current(record);
|
|
1732
|
-
}
|
|
1733
|
-
newRuntime() {
|
|
1734
|
-
let resolveReady;
|
|
1735
|
-
const ready = new Promise(resolve => { resolveReady = resolve; });
|
|
1736
|
-
return { ready, resolveReady, running: new Set(), completed: new Set(), heldDeliveries: new Set(), cancelling: false, stopped: false };
|
|
1737
|
-
}
|
|
1738
1225
|
track(task) {
|
|
1739
1226
|
this.tasks.add(task);
|
|
1740
1227
|
void task.catch(error => {
|
|
1741
|
-
// Persistence/protocol failures fail closed and stop native producers.
|
|
1742
1228
|
this.fault ??= error instanceof Error ? error : new Error('Schedule service failed.');
|
|
1743
|
-
for (const [id, runtime] of this.runtimes)
|
|
1744
|
-
void this.stop(id, runtime).catch(() => { });
|
|
1745
1229
|
}).finally(() => this.tasks.delete(task));
|
|
1746
1230
|
}
|
|
1747
1231
|
operation(task) {
|
|
@@ -2045,8 +1529,6 @@ class ScheduleService {
|
|
|
2045
1529
|
}
|
|
2046
1530
|
catch (error) {
|
|
2047
1531
|
this.fault = error instanceof Error ? error : new Error('Schedule catalog write failed.');
|
|
2048
|
-
for (const [id, runtime] of this.runtimes)
|
|
2049
|
-
void this.stop(id, runtime).catch(() => { });
|
|
2050
1532
|
throw this.fault;
|
|
2051
1533
|
}
|
|
2052
1534
|
}
|