@camstack/server 1.2.154 → 1.2.155
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,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MoleculerService = void 0;
|
|
3
|
+
exports.ChildManifestGate = exports.CHILD_MANIFEST_SKIP_SAMPLE = exports.MoleculerService = void 0;
|
|
4
4
|
exports.childOwnerToken = childOwnerToken;
|
|
5
5
|
exports.buildChildUdsManifest = buildChildUdsManifest;
|
|
6
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
const system_1 = require("@camstack/system");
|
|
8
8
|
const types_1 = require("@camstack/types");
|
|
9
|
-
const agent_readiness_pull_js_1 = require("./agent-readiness-pull.js");
|
|
10
9
|
const cap_router_runtime_js_1 = require("../../api/trpc/cap-router-runtime.js");
|
|
11
10
|
const core_cap_bridge_js_1 = require("../../api/trpc/core-cap-bridge.js");
|
|
11
|
+
const agent_readiness_pull_js_1 = require("./agent-readiness-pull.js");
|
|
12
12
|
const cap_call_fn_js_1 = require("./cap-call-fn.js");
|
|
13
13
|
const cap_route_authority_js_1 = require("./cap-route-authority.js");
|
|
14
14
|
class MoleculerService {
|
|
@@ -43,6 +43,12 @@ class MoleculerService {
|
|
|
43
43
|
* See `docs/decisions/adr-0188-an-unregister-carries-proof-of-ownership.md`.
|
|
44
44
|
*/
|
|
45
45
|
nodeOwners = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Skips the manifest rebuild for a child re-register that carries nothing new
|
|
48
|
+
* — 246 of them in 30 minutes with zero respawns, measured live 2026-08-25.
|
|
49
|
+
* See {@link ChildManifestGate}.
|
|
50
|
+
*/
|
|
51
|
+
childManifestGate = new ChildManifestGate();
|
|
46
52
|
/**
|
|
47
53
|
* Fixed-period agent-readiness snapshot sweep (D8 reconcile) — repairs
|
|
48
54
|
* agent-origin readiness deltas lost while the agent stayed connected.
|
|
@@ -421,6 +427,25 @@ class MoleculerService {
|
|
|
421
427
|
const hubNodeId = this.brokerSafe.nodeID;
|
|
422
428
|
const childNodeId = `${hubNodeId}/${child.childId}`;
|
|
423
429
|
const params = buildChildUdsManifest(childNodeId, child.childId, child.caps);
|
|
430
|
+
// `updateCaps()` re-sends the whole register frame on the same socket,
|
|
431
|
+
// so this fires far more often than a runner starts: 246 rebuilds in 30
|
|
432
|
+
// minutes with zero respawns, measured live. A re-register that carries
|
|
433
|
+
// the same incarnation AND the same manifest has nothing to apply — see
|
|
434
|
+
// ChildManifestGate for why it takes both, and why skipping on either
|
|
435
|
+
// one alone is wrong.
|
|
436
|
+
if (!this.childManifestGate.shouldApply(child.childId, child.incarnation, params)) {
|
|
437
|
+
if (this.childManifestGate.sampleDue()) {
|
|
438
|
+
logger.debug('UDS child re-registered with an unchanged manifest — skipped', {
|
|
439
|
+
meta: {
|
|
440
|
+
nodeId: childNodeId,
|
|
441
|
+
incarnation: child.incarnation,
|
|
442
|
+
skipped: this.childManifestGate.skippedSince(),
|
|
443
|
+
sampleEvery: exports.CHILD_MANIFEST_SKIP_SAMPLE,
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
424
449
|
// The UDS connection is the only thing that can tell two generations of
|
|
425
450
|
// the same runner apart — carry its incarnation into the registry as
|
|
426
451
|
// the owner of every registration this manifest makes.
|
|
@@ -434,6 +459,11 @@ class MoleculerService {
|
|
|
434
459
|
registry.onChildGone((childId, incarnation) => {
|
|
435
460
|
const hubNodeId = this.brokerSafe.nodeID;
|
|
436
461
|
const childNodeId = `${hubNodeId}/${childId}`;
|
|
462
|
+
// The successor's first register must be a FIRST register: leaving the
|
|
463
|
+
// record behind would let a same-incarnation reconnect (mixed-version
|
|
464
|
+
// child, or a socket that came back) be skipped against a manifest the
|
|
465
|
+
// registry no longer holds.
|
|
466
|
+
this.childManifestGate.forget(childId);
|
|
437
467
|
logger.info('UDS child gone — removing from registry', {
|
|
438
468
|
meta: { childId, incarnation },
|
|
439
469
|
});
|
|
@@ -1161,6 +1191,84 @@ exports.MoleculerService = MoleculerService;
|
|
|
1161
1191
|
function childOwnerToken(childNodeId, incarnation) {
|
|
1162
1192
|
return `${childNodeId}#${incarnation}`;
|
|
1163
1193
|
}
|
|
1194
|
+
/**
|
|
1195
|
+
* One skipped-re-register line per this many skips.
|
|
1196
|
+
*
|
|
1197
|
+
* A gate nobody can count is indistinguishable from a child that stopped
|
|
1198
|
+
* re-registering, and those two want opposite investigations. A line per skip
|
|
1199
|
+
* would reproduce exactly the volume the gate exists to remove.
|
|
1200
|
+
*/
|
|
1201
|
+
exports.CHILD_MANIFEST_SKIP_SAMPLE = 25;
|
|
1202
|
+
/** Canonical, order-insensitive text for a child manifest. */
|
|
1203
|
+
function childManifestFingerprint(params) {
|
|
1204
|
+
const addons = params.addons
|
|
1205
|
+
.map((addon) => `${addon.addonId}:${[...addon.capabilities].sort().join(',')}`)
|
|
1206
|
+
.sort();
|
|
1207
|
+
return `${params.nodeId}|${addons.join('|')}`;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Skips a child re-registration that carries nothing new.
|
|
1211
|
+
*
|
|
1212
|
+
* ## What it prevents
|
|
1213
|
+
*
|
|
1214
|
+
* `LocalChildClient.updateCaps()` re-sends the complete `register` frame on the
|
|
1215
|
+
* SAME socket whenever a child re-publishes its cap set. Measured on the live
|
|
1216
|
+
* hub 2026-08-25: **246 full manifest rebuilds in 30 minutes with zero runner
|
|
1217
|
+
* respawns**, every one carrying the same `incarnation` as the one before it
|
|
1218
|
+
* (provider-homeassistant alone: 70). `applyNodeManifest` is diff-based, so the
|
|
1219
|
+
* registry ends in the same state — the RESULT is idempotent, the WORK is not.
|
|
1220
|
+
* Each pass re-stores the manifest, builds two `appliedKeys` maps over every cap
|
|
1221
|
+
* of every hosted addon, and prints a line, on the one thread that also answers
|
|
1222
|
+
* every settings read, every UDS handshake and every cross-runner cap call
|
|
1223
|
+
* (D181).
|
|
1224
|
+
*
|
|
1225
|
+
* ## Why the key is BOTH incarnation and manifest
|
|
1226
|
+
*
|
|
1227
|
+
* Incarnation alone would skip a legitimate `updateCaps` — device-restore adds
|
|
1228
|
+
* device-scoped native caps on the same connection, which is the case the
|
|
1229
|
+
* re-register path was built for. Manifest alone would skip a RESPAWN that came
|
|
1230
|
+
* back with an identical cap set, and a respawn must always re-apply: the owner
|
|
1231
|
+
* token is `childOwnerToken(nodeId, incarnation)`, so skipping it would leave
|
|
1232
|
+
* every provider owned by the dead generation and the successor's disconnect
|
|
1233
|
+
* would unregister nothing.
|
|
1234
|
+
*/
|
|
1235
|
+
class ChildManifestGate {
|
|
1236
|
+
applied = new Map();
|
|
1237
|
+
skipped = 0;
|
|
1238
|
+
sinceSample = 0;
|
|
1239
|
+
/** True when this registration carries something the registry does not have. */
|
|
1240
|
+
shouldApply(childId, incarnation, params) {
|
|
1241
|
+
const fingerprint = childManifestFingerprint(params);
|
|
1242
|
+
const previous = this.applied.get(childId);
|
|
1243
|
+
if (previous !== undefined && previous.incarnation === incarnation) {
|
|
1244
|
+
if (previous.fingerprint === fingerprint) {
|
|
1245
|
+
this.skipped += 1;
|
|
1246
|
+
this.sinceSample += 1;
|
|
1247
|
+
return false;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
this.applied.set(childId, { incarnation, fingerprint });
|
|
1251
|
+
return true;
|
|
1252
|
+
}
|
|
1253
|
+
/** Drop a child's record — its next register is a first register again. */
|
|
1254
|
+
forget(childId) {
|
|
1255
|
+
this.applied.delete(childId);
|
|
1256
|
+
}
|
|
1257
|
+
/** How many have been skipped since the last call. Reading RESETS it. */
|
|
1258
|
+
skippedSince() {
|
|
1259
|
+
const n = this.skipped;
|
|
1260
|
+
this.skipped = 0;
|
|
1261
|
+
return n;
|
|
1262
|
+
}
|
|
1263
|
+
/** True once every {@link CHILD_MANIFEST_SKIP_SAMPLE} skips. */
|
|
1264
|
+
sampleDue() {
|
|
1265
|
+
if (this.sinceSample < exports.CHILD_MANIFEST_SKIP_SAMPLE)
|
|
1266
|
+
return false;
|
|
1267
|
+
this.sinceSample = 0;
|
|
1268
|
+
return true;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
exports.ChildManifestGate = ChildManifestGate;
|
|
1164
1272
|
/**
|
|
1165
1273
|
* E1: Adapt a child's UDS `ChildCapDescriptor[]` into a `RegisterNodeParams`
|
|
1166
1274
|
* that `onRegisterNode` / `applyNodeManifest` can consume.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.155",
|
|
4
4
|
"private": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@camstack/addon-auth": "1.2.30",
|
|
39
39
|
"@camstack/addon-decoder-nodeav": "1.2.26",
|
|
40
40
|
"@camstack/addon-notifiers": "1.2.31",
|
|
41
|
-
"@camstack/addon-pipeline": "1.2.
|
|
41
|
+
"@camstack/addon-pipeline": "1.2.121",
|
|
42
42
|
"@camstack/addon-pipeline-orchestrator": "1.2.104",
|
|
43
|
-
"@camstack/addon-post-analysis": "1.2.
|
|
43
|
+
"@camstack/addon-post-analysis": "1.2.119",
|
|
44
44
|
"@camstack/sdk": "1.2.30",
|
|
45
|
-
"@camstack/system": "1.2.
|
|
45
|
+
"@camstack/system": "1.2.123",
|
|
46
46
|
"@camstack/types": "1.2.103",
|
|
47
47
|
"@camstack/ui-library": "1.2.70",
|
|
48
48
|
"@fastify/compress": "^9.0.0",
|