@camstack/server 1.2.205 → 1.2.207
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/agent/agent-infra-capabilities.js +83 -0
- package/dist/agent/agent-update-service.js +7 -1
- package/dist/agent/main.js +9 -3
- package/dist/api/core/cluster-nodes.router.js +26 -5
- package/dist/api/trpc/generated-cap-routers.js +27 -0
- package/dist/core/agent/agent-registry.service.js +120 -2
- package/dist/core/agent/cluster-node-history-store.js +19 -2
- package/dist/core/server-update/server-update.service.js +6 -1
- package/dist/core/update-availability-store.js +1 -1
- package/dist/main.js +0 -1
- package/dist/manual-boot.js +3 -0
- package/dist/server-root/index.js +66 -48
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGENT_LOCAL_DATA_STORE_ENV = void 0;
|
|
4
|
+
exports.resolveAgentInfraCapabilities = resolveAgentInfraCapabilities;
|
|
5
|
+
/**
|
|
6
|
+
* Which infra capabilities an AGENT boots — and the one it no longer does.
|
|
7
|
+
*
|
|
8
|
+
* ## What changed, and why it is a boot-level fact
|
|
9
|
+
*
|
|
10
|
+
* `AGENT_INFRA` used to be `INFRA_CAPABILITIES`, unfiltered. That list carries
|
|
11
|
+
* `{ name: 'data-store-provider', required: true }`; `sqlite-settings` is the
|
|
12
|
+
* only addon in the tree that declares it, and it lives inside the
|
|
13
|
+
* `@camstack/system` closure the agent scans. So an agent could not boot
|
|
14
|
+
* without opening a database of its own — not a setting, a PRECONDITION.
|
|
15
|
+
*
|
|
16
|
+
* Persistence belongs to the hub. Every addon FORKED on an agent already
|
|
17
|
+
* reaches the hub's store (`ipcParentLink` → the agent's `onUnownedCall` →
|
|
18
|
+
* `$hub-cap-fwd`), and per-node values already live inside the hub's blob as
|
|
19
|
+
* `<key>@<nodeId>`. The only writers of the agent's own file were the handful
|
|
20
|
+
* of infra addons that boot inside agent-main, whose `ctx.settings` resolved
|
|
21
|
+
* `settingsStore` through `localProviderLink` — i.e. against the local door.
|
|
22
|
+
* The commit before this one gave that door the hub as its remote, so dropping
|
|
23
|
+
* the engine leaves nothing stranded.
|
|
24
|
+
*
|
|
25
|
+
* Measured on `little-unraid` before the change: 17 tables, 33 objects, one
|
|
26
|
+
* page each. Every `*:addon-settings` table — `hub-forwarder`,
|
|
27
|
+
* `metrics-native`, `platform-probe`, `storage-orchestrator`, and the shared
|
|
28
|
+
* `addon-settings` — held **0 rows**. The only non-empty tables were
|
|
29
|
+
* `system-settings` (21 rows, all boot-seeded defaults) and `storage_locations`
|
|
30
|
+
* (4 rows, every one `is_system=1 is_default=1`, re-derived from declarations
|
|
31
|
+
* at every boot). Nothing to migrate, and that is a measurement, not an
|
|
32
|
+
* assumption.
|
|
33
|
+
*
|
|
34
|
+
* ## The rollback is an env var, deliberately
|
|
35
|
+
*
|
|
36
|
+
* This path has cost three boot holes already — 1.2.149 (the skip-infra
|
|
37
|
+
* shortcut), 1.2.151 (the D44×D87 crash-loop), 1.2.152 (the `resolveConfig`
|
|
38
|
+
* hang). A change to agent boot that can only be undone by shipping a build is
|
|
39
|
+
* a change that stays broken for a release cycle.
|
|
40
|
+
*
|
|
41
|
+
* **To roll back:** set `CAMSTACK_AGENT_LOCAL_DATA_STORE=1` in the agent
|
|
42
|
+
* container's environment and restart it. That restores `INFRA_CAPABILITIES`
|
|
43
|
+
* EXACTLY — same entries, same order, same `required` flags — so the agent
|
|
44
|
+
* boots its own `sqlite-settings` again and the data door resolves that engine
|
|
45
|
+
* instead of the hub (a local engine always wins over the remote; see
|
|
46
|
+
* `data-store-dispatch.ts`). No redeploy, no revert, and the other two commits
|
|
47
|
+
* in this series stay in place: commit 1 is inert whenever a local engine
|
|
48
|
+
* exists, and commit 3 is documentation.
|
|
49
|
+
*/
|
|
50
|
+
const system_1 = require("@camstack/system");
|
|
51
|
+
/**
|
|
52
|
+
* The env var that puts the local engine back. Named for what it restores, not
|
|
53
|
+
* for what it disables, so an operator reading a container's environment can
|
|
54
|
+
* tell what it does without this file.
|
|
55
|
+
*/
|
|
56
|
+
exports.AGENT_LOCAL_DATA_STORE_ENV = 'CAMSTACK_AGENT_LOCAL_DATA_STORE';
|
|
57
|
+
/** The capability an agent no longer boots. */
|
|
58
|
+
const DATA_STORE_PROVIDER = 'data-store-provider';
|
|
59
|
+
/**
|
|
60
|
+
* Truthy spellings an operator actually types into a docker `-e`. Anything
|
|
61
|
+
* else — including the empty string a declared-but-unset variable produces —
|
|
62
|
+
* is false, because an accidentally-empty variable must not silently restore
|
|
63
|
+
* a local database.
|
|
64
|
+
*/
|
|
65
|
+
function isEnabled(raw) {
|
|
66
|
+
const value = (raw ?? '').trim().toLowerCase();
|
|
67
|
+
return value === '1' || value === 'true' || value === 'yes';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The ordered infra list Phase 1 walks on an agent.
|
|
71
|
+
*
|
|
72
|
+
* Order is load-bearing (`storage-provider` before `storage`, the door after
|
|
73
|
+
* both), so this FILTERS the canonical list rather than rebuilding it — a
|
|
74
|
+
* hand-written copy would drift the first time a capability was added to
|
|
75
|
+
* `INFRA_CAPABILITIES`, and the drift would be a missing provider at boot.
|
|
76
|
+
*
|
|
77
|
+
* `INFRA_CAPABILITIES` itself is never touched: the hub reads the same array.
|
|
78
|
+
*/
|
|
79
|
+
function resolveAgentInfraCapabilities(env) {
|
|
80
|
+
if (isEnabled(env[exports.AGENT_LOCAL_DATA_STORE_ENV]))
|
|
81
|
+
return system_1.INFRA_CAPABILITIES;
|
|
82
|
+
return system_1.INFRA_CAPABILITIES.filter((cap) => cap.name !== DATA_STORE_PROVIDER);
|
|
83
|
+
}
|
|
@@ -158,8 +158,14 @@ class AgentUpdateService extends index_js_1.RootUpdateService {
|
|
|
158
158
|
constructor(options) {
|
|
159
159
|
const restartAgent = options.restartAgent ??
|
|
160
160
|
((requestedBy) => scheduleAgentRestart(options.logger, requestedBy, options.dataDir));
|
|
161
|
+
// Resolved before `super` so the base class stamps `tags.nodeId` on every
|
|
162
|
+
// line. `bindAvailability` can re-point `this.nodeId` later once the hub
|
|
163
|
+
// handshake settles the id; the log tag keeps the boot-time value, which is
|
|
164
|
+
// the same string in every deployment that sets `CAMSTACK_NODE_ID`.
|
|
165
|
+
const nodeId = options.nodeId ?? process.env['CAMSTACK_NODE_ID'] ?? 'agent';
|
|
161
166
|
super({
|
|
162
167
|
spec: index_js_1.HUB_ROOT_SPEC,
|
|
168
|
+
nodeId,
|
|
163
169
|
// The agent's on-disk root IS `@camstack/server` (booted via
|
|
164
170
|
// CAMSTACK_ROLE=agent by the shared starter), so it reads the SAME
|
|
165
171
|
// `CAMSTACK_SERVER_*` boot markers the starter writes.
|
|
@@ -191,7 +197,7 @@ class AgentUpdateService extends index_js_1.RootUpdateService {
|
|
|
191
197
|
env: options.env,
|
|
192
198
|
now: options.now,
|
|
193
199
|
});
|
|
194
|
-
this.nodeId =
|
|
200
|
+
this.nodeId = nodeId;
|
|
195
201
|
this.agentDataDir = options.dataDir;
|
|
196
202
|
this.agentLogger = options.logger;
|
|
197
203
|
this.eventBus = options.eventBus ?? null;
|
package/dist/agent/main.js
CHANGED
|
@@ -43,11 +43,12 @@ const server_management_provider_js_1 = require("../api/core/server-management.p
|
|
|
43
43
|
const package_dir_utils_js_1 = require("../core/addon/package-dir-utils.js");
|
|
44
44
|
const single_copy_cleanup_runner_js_1 = require("../single-copy-cleanup-runner.js");
|
|
45
45
|
const addon_scan_js_1 = require("./addon-scan.js");
|
|
46
|
+
const agent_addon_updates_js_1 = require("./agent-addon-updates.js");
|
|
46
47
|
const agent_config_js_1 = require("./agent-config.js");
|
|
47
48
|
const agent_group_runner_js_1 = require("./agent-group-runner.js");
|
|
48
49
|
const agent_http_js_1 = require("./agent-http.js");
|
|
50
|
+
const agent_infra_capabilities_js_1 = require("./agent-infra-capabilities.js");
|
|
49
51
|
const agent_service_js_1 = require("./agent-service.js");
|
|
50
|
-
const agent_addon_updates_js_1 = require("./agent-addon-updates.js");
|
|
51
52
|
const agent_update_routes_js_1 = require("./agent-update-routes.js");
|
|
52
53
|
const agent_update_service_js_1 = require("./agent-update-service.js");
|
|
53
54
|
const derive_hub_url_js_1 = require("./derive-hub-url.js");
|
|
@@ -823,8 +824,13 @@ async function startAgent(configPath) {
|
|
|
823
824
|
// ---------------------------------------------------------------------------
|
|
824
825
|
// Phase 1: Boot core addons (storage, settings, metrics — NO winston)
|
|
825
826
|
// ---------------------------------------------------------------------------
|
|
826
|
-
// Core infra addons to load on agent —
|
|
827
|
-
|
|
827
|
+
// Core infra addons to load on agent — every infra capability the hub boots
|
|
828
|
+
// EXCEPT `data-store-provider`. An agent has no store of its own: its data door
|
|
829
|
+
// forwards to the hub (`hub-settings-forward.ts`), so booting `sqlite-settings`
|
|
830
|
+
// here would only open a database nothing reads. See
|
|
831
|
+
// `agent-infra-capabilities.ts` for the measurement behind that and for the
|
|
832
|
+
// one-env-var rollback (`CAMSTACK_AGENT_LOCAL_DATA_STORE=1`).
|
|
833
|
+
const AGENT_INFRA = (0, agent_infra_capabilities_js_1.resolveAgentInfraCapabilities)(process.env);
|
|
828
834
|
async function bootCoreAddons(broker, config, registry, loadedAddons, loggerFactory) {
|
|
829
835
|
// Builtins come from the CLOSURE this process is running, exactly as the hub
|
|
830
836
|
// has done since 2026-07-18 — never from a `<addonsDir>/@camstack/system`
|
|
@@ -16,6 +16,28 @@ exports.createClusterNodesRouter = createClusterNodesRouter;
|
|
|
16
16
|
const zod_1 = require("zod");
|
|
17
17
|
const trpc_middleware_js_1 = require("../trpc/trpc.middleware.js");
|
|
18
18
|
const ForgetNodeInputSchema = zod_1.z.object({ nodeId: zod_1.z.string().min(1) });
|
|
19
|
+
/**
|
|
20
|
+
* What forgetting a node ACTUALLY removed.
|
|
21
|
+
*
|
|
22
|
+
* This used to be `{ success: boolean }`, returned as a hardcoded `true` that
|
|
23
|
+
* never looked at `forgetClusterNode` (which returned `void`). On 2026-09-01
|
|
24
|
+
* the operator forgot `hub-test` repeatedly, got `{"success": true}` every
|
|
25
|
+
* time, and watched it stay on the Cluster page — because only one of the two
|
|
26
|
+
* sources of its topology row was being purged. An action that changed nothing
|
|
27
|
+
* must not answer `success`.
|
|
28
|
+
*/
|
|
29
|
+
const ForgetNodeResultSchema = zod_1.z.object({
|
|
30
|
+
/** At least one source of the node's topology row was purged. */
|
|
31
|
+
forgotten: zod_1.z.boolean(),
|
|
32
|
+
/** The durable history row existed and is gone. */
|
|
33
|
+
historyRemoved: zod_1.z.boolean(),
|
|
34
|
+
/** The Moleculer node-catalog entry existed and is gone. */
|
|
35
|
+
registryRemoved: zod_1.z.boolean(),
|
|
36
|
+
/** Read back AFTER the attempt: the node is still in the cluster registry. */
|
|
37
|
+
stillListed: zod_1.z.boolean(),
|
|
38
|
+
/** One operator-grade sentence naming what happened. */
|
|
39
|
+
message: zod_1.z.string(),
|
|
40
|
+
});
|
|
19
41
|
const RepairNodeAddonsInputSchema = zod_1.z.object({ nodeId: zod_1.z.string().min(1) });
|
|
20
42
|
function createClusterNodesRouter(agentRegistry) {
|
|
21
43
|
return (0, trpc_middleware_js_1.trpcRouter)({
|
|
@@ -45,10 +67,9 @@ function createClusterNodesRouter(agentRegistry) {
|
|
|
45
67
|
// forget an offline node (history row + per-node pipeline assignments).
|
|
46
68
|
forgetNode: trpc_middleware_js_1.adminProcedure
|
|
47
69
|
.input(ForgetNodeInputSchema)
|
|
48
|
-
.output(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}),
|
|
70
|
+
.output(ForgetNodeResultSchema)
|
|
71
|
+
// The service's own result IS the answer — this procedure adds nothing
|
|
72
|
+
// and, above all, asserts nothing.
|
|
73
|
+
.mutation(({ input }) => agentRegistry.forgetClusterNode(input.nodeId)),
|
|
53
74
|
});
|
|
54
75
|
}
|
|
@@ -5950,6 +5950,15 @@ function createCapRouter_pipelineAnalytics(getProvider, createRemoteProxy) {
|
|
|
5950
5950
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
5951
5951
|
return p.getEventDensity(methodInput);
|
|
5952
5952
|
}),
|
|
5953
|
+
getEventDensityBatch: trpc_middleware_js_1.protectedProcedure
|
|
5954
|
+
.input(types_85.pipelineAnalyticsCapability.methods.getEventDensityBatch.input.loose())
|
|
5955
|
+
.output(types_85.pipelineAnalyticsCapability.methods.getEventDensityBatch.output)
|
|
5956
|
+
.query(async ({ input, ctx }) => {
|
|
5957
|
+
const { nodeId, ...methodInput } = input;
|
|
5958
|
+
const p = resolveProvider('pipeline-analytics', nodeId, () => getProvider(ctx), createRemoteProxy);
|
|
5959
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
5960
|
+
return p.getEventDensityBatch(methodInput);
|
|
5961
|
+
}),
|
|
5953
5962
|
pruneEventsBefore: trpc_middleware_js_1.adminProcedure
|
|
5954
5963
|
.input(types_85.pipelineAnalyticsCapability.methods.pruneEventsBefore.input.loose())
|
|
5955
5964
|
.output(types_85.pipelineAnalyticsCapability.methods.pruneEventsBefore.output)
|
|
@@ -7651,6 +7660,15 @@ function createCapRouter_recording(getProvider, createRemoteProxy) {
|
|
|
7651
7660
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
7652
7661
|
return p.getAvailability(methodInput);
|
|
7653
7662
|
}),
|
|
7663
|
+
getAvailabilityBatch: trpc_middleware_js_1.protectedProcedure
|
|
7664
|
+
.input(types_95.recordingCapability.methods.getAvailabilityBatch.input.loose())
|
|
7665
|
+
.output(types_95.recordingCapability.methods.getAvailabilityBatch.output)
|
|
7666
|
+
.query(async ({ input, ctx }) => {
|
|
7667
|
+
const { nodeId, ...methodInput } = input;
|
|
7668
|
+
const p = resolveProvider('recording', nodeId, () => getProvider(ctx), createRemoteProxy);
|
|
7669
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
7670
|
+
return p.getAvailabilityBatch(methodInput);
|
|
7671
|
+
}),
|
|
7654
7672
|
getDaysWithRecordings: trpc_middleware_js_1.protectedProcedure
|
|
7655
7673
|
.input(types_95.recordingCapability.methods.getDaysWithRecordings.input.loose())
|
|
7656
7674
|
.output(types_95.recordingCapability.methods.getDaysWithRecordings.output)
|
|
@@ -7660,6 +7678,15 @@ function createCapRouter_recording(getProvider, createRemoteProxy) {
|
|
|
7660
7678
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
7661
7679
|
return p.getDaysWithRecordings(methodInput);
|
|
7662
7680
|
}),
|
|
7681
|
+
getDaysWithRecordingsBatch: trpc_middleware_js_1.protectedProcedure
|
|
7682
|
+
.input(types_95.recordingCapability.methods.getDaysWithRecordingsBatch.input.loose())
|
|
7683
|
+
.output(types_95.recordingCapability.methods.getDaysWithRecordingsBatch.output)
|
|
7684
|
+
.query(async ({ input, ctx }) => {
|
|
7685
|
+
const { nodeId, ...methodInput } = input;
|
|
7686
|
+
const p = resolveProvider('recording', nodeId, () => getProvider(ctx), createRemoteProxy);
|
|
7687
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
7688
|
+
return p.getDaysWithRecordingsBatch(methodInput);
|
|
7689
|
+
}),
|
|
7663
7690
|
getPlaybackManifest: trpc_middleware_js_1.protectedProcedure
|
|
7664
7691
|
.input(types_95.recordingCapability.methods.getPlaybackManifest.input.loose())
|
|
7665
7692
|
.output(types_95.recordingCapability.methods.getPlaybackManifest.output)
|
|
@@ -42,6 +42,23 @@ const system_1 = require("@camstack/system");
|
|
|
42
42
|
const types_1 = require("@camstack/types");
|
|
43
43
|
const agent_addon_backfill_1 = require("./agent-addon-backfill");
|
|
44
44
|
const agent_delivery_ledger_1 = require("./agent-delivery-ledger");
|
|
45
|
+
/** Turn a forget outcome into the sentence the operator reads. */
|
|
46
|
+
function describeForgetOutcome(nodeId, history, registryRemoved, stillListed) {
|
|
47
|
+
const parts = [];
|
|
48
|
+
if (history === 'removed')
|
|
49
|
+
parts.push('history row removed');
|
|
50
|
+
else if (history === 'not-found')
|
|
51
|
+
parts.push('no history row to remove');
|
|
52
|
+
else if (history === 'store-unavailable')
|
|
53
|
+
parts.push('history store unavailable — row fate unknown');
|
|
54
|
+
else
|
|
55
|
+
parts.push('history removal failed');
|
|
56
|
+
parts.push(registryRemoved ? 'cluster registry entry removed' : 'no cluster registry entry');
|
|
57
|
+
if (stillListed) {
|
|
58
|
+
return `${nodeId}: ${parts.join('; ')} — but the node is STILL in the cluster registry and will keep appearing.`;
|
|
59
|
+
}
|
|
60
|
+
return `${nodeId}: ${parts.join('; ')}.`;
|
|
61
|
+
}
|
|
45
62
|
/** Per-call timeout for `$agent.*` RPC during reconciliation. */
|
|
46
63
|
const AGENT_RECONCILE_RPC_TIMEOUT_MS = 8_000;
|
|
47
64
|
/**
|
|
@@ -177,6 +194,13 @@ class AgentRegistryService {
|
|
|
177
194
|
* fakes) stay untouched; a null store means "history disabled" (best-effort).
|
|
178
195
|
*/
|
|
179
196
|
historyStore = null;
|
|
197
|
+
/**
|
|
198
|
+
* Scoped logger, wired post-construction from `manual-boot` for the same
|
|
199
|
+
* reason as the seams above (the logging service is built earlier but the
|
|
200
|
+
* 3-arg constructor and its unit fakes stay untouched). `null` in fakes —
|
|
201
|
+
* every use is optional-chained, so a fake never has to grow a logger.
|
|
202
|
+
*/
|
|
203
|
+
logger = null;
|
|
180
204
|
/**
|
|
181
205
|
* Side-effecting half of the addon back-fill (pack → `$agent.deploy` →
|
|
182
206
|
* `$agent.reload`). Wired post-construction from `manual-boot` because it
|
|
@@ -217,6 +241,10 @@ class AgentRegistryService {
|
|
|
217
241
|
setClusterNodeHistoryStore(store) {
|
|
218
242
|
this.historyStore = store;
|
|
219
243
|
}
|
|
244
|
+
/** Wire the scoped logger (boot order — see the field). */
|
|
245
|
+
setLogger(logger) {
|
|
246
|
+
this.logger = logger;
|
|
247
|
+
}
|
|
220
248
|
/** Wire (or clear) the addon back-fill delivery seam. */
|
|
221
249
|
setAddonBackfill(seam) {
|
|
222
250
|
this.addonBackfill = seam;
|
|
@@ -265,13 +293,103 @@ class AgentRegistryService {
|
|
|
265
293
|
async getClusterNodeHistory() {
|
|
266
294
|
return this.historyStore ? this.historyStore.getAll() : [];
|
|
267
295
|
}
|
|
268
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Permanently forget a node (inline "Forget node") — and report what that
|
|
298
|
+
* actually removed.
|
|
299
|
+
*
|
|
300
|
+
* A topology row for an absent node has TWO sources, and forgetting one of
|
|
301
|
+
* them changes nothing the operator can see:
|
|
302
|
+
*
|
|
303
|
+
* 1. the durable history row (this store), projected by `computeTopology`
|
|
304
|
+
* for nodes no longer in the live Moleculer window, and
|
|
305
|
+
* 2. Moleculer's OWN node catalog, which `listNodes()` reads with
|
|
306
|
+
* `onlyAvailable: false` and renders through `buildOfflineEntry`.
|
|
307
|
+
*
|
|
308
|
+
* Until 2026-09-01 only (1) was purged, and the answer was an unconditional
|
|
309
|
+
* `{success: true}`. `hub-test` had its history row deleted repeatedly and
|
|
310
|
+
* stayed on the Cluster page every time, because (2) still held it —
|
|
311
|
+
* Moleculer purges an offline node on its own 10-minute sweep only while
|
|
312
|
+
* nothing re-announces it, and the operator has no reason to wait for a
|
|
313
|
+
* timer they cannot see.
|
|
314
|
+
*
|
|
315
|
+
* An ONLINE node is REFUSED: dropping a live node from the routing catalog
|
|
316
|
+
* would break every cap call pinned to it, and it re-registers on the next
|
|
317
|
+
* heartbeat anyway — "forget" of a live node is not a slow success, it is
|
|
318
|
+
* not a thing.
|
|
319
|
+
*/
|
|
269
320
|
async forgetClusterNode(nodeId) {
|
|
270
|
-
|
|
321
|
+
if (this.isNodeOnline(nodeId)) {
|
|
322
|
+
const message = `Refused: ${nodeId} is ONLINE. Take the node down first — a live node re-registers immediately.`;
|
|
323
|
+
this.logger?.warn('forget cluster node refused', {
|
|
324
|
+
tags: { nodeId },
|
|
325
|
+
meta: { reason: 'node-online' },
|
|
326
|
+
});
|
|
327
|
+
return {
|
|
328
|
+
forgotten: false,
|
|
329
|
+
historyRemoved: false,
|
|
330
|
+
registryRemoved: false,
|
|
331
|
+
stillListed: true,
|
|
332
|
+
message,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const historyOutcome = this.historyStore
|
|
336
|
+
? await this.historyStore.forget(nodeId)
|
|
337
|
+
: 'store-unavailable';
|
|
338
|
+
const registryRemoved = this.removeFromNodeCatalog(nodeId);
|
|
271
339
|
// Its intended set is gone with the row, so the back-fill breaker's memory
|
|
272
340
|
// of failed deliveries to it is meaningless — drop it too.
|
|
273
341
|
this.backfillTracker.forget(nodeId);
|
|
274
342
|
this.deliveryLedger.forget(nodeId);
|
|
343
|
+
const historyRemoved = historyOutcome === 'removed';
|
|
344
|
+
const stillListed = this.isNodeKnown(nodeId);
|
|
345
|
+
const message = describeForgetOutcome(nodeId, historyOutcome, registryRemoved, stillListed);
|
|
346
|
+
this.logger?.info('forget cluster node', {
|
|
347
|
+
tags: { nodeId },
|
|
348
|
+
meta: { historyOutcome, historyRemoved, registryRemoved, stillListed },
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
forgotten: historyRemoved || registryRemoved,
|
|
352
|
+
historyRemoved,
|
|
353
|
+
registryRemoved,
|
|
354
|
+
stillListed,
|
|
355
|
+
message,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/** Is the node currently AVAILABLE in Moleculer's catalog? */
|
|
359
|
+
isNodeOnline(nodeId) {
|
|
360
|
+
return this.catalogNodeIds({ onlyAvailable: true }).includes(nodeId);
|
|
361
|
+
}
|
|
362
|
+
/** Is the node in Moleculer's catalog at all (available or not)? */
|
|
363
|
+
isNodeKnown(nodeId) {
|
|
364
|
+
return this.catalogNodeIds({ onlyAvailable: false }).includes(nodeId);
|
|
365
|
+
}
|
|
366
|
+
catalogNodeIds(opts) {
|
|
367
|
+
const registry = this.nodeCatalogRegistry();
|
|
368
|
+
return (registry?.getNodeList?.(opts) ?? []).map((n) => n.id);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Drop a node from Moleculer's own catalog — the SAME call Moleculer's
|
|
372
|
+
* discoverer makes in `checkOfflineNodes` once an offline node ages out. It
|
|
373
|
+
* is safe here for exactly the same reason it is safe there: the node is not
|
|
374
|
+
* available, so nothing is routing to it, and a node that comes back
|
|
375
|
+
* re-announces itself and is re-added.
|
|
376
|
+
*/
|
|
377
|
+
removeFromNodeCatalog(nodeId) {
|
|
378
|
+
if (!this.isNodeKnown(nodeId))
|
|
379
|
+
return false;
|
|
380
|
+
const registry = this.nodeCatalogRegistry();
|
|
381
|
+
const nodes = registry?.nodes;
|
|
382
|
+
if (nodes?.delete === undefined) {
|
|
383
|
+
this.logger?.warn('cluster node catalog does not expose delete — row may persist', {
|
|
384
|
+
tags: { nodeId },
|
|
385
|
+
});
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
return nodes.delete(nodeId) === true;
|
|
389
|
+
}
|
|
390
|
+
/** Typed view of the broker's node catalog — one documented boundary cast. */
|
|
391
|
+
nodeCatalogRegistry() {
|
|
392
|
+
return this.moleculer.broker.registry;
|
|
275
393
|
}
|
|
276
394
|
/** Typed view of the Moleculer broker — single documented cast. */
|
|
277
395
|
get broker() {
|
|
@@ -344,20 +344,37 @@ class ClusterNodeHistoryStore {
|
|
|
344
344
|
return [];
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
/**
|
|
347
|
+
/**
|
|
348
|
+
* Permanently forget a node's history row (the inline "Forget node" action).
|
|
349
|
+
*
|
|
350
|
+
* Returns WHAT HAPPENED, not void. The caller's answer to the operator is
|
|
351
|
+
* only as honest as this: an unreachable store, a row that was never there,
|
|
352
|
+
* and a row actually deleted are three different facts, and before
|
|
353
|
+
* 2026-09-01 all three reached the UI as `{"success": true}`.
|
|
354
|
+
*/
|
|
348
355
|
async forget(nodeId) {
|
|
349
356
|
const store = await this.ensureDeclared();
|
|
350
357
|
if (!store)
|
|
351
|
-
return;
|
|
358
|
+
return 'store-unavailable';
|
|
352
359
|
try {
|
|
360
|
+
// Read first: `delete` on this provider is idempotent and cannot tell a
|
|
361
|
+
// removal from a no-op, and "there was nothing to remove" is the answer
|
|
362
|
+
// that stops an operator repeating a working action forever.
|
|
363
|
+
const existed = (await this.readRow(store, nodeId)) !== null;
|
|
353
364
|
await store.delete({ collection: COLLECTION, key: nodeId });
|
|
365
|
+
if (!existed) {
|
|
366
|
+
this.logger.info('cluster node had no history row to forget', { tags: { nodeId } });
|
|
367
|
+
return 'not-found';
|
|
368
|
+
}
|
|
354
369
|
this.logger.info('forgot cluster node', { tags: { nodeId } });
|
|
370
|
+
return 'removed';
|
|
355
371
|
}
|
|
356
372
|
catch (err) {
|
|
357
373
|
this.logger.warn('forget failed (best-effort)', {
|
|
358
374
|
tags: { nodeId },
|
|
359
375
|
meta: { error: (0, types_1.errMsg)(err) },
|
|
360
376
|
});
|
|
377
|
+
return 'failed';
|
|
361
378
|
}
|
|
362
379
|
}
|
|
363
380
|
}
|
|
@@ -64,8 +64,13 @@ class ServerUpdateService extends index_js_1.RootUpdateService {
|
|
|
64
64
|
options.env?.['CAMSTACK_DATA'] ??
|
|
65
65
|
process.env['CAMSTACK_DATA'] ??
|
|
66
66
|
'camstack-data');
|
|
67
|
+
// Resolved before `super` so the base class can stamp `tags.nodeId` on
|
|
68
|
+
// every line it emits — `this.nodeId` below is the same value, kept for
|
|
69
|
+
// the availability emitter.
|
|
70
|
+
const nodeId = options.nodeId ?? 'hub';
|
|
67
71
|
super({
|
|
68
72
|
spec: index_js_1.HUB_ROOT_SPEC,
|
|
73
|
+
nodeId,
|
|
69
74
|
envNames: {
|
|
70
75
|
bootMode: 'CAMSTACK_SERVER_BOOT_MODE',
|
|
71
76
|
activeVersion: 'CAMSTACK_SERVER_ACTIVE_VERSION',
|
|
@@ -97,7 +102,7 @@ class ServerUpdateService extends index_js_1.RootUpdateService {
|
|
|
97
102
|
options.eventBus !== undefined
|
|
98
103
|
? new update_availability_emitter_js_1.UpdateAvailabilityEmitter(options.eventBus, { type: 'core', id: 'server-update-service' }, options.updateAvailabilityStore)
|
|
99
104
|
: null;
|
|
100
|
-
this.nodeId =
|
|
105
|
+
this.nodeId = nodeId;
|
|
101
106
|
}
|
|
102
107
|
async checkServerUpdate() {
|
|
103
108
|
const result = await super.checkServerUpdate();
|
|
@@ -44,7 +44,7 @@ exports.FileUpdateAvailabilityStore = exports.UPDATE_AVAILABILITY_DIR = void 0;
|
|
|
44
44
|
*
|
|
45
45
|
* The mechanism is deliberately the one the neighbouring update code already
|
|
46
46
|
* uses: a small JSON file under the node's data dir, next to
|
|
47
|
-
* `auto-update.json
|
|
47
|
+
* `auto-update.json` and `.restart-pending`. No new
|
|
48
48
|
* database, no settings-store dependency (the emitter runs on the AGENT too,
|
|
49
49
|
* where the hub's SQLite settings store does not exist).
|
|
50
50
|
*/
|
package/dist/main.js
CHANGED
|
@@ -418,7 +418,6 @@ async function bootstrap() {
|
|
|
418
418
|
addonRegistry.setDataPlaneRegistry(dataPlaneRegistry);
|
|
419
419
|
// ── Configure the CapabilityRegistry (created in AddonRegistryService constructor) ──
|
|
420
420
|
const capabilityRegistry = addonRegistry.getCapabilityRegistry();
|
|
421
|
-
capabilityRegistry.setConfigManager(config);
|
|
422
421
|
// Declare every shipped capability BEFORE app.init() so addon
|
|
423
422
|
// registerProvider() calls (in-process or via the Moleculer bridge
|
|
424
423
|
// from forked workers / agents) find their definition during
|
package/dist/manual-boot.js
CHANGED
|
@@ -151,6 +151,9 @@ async function bootManual(opts) {
|
|
|
151
151
|
// reconciliation, but is constructed first (it has no other dependency
|
|
152
152
|
// on AddonRegistryService) — wire it post-construction.
|
|
153
153
|
agentRegistryService.setAddonRegistry(addonRegistryService);
|
|
154
|
+
// Same post-construction reason: the cluster-node lifecycle (forget, catalog
|
|
155
|
+
// removal) must leave a per-node line, and `console.log` is not a log store.
|
|
156
|
+
agentRegistryService.setLogger(loggingService.createLogger('ClusterNodes'));
|
|
154
157
|
// A1: durable, routing-blind offline-node history — persisted through the
|
|
155
158
|
// hub-resident `settings-store` cap (resolved lazily; null until it boots).
|
|
156
159
|
// Wired post-construction so the service's 3-arg constructor stays intact.
|
|
@@ -949,6 +949,8 @@ var require_dist = __commonJS({
|
|
|
949
949
|
spec;
|
|
950
950
|
envNames;
|
|
951
951
|
logger;
|
|
952
|
+
/** Frozen `tags` object stamped on every line — see {@link RootUpdateLogContext}. */
|
|
953
|
+
logTags;
|
|
952
954
|
restartServerFn;
|
|
953
955
|
dataDir;
|
|
954
956
|
execNpm;
|
|
@@ -963,6 +965,9 @@ var require_dist = __commonJS({
|
|
|
963
965
|
this.spec = options.spec;
|
|
964
966
|
this.envNames = options.envNames;
|
|
965
967
|
this.logger = options.logger;
|
|
968
|
+
this.logTags = {
|
|
969
|
+
nodeId: options.nodeId ?? "unknown"
|
|
970
|
+
};
|
|
966
971
|
this.restartServerFn = options.restartServer;
|
|
967
972
|
this.dataDir = path6.resolve(options.dataDir);
|
|
968
973
|
this.execNpm = options.execNpm ?? (async (args, opts) => {
|
|
@@ -1123,64 +1128,67 @@ var require_dist = __commonJS({
|
|
|
1123
1128
|
}
|
|
1124
1129
|
}
|
|
1125
1130
|
// ── Apply ─────────────────────────────────────────────────────────────
|
|
1131
|
+
/**
|
|
1132
|
+
* Every `accepted:false` return from the update engine goes through here.
|
|
1133
|
+
*
|
|
1134
|
+
* A refusal DROPS the operator's request: nothing is staged, nothing
|
|
1135
|
+
* restarts. Before 2026-09-01 it also said nothing — six branches returned
|
|
1136
|
+
* `{accepted:false}` in silence, so "the hub refused" and "the hub was never
|
|
1137
|
+
* called" produced identical evidence (none), and the operator lost an
|
|
1138
|
+
* evening to the difference. The reason is now named, per-node greppable and
|
|
1139
|
+
* on the record before the caller sees the result.
|
|
1140
|
+
*/
|
|
1141
|
+
refuseUpdate(reason, targetVersion, message) {
|
|
1142
|
+
this.logger.warn("root package update refused", {
|
|
1143
|
+
tags: this.logTags,
|
|
1144
|
+
meta: {
|
|
1145
|
+
reason,
|
|
1146
|
+
targetVersion,
|
|
1147
|
+
message
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
return {
|
|
1151
|
+
accepted: false,
|
|
1152
|
+
targetVersion,
|
|
1153
|
+
restarting: false,
|
|
1154
|
+
message
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1126
1157
|
async applyServerUpdate(input) {
|
|
1158
|
+
this.logger.info("root package update requested", {
|
|
1159
|
+
tags: this.logTags,
|
|
1160
|
+
meta: {
|
|
1161
|
+
requestedVersion: input.version ?? null,
|
|
1162
|
+
packageName: this.spec.packageName
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1127
1165
|
const bootMode = this.resolveBootMode();
|
|
1128
1166
|
if (bootMode === "workspace") {
|
|
1129
|
-
return
|
|
1130
|
-
accepted: false,
|
|
1131
|
-
targetVersion: input.version ?? null,
|
|
1132
|
-
restarting: false,
|
|
1133
|
-
message: "Refused: running from a workspace checkout \u2014 the dev loop resolves code from the workspace, a data-root update would never be loaded."
|
|
1134
|
-
};
|
|
1167
|
+
return this.refuseUpdate("workspace-boot-mode", input.version ?? null, "Refused: running from a workspace checkout \u2014 the dev loop resolves code from the workspace, a data-root update would never be loaded.");
|
|
1135
1168
|
}
|
|
1136
1169
|
if (this.inFlight !== "idle") {
|
|
1137
|
-
return {
|
|
1138
|
-
accepted: false,
|
|
1139
|
-
targetVersion: input.version ?? null,
|
|
1140
|
-
restarting: false,
|
|
1141
|
-
message: `Refused: another operation is in flight (${this.inFlight}).`
|
|
1142
|
-
};
|
|
1170
|
+
return this.refuseUpdate("operation-in-flight", input.version ?? null, `Refused: another operation is in flight (${this.inFlight}).`);
|
|
1143
1171
|
}
|
|
1144
1172
|
const pendingBefore = readPendingRootSwap(this.rootDir());
|
|
1145
1173
|
if (pendingBefore !== null) {
|
|
1146
|
-
return {
|
|
1147
|
-
accepted: false,
|
|
1148
|
-
targetVersion: input.version ?? null,
|
|
1149
|
-
restarting: false,
|
|
1150
|
-
message: `Refused: version ${pendingBefore.version} is already staged and awaiting restart.`
|
|
1151
|
-
};
|
|
1174
|
+
return this.refuseUpdate("already-staged", input.version ?? null, `Refused: version ${pendingBefore.version} is already staged and awaiting restart.`);
|
|
1152
1175
|
}
|
|
1153
1176
|
let target = input.version ?? null;
|
|
1154
1177
|
if (target === null) {
|
|
1155
1178
|
const check = await this.checkServerUpdate();
|
|
1156
1179
|
if (check.error !== null || check.latestVersion === null) {
|
|
1157
|
-
return {
|
|
1158
|
-
accepted: false,
|
|
1159
|
-
targetVersion: null,
|
|
1160
|
-
restarting: false,
|
|
1161
|
-
message: `Refused: could not resolve the latest version (${check.error ?? "no version returned"}).`
|
|
1162
|
-
};
|
|
1180
|
+
return this.refuseUpdate("latest-unresolved", null, `Refused: could not resolve the latest version (${check.error ?? "no version returned"}).`);
|
|
1163
1181
|
}
|
|
1164
1182
|
target = check.latestVersion;
|
|
1165
1183
|
}
|
|
1166
1184
|
const runningVersion = this.runningVersion();
|
|
1167
1185
|
if (target === runningVersion) {
|
|
1168
|
-
return {
|
|
1169
|
-
accepted: false,
|
|
1170
|
-
targetVersion: target,
|
|
1171
|
-
restarting: false,
|
|
1172
|
-
message: `Refused: ${this.spec.packageName}@${target} is already running.`
|
|
1173
|
-
};
|
|
1186
|
+
return this.refuseUpdate("already-running", target, `Refused: ${this.spec.packageName}@${target} is already running.`);
|
|
1174
1187
|
}
|
|
1175
1188
|
if (isDevChannelVersion(target)) {
|
|
1176
1189
|
const uploadsDir = devUploadVersionDir(this.rootDir(), target);
|
|
1177
1190
|
if (!fs6.existsSync(uploadsDir)) {
|
|
1178
|
-
return {
|
|
1179
|
-
accepted: false,
|
|
1180
|
-
targetVersion: target,
|
|
1181
|
-
restarting: false,
|
|
1182
|
-
message: `Refused: dev-channel version ${target} has no uploaded tarballs on this node (${uploadsDir} is missing). Dev server deploys are hub-only in this phase \u2014 upload via \`camstack deploy-server\` against this node first.`
|
|
1183
|
-
};
|
|
1191
|
+
return this.refuseUpdate("dev-uploads-missing", target, `Refused: dev-channel version ${target} has no uploaded tarballs on this node (${uploadsDir} is missing). Dev server deploys are hub-only in this phase \u2014 upload via \`camstack deploy-server\` against this node first.`);
|
|
1184
1192
|
}
|
|
1185
1193
|
}
|
|
1186
1194
|
this.inFlight = "staging";
|
|
@@ -1190,6 +1198,7 @@ var require_dist = __commonJS({
|
|
|
1190
1198
|
} catch (err) {
|
|
1191
1199
|
const message = err instanceof Error ? err.message : String(err);
|
|
1192
1200
|
this.logger.error("root package update staging failed", {
|
|
1201
|
+
tags: this.logTags,
|
|
1193
1202
|
meta: {
|
|
1194
1203
|
targetVersion: target,
|
|
1195
1204
|
error: message
|
|
@@ -1211,6 +1220,7 @@ var require_dist = __commonJS({
|
|
|
1211
1220
|
requestedAtMs: this.now()
|
|
1212
1221
|
});
|
|
1213
1222
|
this.logger.info("root package update staged \u2014 restarting to apply", {
|
|
1223
|
+
tags: this.logTags,
|
|
1214
1224
|
meta: {
|
|
1215
1225
|
targetVersion: target,
|
|
1216
1226
|
fromVersion: runningVersion
|
|
@@ -1375,25 +1385,33 @@ var require_dist = __commonJS({
|
|
|
1375
1385
|
* OLD version and orphan the pending swap — the operator should apply
|
|
1376
1386
|
* instead).
|
|
1377
1387
|
*/
|
|
1388
|
+
/** {@link refuseUpdate}'s twin for the plain-restart path. */
|
|
1389
|
+
refuseRestart(reason, targetVersion, message) {
|
|
1390
|
+
this.logger.warn("plain node restart refused", {
|
|
1391
|
+
tags: this.logTags,
|
|
1392
|
+
meta: {
|
|
1393
|
+
reason,
|
|
1394
|
+
targetVersion,
|
|
1395
|
+
message
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
return {
|
|
1399
|
+
accepted: false,
|
|
1400
|
+
targetVersion,
|
|
1401
|
+
restarting: false,
|
|
1402
|
+
message
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1378
1405
|
restartNode() {
|
|
1379
1406
|
const runningVersion = this.runningVersion();
|
|
1380
1407
|
if (this.inFlight !== "idle") {
|
|
1381
|
-
return {
|
|
1382
|
-
accepted: false,
|
|
1383
|
-
targetVersion: runningVersion,
|
|
1384
|
-
restarting: false,
|
|
1385
|
-
message: `Refused: another operation is in flight (${this.inFlight}).`
|
|
1386
|
-
};
|
|
1408
|
+
return this.refuseRestart("operation-in-flight", runningVersion, `Refused: another operation is in flight (${this.inFlight}).`);
|
|
1387
1409
|
}
|
|
1388
1410
|
if (readPendingRootSwap(this.rootDir()) !== null) {
|
|
1389
|
-
return
|
|
1390
|
-
accepted: false,
|
|
1391
|
-
targetVersion: runningVersion,
|
|
1392
|
-
restarting: false,
|
|
1393
|
-
message: "Refused: a version is staged and awaiting restart \u2014 apply it instead of a plain restart."
|
|
1394
|
-
};
|
|
1411
|
+
return this.refuseRestart("already-staged", runningVersion, "Refused: a version is staged and awaiting restart \u2014 apply it instead of a plain restart.");
|
|
1395
1412
|
}
|
|
1396
1413
|
this.logger.info("plain node restart requested", {
|
|
1414
|
+
tags: this.logTags,
|
|
1397
1415
|
meta: {
|
|
1398
1416
|
runningVersion
|
|
1399
1417
|
}
|