@yu_robotics/remote-cli 1.6.244 → 1.6.251

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.
Files changed (155) hide show
  1. package/dist/client/MessageHandler.d.ts +6 -2
  2. package/dist/client/MessageHandler.d.ts.map +1 -1
  3. package/dist/client/MessageHandler.js +144 -48
  4. package/dist/client/MessageHandler.js.map +1 -1
  5. package/dist/client/WebSocketClient.d.ts +3 -0
  6. package/dist/client/WebSocketClient.d.ts.map +1 -1
  7. package/dist/client/WebSocketClient.js +3 -1
  8. package/dist/client/WebSocketClient.js.map +1 -1
  9. package/dist/commands/start.d.ts +5 -0
  10. package/dist/commands/start.d.ts.map +1 -1
  11. package/dist/commands/start.js +37 -0
  12. package/dist/commands/start.js.map +1 -1
  13. package/dist/executor/AgyExecutor.d.ts +39 -2
  14. package/dist/executor/AgyExecutor.d.ts.map +1 -1
  15. package/dist/executor/AgyExecutor.js +383 -38
  16. package/dist/executor/AgyExecutor.js.map +1 -1
  17. package/dist/executor/ClaudePersistentExecutor.d.ts.map +1 -1
  18. package/dist/executor/ClaudePersistentExecutor.js +29 -16
  19. package/dist/executor/ClaudePersistentExecutor.js.map +1 -1
  20. package/dist/executor/DshExecutor.d.ts +1 -0
  21. package/dist/executor/DshExecutor.d.ts.map +1 -1
  22. package/dist/executor/IExecutor.d.ts +1 -1
  23. package/dist/executor/IExecutor.d.ts.map +1 -1
  24. package/dist/executor/acp/AcpClient.d.ts +5 -0
  25. package/dist/executor/acp/AcpClient.d.ts.map +1 -1
  26. package/dist/executor/acp/AcpClient.js +19 -1
  27. package/dist/executor/acp/AcpClient.js.map +1 -1
  28. package/dist/executor/agy/AgyAcpRuntime.d.ts +82 -0
  29. package/dist/executor/agy/AgyAcpRuntime.d.ts.map +1 -0
  30. package/dist/executor/agy/AgyAcpRuntime.js +390 -0
  31. package/dist/executor/agy/AgyAcpRuntime.js.map +1 -0
  32. package/dist/executor/index.d.ts.map +1 -1
  33. package/dist/executor/index.js +2 -1
  34. package/dist/executor/index.js.map +1 -1
  35. package/dist/files/FileInbox.d.ts +1 -0
  36. package/dist/files/FileInbox.d.ts.map +1 -1
  37. package/dist/files/FileInbox.js +49 -4
  38. package/dist/files/FileInbox.js.map +1 -1
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/maintenance/release-notes.json +1 -1
  42. package/dist/managed/tools.d.ts +2 -2
  43. package/dist/scheduling/ScheduleCapabilities.d.ts +4 -4
  44. package/dist/scheduling/ScheduleCapabilities.d.ts.map +1 -1
  45. package/dist/scheduling/ScheduleCapabilities.js +6 -6
  46. package/dist/scheduling/ScheduleCapabilities.js.map +1 -1
  47. package/dist/scheduling/ScheduleCleanup.js +1 -1
  48. package/dist/scheduling/ScheduleCleanup.js.map +1 -1
  49. package/dist/scheduling/ScheduleCommand.d.ts +1 -0
  50. package/dist/scheduling/ScheduleCommand.d.ts.map +1 -1
  51. package/dist/scheduling/ScheduleCommand.js +9 -3
  52. package/dist/scheduling/ScheduleCommand.js.map +1 -1
  53. package/dist/scheduling/ScheduleService.d.ts +27 -1
  54. package/dist/scheduling/ScheduleService.d.ts.map +1 -1
  55. package/dist/scheduling/ScheduleService.js +235 -51
  56. package/dist/scheduling/ScheduleService.js.map +1 -1
  57. package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -1
  58. package/dist/scheduling/ScheduleToolScope.js +12 -2
  59. package/dist/scheduling/ScheduleToolScope.js.map +1 -1
  60. package/dist/scheduling/agy/AgyCheckpoint.d.ts +35 -0
  61. package/dist/scheduling/agy/AgyCheckpoint.d.ts.map +1 -0
  62. package/dist/scheduling/agy/AgyCheckpoint.js +160 -0
  63. package/dist/scheduling/agy/AgyCheckpoint.js.map +1 -0
  64. package/dist/scheduling/agy/AgyHookRelay.d.ts +33 -0
  65. package/dist/scheduling/agy/AgyHookRelay.d.ts.map +1 -0
  66. package/dist/scheduling/agy/AgyHookRelay.js +274 -0
  67. package/dist/scheduling/agy/AgyHookRelay.js.map +1 -0
  68. package/dist/scheduling/agy/AgyScheduleHost.d.ts +42 -0
  69. package/dist/scheduling/agy/AgyScheduleHost.d.ts.map +1 -0
  70. package/dist/scheduling/agy/AgyScheduleHost.js +121 -0
  71. package/dist/scheduling/agy/AgyScheduleHost.js.map +1 -0
  72. package/dist/scheduling/agy/AgySessionSchedules.d.ts +109 -0
  73. package/dist/scheduling/agy/AgySessionSchedules.d.ts.map +1 -0
  74. package/dist/scheduling/agy/AgySessionSchedules.js +476 -0
  75. package/dist/scheduling/agy/AgySessionSchedules.js.map +1 -0
  76. package/dist/scheduling/agy/hookClient.d.ts +4 -0
  77. package/dist/scheduling/agy/hookClient.d.ts.map +1 -0
  78. package/dist/scheduling/agy/hookClient.js +62 -0
  79. package/dist/scheduling/agy/hookClient.js.map +1 -0
  80. package/dist/scheduling/agy/transcript.d.ts +36 -0
  81. package/dist/scheduling/agy/transcript.d.ts.map +1 -0
  82. package/dist/scheduling/agy/transcript.js +108 -0
  83. package/dist/scheduling/agy/transcript.js.map +1 -0
  84. package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts +7 -0
  85. package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts.map +1 -1
  86. package/dist/scheduling/claude/ClaudeSessionSchedules.js +157 -59
  87. package/dist/scheduling/claude/ClaudeSessionSchedules.js.map +1 -1
  88. package/dist/scheduling/toolContract.d.ts +1 -1
  89. package/dist/scheduling/toolContract.js +1 -1
  90. package/dist/scheduling/toolContract.js.map +1 -1
  91. package/dist/scheduling/types.d.ts +10 -2
  92. package/dist/scheduling/types.d.ts.map +1 -1
  93. package/dist/scheduling/types.js.map +1 -1
  94. package/dist/service/SessionHostSupervisor.d.ts +63 -0
  95. package/dist/service/SessionHostSupervisor.d.ts.map +1 -0
  96. package/dist/service/SessionHostSupervisor.js +323 -0
  97. package/dist/service/SessionHostSupervisor.js.map +1 -0
  98. package/dist/sessionHost/HostClient.d.ts +49 -0
  99. package/dist/sessionHost/HostClient.d.ts.map +1 -0
  100. package/dist/sessionHost/HostClient.js +101 -0
  101. package/dist/sessionHost/HostClient.js.map +1 -0
  102. package/dist/sessionHost/HostProtocol.d.ts +65 -0
  103. package/dist/sessionHost/HostProtocol.d.ts.map +1 -0
  104. package/dist/sessionHost/HostProtocol.js +78 -0
  105. package/dist/sessionHost/HostProtocol.js.map +1 -0
  106. package/dist/sessionHost/HostServer.d.ts +52 -0
  107. package/dist/sessionHost/HostServer.d.ts.map +1 -0
  108. package/dist/sessionHost/HostServer.js +413 -0
  109. package/dist/sessionHost/HostServer.js.map +1 -0
  110. package/dist/sessionHost/HostStore.d.ts +43 -0
  111. package/dist/sessionHost/HostStore.d.ts.map +1 -0
  112. package/dist/sessionHost/HostStore.js +206 -0
  113. package/dist/sessionHost/HostStore.js.map +1 -0
  114. package/dist/sessionHost/RetainedFrontend.d.ts +63 -0
  115. package/dist/sessionHost/RetainedFrontend.d.ts.map +1 -0
  116. package/dist/sessionHost/RetainedFrontend.js +244 -0
  117. package/dist/sessionHost/RetainedFrontend.js.map +1 -0
  118. package/dist/sessionHost/RetainedHostLauncher.d.ts +25 -0
  119. package/dist/sessionHost/RetainedHostLauncher.d.ts.map +1 -0
  120. package/dist/sessionHost/RetainedHostLauncher.js +132 -0
  121. package/dist/sessionHost/RetainedHostLauncher.js.map +1 -0
  122. package/dist/sessionHost/RetainedRuntime.d.ts +62 -0
  123. package/dist/sessionHost/RetainedRuntime.d.ts.map +1 -0
  124. package/dist/sessionHost/RetainedRuntime.js +478 -0
  125. package/dist/sessionHost/RetainedRuntime.js.map +1 -0
  126. package/dist/sessionHost/RuntimeJournal.d.ts +47 -0
  127. package/dist/sessionHost/RuntimeJournal.d.ts.map +1 -0
  128. package/dist/sessionHost/RuntimeJournal.js +103 -0
  129. package/dist/sessionHost/RuntimeJournal.js.map +1 -0
  130. package/dist/sessionHost/entry.d.ts +13 -0
  131. package/dist/sessionHost/entry.d.ts.map +1 -0
  132. package/dist/sessionHost/entry.js +107 -0
  133. package/dist/sessionHost/entry.js.map +1 -0
  134. package/dist/thread/ThreadManager.d.ts.map +1 -1
  135. package/dist/thread/ThreadManager.js +33 -0
  136. package/dist/thread/ThreadManager.js.map +1 -1
  137. package/dist/types/ScheduleCards.d.ts +1 -1
  138. package/dist/types/ScheduleCards.d.ts.map +1 -1
  139. package/dist/update/AutomaticUpdater.d.ts +2 -1
  140. package/dist/update/AutomaticUpdater.d.ts.map +1 -1
  141. package/dist/update/AutomaticUpdater.js +26 -12
  142. package/dist/update/AutomaticUpdater.js.map +1 -1
  143. package/dist/update/PinnedHostBundle.d.ts +49 -0
  144. package/dist/update/PinnedHostBundle.d.ts.map +1 -0
  145. package/dist/update/PinnedHostBundle.js +309 -0
  146. package/dist/update/PinnedHostBundle.js.map +1 -0
  147. package/native/prebuilds/darwin-arm64/managed_native.node +0 -0
  148. package/native/prebuilds/darwin-arm64/manifest.json +1 -1
  149. package/native/prebuilds/darwin-x64/managed_native.node +0 -0
  150. package/native/prebuilds/darwin-x64/manifest.json +1 -1
  151. package/native/prebuilds/win32-arm64/managed_native.node +0 -0
  152. package/native/prebuilds/win32-arm64/manifest.json +1 -1
  153. package/native/prebuilds/win32-x64/managed_native.node +0 -0
  154. package/native/prebuilds/win32-x64/manifest.json +1 -1
  155. package/package.json +1 -1
@@ -56,6 +56,7 @@ const MAX_PURGED_IDS = 10_000;
56
56
  const MAX_CLEANUP_RECORDS = 1000;
57
57
  const MAX_PURGE_REQUESTS = 1000;
58
58
  const MAX_PURGE_SELECTION_IDS = 20_000;
59
+ const FORGOTTEN_CLEANUP_WARNING = 'Forgetting cleanup tracking does not confirm native definition absence or predecessor termination. Replay protection is retained. Use native cleanup review/delete in the original session for any remaining native tasks.';
59
60
  function bounded(value, limit) {
60
61
  if (Buffer.byteLength(value, 'utf8') <= limit)
61
62
  return value;
@@ -142,6 +143,8 @@ class ScheduleService {
142
143
  suspending = false;
143
144
  handoffUnresolved = false;
144
145
  suspension;
146
+ hostRetirement;
147
+ hostsRetired = false;
145
148
  constructor(options) {
146
149
  this.options = { ...options };
147
150
  this.now = options.now ?? Date.now;
@@ -263,9 +266,14 @@ class ScheduleService {
263
266
  const current = () => !controller.signal.aborted && !this.closing && !this.fault && !record.cancelRequested
264
267
  && this.current(record) && this.options.canRecover?.(structuredClone(record)) === true;
265
268
  const emit = (event) => {
266
- if (this.runtimes.get(id) !== runtime)
269
+ if (this.runtimes.get(id) !== runtime) {
270
+ if (event.type === 'rebound')
271
+ return Promise.reject(new Error('Native rebound owner retired.'));
267
272
  return;
268
- this.track(this.onEvent(id, structuredClone(event)));
273
+ }
274
+ const task = this.onEvent(id, structuredClone(event));
275
+ this.track(task);
276
+ return task;
269
277
  };
270
278
  let timer;
271
279
  let admitted = false;
@@ -406,7 +414,10 @@ class ScheduleService {
406
414
  async createSchedule(owner, input) {
407
415
  this.checkReady();
408
416
  const backend = input.backend === undefined ? 'claude' : input.backend;
409
- (0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
417
+ // The service accepts installed providers independently of the foreground
418
+ // executor availability policy. MessageHandler keeps that admission gate.
419
+ if (!(0, ScheduleCapabilities_1.isNativeScheduleBackend)(backend))
420
+ (0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
410
421
  const createdAt = this.now();
411
422
  if (!Number.isSafeInteger(createdAt) || createdAt < 0)
412
423
  throw new Error('Invalid schedule clock.');
@@ -453,10 +464,14 @@ class ScheduleService {
453
464
  });
454
465
  try {
455
466
  const handle = await this.options.provider.create(structuredClone(nativeInput), event => {
456
- if (this.runtimes.get(nativeInput.id) !== runtime)
467
+ if (this.runtimes.get(nativeInput.id) !== runtime) {
468
+ if (event.type === 'rebound')
469
+ return Promise.reject(new Error('Native rebound owner retired.'));
457
470
  return;
471
+ }
458
472
  const task = this.onEvent(nativeInput.id, structuredClone(event));
459
473
  this.track(task);
474
+ return task;
460
475
  }, () => this.canAdmitOccurrence(nativeInput.id, runtime));
461
476
  runtime.handle = handle;
462
477
  runtime.resolveReady(handle);
@@ -539,7 +554,8 @@ class ScheduleService {
539
554
  const ids = this.purgeIds(owner, selection);
540
555
  const hash = (value) => (0, node_crypto_1.createHash)('sha256').update(JSON.stringify(value)).digest('hex');
541
556
  const key = hash([ownerOf(owner), requestId]);
542
- const digest = hash('all' in selection ? { all: true } : { ids: [...selection.ids].sort() });
557
+ const digest = hash('all' in selection ? { all: true } : { ids: [...selection.ids].sort(),
558
+ ...(selection.forgetUnresolved ? { forgetUnresolved: true } : {}) });
543
559
  const previous = this.purgeRequests.get(key);
544
560
  if (previous) {
545
561
  if (previous.digest !== digest)
@@ -561,9 +577,11 @@ class ScheduleService {
561
577
  }));
562
578
  }
563
579
  purgeIds(owner, selection) {
564
- const value = object(selection, ['ids', 'all']);
580
+ const value = object(selection, ['ids', 'all', 'forgetUnresolved']);
565
581
  if (value.all !== undefined ? value.all !== true || value.ids !== undefined : !Array.isArray(value.ids))
566
582
  throw new Error('Select exact schedule IDs or all current-owner schedules.');
583
+ if (value.forgetUnresolved !== undefined && (value.forgetUnresolved !== true || value.all !== undefined || !Array.isArray(value.ids) || !value.ids.length))
584
+ throw new Error('Forgetting unresolved cleanup requires exact schedule IDs and forgetUnresolved: true.');
567
585
  const ids = value.all === true ? [...this.records.values()].filter(record => sameOwner(record, owner)).map(record => record.id)
568
586
  .concat([...this.cleanup.values()].filter(record => sameCleanupOwner(record, owner)).map(record => record.id))
569
587
  : [...value.ids];
@@ -580,6 +598,7 @@ class ScheduleService {
580
598
  async purgeSelected(owner, selection, isCurrent) {
581
599
  this.checkReady();
582
600
  validateOwner(owner);
601
+ const forgetUnresolved = 'forgetUnresolved' in selection && selection.forgetUnresolved === true;
583
602
  const selectedIds = await this.serial(async () => {
584
603
  if (!this.current(owner) || !isCurrent())
585
604
  throw new Error('Schedule purge owner is no longer current.');
@@ -589,6 +608,8 @@ class ScheduleService {
589
608
  const record = this.records.get(id);
590
609
  if (!record || !sameOwner(record, owner))
591
610
  continue;
611
+ if (forgetUnresolved)
612
+ continue;
592
613
  record.cancelRequested = true;
593
614
  if (record.recovery)
594
615
  record.recovery.status = 'blocked';
@@ -601,6 +622,10 @@ class ScheduleService {
601
622
  return ids;
602
623
  });
603
624
  const result = { selectedIds, status: 'complete', removedIds: [], historyRemovedIds: [], nativeCleanupUnresolved: [], alreadyRemovedIds: [], pending: [], errors: [] };
625
+ if (forgetUnresolved) {
626
+ result.forgottenCleanupIds = [];
627
+ result.warning = FORGOTTEN_CLEANUP_WARNING;
628
+ }
604
629
  for (const id of selectedIds) {
605
630
  const previouslyPurged = this.purged.has(id);
606
631
  try {
@@ -609,18 +634,29 @@ class ScheduleService {
609
634
  if ((!record || !sameOwner(record, owner)) && (!prior || !sameCleanupOwner(prior, owner))) {
610
635
  throw new Error('Schedule not found for this owner.');
611
636
  }
612
- let task = this.purges.get(id);
613
- if (!task) {
614
- task = this.purgeRecord(owner, id, isCurrent);
615
- this.purges.set(id, task);
616
- void task.finally(() => { if (this.purges.get(id) === task)
637
+ let entry = this.purges.get(id);
638
+ if (entry && entry.forgetUnresolved !== forgetUnresolved) {
639
+ result.pending.push({ id, reason: 'operation_pending', detail: 'A different purge mode is pending; retry this selection after it settles.' });
640
+ continue;
641
+ }
642
+ if (!entry) {
643
+ const task = forgetUnresolved ? this.forgetCleanup(owner, id, isCurrent) : this.purgeRecord(owner, id, isCurrent);
644
+ entry = { forgetUnresolved, task };
645
+ this.purges.set(id, entry);
646
+ const admitted = entry;
647
+ void task.finally(() => { if (this.purges.get(id) === admitted)
617
648
  this.purges.delete(id); }).catch(() => { });
618
649
  }
619
- const outcome = await task;
650
+ const outcome = await entry.task;
620
651
  if (outcome.status === 'pending')
621
652
  result.pending.push({ id, reason: outcome.reason, detail: outcome.detail });
622
- else
653
+ else {
623
654
  (outcome.status === 'removed' ? result.removedIds : result.alreadyRemovedIds).push(id);
655
+ if (outcome.forgottenCleanup) {
656
+ (result.forgottenCleanupIds ??= []).push(id);
657
+ result.warning = FORGOTTEN_CLEANUP_WARNING;
658
+ }
659
+ }
624
660
  }
625
661
  catch (error) {
626
662
  if (this.purged.has(id) && sameCleanupOwner(this.purged.get(id), owner))
@@ -637,6 +673,37 @@ class ScheduleService {
637
673
  result.status = 'partial';
638
674
  return result;
639
675
  }
676
+ /** User-requested metadata erasure, not verification or native mutation. The
677
+ * permanent ID/owner fence survives even when the deletion selector is gone. */
678
+ forgetCleanup(owner, id, isCurrent) {
679
+ return this.serial(async () => {
680
+ this.checkReady();
681
+ if (!this.current(owner) || !isCurrent() || this.closing || this.suspending)
682
+ throw new Error('Schedule cleanup context changed.');
683
+ const prior = this.purged.get(id);
684
+ if (!prior || !sameCleanupOwner(prior, owner) || this.records.has(id))
685
+ throw new Error('Purge owned history before forgetting unresolved cleanup tracking.');
686
+ if (this.options.isNativeMutationPending?.(owner) || this.recordOperations.has(id) || this.recoveryRun
687
+ || this.refreshes || this.retainedCancellations.has(id) || this.runtimes.has(id))
688
+ return { status: 'pending', reason: 'operation_pending', detail: 'Native work or cleanup is still pending; tracking was not forgotten.' };
689
+ if (this.delivering.has(id))
690
+ return { status: 'pending', reason: 'delivery_pending', detail: 'An external delivery is already in flight; tracking was not forgotten.' };
691
+ const item = this.cleanup.get(id);
692
+ if (!item)
693
+ return { status: 'alreadyRemoved' };
694
+ if (!sameCleanupOwner(item, owner))
695
+ throw new Error('Schedule cleanup not found for this owner.');
696
+ this.cleanup.delete(id);
697
+ try {
698
+ await this.persist();
699
+ }
700
+ catch (error) {
701
+ this.cleanup.set(id, item);
702
+ throw error;
703
+ }
704
+ return { status: 'alreadyRemoved', forgottenCleanup: true };
705
+ });
706
+ }
640
707
  async retryCleanup(owner, id, isCurrent) {
641
708
  const item = this.cleanup.get(id);
642
709
  if (this.options.isNativeMutationPending?.(owner))
@@ -793,11 +860,87 @@ class ScheduleService {
793
860
  return erase(evidence);
794
861
  });
795
862
  }
863
+ /** Durable outputs still awaiting their external delivery receipt. */
864
+ hasPendingResults() { return this.pending.size > 0; }
796
865
  /** Includes terminal jobs whose native process exit is still unconfirmed. */
797
866
  hasActiveSchedules(threadId) {
798
867
  return [...this.records.values()].some(record => (!threadId || record.threadId === threadId)
799
868
  && (LIVE.has(record.state) || recoveryOwnsWork(record) || (this.runtimes.has(record.id) && !this.runtimes.get(record.id).stopped)));
800
869
  }
870
+ /** Admission to explicit process retirement, NOT proof of native exit or queue
871
+ * reconstruction. Only the original live handles can supply deletion receipts.
872
+ */
873
+ canRetireDrainedHosts() {
874
+ if (!this.initialized || this.closing || this.fault || this.hostRetirement || this.suspending
875
+ || this.handoffUnresolved || this.recoveryRun || this.operations.size || this.tasks.size
876
+ || this.recordOperations.size || this.pending.size || this.delivering.size || this.refreshes
877
+ || this.retainedCancellations.size || this.purges.size || this.cleanup.size)
878
+ return false;
879
+ try {
880
+ this.catalogGate?.verify();
881
+ return [...this.records.values()].every(record => {
882
+ if (record.error || record.recovery || !this.current(record) || this.options.isNativeMutationPending?.(ownerOf(record)))
883
+ return false;
884
+ const runtime = this.runtimes.get(record.id);
885
+ if (!runtime)
886
+ return record.state === 'cancelled' && record.cancelRequested === true && record.cleanupConfirmed === true;
887
+ if (!runtime.handle || runtime.running.size || runtime.heldDeliveries.size || runtime.cancelling || runtime.releasing)
888
+ return false;
889
+ if (record.state === 'completed')
890
+ return record.rule.kind === 'once' && runtime.completed.size > 0;
891
+ return record.state === 'cancelled' && record.cancelRequested === true && runtime.removalConfirmed === true
892
+ && (runtime.handle.nativeDefinitionAbsent === true || runtime.stopped && record.cleanupConfirmed === true);
893
+ });
894
+ }
895
+ catch {
896
+ return false;
897
+ }
898
+ }
899
+ /** Synchronous fence: no asynchronous gap between checking and revoking new
900
+ * schedule operations. Retain exact pre-exit deletion receipts for finalization.
901
+ */
902
+ beginDrainedHostRetirement() {
903
+ if (this.hostRetirement)
904
+ return;
905
+ if (!this.canRetireDrainedHosts())
906
+ throw new Error('Native schedules are not drained for explicit host retirement.');
907
+ this.hostRetirement = new Map([...this.runtimes].map(([id, runtime]) => [id,
908
+ { runtime, cancelled: this.records.get(id)?.cancelRequested === true && runtime.removalConfirmed === true }]));
909
+ }
910
+ /** Called only after the owner joined its original executor groups and drained
911
+ * native callback ingestion. Never calls stop/cancel/releaseForRestart on a
912
+ * provider. Failure preserves the same retirement fence, handles and catalog.
913
+ */
914
+ async finishDrainedHostRetirement() {
915
+ if (!this.hostRetirement)
916
+ throw new Error('Explicit host retirement was not admitted.');
917
+ while (this.tasks.size)
918
+ await Promise.allSettled([...this.tasks]);
919
+ await this.deliveryTail;
920
+ await this.serial(async () => {
921
+ if (this.fault)
922
+ throw this.fault;
923
+ if (this.pending.size || this.operations.size || this.recordOperations.size || this.delivering.size)
924
+ throw new Error('Native retirement still owns pending work or output.');
925
+ for (const [id, proof] of this.hostRetirement) {
926
+ const runtime = this.runtimes.get(id), record = this.records.get(id);
927
+ if (runtime !== proof.runtime || !record || runtime.running.size || runtime.heldDeliveries.size
928
+ || !(runtime.stopped || runtime.handle?.retirementConfirmed === true))
929
+ throw new Error('Exact native host retirement is unconfirmed.');
930
+ }
931
+ for (const [id, proof] of this.hostRetirement) {
932
+ proof.runtime.stopped = true;
933
+ proof.runtime.releaseAdmission?.();
934
+ proof.runtime.releaseAdmission = undefined;
935
+ // AGY invalidates its inventory view after exit. Preserve the exact
936
+ // deletion receipt captured BEFORE exit rather than querying a new host.
937
+ if (proof.cancelled)
938
+ this.records.get(id).cleanupConfirmed = true;
939
+ }
940
+ await this.persist();
941
+ this.hostsRetired = true;
942
+ });
943
+ }
801
944
  /** Card eligibility includes retryable cleanup even for a terminal catalog record. */
802
945
  canCancel(owner, id) {
803
946
  this.checkReady();
@@ -858,50 +1001,60 @@ class ScheduleService {
858
1001
  await this.persist();
859
1002
  });
860
1003
  }
861
- /** User-requested native reconciliation only; no background polling is installed. */
1004
+ /** Observe native inventory without deleting definitions or retiring native work. */
862
1005
  refresh(owner) {
863
1006
  this.refreshes++;
864
- return this.operation(this.refreshNative(owner).finally(() => { this.refreshes--; }));
1007
+ return this.operation(this.refreshNative(structuredClone(owner)).finally(() => { this.refreshes--; }));
865
1008
  }
866
1009
  async refreshNative(owner) {
867
1010
  this.checkReady();
868
1011
  validateOwner(owner);
869
1012
  const candidates = await this.serial(async () => [...this.records.values()]
870
1013
  .filter(record => sameOwner(record, owner)).map(record => record.id));
1014
+ let failure;
871
1015
  for (const id of candidates) {
1016
+ const record = this.records.get(id);
872
1017
  const runtime = this.runtimes.get(id);
873
- if (!runtime?.handle || runtime.stopped || runtime.cancelling || runtime.running.size || !this.current(owner))
1018
+ const handle = runtime?.handle;
1019
+ if (!record || !runtime || !handle)
874
1020
  continue;
875
- if (!LIVE.has(this.records.get(id).state)) {
876
- await this.stop(id, runtime);
1021
+ const nativeId = record.nativeId;
1022
+ const completed = runtime.completed.size;
1023
+ // Recheck after every read: cancellation, execution or rebound may have
1024
+ // advanced while inventory was awaiting its native receipt.
1025
+ const readable = () => !this.closing && !this.fault && !this.suspending && this.current(owner)
1026
+ && this.records.get(id) === record && record.nativeId === nativeId && record.state === 'active' && !record.cancelRequested
1027
+ && this.runtimes.get(id) === runtime && runtime.handle === handle && !runtime.stopped && !runtime.cancelling
1028
+ && !runtime.running.size && runtime.completed.size === completed && !runtime.stopPromise && !runtime.releaseAdmission
1029
+ && !this.recordOperations.has(id) && !this.retainedCancellations.has(id);
1030
+ if (!readable())
877
1031
  continue;
878
- }
1032
+ let present;
879
1033
  try {
880
- const present = await runtime.handle.list();
881
- if (present)
882
- continue;
883
- await this.serial(async () => {
884
- const record = this.records.get(id);
885
- if (LIVE.has(record.state)) {
886
- record.state = 'interrupted';
887
- record.error = 'Native schedule is no longer listed; execution completion is not confirmed.';
888
- await this.persist();
889
- }
890
- });
891
- await this.stop(id, runtime);
1034
+ present = await handle.list();
1035
+ if (typeof present !== 'boolean')
1036
+ throw new Error('Native inventory returned no verified presence or absence.');
892
1037
  }
893
1038
  catch (error) {
894
- await this.serial(async () => {
895
- const record = this.records.get(id);
896
- if (LIVE.has(record.state))
897
- record.state = 'interrupted';
898
- record.error = errorText(error);
899
- if (!this.fault)
900
- await this.persist();
901
- });
902
- await this.stop(id, runtime);
1039
+ // Read uncertainty is not absence or cancellation authority. Leave the
1040
+ // durable record, recovery fences and future occurrence admission intact.
1041
+ if (readable())
1042
+ failure ??= new Error(`Native inventory could not be verified for ${id}: ${errorText(error)}`);
1043
+ continue;
903
1044
  }
1045
+ if (present)
1046
+ continue;
1047
+ await this.serial(async () => {
1048
+ if (!readable())
1049
+ return;
1050
+ record.state = 'interrupted';
1051
+ const detail = 'Native schedule is no longer listed; execution completion and cleanup are not confirmed.';
1052
+ record.error = record.error ? `${bounded(record.error, ERROR_BYTES - Buffer.byteLength(detail) - 1)}\n${detail}` : detail;
1053
+ await this.persist();
1054
+ });
904
1055
  }
1056
+ if (failure)
1057
+ throw failure;
905
1058
  }
906
1059
  cancel(owner, id) {
907
1060
  return this.operation(this.recordOperation(id, this.cancelSchedule(owner, id)));
@@ -1021,7 +1174,7 @@ class ScheduleService {
1021
1174
  }
1022
1175
  /** Snapshot eligibility is only admission to a handoff, never permission to install. */
1023
1176
  canSuspendForRestart() {
1024
- if (!this.initialized || this.closing || this.fault || this.suspending || this.recoveryRun || this.operations.size || this.pending.size)
1177
+ if (!this.initialized || this.closing || this.hostRetirement || this.fault || this.suspending || this.recoveryRun || this.operations.size || this.pending.size)
1025
1178
  return false;
1026
1179
  return [...this.records.values()].filter(record => LIVE.has(record.state) || recoveryOwnsWork(record)
1027
1180
  || !!this.runtimes.get(record.id) && !this.runtimes.get(record.id).stopped).every(record => {
@@ -1163,6 +1316,8 @@ class ScheduleService {
1163
1316
  return [...this.records.values()].some(record => !!record.recovery);
1164
1317
  }
1165
1318
  destroy() {
1319
+ if (this.hostRetirement && !this.hostsRetired)
1320
+ return Promise.reject(new Error('Explicit native host retirement remains unresolved.'));
1166
1321
  if (this.destruction)
1167
1322
  return this.destruction;
1168
1323
  const preserve = !this.closing && this.hasActiveSchedules() && this.canSuspendForRestart();
@@ -1297,11 +1452,18 @@ class ScheduleService {
1297
1452
  let cleanup = false;
1298
1453
  const runtime = this.runtimes.get(id);
1299
1454
  await this.serial(async () => {
1300
- if (!runtime || this.runtimes.get(id) !== runtime || !this.records.has(id))
1455
+ if (!runtime || this.runtimes.get(id) !== runtime || !this.records.has(id)) {
1456
+ if (event.type === 'rebound')
1457
+ throw new Error('Native rebound owner retired.');
1301
1458
  return;
1459
+ }
1302
1460
  if (this.fault)
1303
1461
  throw this.fault;
1304
1462
  const record = this.records.get(id);
1463
+ if (this.hostRetirement && (event.type === 'started' || event.type === 'rebound'
1464
+ || (event.type === 'completed' || event.type === 'skipped') && !runtime.completed.has(event.occurrenceId))) {
1465
+ throw new Error('Unexpected native work during explicit retirement; retain the native event journal.');
1466
+ }
1305
1467
  if (this.suspending && event.type === 'stopped') {
1306
1468
  if (event.exitConfirmed === false)
1307
1469
  throw new Error('Native handoff exit unconfirmed.');
@@ -1324,6 +1486,8 @@ class ScheduleService {
1324
1486
  if (runtime.releasing && event.type === 'stopped' && event.exitConfirmed !== false)
1325
1487
  return;
1326
1488
  const ownerCurrent = this.current(record);
1489
+ if (event.type === 'rebound' && (this.closing || !ownerCurrent))
1490
+ throw new Error('Native rebound owner retired.');
1327
1491
  if (this.closing || !ownerCurrent) {
1328
1492
  if (record.recovery && (!ownerCurrent || event.type !== 'stopped' || event.exitConfirmed === false))
1329
1493
  record.recovery.status = 'blocked';
@@ -1339,6 +1503,19 @@ class ScheduleService {
1339
1503
  await this.persist();
1340
1504
  return;
1341
1505
  }
1506
+ if (event.type === 'rebound') {
1507
+ // A provider's clean same-conversation handoff changes definition identity,
1508
+ // never occurrence identity. Serialize with cancellation and outbox writes.
1509
+ text(event.nativeId, 8192);
1510
+ text(event.previousNativeId, 8192);
1511
+ if (record.state !== 'active' || record.cancelRequested || runtime.running.size
1512
+ || record.nativeId !== event.previousNativeId || runtime.handle?.nativeId !== event.nativeId) {
1513
+ throw new Error('Native definition rebound does not match active ownership.');
1514
+ }
1515
+ record.nativeId = event.nativeId;
1516
+ await this.persist();
1517
+ return;
1518
+ }
1342
1519
  const finishingCancelled = record.state === 'cancelled' && runtime.handle?.cancellationKeepsRunning
1343
1520
  && event.type === 'completed' && runtime.running.has(event.occurrenceId);
1344
1521
  if ((!finishingCancelled && record.state === 'cancelled') || record.state === 'failed' || record.state === 'completed')
@@ -1419,8 +1596,13 @@ class ScheduleService {
1419
1596
  // Persistence failures still set the service fault inside persist().
1420
1597
  if (cleanup && !runtime.cancelling)
1421
1598
  this.track(this.stop(id, runtime).catch(() => { }));
1422
- if (delivery)
1423
- await this.attemptDeliveries([delivery], true);
1599
+ if (delivery) {
1600
+ const delivering = this.attemptDeliveries([delivery], true);
1601
+ if (this.options.deferDelivery)
1602
+ this.track(delivering);
1603
+ else
1604
+ await delivering;
1605
+ }
1424
1606
  }
1425
1607
  attemptDeliveries(ids, firstAttempt = false) {
1426
1608
  const run = this.deliveryTail.then(async () => {
@@ -1496,7 +1678,7 @@ class ScheduleService {
1496
1678
  }
1497
1679
  // A shared session can delete future firings while an occurrence still
1498
1680
  // finishes. Keep ownership until its terminal stopped notification.
1499
- if (!handle?.cancellationKeepsRunning || !runtime.running.size)
1681
+ if (handle?.retirementConfirmed !== false && (!handle?.cancellationKeepsRunning || !runtime.running.size))
1500
1682
  runtime.stopped = true;
1501
1683
  if (runtime.stopped) {
1502
1684
  runtime.releaseAdmission?.();
@@ -1544,7 +1726,7 @@ class ScheduleService {
1544
1726
  }
1545
1727
  canAdmitOccurrence(id, runtime) {
1546
1728
  const record = this.records.get(id);
1547
- return !!record && this.runtimes.get(id) === runtime && !this.closing && !this.fault
1729
+ return !!record && this.runtimes.get(id) === runtime && !this.closing && !this.hostRetirement && !this.fault
1548
1730
  && !runtime.stopped && !runtime.cancelling && !record.cancelRequested
1549
1731
  && LIVE.has(record.state) && this.current(record);
1550
1732
  }
@@ -1558,8 +1740,9 @@ class ScheduleService {
1558
1740
  void task.catch(error => {
1559
1741
  // Persistence/protocol failures fail closed and stop native producers.
1560
1742
  this.fault ??= error instanceof Error ? error : new Error('Schedule service failed.');
1561
- for (const [id, runtime] of this.runtimes)
1562
- void this.stop(id, runtime).catch(() => { });
1743
+ if (!this.hostRetirement)
1744
+ for (const [id, runtime] of this.runtimes)
1745
+ void this.stop(id, runtime).catch(() => { });
1563
1746
  }).finally(() => this.tasks.delete(task));
1564
1747
  }
1565
1748
  operation(task) {
@@ -1599,7 +1782,7 @@ class ScheduleService {
1599
1782
  checkReady() {
1600
1783
  if (this.fault)
1601
1784
  throw this.fault;
1602
- if (!this.initialized || this.closing || this.suspending)
1785
+ if (!this.initialized || this.closing || this.hostRetirement || this.suspending)
1603
1786
  throw new Error('Schedule service is not initialized or is closed.');
1604
1787
  }
1605
1788
  serial(operation) {
@@ -1831,8 +2014,9 @@ class ScheduleService {
1831
2014
  }
1832
2015
  catch (error) {
1833
2016
  this.fault = error instanceof Error ? error : new Error('Schedule catalog write failed.');
1834
- for (const [id, runtime] of this.runtimes)
1835
- void this.stop(id, runtime).catch(() => { });
2017
+ if (!this.hostRetirement)
2018
+ for (const [id, runtime] of this.runtimes)
2019
+ void this.stop(id, runtime).catch(() => { });
1836
2020
  throw this.fault;
1837
2021
  }
1838
2022
  finally {