@camstack/system 1.2.136 → 1.2.138

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 (54) hide show
  1. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  2. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  3. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/alerts/alerts.addon.js +1 -1
  6. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  7. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  8. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  9. package/dist/builtins/console-logging/index.js +1 -1
  10. package/dist/builtins/console-logging/index.mjs +1 -1
  11. package/dist/builtins/core-blocks/core-blocks.addon.js +1 -1
  12. package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
  13. package/dist/builtins/device-manager/device-bindings-store.d.ts +10 -4
  14. package/dist/builtins/device-manager/device-manager.addon.js +189 -25
  15. package/dist/builtins/device-manager/device-manager.addon.mjs +189 -25
  16. package/dist/builtins/device-manager/device-row-store.d.ts +20 -1
  17. package/dist/builtins/device-manager/fleet-read-census.d.ts +47 -0
  18. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  19. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  20. package/dist/builtins/hub-forwarder/index.js +1 -1
  21. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  22. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  23. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  24. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  25. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  26. package/dist/builtins/local-network/local-network.addon.js +1 -1
  27. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  28. package/dist/builtins/loki-logging/index.js +1 -1
  29. package/dist/builtins/loki-logging/index.mjs +1 -1
  30. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  31. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  32. package/dist/builtins/platform-probe/index.js +1 -1
  33. package/dist/builtins/platform-probe/index.mjs +1 -1
  34. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  35. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  36. package/dist/builtins/snapshot/index.js +1 -1
  37. package/dist/builtins/snapshot/index.mjs +1 -1
  38. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  39. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  40. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  41. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  42. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  43. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  44. package/dist/builtins/system-config/system-config.addon.js +1 -1
  45. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  46. package/dist/builtins/winston-logging/index.js +1 -1
  47. package/dist/builtins/winston-logging/index.mjs +1 -1
  48. package/dist/{dist-Bh25kEUH.mjs → dist-DMOTtKH8.mjs} +310 -63
  49. package/dist/{dist-D-R0SuP-.js → dist-mQ3BkrJd.js} +310 -63
  50. package/dist/index.js +1 -1
  51. package/dist/index.mjs +1 -1
  52. package/dist/{retired-settings-keys-BZbOXqch.mjs → retired-settings-keys-CPRvyt-E.mjs} +1 -1
  53. package/dist/{retired-settings-keys-CqD6rSQx.js → retired-settings-keys-Dvkcu_zf.js} +1 -1
  54. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { Ct as DeviceFeature, E as buildStreamParamsConfigSchema, F as deviceStatusCapability, Gt as EventCategory, Lt as isDeviceConfigCap, N as deviceManagerCapability, Ot as WELL_KNOWN_TAB_MAP, P as deviceStateCapability, R as enumerateItemArrayFields, Tt as DeviceType, Wt as sleep, a as CAP_NAMES_WITH_STATUS, at as runtimeStatePolicyFor, et as normalizeUnit, nt as parseStreamParamsFormPatch, p as STREAM_PROFILE_META, t as ALL_CAPABILITY_DEFINITIONS, u as DeviceStatusSchema, vt as errMsg, wt as DeviceRole, yt as BaseAddon, z as enumerateSchemaFields } from "../../dist-Bh25kEUH.mjs";
2
- import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-BZbOXqch.mjs";
1
+ import { Ct as DeviceFeature, E as buildStreamParamsConfigSchema, F as deviceStatusCapability, Gt as EventCategory, Lt as isDeviceConfigCap, N as deviceManagerCapability, Ot as WELL_KNOWN_TAB_MAP, P as deviceStateCapability, R as enumerateItemArrayFields, Tt as DeviceType, Wt as sleep, a as CAP_NAMES_WITH_STATUS, at as runtimeStatePolicyFor, et as normalizeUnit, nt as parseStreamParamsFormPatch, p as STREAM_PROFILE_META, t as ALL_CAPABILITY_DEFINITIONS, u as DeviceStatusSchema, vt as errMsg, wt as DeviceRole, yt as BaseAddon, z as enumerateSchemaFields } from "../../dist-DMOTtKH8.mjs";
2
+ import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-CPRvyt-E.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { canonicalDeviceFingerprint } from "@camstack/types/node";
5
5
  //#region src/builtins/device-manager/adoption-job-engine.ts
@@ -589,16 +589,33 @@ function capAppliesToDeviceType(def, deviceType) {
589
589
  return declared.some((t) => t === deviceType);
590
590
  }
591
591
  async function getBindings(deps, input) {
592
- const storeKey = String(input.deviceId);
593
- const perDevice = (await readBindingsStore(deps)).deviceBindings[storeKey] ?? {};
594
592
  const row = await deps.rows.get(input.deviceId);
595
- const deviceType = resolveDeviceType(deps, row, input.deviceId);
596
- const presence = await resolveDevicePresence(deps, row, input.deviceId);
593
+ return resolveBindingsForDevice(deps, input.deviceId, row);
594
+ }
595
+ /**
596
+ * The `getBindings` resolver, taking the device's row as a PARAMETER instead
597
+ * of fetching it.
598
+ *
599
+ * `getBindings` (one device) and `getBindingsBatch` / `getAllBindings` (many)
600
+ * share this — the routing rules and the per-device shape stay identical by
601
+ * construction. The split exists so the batch callers can resolve every row
602
+ * they need in ONE store round trip ({@link DeviceRowStore.getMany} /
603
+ * {@link DeviceRowStore.listAll}) instead of looping this function's own
604
+ * `deps.rows.get(deviceId)`, which is the primary-key-lookup-per-loop-
605
+ * iteration shape measured on the live hub 2026-08-25: `get
606
+ * device-manager:devices` at 1 656 calls/min steady-state and 17 687 during
607
+ * boot, one row per call.
608
+ */
609
+ async function resolveBindingsForDevice(deps, deviceId, row) {
610
+ const storeKey = String(deviceId);
611
+ const perDevice = (await readBindingsStore(deps)).deviceBindings[storeKey] ?? {};
612
+ const deviceType = resolveDeviceType(deps, row, deviceId);
613
+ const presence = await resolveDevicePresence(deps, row, deviceId);
597
614
  const entries = [];
598
615
  const seenCaps = /* @__PURE__ */ new Set();
599
- const resolveRemote = (capName) => deps.remoteNativeCaps.get(input.deviceId)?.get(capName) ?? resolveRemoteNativeCapFromRegistry(deps, capName, input.deviceId);
616
+ const resolveRemote = (capName) => deps.remoteNativeCaps.get(deviceId)?.get(capName) ?? resolveRemoteNativeCapFromRegistry(deps, capName, deviceId);
600
617
  for (const [capName, { wrapperAddonId }] of Object.entries(perDevice)) {
601
- const hubLocalNative = deps.capabilityRegistry?.getNativeAddonId(capName, input.deviceId) ?? null;
618
+ const hubLocalNative = deps.capabilityRegistry?.getNativeAddonId(capName, deviceId) ?? null;
602
619
  const remoteNative = resolveRemote(capName);
603
620
  const nativeAddonId = hubLocalNative ?? remoteNative?.addonId ?? "";
604
621
  const nativeNodeId = hubLocalNative ? deps.ctx.kernel.localNodeId ?? "hub" : remoteNative?.nodeId ?? deps.ctx.kernel.localNodeId ?? "hub";
@@ -615,7 +632,7 @@ async function getBindings(deps, input) {
615
632
  });
616
633
  seenCaps.add(capName);
617
634
  }
618
- if (presence === "absent") deps.ctx.logger.debug("bindings requested for absent device — returning none", { tags: { deviceId: input.deviceId } });
635
+ if (presence === "absent") deps.ctx.logger.debug("bindings requested for absent device — returning none", { tags: { deviceId } });
619
636
  else if (deps.capabilityRegistry) {
620
637
  const skippedForType = [];
621
638
  for (const capName of deps.capabilityRegistry.getCapsWithDefaultWrapper()) {
@@ -626,7 +643,7 @@ async function getBindings(deps, input) {
626
643
  }
627
644
  const defaultWrapperAddonId = deps.capabilityRegistry.getDefaultWrapperForCap(capName);
628
645
  if (!defaultWrapperAddonId) continue;
629
- const hubLocalNative = deps.capabilityRegistry.getNativeAddonId(capName, input.deviceId) ?? null;
646
+ const hubLocalNative = deps.capabilityRegistry.getNativeAddonId(capName, deviceId) ?? null;
630
647
  const remoteNative = resolveRemote(capName);
631
648
  const nativeAddonId = hubLocalNative ?? remoteNative?.addonId ?? "";
632
649
  entries.push({
@@ -639,16 +656,16 @@ async function getBindings(deps, input) {
639
656
  seenCaps.add(capName);
640
657
  }
641
658
  if (skippedForType.length > 0) deps.ctx.logger.debug("getBindings: default wrappers skipped — deviceTypes mismatch", {
642
- tags: { deviceId: input.deviceId },
659
+ tags: { deviceId },
643
660
  meta: {
644
661
  deviceType,
645
662
  skipped: skippedForType
646
663
  }
647
664
  });
648
665
  }
649
- if (deps.capabilityRegistry) for (const capName of deps.capabilityRegistry.getNativeCapsForDevice(input.deviceId)) {
666
+ if (deps.capabilityRegistry) for (const capName of deps.capabilityRegistry.getNativeCapsForDevice(deviceId)) {
650
667
  if (seenCaps.has(capName)) continue;
651
- const nativeAddonId = deps.capabilityRegistry.getNativeAddonId(capName, input.deviceId) ?? "";
668
+ const nativeAddonId = deps.capabilityRegistry.getNativeAddonId(capName, deviceId) ?? "";
652
669
  entries.push({
653
670
  capName,
654
671
  kind: "native",
@@ -658,7 +675,7 @@ async function getBindings(deps, input) {
658
675
  });
659
676
  seenCaps.add(capName);
660
677
  }
661
- const pushFed = deps.remoteNativeCaps.get(input.deviceId);
678
+ const pushFed = deps.remoteNativeCaps.get(deviceId);
662
679
  if (pushFed) for (const [capName, info] of pushFed) {
663
680
  if (seenCaps.has(capName)) continue;
664
681
  entries.push({
@@ -670,9 +687,9 @@ async function getBindings(deps, input) {
670
687
  });
671
688
  seenCaps.add(capName);
672
689
  }
673
- const clusterCaps = deps.ctx.kernel.listClusterNativeCapsForDevice?.(input.deviceId) ?? deps.ctx.kernel.listClusterNativeCaps?.();
690
+ const clusterCaps = deps.ctx.kernel.listClusterNativeCapsForDevice?.(deviceId) ?? deps.ctx.kernel.listClusterNativeCaps?.();
674
691
  if (clusterCaps) for (const entry of clusterCaps) {
675
- if (entry.deviceId !== input.deviceId) continue;
692
+ if (entry.deviceId !== deviceId) continue;
676
693
  if (seenCaps.has(entry.capName)) continue;
677
694
  if (!entry.addonId) continue;
678
695
  const localNodeId = deps.ctx.kernel.localNodeId ?? "hub";
@@ -687,7 +704,7 @@ async function getBindings(deps, input) {
687
704
  seenCaps.add(entry.capName);
688
705
  }
689
706
  return {
690
- deviceId: input.deviceId,
707
+ deviceId,
691
708
  entries
692
709
  };
693
710
  }
@@ -700,14 +717,22 @@ async function getBindings(deps, input) {
700
717
  * caller needing seventy-five paid either 75 round-trips (1211 ms / 118 KB) or
701
718
  * `getAllBindings` (511 ms / 679 KB of mostly-unwanted rows).
702
719
  *
703
- * Sequential on purpose, like `getAllBindings`: `getBindings` is a pair of
704
- * store reads on this process's own event loop, so concurrency buys nothing
705
- * and a fan-out of `Promise.all` over hundreds of ids only makes the queue
706
- * less fair to everything else on it.
720
+ * Sequential on purpose, like `getAllBindings`: `resolveBindingsForDevice`'s
721
+ * remaining per-device work (the bindings-store read, the routing rules) runs
722
+ * on this process's own event loop, so concurrency buys nothing there and a
723
+ * fan-out of `Promise.all` over hundreds of ids only makes the queue less fair
724
+ * to everything else on it. The one part that DOES amortise across the whole
725
+ * set — the device row lookup — is fetched ONCE, ahead of the loop
726
+ * ({@link DeviceRowStore.getMany}), rather than once per iteration: measured
727
+ * on the live hub 2026-08-25, `get device-manager:devices` ran 1 656
728
+ * calls/min steady-state, one row per call, which is exactly what looping
729
+ * `getBindings`'s own `rows.get(deviceId)` here produced.
707
730
  */
708
731
  async function getBindingsBatch(deps, input) {
732
+ const ids = [...new Set(input.deviceIds)];
733
+ const rows = await deps.rows.getMany(ids);
709
734
  const out = [];
710
- for (const deviceId of new Set(input.deviceIds)) out.push(await getBindings(deps, { deviceId }));
735
+ for (const deviceId of ids) out.push(await resolveBindingsForDevice(deps, deviceId, rows.get(deviceId) ?? null));
711
736
  return out;
712
737
  }
713
738
  /**
@@ -722,8 +747,13 @@ async function getBindingsBatch(deps, input) {
722
747
  * payload periodically.
723
748
  */
724
749
  async function getAllBindings(deps) {
750
+ const fleet = await deps.rows.listAll();
751
+ const rowById = /* @__PURE__ */ new Map();
725
752
  const ids = /* @__PURE__ */ new Set();
726
- for (const row of await deps.rows.listAll()) ids.add(row.meta.id);
753
+ for (const row of fleet) {
754
+ rowById.set(row.meta.id, row);
755
+ ids.add(row.meta.id);
756
+ }
727
757
  const registered = deps.ctx.kernel?.deviceRegistry?.getAll() ?? [];
728
758
  for (const device of registered) ids.add(device.id);
729
759
  if (ids.size === 0) {
@@ -731,7 +761,7 @@ async function getAllBindings(deps) {
731
761
  return [];
732
762
  }
733
763
  const out = [];
734
- for (const deviceId of [...ids].sort((a, b) => a - b)) out.push(await getBindings(deps, { deviceId }));
764
+ for (const deviceId of [...ids].sort((a, b) => a - b)) out.push(await resolveBindingsForDevice(deps, deviceId, rowById.get(deviceId) ?? null));
735
765
  return out;
736
766
  }
737
767
  /**
@@ -3914,6 +3944,112 @@ var DeviceMetaStore = class {
3914
3944
  };
3915
3945
  };
3916
3946
  //#endregion
3947
+ //#region src/builtins/device-manager/fleet-read-census.ts
3948
+ /** How many stack frames identify a call site. One frame is a method; three are
3949
+ * a cause — `listFleet < listAll < onDeviceRegistered` is the answer, `listAll`
3950
+ * alone is not. Same choice, for the same reason, as `read-census.ts`. */
3951
+ var CENSUS_STACK_FRAMES = 3;
3952
+ function siteFromStack(stack) {
3953
+ if (stack === void 0) return "unknown";
3954
+ const frames = stack.split("\n").slice(1).map((line) => line.trim().replace(/^at\s+/, "")).filter((line) => line.length > 0).slice(0, CENSUS_STACK_FRAMES).map((line) => {
3955
+ const open = line.indexOf(" (");
3956
+ return (open > 0 ? line.slice(0, open) : line).replace(/^async\s+/, "");
3957
+ });
3958
+ return frames.length === 0 ? "unknown" : frames.join(" < ");
3959
+ }
3960
+ var FleetReadCensus = class FleetReadCensus {
3961
+ /**
3962
+ * Longest window the census may be armed for.
3963
+ *
3964
+ * Ten minutes covers a boot several times over and bounds what an operator
3965
+ * pays if they set the variable and forget it. A diagnostic that can be left
3966
+ * on becomes a tax nobody remembers enabling.
3967
+ */
3968
+ static MAX_WINDOW_MS = 10 * 6e4;
3969
+ windowMs;
3970
+ closesAt;
3971
+ counts = /* @__PURE__ */ new Map();
3972
+ reported = false;
3973
+ constructor(rawEnv, nowMs) {
3974
+ const parsed = rawEnv === void 0 ? NaN : Number(rawEnv);
3975
+ const valid = Number.isFinite(parsed) && parsed > 0;
3976
+ this.windowMs = valid ? Math.min(parsed, FleetReadCensus.MAX_WINDOW_MS) : 0;
3977
+ this.closesAt = valid ? nowMs + this.windowMs : 0;
3978
+ }
3979
+ get armed() {
3980
+ return this.windowMs > 0;
3981
+ }
3982
+ /** Test seam: pretend the window closed. Production reads the clock. */
3983
+ closeAt(nowMs) {
3984
+ if (nowMs >= this.closesAt) this.forceClosed = true;
3985
+ }
3986
+ forceClosed = false;
3987
+ isOpen(nowMs) {
3988
+ if (!this.armed || this.forceClosed) return false;
3989
+ return nowMs < this.closesAt;
3990
+ }
3991
+ /**
3992
+ * Capture the caller, or `null` when the window is shut.
3993
+ *
3994
+ * Called at the START of a read. A read that began inside the window belongs
3995
+ * to it even if it lands after the close — otherwise the slow reads at the
3996
+ * edge would be attributed to nobody, and the slow ones are the interesting
3997
+ * ones.
3998
+ */
3999
+ siteOf(nowMs = Date.now()) {
4000
+ if (!this.isOpen(nowMs)) return null;
4001
+ const holder = {};
4002
+ Error.captureStackTrace(holder, this.siteOf);
4003
+ return siteFromStack(holder.stack);
4004
+ }
4005
+ /** Count one read at an already-captured site. A `null` site is not counted. */
4006
+ record(site, rowCount) {
4007
+ if (site === null) return;
4008
+ const existing = this.counts.get(site);
4009
+ if (existing === void 0) {
4010
+ this.counts.set(site, {
4011
+ site,
4012
+ calls: 1,
4013
+ rows: rowCount
4014
+ });
4015
+ return;
4016
+ }
4017
+ existing.calls += 1;
4018
+ existing.rows += rowCount;
4019
+ }
4020
+ /** Attributed sites, busiest first. */
4021
+ rows() {
4022
+ return [...this.counts.values()].map((c) => ({
4023
+ site: c.site,
4024
+ calls: c.calls,
4025
+ rows: c.rows
4026
+ })).sort((a, b) => b.calls - a.calls);
4027
+ }
4028
+ /**
4029
+ * Emit the report ONCE.
4030
+ *
4031
+ * `perMin` is included because the raw count is unreadable without the window
4032
+ * it was taken over — "4 149" means nothing until you know it was 66 seconds.
4033
+ */
4034
+ report(logger, elapsedMs) {
4035
+ if (this.reported || !this.armed) return;
4036
+ this.reported = true;
4037
+ const rows = this.rows();
4038
+ const totalCalls = rows.reduce((acc, r) => acc + r.calls, 0);
4039
+ logger.info("fleet read census", { meta: {
4040
+ elapsedMs,
4041
+ sites: rows.length,
4042
+ totalCalls,
4043
+ rows: rows.map((r) => ({
4044
+ site: r.site,
4045
+ calls: r.calls,
4046
+ rows: r.rows,
4047
+ perMin: elapsedMs === 0 ? 0 : Math.round(r.calls * 6e4 / elapsedMs)
4048
+ }))
4049
+ } });
4050
+ }
4051
+ };
4052
+ //#endregion
3917
4053
  //#region src/builtins/device-manager/device-row-store.ts
3918
4054
  /**
3919
4055
  * @durable class=ledger owner=device-manager
@@ -4243,9 +4379,17 @@ var DeviceRowStore = class {
4243
4379
  backend;
4244
4380
  logger;
4245
4381
  declared = null;
4246
- constructor(backend, logger) {
4382
+ /** Call-site attribution for fleet reads. Armed only by
4383
+ * `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
4384
+ census;
4385
+ constructor(backend, logger, census) {
4247
4386
  this.backend = backend;
4248
4387
  this.logger = logger;
4388
+ this.census = census ?? new FleetReadCensus(process.env["CAMSTACK_FLEET_READ_CENSUS_MS"], Date.now());
4389
+ if (this.census.armed) {
4390
+ const startedAt = Date.now();
4391
+ setTimeout(() => this.census.report(this.logger, Date.now() - startedAt), this.census.windowMs).unref?.();
4392
+ }
4249
4393
  }
4250
4394
  /**
4251
4395
  * Lazy, idempotent `declareCollection`, memoised on the PROMISE so N
@@ -4324,6 +4468,24 @@ var DeviceRowStore = class {
4324
4468
  }, opts.slim === true ? DEVICE_ROWS_SLIM_COLUMNS : void 0);
4325
4469
  }
4326
4470
  /**
4471
+ * Many devices, by numeric id, in ONE query.
4472
+ *
4473
+ * `get(id)` called once per id in a loop is the primary-key lookup this
4474
+ * store exists to make cheap, repeated until it isn't — measured on the
4475
+ * live hub 2026-08-25: `get device-manager:devices` at 1 656 calls/min
4476
+ * steady-state and 17 687 during boot, exactly one row per call. This
4477
+ * collapses that into the same `whereIn` {@link listFleet} already does for
4478
+ * a fleet read, keyed by id.
4479
+ *
4480
+ * A requested id the fleet does not know is simply ABSENT from the map —
4481
+ * never a fabricated row, matching {@link get}'s `null`. An empty `ids`
4482
+ * reads nothing at all, same as `listFleet({ deviceIds: [] })`.
4483
+ */
4484
+ async getMany(ids) {
4485
+ const rows = await this.listFleet({ deviceIds: ids });
4486
+ return new Map(rows.map((row) => [row.meta.id, row]));
4487
+ }
4488
+ /**
4327
4489
  * The device an addon knows as `stableId`, or `null`.
4328
4490
  *
4329
4491
  * `(addonId, stableId)` is the addon-facing identity — unique by
@@ -4396,11 +4558,13 @@ var DeviceRowStore = class {
4396
4558
  }
4397
4559
  async list(filter, columns) {
4398
4560
  await this.declare();
4561
+ const site = this.census.siteOf();
4399
4562
  const records = await this.backend.query({
4400
4563
  collection: DEVICE_ROWS_COLLECTION,
4401
4564
  filter,
4402
4565
  ...columns === void 0 ? {} : { columns }
4403
4566
  });
4567
+ this.census.record(site, records.length);
4404
4568
  const out = [];
4405
4569
  for (const record of records) {
4406
4570
  const decoded = decodeDeviceRow(record.data);
@@ -1,6 +1,7 @@
1
1
  import { ChildLayout, CollectionColumn, CollectionIndex, DeviceDisplayOverride, IScopedLogger, MutationFilter, QueryFilter, SettingsRecord, SettingsStoreClient } from '@camstack/types';
2
2
  import { RetiredRowStore } from '../sqlite-storage/retired-settings-keys.js';
3
3
  import { PersistedDeviceMeta } from './device-meta-types.js';
4
+ import { FleetReadCensus } from './fleet-read-census.js';
4
5
  /**
5
6
  * @durable class=ledger owner=device-manager
6
7
  * write="one row per device, written by `allocateDeviceId` (identity placeholder),
@@ -211,7 +212,10 @@ export declare class DeviceRowStore {
211
212
  private readonly backend;
212
213
  private readonly logger;
213
214
  private declared;
214
- constructor(backend: DeviceRowBackend, logger: IScopedLogger);
215
+ /** Call-site attribution for fleet reads. Armed only by
216
+ * `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
217
+ private readonly census;
218
+ constructor(backend: DeviceRowBackend, logger: IScopedLogger, census?: FleetReadCensus);
215
219
  /**
216
220
  * Lazy, idempotent `declareCollection`, memoised on the PROMISE so N
217
221
  * concurrent first-callers issue one declaration rather than N. A rejection
@@ -243,6 +247,21 @@ export declare class DeviceRowStore {
243
247
  readonly deviceIds?: readonly number[];
244
248
  readonly slim?: boolean;
245
249
  }): Promise<readonly DeviceRow[]>;
250
+ /**
251
+ * Many devices, by numeric id, in ONE query.
252
+ *
253
+ * `get(id)` called once per id in a loop is the primary-key lookup this
254
+ * store exists to make cheap, repeated until it isn't — measured on the
255
+ * live hub 2026-08-25: `get device-manager:devices` at 1 656 calls/min
256
+ * steady-state and 17 687 during boot, exactly one row per call. This
257
+ * collapses that into the same `whereIn` {@link listFleet} already does for
258
+ * a fleet read, keyed by id.
259
+ *
260
+ * A requested id the fleet does not know is simply ABSENT from the map —
261
+ * never a fabricated row, matching {@link get}'s `null`. An empty `ids`
262
+ * reads nothing at all, same as `listFleet({ deviceIds: [] })`.
263
+ */
264
+ getMany(ids: readonly number[]): Promise<ReadonlyMap<number, DeviceRow>>;
246
265
  /**
247
266
  * The device an addon knows as `stableId`, or `null`.
248
267
  *
@@ -0,0 +1,47 @@
1
+ import { IScopedLogger } from '@camstack/types';
2
+ /** One attributed call site. */
3
+ export interface FleetCensusRow {
4
+ readonly site: string;
5
+ readonly calls: number;
6
+ readonly rows: number;
7
+ }
8
+ export declare class FleetReadCensus {
9
+ /**
10
+ * Longest window the census may be armed for.
11
+ *
12
+ * Ten minutes covers a boot several times over and bounds what an operator
13
+ * pays if they set the variable and forget it. A diagnostic that can be left
14
+ * on becomes a tax nobody remembers enabling.
15
+ */
16
+ static readonly MAX_WINDOW_MS: number;
17
+ readonly windowMs: number;
18
+ private readonly closesAt;
19
+ private readonly counts;
20
+ private reported;
21
+ constructor(rawEnv: string | undefined, nowMs: number);
22
+ get armed(): boolean;
23
+ /** Test seam: pretend the window closed. Production reads the clock. */
24
+ closeAt(nowMs: number): void;
25
+ private forceClosed;
26
+ private isOpen;
27
+ /**
28
+ * Capture the caller, or `null` when the window is shut.
29
+ *
30
+ * Called at the START of a read. A read that began inside the window belongs
31
+ * to it even if it lands after the close — otherwise the slow reads at the
32
+ * edge would be attributed to nobody, and the slow ones are the interesting
33
+ * ones.
34
+ */
35
+ siteOf(nowMs?: number): string | null;
36
+ /** Count one read at an already-captured site. A `null` site is not counted. */
37
+ record(site: string | null, rowCount: number): void;
38
+ /** Attributed sites, busiest first. */
39
+ rows(): readonly FleetCensusRow[];
40
+ /**
41
+ * Emit the report ONCE.
42
+ *
43
+ * `perMin` is included because the raw count is unreadable without the window
44
+ * it was taken over — "4 149" means nothing until you know it was 66 seconds.
45
+ */
46
+ report(logger: IScopedLogger, elapsedMs: number): void;
47
+ }
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  //#region src/builtins/doorbell/trigger-engine.ts
8
8
  /**
9
9
  * Pure trigger logic for the virtual-doorbell builtin — edge detection over
@@ -1,4 +1,4 @@
1
- import { G as isSameAddonId, Gt as EventCategory, I as doorbellCapability, Mt as createEvent, Tt as DeviceType, vt as errMsg, w as bareAddonId, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { G as isSameAddonId, Gt as EventCategory, I as doorbellCapability, Mt as createEvent, Tt as DeviceType, vt as errMsg, w as bareAddonId, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  //#region src/builtins/doorbell/trigger-engine.ts
3
3
  /**
4
4
  * Pure trigger logic for the virtual-doorbell builtin — edge detection over
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  const require_formatter = require("../../formatter-DqAKDlvN.js");
8
8
  //#region src/builtins/hub-forwarder/hub-forwarder-destination.ts
9
9
  var DEFAULT_OUTBOUND_BUFFER_SIZE = 500;
@@ -1,4 +1,4 @@
1
- import { X as logDestinationCapability, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { X as logDestinationCapability, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-B7qW8bPJ.mjs";
3
3
  //#region src/builtins/hub-forwarder/hub-forwarder-destination.ts
4
4
  var DEFAULT_OUTBOUND_BUFFER_SIZE = 500;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-D-R0SuP-.js");
3
+ const require_dist = require("../../dist-mQ3BkrJd.js");
4
4
  //#region src/builtins/liveness-monitor/liveness-checks.ts
5
5
  var NO_DEVICES = "liveness:no-devices";
6
6
  var ALL_OFFLINE = "liveness:all-devices-offline";
@@ -1,4 +1,4 @@
1
- import { Gt as EventCategory, Mt as createEvent, vt as errMsg, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { Gt as EventCategory, Mt as createEvent, vt as errMsg, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  //#region src/builtins/liveness-monitor/liveness-checks.ts
3
3
  var NO_DEVICES = "liveness:no-devices";
4
4
  var ALL_OFFLINE = "liveness:all-devices-offline";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  node_crypto = require_chunk.__toESM(node_crypto);
9
9
  let crypto$1 = require("crypto");
@@ -1,5 +1,5 @@
1
1
  import { i as __require, o as __toESM, t as __commonJSMin } from "../../chunk-CNf5ZN-e.mjs";
2
- import { S as authProviderCapability, _ as UserRecordSchema, ht as userManagementCapability, m as ScopedTokenSchema, r as ApiKeyRecordSchema, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
2
+ import { S as authProviderCapability, _ as UserRecordSchema, ht as userManagementCapability, m as ScopedTokenSchema, r as ApiKeyRecordSchema, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
3
3
  import * as crypto$2 from "node:crypto";
4
4
  import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
5
5
  import nodeCrypto from "crypto";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-D-R0SuP-.js");
3
+ const require_dist = require("../../dist-mQ3BkrJd.js");
4
4
  const require_tls = require("../../tls-u8QCJCFE.js");
5
5
  let node_fs_promises = require("node:fs/promises");
6
6
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Gt as EventCategory, Y as localNetworkCapability, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { Gt as EventCategory, Y as localNetworkCapability, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  import { S as readLanHttpState, _ as DEFAULT_LAN_HTTP_PORT, a as writeTlsMode, i as writeExtraSans, l as reissueTlsLeaf, n as readTlsAccessStatus, o as validateUploadedTls, r as readTlsMode, s as ensureTlsCert, t as readExtraSans, y as applyLanHttp } from "../../tls-CQhPGSJm.mjs";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  //#region src/builtins/loki-logging/loki-payload.ts
8
8
  /**
9
9
  * Loki rejects a label name that is not a valid Prometheus label
@@ -1,4 +1,4 @@
1
- import { X as logDestinationCapability, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { X as logDestinationCapability, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  //#region src/builtins/loki-logging/loki-payload.ts
3
3
  /**
4
4
  * Loki rejects a label name that is not a valid Prometheus label
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_util = require("node:util");
9
9
  let node_os = require("node:os");
@@ -1,4 +1,4 @@
1
- import { $ as metricsProviderCapability, Gt as EventCategory, Mt as createEvent, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { $ as metricsProviderCapability, Gt as EventCategory, Mt as createEvent, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  import { execFile, execFileSync } from "node:child_process";
3
3
  import { promisify } from "node:util";
4
4
  import * as os from "node:os";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_util = require("node:util");
9
9
  let node_os = require("node:os");
@@ -1,5 +1,5 @@
1
1
  import { o as __toESM } from "../../chunk-CNf5ZN-e.mjs";
2
- import { Gt as EventCategory, L as enumerateInferenceDevices, Pt as emitReadiness, ct as scoreRuntimes, rt as platformProbeCapability, vt as errMsg, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
2
+ import { Gt as EventCategory, L as enumerateInferenceDevices, Pt as emitReadiness, ct as scoreRuntimes, rt as platformProbeCapability, vt as errMsg, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
3
3
  import { execFile } from "node:child_process";
4
4
  import { promisify } from "node:util";
5
5
  import * as os from "node:os";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  //#region src/builtins/remote-access-orchestrator/enabled-providers-reconcile.ts
8
8
  /**
9
9
  * Reconcile the durable `enabledProviders` set against authoritative
@@ -1,4 +1,4 @@
1
- import { Gt as EventCategory, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { Gt as EventCategory, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  //#region src/builtins/remote-access-orchestrator/enabled-providers-reconcile.ts
3
3
  /**
4
4
  * Reconcile the durable `enabledProviders` set against authoritative
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let zod = require("zod");
8
8
  let node_crypto = require("node:crypto");
9
9
  let _camstack_types_node = require("@camstack/types/node");
@@ -1,4 +1,4 @@
1
- import { Ct as DeviceFeature, Gt as EventCategory, M as deriveBatteryPresence, Rt as nodePin, T as batteryCapability, Tt as DeviceType, i as BatteryStatusSchema, mt as streamQualityLabel, ut as snapshotCapability, vt as errMsg, w as bareAddonId, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { Ct as DeviceFeature, Gt as EventCategory, M as deriveBatteryPresence, Rt as nodePin, T as batteryCapability, Tt as DeviceType, i as BatteryStatusSchema, mt as streamQualityLabel, ut as snapshotCapability, vt as errMsg, w as bareAddonId, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  import { z } from "zod";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { signExpiringUrl, verifyExpiringUrl } from "@camstack/types/node";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  let node_fs_promises = require("node:fs/promises");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { V as filesystemBrowseCapability, pt as storageProviderCapability, yt as BaseAddon } from "../../dist-Bh25kEUH.mjs";
1
+ import { V as filesystemBrowseCapability, pt as storageProviderCapability, yt as BaseAddon } from "../../dist-DMOTtKH8.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { mkdir, readdir, realpath, statfs } from "node:fs/promises";
4
4
  import * as path$1 from "node:path";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D-R0SuP-.js");
6
+ const require_dist = require("../../dist-mQ3BkrJd.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  let node_fs_promises = require("node:fs/promises");
9
9
  node_fs_promises = require_chunk.__toESM(node_fs_promises);
@@ -1,4 +1,4 @@
1
- import { dt as storageCapability, ft as storageMigrationCapability, g as StorageMigrationJobSchema, h as StorageLocationTypeSchema, lt as settingsStoreCapability, yt as BaseAddon, zt as parseJsonObject } from "../../dist-Bh25kEUH.mjs";
1
+ import { dt as storageCapability, ft as storageMigrationCapability, g as StorageMigrationJobSchema, h as StorageLocationTypeSchema, lt as settingsStoreCapability, yt as BaseAddon, zt as parseJsonObject } from "../../dist-DMOTtKH8.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import * as fs from "node:fs/promises";
4
4
  import * as path$1 from "node:path";