@camstack/server 1.2.154 → 1.2.156

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.
@@ -2748,6 +2748,15 @@ function createCapRouter_deviceManager(getProvider, createRemoteProxy) {
2748
2748
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
2749
2749
  return p.getLinkedDevices(methodInput);
2750
2750
  }),
2751
+ getLinkedDevicesBatch: trpc_middleware_js_1.protectedProcedure
2752
+ .input(types_41.deviceManagerCapability.methods.getLinkedDevicesBatch.input.loose())
2753
+ .output(types_41.deviceManagerCapability.methods.getLinkedDevicesBatch.output)
2754
+ .query(async ({ input, ctx }) => {
2755
+ const { nodeId, ...methodInput } = input;
2756
+ const p = resolveProvider('device-manager', nodeId, () => getProvider(ctx), createRemoteProxy);
2757
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
2758
+ return p.getLinkedDevicesBatch(methodInput);
2759
+ }),
2751
2760
  getStreamSources: trpc_middleware_js_1.protectedProcedure
2752
2761
  .input(types_41.deviceManagerCapability.methods.getStreamSources.input.loose())
2753
2762
  .output(types_41.deviceManagerCapability.methods.getStreamSources.output)
@@ -2856,6 +2865,15 @@ function createCapRouter_deviceManager(getProvider, createRemoteProxy) {
2856
2865
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
2857
2866
  return p.getBindings(methodInput);
2858
2867
  }),
2868
+ getBindingsBatch: trpc_middleware_js_1.protectedProcedure
2869
+ .input(types_41.deviceManagerCapability.methods.getBindingsBatch.input.loose())
2870
+ .output(types_41.deviceManagerCapability.methods.getBindingsBatch.output)
2871
+ .query(async ({ input, ctx }) => {
2872
+ const { nodeId, ...methodInput } = input;
2873
+ const p = resolveProvider('device-manager', nodeId, () => getProvider(ctx), createRemoteProxy);
2874
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
2875
+ return p.getBindingsBatch(methodInput);
2876
+ }),
2859
2877
  getAllBindings: trpc_middleware_js_1.protectedProcedure
2860
2878
  .input(types_41.deviceManagerCapability.methods.getAllBindings.input.loose())
2861
2879
  .output(types_41.deviceManagerCapability.methods.getAllBindings.output)
@@ -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,30 @@ 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
+ // INFO, not debug: the count IS the deliverable. A gate whose only
439
+ // evidence sits below the production log level is a gate nobody can
440
+ // tell apart from a child that stopped registering, and at one line
441
+ // per CHILD_MANIFEST_SKIP_SAMPLE this is ~8 lines an hour at the
442
+ // rate measured before the gate existed.
443
+ logger.info('UDS child re-registered with an unchanged manifest — skipped', {
444
+ meta: {
445
+ nodeId: childNodeId,
446
+ incarnation: child.incarnation,
447
+ skipped: this.childManifestGate.skippedSince(),
448
+ sampleEvery: exports.CHILD_MANIFEST_SKIP_SAMPLE,
449
+ },
450
+ });
451
+ }
452
+ return;
453
+ }
424
454
  // The UDS connection is the only thing that can tell two generations of
425
455
  // the same runner apart — carry its incarnation into the registry as
426
456
  // the owner of every registration this manifest makes.
@@ -434,6 +464,11 @@ class MoleculerService {
434
464
  registry.onChildGone((childId, incarnation) => {
435
465
  const hubNodeId = this.brokerSafe.nodeID;
436
466
  const childNodeId = `${hubNodeId}/${childId}`;
467
+ // The successor's first register must be a FIRST register: leaving the
468
+ // record behind would let a same-incarnation reconnect (mixed-version
469
+ // child, or a socket that came back) be skipped against a manifest the
470
+ // registry no longer holds.
471
+ this.childManifestGate.forget(childId);
437
472
  logger.info('UDS child gone — removing from registry', {
438
473
  meta: { childId, incarnation },
439
474
  });
@@ -1161,6 +1196,84 @@ exports.MoleculerService = MoleculerService;
1161
1196
  function childOwnerToken(childNodeId, incarnation) {
1162
1197
  return `${childNodeId}#${incarnation}`;
1163
1198
  }
1199
+ /**
1200
+ * One skipped-re-register line per this many skips.
1201
+ *
1202
+ * A gate nobody can count is indistinguishable from a child that stopped
1203
+ * re-registering, and those two want opposite investigations. A line per skip
1204
+ * would reproduce exactly the volume the gate exists to remove.
1205
+ */
1206
+ exports.CHILD_MANIFEST_SKIP_SAMPLE = 25;
1207
+ /** Canonical, order-insensitive text for a child manifest. */
1208
+ function childManifestFingerprint(params) {
1209
+ const addons = params.addons
1210
+ .map((addon) => `${addon.addonId}:${[...addon.capabilities].sort().join(',')}`)
1211
+ .sort();
1212
+ return `${params.nodeId}|${addons.join('|')}`;
1213
+ }
1214
+ /**
1215
+ * Skips a child re-registration that carries nothing new.
1216
+ *
1217
+ * ## What it prevents
1218
+ *
1219
+ * `LocalChildClient.updateCaps()` re-sends the complete `register` frame on the
1220
+ * SAME socket whenever a child re-publishes its cap set. Measured on the live
1221
+ * hub 2026-08-25: **246 full manifest rebuilds in 30 minutes with zero runner
1222
+ * respawns**, every one carrying the same `incarnation` as the one before it
1223
+ * (provider-homeassistant alone: 70). `applyNodeManifest` is diff-based, so the
1224
+ * registry ends in the same state — the RESULT is idempotent, the WORK is not.
1225
+ * Each pass re-stores the manifest, builds two `appliedKeys` maps over every cap
1226
+ * of every hosted addon, and prints a line, on the one thread that also answers
1227
+ * every settings read, every UDS handshake and every cross-runner cap call
1228
+ * (D181).
1229
+ *
1230
+ * ## Why the key is BOTH incarnation and manifest
1231
+ *
1232
+ * Incarnation alone would skip a legitimate `updateCaps` — device-restore adds
1233
+ * device-scoped native caps on the same connection, which is the case the
1234
+ * re-register path was built for. Manifest alone would skip a RESPAWN that came
1235
+ * back with an identical cap set, and a respawn must always re-apply: the owner
1236
+ * token is `childOwnerToken(nodeId, incarnation)`, so skipping it would leave
1237
+ * every provider owned by the dead generation and the successor's disconnect
1238
+ * would unregister nothing.
1239
+ */
1240
+ class ChildManifestGate {
1241
+ applied = new Map();
1242
+ skipped = 0;
1243
+ sinceSample = 0;
1244
+ /** True when this registration carries something the registry does not have. */
1245
+ shouldApply(childId, incarnation, params) {
1246
+ const fingerprint = childManifestFingerprint(params);
1247
+ const previous = this.applied.get(childId);
1248
+ if (previous !== undefined && previous.incarnation === incarnation) {
1249
+ if (previous.fingerprint === fingerprint) {
1250
+ this.skipped += 1;
1251
+ this.sinceSample += 1;
1252
+ return false;
1253
+ }
1254
+ }
1255
+ this.applied.set(childId, { incarnation, fingerprint });
1256
+ return true;
1257
+ }
1258
+ /** Drop a child's record — its next register is a first register again. */
1259
+ forget(childId) {
1260
+ this.applied.delete(childId);
1261
+ }
1262
+ /** How many have been skipped since the last call. Reading RESETS it. */
1263
+ skippedSince() {
1264
+ const n = this.skipped;
1265
+ this.skipped = 0;
1266
+ return n;
1267
+ }
1268
+ /** True once every {@link CHILD_MANIFEST_SKIP_SAMPLE} skips. */
1269
+ sampleDue() {
1270
+ if (this.sinceSample < exports.CHILD_MANIFEST_SKIP_SAMPLE)
1271
+ return false;
1272
+ this.sinceSample = 0;
1273
+ return true;
1274
+ }
1275
+ }
1276
+ exports.ChildManifestGate = ChildManifestGate;
1164
1277
  /**
1165
1278
  * E1: Adapt a child's UDS `ChildCapDescriptor[]` into a `RegisterNodeParams`
1166
1279
  * that `onRegisterNode` / `applyNodeManifest` can consume.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.154",
3
+ "version": "1.2.156",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -33,18 +33,18 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@camstack/addon-admin-ui": "1.2.96",
37
- "@camstack/addon-agent-ui": "1.2.28",
38
- "@camstack/addon-auth": "1.2.30",
39
- "@camstack/addon-decoder-nodeav": "1.2.26",
40
- "@camstack/addon-notifiers": "1.2.31",
41
- "@camstack/addon-pipeline": "1.2.120",
42
- "@camstack/addon-pipeline-orchestrator": "1.2.104",
43
- "@camstack/addon-post-analysis": "1.2.118",
44
- "@camstack/sdk": "1.2.30",
45
- "@camstack/system": "1.2.122",
46
- "@camstack/types": "1.2.103",
47
- "@camstack/ui-library": "1.2.70",
36
+ "@camstack/addon-admin-ui": "1.2.97",
37
+ "@camstack/addon-agent-ui": "1.2.29",
38
+ "@camstack/addon-auth": "1.2.31",
39
+ "@camstack/addon-decoder-nodeav": "1.2.27",
40
+ "@camstack/addon-notifiers": "1.2.32",
41
+ "@camstack/addon-pipeline": "1.2.122",
42
+ "@camstack/addon-pipeline-orchestrator": "1.2.105",
43
+ "@camstack/addon-post-analysis": "1.2.120",
44
+ "@camstack/sdk": "1.2.31",
45
+ "@camstack/system": "1.2.124",
46
+ "@camstack/types": "1.2.104",
47
+ "@camstack/ui-library": "1.2.71",
48
48
  "@fastify/compress": "^9.0.0",
49
49
  "@fastify/cookie": "^11.0.2",
50
50
  "@fastify/cors": "^11.2.0",