@camstack/server 1.2.779 → 1.2.781

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 (114) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/agent/main.js +5 -1
  3. package/dist/agent/stale-addon-gate.js +52 -15
  4. package/dist/api/addon-upload.js +41 -0
  5. package/dist/api/core/cap-providers.js +19 -29
  6. package/dist/api/core/integration-role.js +15 -2
  7. package/dist/api/tarball-manifest.js +10 -1
  8. package/dist/api/trpc/cap-router-runtime.js +18 -9
  9. package/dist/api/trpc/generated-cap-mounts.js +1 -9
  10. package/dist/api/trpc/generated-cap-routers.js +9 -88
  11. package/dist/core/addon/addon-package.service.js +24 -8
  12. package/dist/core/addon/addon-registry.service.js +61 -10
  13. package/dist/core/addon/hub-spawn-gate.js +92 -0
  14. package/dist/core/addon/integration-instances-provider.js +22 -0
  15. package/dist/core/agent/agent-registry.service.js +6 -2
  16. package/dist/core/agent/delivery-requirements.js +22 -6
  17. package/dist/core/updates/required-addon-update.js +188 -0
  18. package/dist/launcher.js +4 -0
  19. package/dist/manual-boot.js +27 -0
  20. package/dist/server-root/index.js +74 -3
  21. package/package.json +7 -11
  22. package/system/dist/addon-runner.js +188 -5
  23. package/system/dist/addon-runner.mjs +189 -6
  24. package/system/dist/{agent-https-swBZI1iJ.js → agent-https-A9wsxVGn.js} +1 -1
  25. package/system/dist/{agent-https-BrINLeNj.mjs → agent-https-DuxDC67S.mjs} +1 -1
  26. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  27. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  28. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  29. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  30. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  31. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  32. package/system/dist/builtins/autotrack/index.js +1 -1
  33. package/system/dist/builtins/autotrack/index.mjs +1 -1
  34. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  35. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  36. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  37. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  38. package/system/dist/builtins/camera-grid/index.js +1 -1
  39. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  40. package/system/dist/builtins/composer/composer.addon.js +3 -3
  41. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  42. package/system/dist/builtins/console-logging/index.js +1 -1
  43. package/system/dist/builtins/console-logging/index.mjs +1 -1
  44. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  45. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  46. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  47. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  48. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  49. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  50. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  51. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  52. package/system/dist/builtins/keychain/index.js +4 -4
  53. package/system/dist/builtins/keychain/index.mjs +4 -4
  54. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  56. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  57. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  58. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  60. package/system/dist/builtins/loki-logging/index.js +1 -1
  61. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  62. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  64. package/system/dist/builtins/platform-probe/index.js +1 -1
  65. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  66. package/system/dist/builtins/record-entries/index.js +1 -1
  67. package/system/dist/builtins/record-entries/index.mjs +1 -1
  68. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  70. package/system/dist/builtins/snapshot/index.js +1 -1
  71. package/system/dist/builtins/snapshot/index.mjs +1 -1
  72. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  74. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  76. package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +5 -1
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +12 -4
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +12 -4
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  80. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  81. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  82. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  83. package/system/dist/builtins/winston-logging/index.js +1 -1
  84. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  85. package/system/dist/{capture-engine-D_ImDrdj.mjs → capture-engine-CEChNpAD.mjs} +1 -1
  86. package/system/dist/{capture-engine-BXV6UiHl.js → capture-engine-D6mXfLFQ.js} +1 -1
  87. package/system/dist/{composition-sources-BjktkDte.mjs → composition-sources-6XYW86Kw.mjs} +1 -1
  88. package/system/dist/{composition-sources-DjTxqryW.js → composition-sources-cVWKVph4.js} +1 -1
  89. package/system/dist/{constants-CGXiM2LV.js → constants-B5Yg02ii.js} +1 -1
  90. package/system/dist/{constants-C68806R6.mjs → constants-DqwDEYfb.mjs} +1 -1
  91. package/system/dist/{device-ca-D_q1MiQ3.js → device-ca-BVz14dRd.js} +1 -1
  92. package/system/dist/{device-ca-CFRagVlE.mjs → device-ca-oY4Xqd7s.mjs} +1 -1
  93. package/system/dist/{dist-C9Ms2Ul9.js → dist-B4wrqheM.js} +833 -631
  94. package/system/dist/{dist-BzpjKSec.mjs → dist-BX8nZeXV.mjs} +804 -632
  95. package/system/dist/file-host-worker.js +1 -1
  96. package/system/dist/file-host-worker.mjs +1 -1
  97. package/system/dist/{hub-mdns-ciao-CFsSp0tc.mjs → hub-mdns-ciao-BDPMfOgq.mjs} +2 -2
  98. package/system/dist/{hub-mdns-ciao-C87S9O_n.js → hub-mdns-ciao-CiMMA0rT.js} +2 -2
  99. package/system/dist/index.js +441 -31
  100. package/system/dist/index.mjs +436 -33
  101. package/system/dist/kernel/addon-installer.d.ts +44 -1
  102. package/system/dist/kernel/held-installs.d.ts +21 -0
  103. package/system/dist/kernel/index.d.ts +6 -0
  104. package/system/dist/kernel/moleculer/migration-api-facade.d.ts +73 -0
  105. package/system/dist/kernel/moleculer/trpc-links.d.ts +8 -0
  106. package/system/dist/kernel/requires-registry.d.ts +31 -0
  107. package/system/dist/{legacy-integration-rows-door-CI-AaB-M.mjs → legacy-integration-rows-door-DDA3YOxL.mjs} +1 -1
  108. package/system/dist/{legacy-integration-rows-door-C_aaT1DH.js → legacy-integration-rows-door-YuWqHZW4.js} +1 -1
  109. package/system/dist/migrations/hub/__fixtures__/seed.d.ts +23 -0
  110. package/system/dist/{restore-archive-D3K33hws.mjs → restore-archive-BrtpgNCt.mjs} +82 -82
  111. package/system/dist/{restore-archive-BC8OECG8.js → restore-archive-Cn9OShm4.js} +1 -1
  112. package/system/dist/{wal-maintenance-Bf9m0JZr.js → wal-maintenance-BTzu3s-6.js} +0 -0
  113. package/system/dist/{wal-maintenance-CMjTxyAC.mjs → wal-maintenance-jgyV9NbL.mjs} +0 -0
  114. package/system/package.json +1 -1
@@ -44,6 +44,7 @@ const node_crypto_1 = require("node:crypto");
44
44
  const fs = __importStar(require("node:fs"));
45
45
  const os = __importStar(require("node:os"));
46
46
  const path = __importStar(require("node:path"));
47
+ const hub_spawn_gate_js_1 = require("./hub-spawn-gate.js");
47
48
  const system_1 = require("@camstack/server/system");
48
49
  const types_1 = require("@camstack/types");
49
50
  const types_2 = require("@camstack/types");
@@ -886,7 +887,7 @@ class AddonRegistryService {
886
887
  this.logger.info('Spawning isolated infrastructure builtins', {
887
888
  meta: { addonIds: isolatedInfraIds },
888
889
  });
889
- await spawnRunnerPlan(this.buildAddonGroupPlan(isolatedInfraIds));
890
+ await spawnRunnerPlan(this.buildSpawnPlan(isolatedInfraIds));
890
891
  },
891
892
  waitForDataStoreProvider: async () => {
892
893
  if (isolatedInfraIds.length === 0)
@@ -943,7 +944,7 @@ class AddonRegistryService {
943
944
  }
944
945
  },
945
946
  spawnForkedAddons: async () => {
946
- await spawnRunnerPlan(this.buildAddonGroupPlan(allIds.filter((id) => !isolatedBuiltins.has(id))));
947
+ await spawnRunnerPlan(this.buildSpawnPlan(allIds.filter((id) => !isolatedBuiltins.has(id))));
947
948
  },
948
949
  bootInProcessConsumers: async () => {
949
950
  // Pass 2 — remaining core builtins, in capability-dependency order.
@@ -1004,7 +1005,7 @@ class AddonRegistryService {
1004
1005
  this.logger.info('Spawning isolated system builtins', {
1005
1006
  meta: { addonIds: isolatedConsumerIds },
1006
1007
  });
1007
- await spawnRunnerPlan(this.buildAddonGroupPlan(isolatedConsumerIds));
1008
+ await spawnRunnerPlan(this.buildSpawnPlan(isolatedConsumerIds));
1008
1009
  },
1009
1010
  });
1010
1011
  const initializedIds = [...this.addonEntries.entries()]
@@ -1910,9 +1911,7 @@ class AddonRegistryService {
1910
1911
  const suppressed = new Set([addonId]);
1911
1912
  if (this.isForkedAddonEntry(entry)) {
1912
1913
  const runnerId = (0, types_2.resolveRunnerId)(entry.declaration, addonId);
1913
- for (const { addonId: siblingId } of this.buildAddonGroupPlan([
1914
- ...this.addonEntries.keys(),
1915
- ]).get(runnerId) ?? []) {
1914
+ for (const { addonId: siblingId } of this.buildSpawnPlan([...this.addonEntries.keys()], () => undefined).get(runnerId) ?? []) {
1916
1915
  suppressed.add(siblingId);
1917
1916
  }
1918
1917
  }
@@ -3120,6 +3119,7 @@ class AddonRegistryService {
3120
3119
  transportForOwner: (owner) => this.inProcessKeychainTransport(owner),
3121
3120
  eventBus: this.eventBusService,
3122
3121
  });
3122
+ const records = this.recordsForOwner(addonId, secrets);
3123
3123
  const ctx = {
3124
3124
  id: `addon:${addonId}`,
3125
3125
  logger,
@@ -3214,7 +3214,16 @@ class AddonRegistryService {
3214
3214
  // (no wire, no stamp): the same single place identity is trusted as for
3215
3215
  // the keychain. `ctx.records` is the owner's own door; a builtin that
3216
3216
  // acts for another owner (the entries service) builds one with `recordsForOwner`.
3217
- records: this.recordsForOwner(addonId, secrets),
3217
+ records,
3218
+ // The one surface a migration may reach (planning#447), over this context's own handles.
3219
+ migrationApi: (0, system_1.createMigrationApiOverContext)({
3220
+ nodeId: this.broker.nodeID,
3221
+ logger,
3222
+ api: () => registry.getAddonApi(addonId),
3223
+ records,
3224
+ secrets,
3225
+ settings: settingsView,
3226
+ }),
3218
3227
  useCapability(capName, scope = { type: 'global' }) {
3219
3228
  return getOrCreateHandle(capName, scope, 15_000);
3220
3229
  },
@@ -3333,6 +3342,39 @@ class AddonRegistryService {
3333
3342
  * Read-only. Used by the bootstrap to plan spawns up-front and by
3334
3343
  * diagnostics that want to render the current topology.
3335
3344
  */
3345
+ /**
3346
+ * The plan the hub actually SPAWNS: `buildAddonGroupPlan` over the ids whose
3347
+ * package passes the stale gate (planning#447). An addon below the running
3348
+ * server's `requires.addons`, or needing a newer server, stays unspawned and
3349
+ * is logged with both versions; the post-swap required-addon update brings it
3350
+ * current and a reload spawns it then.
3351
+ */
3352
+ buildSpawnPlan(addonIds, log = (line) => this.logger.warn(line)) {
3353
+ return this.buildAddonGroupPlan(this.spawnableIds(addonIds, log));
3354
+ }
3355
+ spawnableIds(addonIds, log) {
3356
+ return (0, hub_spawn_gate_js_1.spawnableAddonIds)({
3357
+ addonIds,
3358
+ candidateOf: (id) => this.staleCandidateOf(id),
3359
+ context: (0, hub_spawn_gate_js_1.readHubStaleGateContext)(),
3360
+ infraCapabilities: new Set(system_1.INFRA_CAPABILITIES.map((c) => c.name)),
3361
+ log,
3362
+ });
3363
+ }
3364
+ staleCandidateOf(addonId) {
3365
+ const entry = this.addonEntries.get(addonId);
3366
+ if (!entry?.declaration || !entry.addonDir)
3367
+ return undefined;
3368
+ return {
3369
+ groupId: (0, types_2.resolveRunnerId)(entry.declaration, addonId),
3370
+ addonId,
3371
+ addonDir: entry.addonDir,
3372
+ version: entry.declaration.version ?? entry.packageVersion,
3373
+ packageName: entry.packageName,
3374
+ packageVersion: entry.packageVersion,
3375
+ capabilities: entry.declaredCapabilities,
3376
+ };
3377
+ }
3336
3378
  buildAddonGroupPlan(addonIds) {
3337
3379
  const plan = new Map();
3338
3380
  for (const id of addonIds) {
@@ -3526,9 +3568,18 @@ class AddonRegistryService {
3526
3568
  throw new Error(`ensureForkedRunner("${addonId}") requires an on-disk forked addon`);
3527
3569
  }
3528
3570
  const runnerId = (0, types_2.resolveRunnerId)(entry.declaration, addonId);
3529
- const roster = this.buildAddonGroupPlan([...this.addonEntries.keys()]).get(runnerId) ?? [
3530
- { addonId, addonDir: entry.addonDir },
3531
- ];
3571
+ // The same gate as the boot plan: a restart, a hot-install or a retry must not spawn an addon
3572
+ // the running server cannot host, nor carry a held-back sibling into its runner.
3573
+ const held = [];
3574
+ if (this.spawnableIds([addonId], (line) => held.push(line)).length === 0) {
3575
+ const reason = held.join('; ');
3576
+ this.logger.warn('ensureForkedRunner: addon is held back by the stale gate, not spawned', {
3577
+ tags: { addonId },
3578
+ meta: { reason },
3579
+ });
3580
+ throw new Error(`addon "${addonId}" is held back until its package is reconciled: ${reason}`);
3581
+ }
3582
+ const roster = this.buildSpawnPlan([...this.addonEntries.keys()], () => undefined).get(runnerId) ?? [{ addonId, addonDir: entry.addonDir }];
3532
3583
  // Claim before the queue so a member that arrives while this one is
3533
3584
  // waiting is visible to the fork that has not started yet. Solo runners
3534
3585
  // (roster of one) never claim — each of their restarts forks.
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.spawnableAddonIds = spawnableAddonIds;
37
+ exports.readHubStaleGateContext = readHubStaleGateContext;
38
+ /**
39
+ * The hub's spawn gate for a stale addon package (planning#447, D989).
40
+ *
41
+ * An agent already holds an addon back when its package is below what the
42
+ * running server requires (`agent/stale-addon-gate.ts`, #346). The hub planned
43
+ * every addon it found on disk, so after a server swap an addon built for the
44
+ * previous framework was spawned, crashed, and burned the D6 respawn budget
45
+ * before the post-swap update reached it. The hub now asks the SAME gate before
46
+ * it plans a runner: a held-back addon stays unspawned, is logged with both
47
+ * versions, and is not part of the plan.
48
+ */
49
+ const path = __importStar(require("node:path"));
50
+ const stale_addon_gate_js_1 = require("../../agent/stale-addon-gate.js");
51
+ const addon_requirements_js_1 = require("./addon-requirements.js");
52
+ const installed_addon_versions_js_1 = require("./installed-addon-versions.js");
53
+ /** The ids of `addonIds` that may be spawned; every held-back one is logged. */
54
+ function spawnableAddonIds(input) {
55
+ const candidates = [];
56
+ const known = new Set();
57
+ for (const id of input.addonIds) {
58
+ const candidate = input.candidateOf(id);
59
+ if (candidate === undefined)
60
+ continue;
61
+ known.add(id);
62
+ candidates.push(candidate);
63
+ }
64
+ const { ready, deferred, unjudged } = (0, stale_addon_gate_js_1.gateStaleCandidates)(candidates, input.context);
65
+ for (const line of unjudged)
66
+ input.log(line);
67
+ const readyIds = new Set(ready.map((c) => c.addonId));
68
+ for (const d of deferred) {
69
+ const isInfra = d.candidate.capabilities.some((c) => input.infraCapabilities.has(typeof c === 'string' ? c : c.name));
70
+ if (isInfra) {
71
+ // Holding a data-store or storage provider leaves the node with no storage at all.
72
+ readyIds.add(d.candidate.addonId);
73
+ input.log(`${d.reason} — infrastructure provider, SPAWNED ANYWAY so the node keeps its storage`);
74
+ }
75
+ else {
76
+ input.log(d.reason);
77
+ }
78
+ }
79
+ // An id the registry cannot describe is not this gate's to judge: keep it, the plan drops it as before.
80
+ return input.addonIds.filter((id) => readyIds.has(id) || !known.has(id));
81
+ }
82
+ /** The gate's facts for THIS hub, read from disk: the running server and the addons dir. */
83
+ function readHubStaleGateContext() {
84
+ const dataDir = path.resolve(process.env.CAMSTACK_DATA ?? 'camstack-data');
85
+ const addonsDir = process.env.CAMSTACK_ADDONS_DIR ?? path.resolve(dataDir, 'addons');
86
+ return {
87
+ serverVersion: (0, addon_requirements_js_1.readRunningServerVersion)(),
88
+ serverRequiresAddons: (0, addon_requirements_js_1.readRunningServerAddonMinimums)(),
89
+ installedVersions: (0, installed_addon_versions_js_1.readInstalledAddonVersions)(addonsDir),
90
+ requiresOfDir: stale_addon_gate_js_1.readPackageRequires,
91
+ };
92
+ }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isIntegrationInstancesProvider = isIntegrationInstancesProvider;
4
4
  exports.findInstancesProvider = findInstancesProvider;
5
+ exports.kindsFor = kindsFor;
6
+ exports.instancesOfSection = instancesOfSection;
5
7
  /** Structural check for an addon's `integration-instances` provider. */
6
8
  function isIntegrationInstancesProvider(value) {
7
9
  return (value !== null &&
@@ -19,3 +21,23 @@ function findInstancesProvider(registry, addonId) {
19
21
  const provider = registry.getProviderByAddon('integration-instances', addonId);
20
22
  return isIntegrationInstancesProvider(provider) ? provider : null;
21
23
  }
24
+ /**
25
+ * The kinds of the provider that are configured for `functionCap` (a page section is the kinds
26
+ * whose `functionCap` it names, D1013). A provider that declares no kinds has no sections.
27
+ */
28
+ async function kindsFor(provider, functionCap) {
29
+ const description = await provider.describe();
30
+ return (description.kinds ?? []).filter((kind) => kind.functionCap === functionCap);
31
+ }
32
+ /**
33
+ * The provider's instances of one section: those whose `kind` is one of `kindsFor(functionCap)`.
34
+ * A provider with no kinds is a single-section holder and answers every instance.
35
+ */
36
+ async function instancesOfSection(provider, functionCap) {
37
+ const description = await provider.describe();
38
+ const all = await provider.listInstances();
39
+ if (description.kinds === undefined || description.kinds.length === 0)
40
+ return all;
41
+ const ids = new Set(description.kinds.filter((kind) => kind.functionCap === functionCap).map((kind) => kind.id));
42
+ return all.filter((instance) => instance.kind !== undefined && ids.has(instance.kind));
43
+ }
@@ -278,6 +278,10 @@ class AgentRegistryService {
278
278
  deliveryRequiresOf = null;
279
279
  /** The server version each node last reported on `$agent.status`; `null` = reported none. */
280
280
  nodeServerVersions = new Map();
281
+ /** The `@camstack/server` version `nodeId` last reported on reconcile; `null` when none. */
282
+ nodeServerVersion(nodeId) {
283
+ return this.nodeServerVersions.get(nodeId) ?? null;
284
+ }
281
285
  convergenceTimer = null;
282
286
  convergenceRunning = false;
283
287
  convergenceRerun = null;
@@ -1190,9 +1194,9 @@ class AgentRegistryService {
1190
1194
  // held, naming both versions; the node keeps what it has.
1191
1195
  const requiresOf = this.deliveryRequiresOf;
1192
1196
  if (requiresOf !== null && planned.targets.length > 0) {
1193
- const split = await (0, delivery_requirements_1.splitByNodeRequirements)(planned.targets, this.nodeServerVersions.get(agentId) ?? null, requiresOf);
1197
+ const split = await (0, delivery_requirements_1.splitByNodeRequirements)(planned.targets, this.nodeServerVersions.get(agentId) ?? null, requiresOf, live, new Set(plan.remove.map((r) => r.name)));
1194
1198
  for (const held of split.held) {
1195
- this.logger?.warn('convergence: delivery held, the node server is older than the addon needs', {
1199
+ this.logger?.warn('convergence: delivery held, the node is older than the addon needs', {
1196
1200
  tags: { nodeId: agentId },
1197
1201
  meta: { package: held.target.name, version: held.target.version, reason: held.reason },
1198
1202
  });
@@ -8,20 +8,36 @@ exports.splitByNodeRequirements = splitByNodeRequirements;
8
8
  * `camstack.requires.server` above what that agent runs would be installed
9
9
  * onto a server that cannot host it. Such a delivery is HELD, with the
10
10
  * versions on both sides named, and goes through once the node's server has
11
- * been updated. A node that does not report its server version cannot be
12
- * judged, and an unjudged node never passes a declared minimum.
11
+ * been updated. The same holds for `requires.addons`: a version that needs an
12
+ * addon package newer than the node's live roster holds (or than the same batch
13
+ * delivers) waits. A node that does not report its server version cannot be
14
+ * judged, and an unjudged node never passes a declared minimum. Only a package
15
+ the node carries (its roster, or the same batch) is judged against an addon
16
+ minimum: one the node will never install (hub-only) cannot hold a delivery.
13
17
  */
14
18
  const types_1 = require("@camstack/types");
15
- async function splitByNodeRequirements(targets, nodeServerVersion, requiresOf) {
19
+ async function splitByNodeRequirements(targets, nodeServerVersion, requiresOf, roster = [],
20
+ /** Packages this pass removes from the node: never judged, they are leaving. */
21
+ leaving = new Set()) {
22
+ // What the node will hold once this batch lands: its live roster, then the batch on top.
23
+ const addons = {};
24
+ for (const entry of roster)
25
+ addons[entry.name] = entry.version;
26
+ for (const target of targets)
27
+ addons[target.name] = target.version;
16
28
  const deliver = [];
17
29
  const held = [];
18
30
  for (const target of targets) {
19
31
  const unmet = (0, types_1.unmetRequirements)(await requiresOf(target.name, target.version), {
20
32
  server: nodeServerVersion,
21
- // What the node runs of other addons is not known here; only the server binds a delivery.
22
- addons: {},
33
+ addons,
23
34
  wrapper: null,
24
- }).filter((u) => u.kind === 'server-too-old');
35
+ }).filter((u) => u.kind === 'server-too-old' ||
36
+ // Only a package this node carries (its roster, or this batch) can be too old: a hub-only
37
+ // addon is never delivered here, and a package being removed is leaving.
38
+ (u.kind === 'addon-too-old' &&
39
+ Object.hasOwn(addons, u.packageName) &&
40
+ !leaving.has(u.packageName)));
25
41
  if (unmet.length === 0) {
26
42
  deliver.push(target);
27
43
  continue;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HELD_INSTALL_CATEGORY = exports.REQUIRED_ADDON_UPDATE_CATEGORY = void 0;
4
+ exports.requiredAddonAlertId = requiredAddonAlertId;
5
+ exports.addonsBelowMinimum = addonsBelowMinimum;
6
+ exports.runRequiredAddonUpdates = runRequiredAddonUpdates;
7
+ exports.heldInstallAlertId = heldInstallAlertId;
8
+ exports.raiseHeldInstallAlerts = raiseHeldInstallAlerts;
9
+ const types_1 = require("@camstack/types");
10
+ exports.REQUIRED_ADDON_UPDATE_CATEGORY = 'addon.required-update-failed';
11
+ function requiredAddonAlertId(packageName) {
12
+ return `required-addon-update:${packageName}`;
13
+ }
14
+ /** Packages installed below their minimum. An unreadable copy is below (a failed read is not a pass). */
15
+ function addonsBelowMinimum(minimums, installed) {
16
+ const below = [];
17
+ for (const [name, range] of Object.entries(minimums)) {
18
+ const minimum = (0, types_1.minimumOf)(range);
19
+ if (minimum === null)
20
+ continue;
21
+ // A package that is not installed is not stale: nothing runs, nothing to update.
22
+ if (!(name in installed))
23
+ continue;
24
+ const have = installed[name] ?? null;
25
+ if (have === null || (0, types_1.compareVersions)(have, minimum) < 0) {
26
+ below.push({ name, installed: have, minimum });
27
+ }
28
+ }
29
+ return below;
30
+ }
31
+ function failureAlert(name, reason, now) {
32
+ return {
33
+ id: requiredAddonAlertId(name),
34
+ category: exports.REQUIRED_ADDON_UPDATE_CATEGORY,
35
+ severity: 'critical',
36
+ title: `${name} could not be updated`,
37
+ message: `The running server needs a newer ${name} and updating it failed (${reason}). The addon stays stopped until an update succeeds; the rest of the node is running.`,
38
+ status: 'active',
39
+ read: false,
40
+ createdAt: now,
41
+ updatedAt: now,
42
+ source: { type: 'addon', id: name },
43
+ metadata: { packageName: name },
44
+ };
45
+ }
46
+ async function runRequiredAddonUpdates(deps) {
47
+ const now = deps.now ?? Date.now;
48
+ const below = addonsBelowMinimum(deps.minimums, deps.installed());
49
+ const updated = [];
50
+ const failed = [];
51
+ for (const item of below) {
52
+ deps.logger.info('Updating an addon the running server requires', {
53
+ meta: {
54
+ name: item.name,
55
+ installed: item.installed,
56
+ minimum: item.minimum,
57
+ },
58
+ });
59
+ const outcome = await deps.updatePackage(item.name).catch((error) => ({
60
+ success: false,
61
+ error: (0, types_1.errMsg)(error),
62
+ }));
63
+ if (outcome.success) {
64
+ updated.push(item.name);
65
+ await resolveAlert(deps, item.name);
66
+ continue;
67
+ }
68
+ const reason = outcome.error ?? 'the update did not succeed';
69
+ failed.push({ name: item.name, reason });
70
+ deps.logger.warn('Required addon update failed — the addon stays held back', {
71
+ meta: {
72
+ name: item.name,
73
+ installed: item.installed,
74
+ minimum: item.minimum,
75
+ reason,
76
+ },
77
+ });
78
+ await raiseAlert(deps, item.name, reason, now());
79
+ }
80
+ return { updated, failed };
81
+ }
82
+ async function raiseAlert(deps, name, reason, now) {
83
+ const alerts = deps.getAlerts();
84
+ if (alerts === undefined) {
85
+ deps.logger.warn('Required addon update alert skipped — alerts capability missing', {
86
+ meta: { name },
87
+ });
88
+ return;
89
+ }
90
+ try {
91
+ await alerts.emit(failureAlert(name, reason, now));
92
+ }
93
+ catch (error) {
94
+ deps.logger.warn('Required addon update alert emit failed', {
95
+ meta: { name, error: (0, types_1.errMsg)(error) },
96
+ });
97
+ }
98
+ }
99
+ async function resolveAlert(deps, name) {
100
+ const alerts = deps.getAlerts();
101
+ if (alerts === undefined)
102
+ return;
103
+ try {
104
+ await alerts.update({
105
+ alertId: requiredAddonAlertId(name),
106
+ patch: { status: 'completed', read: true },
107
+ });
108
+ }
109
+ catch (error) {
110
+ deps.logger.debug('Required addon alert resolve skipped', {
111
+ meta: { name, error: (0, types_1.errMsg)(error) },
112
+ });
113
+ }
114
+ }
115
+ function heldInstallAlertId(packageName) {
116
+ return `install-held:${packageName}`;
117
+ }
118
+ exports.HELD_INSTALL_CATEGORY = 'addon.install-held';
119
+ /**
120
+ * The boot installer cannot raise an alert (it runs before any service); the
121
+ * installs it held back are raised here, once the alerts provider is up.
122
+ */
123
+ async function raiseHeldInstallAlerts(input) {
124
+ const alerts = input.getAlerts();
125
+ const now = (input.now ?? Date.now)();
126
+ if (alerts !== undefined)
127
+ await resolveInstalledHeldAlerts(alerts, input.held, input.logger);
128
+ if (input.held.length === 0)
129
+ return;
130
+ for (const h of input.held) {
131
+ if (alerts === undefined) {
132
+ input.logger.warn('A held install could not be raised — alerts capability missing', {
133
+ meta: { name: h.packageName, code: h.code, reason: h.reason },
134
+ });
135
+ continue;
136
+ }
137
+ const alert = {
138
+ id: heldInstallAlertId(h.packageName),
139
+ category: exports.HELD_INSTALL_CATEGORY,
140
+ severity: 'critical',
141
+ title: `${h.packageName} was not installed`,
142
+ message: `The boot installer did not install ${h.packageName} (${h.spec}): ${h.reason}. The addon is missing until a compatible version can be installed.`,
143
+ status: 'active',
144
+ read: false,
145
+ createdAt: now,
146
+ updatedAt: now,
147
+ source: { type: 'addon', id: h.packageName },
148
+ metadata: { packageName: h.packageName, code: h.code },
149
+ };
150
+ try {
151
+ await alerts.emit(alert);
152
+ }
153
+ catch (error) {
154
+ input.logger.warn('Held install alert emit failed', {
155
+ meta: { name: h.packageName, error: (0, types_1.errMsg)(error) },
156
+ });
157
+ }
158
+ }
159
+ }
160
+ /**
161
+ * The held list lives in the process, so a boot that installs the package starts with
162
+ * it empty while the alert of the earlier boot is still active: resolve every active
163
+ * held-install alert whose package this boot did not hold.
164
+ */
165
+ async function resolveInstalledHeldAlerts(alerts, held, logger) {
166
+ if (alerts.list === undefined)
167
+ return;
168
+ const stillHeld = new Set(held.map((h) => h.packageName));
169
+ try {
170
+ const existing = await alerts.list({ limit: 500 });
171
+ for (const alert of existing) {
172
+ if (alert.category !== exports.HELD_INSTALL_CATEGORY || alert.status !== 'active')
173
+ continue;
174
+ const name = alert.source?.id;
175
+ if (name === undefined || stillHeld.has(name))
176
+ continue;
177
+ await alerts.update({
178
+ alertId: alert.id,
179
+ patch: { status: 'completed', read: true },
180
+ });
181
+ }
182
+ }
183
+ catch (error) {
184
+ logger.warn('Held install alert resolve failed', {
185
+ meta: { error: (0, types_1.errMsg)(error) },
186
+ });
187
+ }
188
+ }
package/dist/launcher.js CHANGED
@@ -205,9 +205,13 @@ async function launch() {
205
205
  bundledAddonsDir = bundledDir;
206
206
  console.log(`[launcher] Using bundled addons from ${bundledDir}`);
207
207
  }
208
+ // The running server's own version judges a registry install at boot: an addon
209
+ // that needs a newer server is held back instead of installed to crash (D989).
210
+ const ownVersion = readOwnManifest()?.version;
208
211
  const installer = new AddonInstaller({
209
212
  addonsDir,
210
213
  ...(bundledAddonsDir ? { bundledAddonsDir } : {}),
214
+ serverVersion: typeof ownVersion === 'string' && ownVersion.length > 0 ? ownVersion : null,
211
215
  });
212
216
  // The first-boot addon set always comes from the package; no config key
213
217
  // overrides it.
@@ -86,6 +86,9 @@ const update_availability_emitter_js_1 = require("./core/update-availability-emi
86
86
  const update_availability_store_js_1 = require("./core/update-availability-store.js");
87
87
  const agent_installed_packages_js_1 = require("./core/updates/agent-installed-packages.js");
88
88
  const registry_reachability_js_1 = require("./core/updates/registry-reachability.js");
89
+ const required_addon_update_js_1 = require("./core/updates/required-addon-update.js");
90
+ const addon_requirements_js_1 = require("./core/addon/addon-requirements.js");
91
+ const installed_addon_versions_js_1 = require("./core/addon/installed-addon-versions.js");
89
92
  const update_check_scheduler_js_1 = require("./core/updates/update-check-scheduler.js");
90
93
  const wrapper_update_checker_js_1 = require("./core/updates/wrapper-update-checker.js");
91
94
  // ---------------------------------------------------------------------------
@@ -429,6 +432,30 @@ async function bootManual(opts) {
429
432
  });
430
433
  addonPackageService.setUpdateCheckRescheduler(() => updateCheckScheduler.reschedule());
431
434
  updateCheckScheduler.start();
435
+ // The running server's `requires.addons` are brought current once the addons
436
+ // are up, with auto-update on or off (planning#447). A failure is an alert and
437
+ // the boot goes on; agents follow through the registration reconcile (D840).
438
+ eventBusService.subscribe({ category: types_1.EventCategory.SystemAddonsReady }, () => {
439
+ // Installs the boot installer held back (no version fits this server, or the registry could
440
+ // not be read) are alerts too: the installer ran before any service existed.
441
+ void (0, required_addon_update_js_1.raiseHeldInstallAlerts)({
442
+ held: (0, system_1.listHeldInstalls)(),
443
+ getAlerts: () => addonRegistryService.getCapabilityRegistry().getSingleton('alerts') ?? undefined,
444
+ logger: updateCheckLogger,
445
+ }).catch((err) => updateCheckLogger.warn('Held install alerts failed', {
446
+ meta: { error: err instanceof Error ? err.message : String(err) },
447
+ }));
448
+ void (0, required_addon_update_js_1.runRequiredAddonUpdates)({
449
+ minimums: (0, addon_requirements_js_1.readRunningServerAddonMinimums)(),
450
+ installed: () => (0, installed_addon_versions_js_1.readInstalledAddonVersions)(process.env.CAMSTACK_ADDONS_DIR ??
451
+ path.resolve(process.env.CAMSTACK_DATA ?? 'camstack-data', 'addons')),
452
+ updatePackage: (name) => addonPackageService.updatePackage(name),
453
+ getAlerts: () => addonRegistryService.getCapabilityRegistry().getSingleton('alerts') ?? undefined,
454
+ logger: updateCheckLogger,
455
+ }).catch((err) => updateCheckLogger.warn('Required addon update job failed', {
456
+ meta: { error: err instanceof Error ? err.message : String(err) },
457
+ }));
458
+ });
432
459
  // ---- Container ---------------------------------------------------------
433
460
  const container = new ServiceContainer();
434
461
  container.register(config_service_1.ConfigService, configService);