@camstack/addon-pipeline 1.2.94 → 1.2.96

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 (36) hide show
  1. package/dist/{addon-utils-DnUCCZVx.js → addon-utils-B6usm-YO.js} +1 -1
  2. package/dist/audio-analyzer/index.js +58 -4
  3. package/dist/audio-analyzer/index.mjs +56 -2
  4. package/dist/detection-pipeline/index.js +194 -6
  5. package/dist/detection-pipeline/index.mjs +191 -3
  6. package/dist/{dist-XbrYiMV3.mjs → dist-LIWfUNC_.mjs} +324 -2
  7. package/dist/{dist-BbRv3bM2.js → dist-w9QWDvWn.js} +341 -1
  8. package/dist/{event-loop-stall-monitor-CFWrOZ6G.mjs → event-loop-stall-monitor-BDC8qURn.mjs} +1 -1
  9. package/dist/{event-loop-stall-monitor-D9hqbc68.js → event-loop-stall-monitor-DndI0S2s.js} +1 -1
  10. package/dist/{lazy-sharp-U0EtN7_C.js → lazy-sharp-BVqBydNU.js} +1 -1
  11. package/dist/motion-wasm/index.js +2 -2
  12. package/dist/motion-wasm/index.mjs +1 -1
  13. package/dist/pipeline-runner/index.js +4 -4
  14. package/dist/pipeline-runner/index.mjs +3 -3
  15. package/dist/process-memory-C6zWIgos.js +78 -0
  16. package/dist/process-memory-k45KJaKH.mjs +66 -0
  17. package/dist/recorder/index.js +423 -47
  18. package/dist/recorder/index.mjs +422 -46
  19. package/dist/session-decode/decode-worker-child.js +2 -2
  20. package/dist/session-decode/decode-worker-child.mjs +1 -1
  21. package/dist/stream-broker/_stub.js +1 -1
  22. package/dist/stream-broker/{_virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-BNOPhQ-y.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-CJWMZMhQ.mjs} +3 -3
  23. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-D2WOTeYi.mjs +26 -0
  24. package/dist/stream-broker/{hostInit-DCV2-mSi.mjs → hostInit-CGIo3d4K.mjs} +3 -3
  25. package/dist/stream-broker/index.js +25 -7
  26. package/dist/stream-broker/index.mjs +25 -7
  27. package/dist/stream-broker/remoteEntry.js +1 -1
  28. package/dist/{worker-protocol-D0ewr67U.mjs → worker-protocol-DTe7Ntat.mjs} +1 -1
  29. package/dist/{worker-protocol-CNC-ZcU3.js → worker-protocol-DqrXmX0g.js} +1 -1
  30. package/package.json +12 -7
  31. package/python/inference_pool.py +178 -3
  32. package/python/test_inference_pool_backpressure.py +7 -1
  33. package/python/test_inference_pool_memstats.py +146 -0
  34. package/dist/node-topology-platform-BkR_k6WT.mjs +0 -15
  35. package/dist/node-topology-platform-CFZ7F4xW.js +0 -20
  36. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DMyOrQHq.mjs +0 -26
@@ -22,7 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  }) : target, mod));
23
23
  //#endregion
24
24
  let node_crypto = require("node:crypto");
25
- //#region ../types/dist/event-category-C0lyLd5U.mjs
25
+ //#region ../types/dist/event-category-XfKNtfCc.mjs
26
26
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
27
27
  EventCategory["SystemBoot"] = "system.boot";
28
28
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -61,6 +61,22 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
61
61
  EventCategory["AddonInstalled"] = "addon.installed";
62
62
  EventCategory["AddonUninstalled"] = "addon.uninstalled";
63
63
  EventCategory["AddonCrashed"] = "addon.crashed";
64
+ /**
65
+ * A RUNNER the D6 crash circuit-breaker gave up on — terminal.
66
+ *
67
+ * `AddonCrashed` is the routine, self-healing fact ("it crashed; it is being
68
+ * respawned"); this is the one that never resolves itself. Emitted exactly
69
+ * once per trip, by `process-service.ts`, carrying the node, the runner, the
70
+ * addons it hosted and the crash count that tripped the breaker.
71
+ *
72
+ * It exists because a runner marked terminally `failed` used to be SILENT:
73
+ * on 2026-08-18 the `recorder` runner died of three unhandled ffmpeg spawn
74
+ * errors, the breaker stopped respawning it (correctly), `/health` kept
75
+ * returning 200, and fleet-wide recording was gone for 3h15 before the
76
+ * operator's phone told him. The Notification Center's system-event intake
77
+ * consumes this category and maps it to the `addon-crash-loop` kind.
78
+ */
79
+ EventCategory["AddonRunnerFailed"] = "addon.runner-failed";
64
80
  EventCategory["AddonError"] = "addon.error";
65
81
  EventCategory["AddonPageReady"] = "addon.page-ready";
66
82
  EventCategory["AddonWidgetReady"] = "addon.widget-ready";
@@ -16094,6 +16110,7 @@ var NcSystemEventKindSchema = _enum([
16094
16110
  "node-offline",
16095
16111
  "node-inference-unavailable",
16096
16112
  "detection-blind",
16113
+ "addon-crash-loop",
16097
16114
  "addon-update-available",
16098
16115
  "server-update-available",
16099
16116
  "alarm-triggered",
@@ -22013,6 +22030,14 @@ var ClipSchema = object({
22013
22030
  endMs: number()
22014
22031
  }),
22015
22032
  /**
22033
+ * Distinct object classes attached to this visit (`person`, `car`, …),
22034
+ * dominant first, capped at {@link MAX_CLIP_LABELS}. The ribbon renders these
22035
+ * instead of the bare kind — "Object" tells the operator nothing a colour bar
22036
+ * did not. Absent (never empty) when the visit attached no classified object
22037
+ * event, so a motion/audio-only visit keeps its kind label.
22038
+ */
22039
+ labels: array(string()).max(3).optional(),
22040
+ /**
22016
22041
  * Lazy thumbnail URL, never inlined.
22017
22042
  *
22018
22043
  * Recording-derived clips (events-mode keep-window, and the prepared
@@ -36448,6 +36473,303 @@ function maskUrlCredentials(rawUrl) {
36448
36473
  return rawUrl;
36449
36474
  }
36450
36475
  }
36476
+ var MB = 1024 * 1024;
36477
+ var DEFAULT_POOL_MEMORY_POLICY = {
36478
+ sampleIntervalMs: 6e4,
36479
+ baselineSettleSamples: 5,
36480
+ baselineSampleCount: 3,
36481
+ restartMultiple: 4,
36482
+ floorBytes: 1024 * MB,
36483
+ ceilingBytes: 3072 * MB,
36484
+ cooldownMs: 30 * 6e4,
36485
+ maxRestartsPerWindow: 6,
36486
+ restartWindowMs: 1440 * 6e4
36487
+ };
36488
+ /**
36489
+ * Resolve the policy from env overrides (`CAMSTACK_POOL_MEM_*`). Garbage or
36490
+ * absent values keep the default — an operator typo must never disable the
36491
+ * bound or set it to zero.
36492
+ */
36493
+ function resolvePoolMemoryPolicy(env) {
36494
+ const num = (key, fallback, min) => {
36495
+ const raw = env[key];
36496
+ if (raw === void 0) return fallback;
36497
+ const parsed = Number(raw);
36498
+ return Number.isFinite(parsed) && parsed >= min ? parsed : fallback;
36499
+ };
36500
+ const d = DEFAULT_POOL_MEMORY_POLICY;
36501
+ return {
36502
+ sampleIntervalMs: num("CAMSTACK_POOL_MEM_INTERVAL_MS", d.sampleIntervalMs, 5e3),
36503
+ baselineSettleSamples: d.baselineSettleSamples,
36504
+ baselineSampleCount: d.baselineSampleCount,
36505
+ restartMultiple: num("CAMSTACK_POOL_MEM_MULTIPLE", d.restartMultiple, 1.5),
36506
+ floorBytes: num("CAMSTACK_POOL_MEM_FLOOR_MB", d.floorBytes / MB, 128) * MB,
36507
+ ceilingBytes: num("CAMSTACK_POOL_MEM_CEILING_MB", d.ceilingBytes / MB, 256) * MB,
36508
+ cooldownMs: num("CAMSTACK_POOL_MEM_COOLDOWN_MS", d.cooldownMs, 6e4),
36509
+ maxRestartsPerWindow: num("CAMSTACK_POOL_MEM_MAX_RESTARTS", d.maxRestartsPerWindow, 1),
36510
+ restartWindowMs: num("CAMSTACK_POOL_MEM_RESTART_WINDOW_MS", d.restartWindowMs, 6e4)
36511
+ };
36512
+ }
36513
+ /** Parse the fields this watchdog needs out of `/proc/<pid>/status` text.
36514
+ * Returns null when VmRSS is missing (dead pid, kernel thread, bad read). */
36515
+ function parseProcStatus(text) {
36516
+ const kb = (label) => {
36517
+ const match = text.match(new RegExp(`^${label}:\\s+(\\d+)\\s*kB`, "m"));
36518
+ return match ? Number(match[1]) * 1024 : null;
36519
+ };
36520
+ const rssBytes = kb("VmRSS");
36521
+ if (rssBytes === null) return null;
36522
+ const threadsMatch = text.match(/^Threads:\s+(\d+)/m);
36523
+ return {
36524
+ rssBytes,
36525
+ vmBytes: kb("VmSize") ?? 0,
36526
+ hwmBytes: kb("VmHWM") ?? 0,
36527
+ swapBytes: kb("VmSwap") ?? 0,
36528
+ threads: threadsMatch ? Number(threadsMatch[1]) : 0
36529
+ };
36530
+ }
36531
+ function initialPoolMemoryState() {
36532
+ return {
36533
+ settleSeen: 0,
36534
+ baselineWindow: [],
36535
+ baselineBytes: null,
36536
+ restartsAt: [],
36537
+ lastRestartAt: null
36538
+ };
36539
+ }
36540
+ function median(values) {
36541
+ const sorted = [...values].sort((a, b) => a - b);
36542
+ return sorted[Math.floor(sorted.length / 2)];
36543
+ }
36544
+ function advanceBaseline(state, rssBytes, policy) {
36545
+ if (state.baselineBytes !== null) return state;
36546
+ if (state.settleSeen < policy.baselineSettleSamples) return {
36547
+ ...state,
36548
+ settleSeen: state.settleSeen + 1
36549
+ };
36550
+ const window = [...state.baselineWindow, rssBytes];
36551
+ if (window.length < policy.baselineSampleCount) return {
36552
+ ...state,
36553
+ baselineWindow: window
36554
+ };
36555
+ return {
36556
+ ...state,
36557
+ baselineWindow: window,
36558
+ baselineBytes: median(window)
36559
+ };
36560
+ }
36561
+ /** The one place a pool's restart threshold is computed. */
36562
+ function poolMemoryThreshold(baselineBytes, policy) {
36563
+ if (baselineBytes === null) return policy.ceilingBytes;
36564
+ return Math.min(policy.ceilingBytes, Math.max(policy.floorBytes, policy.restartMultiple * baselineBytes));
36565
+ }
36566
+ function pruneRestarts(restartsAt, nowMs, policy) {
36567
+ return restartsAt.filter((t) => nowMs - t < policy.restartWindowMs);
36568
+ }
36569
+ /**
36570
+ * Evaluate one RSS sample. Pure: returns the successor state plus the verdict.
36571
+ * The caller performs (and logs) the restart, then commits it via
36572
+ * {@link commitWatchdogRestart}.
36573
+ */
36574
+ function evaluatePoolMemory(state, rssBytes, nowMs, policy) {
36575
+ const next = advanceBaseline(state, rssBytes, policy);
36576
+ const thresholdBytes = poolMemoryThreshold(next.baselineBytes, policy);
36577
+ if (rssBytes <= thresholdBytes) return {
36578
+ state: next,
36579
+ action: next.baselineBytes === null ? "baseline-pending" : "ok",
36580
+ baselineBytes: next.baselineBytes,
36581
+ thresholdBytes
36582
+ };
36583
+ const inWindow = pruneRestarts(next.restartsAt, nowMs, policy);
36584
+ const pruned = {
36585
+ ...next,
36586
+ restartsAt: inWindow
36587
+ };
36588
+ if (inWindow.length >= policy.maxRestartsPerWindow) return {
36589
+ state: pruned,
36590
+ action: "exhausted",
36591
+ baselineBytes: next.baselineBytes,
36592
+ thresholdBytes
36593
+ };
36594
+ if (pruned.lastRestartAt !== null && nowMs - pruned.lastRestartAt < policy.cooldownMs) return {
36595
+ state: pruned,
36596
+ action: "cooldown",
36597
+ baselineBytes: next.baselineBytes,
36598
+ thresholdBytes
36599
+ };
36600
+ return {
36601
+ state: pruned,
36602
+ action: "restart",
36603
+ baselineBytes: next.baselineBytes,
36604
+ thresholdBytes
36605
+ };
36606
+ }
36607
+ /** Record a performed watchdog restart: budget consumed, baseline reset —
36608
+ * the recreated pool is a NEW process and gets a fresh settle window. */
36609
+ function commitWatchdogRestart(state, nowMs) {
36610
+ return {
36611
+ ...initialPoolMemoryState(),
36612
+ restartsAt: [...state.restartsAt, nowMs],
36613
+ lastRestartAt: nowMs
36614
+ };
36615
+ }
36616
+ /** Reset baseline tracking (pool process replaced OUTSIDE the watchdog —
36617
+ * kernel OOM kill + respawn, idle-reaper eviction, tuning respawn). The
36618
+ * restart budget is kept: it bounds the WATCHDOG, not the pool. */
36619
+ function resetPoolBaseline(state) {
36620
+ return {
36621
+ ...initialPoolMemoryState(),
36622
+ restartsAt: state.restartsAt,
36623
+ lastRestartAt: state.lastRestartAt
36624
+ };
36625
+ }
36626
+ /**
36627
+ * Pick ONE pool to restart this sweep — the worst overage ratio. Restarting
36628
+ * several pools at once (e.g. after a model rollout grew every baseline)
36629
+ * would take detection down on every camera simultaneously; one per sweep
36630
+ * means the survivors keep serving while the worst offender reloads, and the
36631
+ * next sweep (one interval later) takes the next one.
36632
+ */
36633
+ function pickRestartCandidate(candidates) {
36634
+ if (candidates.length === 0) return null;
36635
+ let worst = candidates[0];
36636
+ for (const c of candidates) if (c.rssBytes / c.thresholdBytes > worst.rssBytes / worst.thresholdBytes) worst = c;
36637
+ return worst.key;
36638
+ }
36639
+ var PoolMemoryWatchdog = class {
36640
+ pools = /* @__PURE__ */ new Map();
36641
+ timer = null;
36642
+ sweeping = false;
36643
+ stopped = false;
36644
+ opts;
36645
+ now;
36646
+ setTimer;
36647
+ clearTimer;
36648
+ constructor(opts) {
36649
+ this.opts = opts;
36650
+ this.now = opts.now ?? (() => Date.now());
36651
+ this.setTimer = opts.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
36652
+ this.clearTimer = opts.clearTimer ?? ((t) => clearTimeout(t));
36653
+ }
36654
+ start() {
36655
+ if (this.timer || this.stopped) return;
36656
+ this.arm();
36657
+ }
36658
+ stop() {
36659
+ this.stopped = true;
36660
+ if (this.timer) {
36661
+ this.clearTimer(this.timer);
36662
+ this.timer = null;
36663
+ }
36664
+ }
36665
+ arm() {
36666
+ const timer = this.setTimer(() => {
36667
+ this.sweep().finally(() => {
36668
+ if (!this.stopped) this.arm();
36669
+ });
36670
+ }, this.opts.policy.sampleIntervalMs);
36671
+ if (typeof timer.unref === "function") timer.unref();
36672
+ this.timer = timer;
36673
+ }
36674
+ /** One sweep: sample → log every pool → restart at most one. Public so the
36675
+ * loop is testable without fake global timers. */
36676
+ async sweep() {
36677
+ if (this.sweeping) return;
36678
+ this.sweeping = true;
36679
+ try {
36680
+ await this.doSweep();
36681
+ } catch (err) {
36682
+ this.opts.log.warn("pool memory sweep failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
36683
+ } finally {
36684
+ this.sweeping = false;
36685
+ }
36686
+ }
36687
+ async doSweep() {
36688
+ const nowMs = this.now();
36689
+ const samples = await this.opts.sample();
36690
+ const candidates = [];
36691
+ const verdictByKey = /* @__PURE__ */ new Map();
36692
+ for (const t of samples) {
36693
+ const tracked = this.pools.get(t.key);
36694
+ let state = tracked?.state ?? initialPoolMemoryState();
36695
+ if (tracked && tracked.pids.length > 0 && !samePids(tracked.pids, t.pids)) {
36696
+ this.opts.log.warn("pool process changed outside the watchdog — re-baselining", { meta: {
36697
+ poolKey: t.key,
36698
+ previousPids: tracked.pids,
36699
+ pids: t.pids
36700
+ } });
36701
+ state = resetPoolBaseline(state);
36702
+ }
36703
+ const verdict = evaluatePoolMemory(state, t.rssBytes, nowMs, this.opts.policy);
36704
+ this.pools.set(t.key, {
36705
+ state: verdict.state,
36706
+ pids: t.pids
36707
+ });
36708
+ verdictByKey.set(t.key, verdict);
36709
+ this.opts.log.info("pool memory", { meta: {
36710
+ poolKey: t.key,
36711
+ pids: t.pids,
36712
+ rssMb: Math.round(t.rssBytes / MB),
36713
+ baselineMb: verdict.baselineBytes === null ? null : Math.round(verdict.baselineBytes / MB),
36714
+ thresholdMb: Math.round(verdict.thresholdBytes / MB),
36715
+ action: verdict.action,
36716
+ ...t.meta
36717
+ } });
36718
+ if (verdict.action === "restart") candidates.push({
36719
+ key: t.key,
36720
+ rssBytes: t.rssBytes,
36721
+ thresholdBytes: verdict.thresholdBytes
36722
+ });
36723
+ else if (verdict.action === "cooldown") this.opts.log.warn("pool over memory threshold but inside restart cooldown", { meta: {
36724
+ poolKey: t.key,
36725
+ rssMb: Math.round(t.rssBytes / MB),
36726
+ thresholdMb: Math.round(verdict.thresholdBytes / MB),
36727
+ cooldownMs: this.opts.policy.cooldownMs
36728
+ } });
36729
+ else if (verdict.action === "exhausted") this.opts.log.error("pool memory watchdog gave up — restart budget exhausted, pool leaks faster than restarts can pay for; needs a heap profile (py-spy / tracemalloc)", { meta: {
36730
+ poolKey: t.key,
36731
+ rssMb: Math.round(t.rssBytes / MB),
36732
+ thresholdMb: Math.round(verdict.thresholdBytes / MB),
36733
+ maxRestartsPerWindow: this.opts.policy.maxRestartsPerWindow,
36734
+ restartWindowMs: this.opts.policy.restartWindowMs
36735
+ } });
36736
+ }
36737
+ for (const key of [...this.pools.keys()]) if (!samples.some((t) => t.key === key)) this.pools.delete(key);
36738
+ const pickedKey = pickRestartCandidate(candidates);
36739
+ if (pickedKey === null) return;
36740
+ const picked = candidates.find((c) => c.key === pickedKey);
36741
+ const verdict = verdictByKey.get(pickedKey);
36742
+ const tracked = this.pools.get(pickedKey);
36743
+ const restartsInWindow = tracked.state.restartsAt.length + 1;
36744
+ this.opts.log.warn("pool memory watchdog restarting pool — RSS over threshold", { meta: {
36745
+ poolKey: pickedKey,
36746
+ pids: tracked.pids,
36747
+ rssMb: Math.round(picked.rssBytes / MB),
36748
+ thresholdMb: Math.round(picked.thresholdBytes / MB),
36749
+ baselineMb: verdict.baselineBytes === null ? null : Math.round(verdict.baselineBytes / MB),
36750
+ restartsInWindow,
36751
+ deferredCandidates: candidates.filter((c) => c.key !== pickedKey).map((c) => c.key)
36752
+ } });
36753
+ try {
36754
+ await this.opts.restart(pickedKey);
36755
+ this.pools.set(pickedKey, {
36756
+ state: commitWatchdogRestart(tracked.state, this.now()),
36757
+ pids: []
36758
+ });
36759
+ } catch (err) {
36760
+ this.opts.log.error("pool memory watchdog restart failed", { meta: {
36761
+ poolKey: pickedKey,
36762
+ error: err instanceof Error ? err.message : String(err)
36763
+ } });
36764
+ }
36765
+ }
36766
+ };
36767
+ function samePids(a, b) {
36768
+ if (a.length !== b.length) return false;
36769
+ const sortedA = [...a].sort((x, y) => x - y);
36770
+ const sortedB = [...b].sort((x, y) => x - y);
36771
+ return sortedA.every((v, i) => v === sortedB[i]);
36772
+ }
36451
36773
  /**
36452
36774
  * Fixed-capacity ring buffer. When full, push() overwrites the oldest entry.
36453
36775
  * drain() returns up to maxCount items in FIFO order and removes them.
@@ -36935,6 +37257,12 @@ Object.defineProperty(exports, "OpsLogEntrySchema", {
36935
37257
  return OpsLogEntrySchema;
36936
37258
  }
36937
37259
  });
37260
+ Object.defineProperty(exports, "PoolMemoryWatchdog", {
37261
+ enumerable: true,
37262
+ get: function() {
37263
+ return PoolMemoryWatchdog;
37264
+ }
37265
+ });
36938
37266
  Object.defineProperty(exports, "RATE_CONTROL_RELAXED", {
36939
37267
  enumerable: true,
36940
37268
  get: function() {
@@ -37223,6 +37551,12 @@ Object.defineProperty(exports, "parseJsonUnknown", {
37223
37551
  return parseJsonUnknown;
37224
37552
  }
37225
37553
  });
37554
+ Object.defineProperty(exports, "parseProcStatus", {
37555
+ enumerable: true,
37556
+ get: function() {
37557
+ return parseProcStatus;
37558
+ }
37559
+ });
37226
37560
  Object.defineProperty(exports, "parseProfileBrokerId", {
37227
37561
  enumerable: true,
37228
37562
  get: function() {
@@ -37277,6 +37611,12 @@ Object.defineProperty(exports, "resolveEgressDecodeHwAccel", {
37277
37611
  return resolveEgressDecodeHwAccel;
37278
37612
  }
37279
37613
  });
37614
+ Object.defineProperty(exports, "resolvePoolMemoryPolicy", {
37615
+ enumerable: true,
37616
+ get: function() {
37617
+ return resolvePoolMemoryPolicy;
37618
+ }
37619
+ });
37280
37620
  Object.defineProperty(exports, "resolveRecordingProfiles", {
37281
37621
  enumerable: true,
37282
37622
  get: function() {
@@ -1,4 +1,4 @@
1
- import { H as hfModelUrl, a as COCO_80_LABELS, o as COCO_TO_MACRO, r as AUDIO_MACRO_LABELS } from "./dist-XbrYiMV3.mjs";
1
+ import { U as hfModelUrl, a as COCO_80_LABELS, o as COCO_TO_MACRO, r as AUDIO_MACRO_LABELS } from "./dist-LIWfUNC_.mjs";
2
2
  import { PerformanceObserver } from "node:perf_hooks";
3
3
  //#region src/detection-pipeline/registry/model-catalogs.ts
4
4
  var HF_REPO = "camstack/camstack-models";
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-BbRv3bM2.js");
1
+ const require_dist = require("./dist-w9QWDvWn.js");
2
2
  let node_perf_hooks = require("node:perf_hooks");
3
3
  //#region src/detection-pipeline/registry/model-catalogs.ts
4
4
  var HF_REPO = "camstack/camstack-models";
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-BbRv3bM2.js");
1
+ const require_dist = require("./dist-w9QWDvWn.js");
2
2
  let node_url = require("node:url");
3
3
  let node_module = require("node:module");
4
4
  let node_path = require("node:path");
@@ -2,8 +2,8 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_dist = require("../dist-BbRv3bM2.js");
6
- const require_lazy_sharp = require("../lazy-sharp-U0EtN7_C.js");
5
+ const require_dist = require("../dist-w9QWDvWn.js");
6
+ const require_lazy_sharp = require("../lazy-sharp-BVqBydNU.js");
7
7
  let node_path = require("node:path");
8
8
  let node_fs = require("node:fs");
9
9
  //#region src/motion-wasm/wasm-motion-detector.ts
@@ -1,4 +1,4 @@
1
- import { G as motionDetectionCapability, V as evaluateZoneRules, dt as BaseAddon, gt as hydrateSchema, mt as DeviceType } from "../dist-XbrYiMV3.mjs";
1
+ import { H as evaluateZoneRules, K as motionDetectionCapability, _t as DeviceType, mt as BaseAddon, yt as hydrateSchema } from "../dist-LIWfUNC_.mjs";
2
2
  import { t as getSharp } from "../lazy-sharp-6oymT_yf.mjs";
3
3
  import { join } from "node:path";
4
4
  import { readFileSync } from "node:fs";
@@ -2,11 +2,11 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_dist = require("../dist-BbRv3bM2.js");
6
- const require_event_loop_stall_monitor = require("../event-loop-stall-monitor-D9hqbc68.js");
7
- const require_worker_protocol = require("../worker-protocol-CNC-ZcU3.js");
5
+ const require_dist = require("../dist-w9QWDvWn.js");
6
+ const require_event_loop_stall_monitor = require("../event-loop-stall-monitor-DndI0S2s.js");
7
+ const require_worker_protocol = require("../worker-protocol-DqrXmX0g.js");
8
8
  const require_hub_hostname = require("../hub-hostname-DAJXlOgV.js");
9
- const require_lazy_sharp = require("../lazy-sharp-U0EtN7_C.js");
9
+ const require_lazy_sharp = require("../lazy-sharp-BVqBydNU.js");
10
10
  const require_remote_restream = require("../remote-restream-BYbAsgUf.js");
11
11
  let sharp = require("sharp");
12
12
  sharp = require_dist.__toESM(sharp);
@@ -1,6 +1,6 @@
1
- import { At as literal, Dt as boolean, Et as array, F as deriveDetailCropRect, It as EventCategory, K as pickDetailCropConvention, Mt as object, N as defineCustomActions, Pt as string, Tt as _enum, Y as pipelineRunnerCapability, at as errMsg, bt as nodePin, c as DEFAULT_DETAIL_CROP_CONVENTION, d as DEVICE_BACKEND_TO_FORMAT, dt as BaseAddon, ht as createEvent, j as customAction, jt as number, kt as lazy, q as pickNativeLeaseOverride } from "../dist-XbrYiMV3.mjs";
2
- import { c as getStepDefinition, t as attributeStall } from "../event-loop-stall-monitor-CFWrOZ6G.mjs";
3
- import { a as nativeLeaseSettingEnv, t as isWorkerReply } from "../worker-protocol-D0ewr67U.mjs";
1
+ import { At as boolean, Ct as nodePin, Ft as object, I as deriveDetailCropRect, J as pickDetailCropConvention, Lt as string, M as customAction, Mt as lazy, Nt as literal, Ot as _enum, P as defineCustomActions, Pt as number, Y as pickNativeLeaseOverride, Z as pipelineRunnerCapability, c as DEFAULT_DETAIL_CROP_CONVENTION, ct as errMsg, d as DEVICE_BACKEND_TO_FORMAT, kt as array, mt as BaseAddon, vt as createEvent, zt as EventCategory } from "../dist-LIWfUNC_.mjs";
2
+ import { c as getStepDefinition, t as attributeStall } from "../event-loop-stall-monitor-BDC8qURn.mjs";
3
+ import { a as nativeLeaseSettingEnv, t as isWorkerReply } from "../worker-protocol-DTe7Ntat.mjs";
4
4
  import { t as resolveHubHostname } from "../hub-hostname-cCknRYKj.mjs";
5
5
  import { t as getSharp } from "../lazy-sharp-6oymT_yf.mjs";
6
6
  import { i as withDetectionIntent, n as profileForStreamId, t as isRemoteRestream } from "../remote-restream-Ci7RXNGb.mjs";
@@ -0,0 +1,78 @@
1
+ const require_dist = require("./dist-w9QWDvWn.js");
2
+ let node_child_process = require("node:child_process");
3
+ let node_fs = require("node:fs");
4
+ node_fs = require_dist.__toESM(node_fs);
5
+ //#region src/shared/node-topology-platform.ts
6
+ /**
7
+ * Pick a node's `{ platform, arch }` from the cluster topology. Returns an empty
8
+ * object when the topology is missing or the node is absent (caller falls back).
9
+ */
10
+ function pickNodePlatformArch(topology, nodeId) {
11
+ const entry = topology?.find((n) => n.id === nodeId);
12
+ if (!entry) return {};
13
+ return {
14
+ platform: entry.platform,
15
+ arch: entry.arch
16
+ };
17
+ }
18
+ //#endregion
19
+ //#region src/shared/process-memory.ts
20
+ /**
21
+ * Read a child process's memory footprint for the pool memory watchdog.
22
+ *
23
+ * Linux (the fleet): parse `/proc/<pid>/status` — RSS, VmSize, VmHWM (peak
24
+ * RSS ≈ getrusage maxrss), VmSwap and Threads in one 4 KB read, no exec.
25
+ * macOS (dev only): `ps -o rss=` gives RSS alone; the extended fields read 0.
26
+ *
27
+ * Returns null when the pid is gone or unreadable — the CALLER logs the
28
+ * dropped sample (a pool the watchdog silently stopped seeing is a bound
29
+ * that silently stopped existing).
30
+ *
31
+ * The parse itself (`parseProcStatus`) lives in `@camstack/types` next to the
32
+ * watchdog policy so it is unit-tested once and shared with
33
+ * `addon-post-analysis`, which cannot import this addon. Only the `fs` read
34
+ * lives here.
35
+ */
36
+ var IS_LINUX = process.platform === "linux";
37
+ async function readProcessMemory(pid) {
38
+ if (IS_LINUX) try {
39
+ return require_dist.parseProcStatus(await node_fs.promises.readFile(`/proc/${pid}/status`, "utf8"));
40
+ } catch {
41
+ return null;
42
+ }
43
+ return readViaPs(pid);
44
+ }
45
+ function readViaPs(pid) {
46
+ return new Promise((resolve) => {
47
+ (0, node_child_process.execFile)("ps", [
48
+ "-o",
49
+ "rss=",
50
+ "-p",
51
+ String(pid)
52
+ ], { timeout: 2e3 }, (err, stdout) => {
53
+ if (err) return resolve(null);
54
+ const kb = Number(stdout.trim());
55
+ if (!Number.isFinite(kb) || kb <= 0) return resolve(null);
56
+ resolve({
57
+ rssBytes: kb * 1024,
58
+ vmBytes: 0,
59
+ hwmBytes: 0,
60
+ swapBytes: 0,
61
+ threads: 0
62
+ });
63
+ });
64
+ });
65
+ }
66
+ //#endregion
67
+ Object.defineProperty(exports, "pickNodePlatformArch", {
68
+ enumerable: true,
69
+ get: function() {
70
+ return pickNodePlatformArch;
71
+ }
72
+ });
73
+ Object.defineProperty(exports, "readProcessMemory", {
74
+ enumerable: true,
75
+ get: function() {
76
+ return readProcessMemory;
77
+ }
78
+ });
@@ -0,0 +1,66 @@
1
+ import { q as parseProcStatus } from "./dist-LIWfUNC_.mjs";
2
+ import { execFile } from "node:child_process";
3
+ import * as fs from "node:fs";
4
+ //#region src/shared/node-topology-platform.ts
5
+ /**
6
+ * Pick a node's `{ platform, arch }` from the cluster topology. Returns an empty
7
+ * object when the topology is missing or the node is absent (caller falls back).
8
+ */
9
+ function pickNodePlatformArch(topology, nodeId) {
10
+ const entry = topology?.find((n) => n.id === nodeId);
11
+ if (!entry) return {};
12
+ return {
13
+ platform: entry.platform,
14
+ arch: entry.arch
15
+ };
16
+ }
17
+ //#endregion
18
+ //#region src/shared/process-memory.ts
19
+ /**
20
+ * Read a child process's memory footprint for the pool memory watchdog.
21
+ *
22
+ * Linux (the fleet): parse `/proc/<pid>/status` — RSS, VmSize, VmHWM (peak
23
+ * RSS ≈ getrusage maxrss), VmSwap and Threads in one 4 KB read, no exec.
24
+ * macOS (dev only): `ps -o rss=` gives RSS alone; the extended fields read 0.
25
+ *
26
+ * Returns null when the pid is gone or unreadable — the CALLER logs the
27
+ * dropped sample (a pool the watchdog silently stopped seeing is a bound
28
+ * that silently stopped existing).
29
+ *
30
+ * The parse itself (`parseProcStatus`) lives in `@camstack/types` next to the
31
+ * watchdog policy so it is unit-tested once and shared with
32
+ * `addon-post-analysis`, which cannot import this addon. Only the `fs` read
33
+ * lives here.
34
+ */
35
+ var IS_LINUX = process.platform === "linux";
36
+ async function readProcessMemory(pid) {
37
+ if (IS_LINUX) try {
38
+ return parseProcStatus(await fs.promises.readFile(`/proc/${pid}/status`, "utf8"));
39
+ } catch {
40
+ return null;
41
+ }
42
+ return readViaPs(pid);
43
+ }
44
+ function readViaPs(pid) {
45
+ return new Promise((resolve) => {
46
+ execFile("ps", [
47
+ "-o",
48
+ "rss=",
49
+ "-p",
50
+ String(pid)
51
+ ], { timeout: 2e3 }, (err, stdout) => {
52
+ if (err) return resolve(null);
53
+ const kb = Number(stdout.trim());
54
+ if (!Number.isFinite(kb) || kb <= 0) return resolve(null);
55
+ resolve({
56
+ rssBytes: kb * 1024,
57
+ vmBytes: 0,
58
+ hwmBytes: 0,
59
+ swapBytes: 0,
60
+ threads: 0
61
+ });
62
+ });
63
+ });
64
+ }
65
+ //#endregion
66
+ export { pickNodePlatformArch as n, readProcessMemory as t };