@sagentlab/navarch-runtime 0.1.75 → 0.1.76

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.
@@ -1,16 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuntimeUpdateCoordinator = void 0;
3
+ exports.RuntimeUpdateCoordinator = exports.UPDATE_RETRY_MAX_MS = exports.UPDATE_RETRY_BASE_MS = void 0;
4
4
  const logger_cjs_1 = require("./logger.cjs");
5
5
  const update_installer_cjs_1 = require("./update-installer.cjs");
6
6
  const version_cjs_1 = require("./version.cjs");
7
7
  const supervisor_cjs_1 = require("./supervisor.cjs");
8
8
  const log = (0, logger_cjs_1.createLogger)("update");
9
+ // A failed stage reports `failed`, which sends a heartbeat at once, whose
10
+ // response repeats the same directive. Without a pause that loop re-runs
11
+ // `npm pack` several times a second (seen while npm's CDN still served the
12
+ // pre-publish packument for a freshly rolled-out version).
13
+ exports.UPDATE_RETRY_BASE_MS = 30_000;
14
+ exports.UPDATE_RETRY_MAX_MS = 10 * 60_000;
15
+ function directiveKey(directive) {
16
+ return `${directive.target_version}\0${directive.integrity}`;
17
+ }
9
18
  class RuntimeUpdateCoordinator {
10
19
  options;
11
20
  targetInProgress = null;
12
21
  restartInProgress = null;
13
22
  warnedUnsupervised = false;
23
+ lastFailure = null;
14
24
  constructor(options) {
15
25
  this.options = options;
16
26
  }
@@ -26,6 +36,9 @@ class RuntimeUpdateCoordinator {
26
36
  }
27
37
  if (this.targetInProgress)
28
38
  return;
39
+ const key = directiveKey(directive);
40
+ if (this.lastFailure?.key === key && this.now() < this.lastFailure.retryAt)
41
+ return;
29
42
  this.targetInProgress = directive.target_version;
30
43
  void this.apply(directive);
31
44
  }
@@ -57,6 +70,9 @@ class RuntimeUpdateCoordinator {
57
70
  this.restartInProgress = null;
58
71
  }
59
72
  }
73
+ now() {
74
+ return (this.options.now ?? Date.now)();
75
+ }
60
76
  async apply(directive) {
61
77
  const { config, heartbeat, claimLoop, capacity } = this.options;
62
78
  try {
@@ -73,7 +89,11 @@ class RuntimeUpdateCoordinator {
73
89
  }
74
90
  catch (error) {
75
91
  const message = error instanceof Error ? error.message : String(error);
76
- log.error(`runtime update failed: ${message}`);
92
+ const key = directiveKey(directive);
93
+ const failures = this.lastFailure?.key === key ? this.lastFailure.failures + 1 : 1;
94
+ const delayMs = Math.min(exports.UPDATE_RETRY_BASE_MS * 2 ** (failures - 1), exports.UPDATE_RETRY_MAX_MS);
95
+ this.lastFailure = { key, failures, retryAt: this.now() + delayMs };
96
+ log.error(`runtime update failed: ${message} (retrying ${directive.target_version} in ${Math.round(delayMs / 1000)}s)`);
77
97
  heartbeat.setUpdateState("failed", message.slice(0, 500));
78
98
  claimLoop.start();
79
99
  this.targetInProgress = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",