agent-transport-system 0.7.19 → 0.7.20

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/ats.js CHANGED
@@ -27,7 +27,7 @@ import wrapAnsi from "wrap-ansi";
27
27
  import { Box, Container, Editor, Key, ProcessTerminal, TUI, Text, getEditorKeybindings, matchesKey } from "@mariozechner/pi-tui";
28
28
 
29
29
  //#region package.json
30
- var version = "0.7.19";
30
+ var version = "0.7.20";
31
31
  var package_default = {
32
32
  $schema: "https://www.schemastore.org/package.json",
33
33
  name: "agent-transport-system",
@@ -26205,6 +26205,28 @@ async function recoverLifecycleFailure(input) {
26205
26205
  const originalErrorMessage = toErrorMessage$19(input.error);
26206
26206
  const originalFailureStage = resolveLifecycleFailureStage(input.error, input.state.failureStage);
26207
26207
  const originalReasonCodes = resolveLifecycleFailureReasonCodes(input.error);
26208
+ const restartedCurrentVersion = await recoverBackgroundLifecycleVerificationFailure({
26209
+ commandOptions: input.commandOptions,
26210
+ error: input.error,
26211
+ expectedVersion: input.expectedVersion,
26212
+ failureStage: originalFailureStage,
26213
+ operation: input.operation,
26214
+ restorePoint: input.restorePoint,
26215
+ serviceManager: input.serviceManager,
26216
+ target: input.target
26217
+ }).catch(() => null);
26218
+ if (restartedCurrentVersion) return {
26219
+ status: "aligned",
26220
+ targetVersion: input.expectedVersion,
26221
+ inventoryBefore: input.inventoryBefore,
26222
+ inventoryAfter: restartedCurrentVersion,
26223
+ reasonCodes: [],
26224
+ completedPhases: input.state.completedPhases,
26225
+ desiredState: input.restorePoint.desiredState,
26226
+ shouldStartAfterLifecycle: input.restorePoint.shouldStartAfterLifecycle,
26227
+ backupDataPath: null,
26228
+ errorMessage: null
26229
+ };
26208
26230
  if (input.restorePoint.trusted) {
26209
26231
  const restoredPrevious = await restoreVerifiedPreviousState({
26210
26232
  restorePoint: input.restorePoint,
@@ -26334,6 +26356,47 @@ async function transitionLifecycleToStoppedSafeCurrentVersion(input) {
26334
26356
  target: buildDaemonServiceTargetSpec({ daemonVersion: input.expectedVersion })
26335
26357
  });
26336
26358
  }
26359
+ async function recoverBackgroundLifecycleVerificationFailure(input) {
26360
+ if (!shouldRecoverBackgroundLifecycleVerificationFailure({
26361
+ failureInventory: readLifecycleFailureInventory(input.error),
26362
+ failureStage: input.failureStage,
26363
+ restorePoint: input.restorePoint
26364
+ })) return null;
26365
+ await input.serviceManager.stop();
26366
+ await input.serviceManager.waitUntilStopped();
26367
+ await ensureNoOwnedProcessesRemain();
26368
+ await startLifecycleServiceWithRetry({
26369
+ serviceCommandSpec: buildDaemonSystemServiceCommandSpec({
26370
+ controller: input.serviceManager.controller,
26371
+ environmentTarget: input.commandOptions.environmentTarget
26372
+ }),
26373
+ serviceManager: input.serviceManager
26374
+ });
26375
+ await input.serviceManager.waitUntilRunning();
26376
+ return await waitForVerifiedLifecycleInventory({
26377
+ desiredState: "background",
26378
+ expectedVersion: input.expectedVersion,
26379
+ operation: input.operation,
26380
+ shouldStartAfterLifecycle: true,
26381
+ target: input.target
26382
+ });
26383
+ }
26384
+ function shouldRecoverBackgroundLifecycleVerificationFailure(input) {
26385
+ if (input.failureStage !== "verify_final_inventory" || input.restorePoint.desiredState !== "background" || input.restorePoint.shouldStartAfterLifecycle !== true || !input.failureInventory) return false;
26386
+ const anomalyCodes = input.failureInventory.anomalies.map((anomaly) => anomaly.code);
26387
+ if (anomalyCodes.length === 0) return false;
26388
+ const recoverableCodes = new Set(["manager_running_without_runtime", "runtime_stale"]);
26389
+ return anomalyCodes.every((code) => recoverableCodes.has(code));
26390
+ }
26391
+ function readLifecycleFailureInventory(error) {
26392
+ if (!(error instanceof DaemonServiceLifecycleStageError)) return null;
26393
+ return isDaemonServiceInventory(error.cause) ? error.cause : null;
26394
+ }
26395
+ function isDaemonServiceInventory(value) {
26396
+ if (!(value && typeof value === "object")) return false;
26397
+ const candidate = value;
26398
+ return Array.isArray(candidate.anomalies) && !!candidate.runtimeStatus;
26399
+ }
26337
26400
  function createLifecycleRestorePoint(input) {
26338
26401
  return {
26339
26402
  desiredState: input.desiredState,
@@ -26618,6 +26681,7 @@ async function waitForVerifiedLifecycleInventory(input) {
26618
26681
  shouldStartAfterLifecycle: input.shouldStartAfterLifecycle
26619
26682
  })) throw new DaemonServiceLifecycleStageError({
26620
26683
  message: verificationError,
26684
+ reasonCodes: readDaemonServiceInventoryAnomalyCodes(inventory),
26621
26685
  stage: "verify_final_inventory",
26622
26686
  cause: inventory
26623
26687
  });
@@ -26627,10 +26691,14 @@ async function waitForVerifiedLifecycleInventory(input) {
26627
26691
  }
26628
26692
  throw new DaemonServiceLifecycleStageError({
26629
26693
  message: lastError ?? "ATS could not verify the final local service inventory state.",
26694
+ reasonCodes: lastInventory ? readDaemonServiceInventoryAnomalyCodes(lastInventory) : [],
26630
26695
  stage: "verify_final_inventory",
26631
26696
  cause: lastInventory
26632
26697
  });
26633
26698
  }
26699
+ function readDaemonServiceInventoryAnomalyCodes(inventory) {
26700
+ return inventory.anomalies.map((anomaly) => anomaly.code);
26701
+ }
26634
26702
  async function startLifecycleServiceWithRetry(input) {
26635
26703
  try {
26636
26704
  await input.serviceManager.start();