@camstack/addon-pipeline 1.2.132 → 1.2.133
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/{addon-utils-DzCn6z7v.js → addon-utils-FV2O25id.js} +1 -1
- package/dist/audio-analyzer/index.js +3 -3
- package/dist/audio-analyzer/index.mjs +2 -2
- package/dist/detection-pipeline/index.js +5 -5
- package/dist/detection-pipeline/index.mjs +3 -3
- package/dist/{dist-BZYUUBUx.mjs → dist-7Uc6NdFm.mjs} +653 -65
- package/dist/{dist-DBP47QOz.js → dist-DsnZUYTs.js} +670 -64
- package/dist/{event-loop-stall-monitor-CiH_MHfO.js → event-loop-stall-monitor-D86J6d2c.js} +1 -1
- package/dist/{event-loop-stall-monitor-IACE22fK.mjs → event-loop-stall-monitor-XzDMVU9d.mjs} +1 -1
- package/dist/{lazy-sharp-B_kETjyQ.js → lazy-sharp-UzEUL79V.js} +1 -1
- package/dist/motion-wasm/index.js +2 -2
- package/dist/motion-wasm/index.mjs +1 -1
- package/dist/pipeline-runner/index.js +4 -4
- package/dist/pipeline-runner/index.mjs +3 -3
- package/dist/{process-memory-C7rsraCR.mjs → process-memory-Ci90-zF_.mjs} +1 -1
- package/dist/{process-memory-CtXQAA3d.js → process-memory-Co59RQIK.js} +1 -1
- package/dist/recorder/index.js +446 -86
- package/dist/recorder/index.mjs +445 -85
- package/dist/{segment-demux-js-BL1UDdiI.mjs → segment-demux-js-0NZ9TXro.mjs} +1 -1
- package/dist/{segment-demux-js-wTzFi5UW.js → segment-demux-js-DKcc0bxA.js} +1 -1
- package/dist/session-decode/decode-worker-child.js +195 -13
- package/dist/session-decode/decode-worker-child.mjs +194 -12
- package/dist/stream-broker/_stub.js +2 -2
- package/dist/stream-broker/{_virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-DlKJZ-_M.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-Dqj2f3H7.mjs} +3 -3
- package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-CVBnNONy.mjs +26 -0
- package/dist/stream-broker/{_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-BUw_aTfK.mjs → _virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-77rGxv1J.mjs} +1 -1
- package/dist/stream-broker/demux-worker-child.js +1 -1
- package/dist/stream-broker/demux-worker-child.mjs +1 -1
- package/dist/stream-broker/{hostInit-kDKgfUjp.mjs → hostInit-DnwyBL4I.mjs} +3 -3
- package/dist/stream-broker/index.js +2 -2
- package/dist/stream-broker/index.mjs +2 -2
- package/dist/stream-broker/remoteEntry.js +1 -1
- package/dist/{worker-protocol-Cut8984B.mjs → worker-protocol-CMDUAqvX.mjs} +12 -6
- package/dist/{worker-protocol-C3zaz0Jv.js → worker-protocol-DzRUHIcM.js} +12 -6
- package/package.json +1 -1
- package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DXKTNEae.mjs +0 -26
package/dist/recorder/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const require_dist = require("../dist-
|
|
1
|
+
const require_dist = require("../dist-DsnZUYTs.js");
|
|
2
2
|
const require_hub_hostname = require("../hub-hostname-DAJXlOgV.js");
|
|
3
3
|
const require_restream_intent = require("../restream-intent-Cv9x3jmu.js");
|
|
4
|
-
const require_addon_utils = require("../addon-utils-
|
|
4
|
+
const require_addon_utils = require("../addon-utils-FV2O25id.js");
|
|
5
5
|
const require_retire_root_keys = require("../retire-root-keys-KE6D6Xh_.js");
|
|
6
6
|
let node_crypto = require("node:crypto");
|
|
7
7
|
let node_child_process = require("node:child_process");
|
|
@@ -33,6 +33,185 @@ function subscribeEventCapture(deps) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
//#endregion
|
|
36
|
+
//#region src/recorder/object-trigger.ts
|
|
37
|
+
/**
|
|
38
|
+
* Il gate fra `pipeline-analytics.detection-event` e "apri una finestra di
|
|
39
|
+
* registrazione".
|
|
40
|
+
*
|
|
41
|
+
* Fratello di `recorder/event-capture.ts` e per lo stesso motivo: la qualifica
|
|
42
|
+
* ha dei rami, e un ramo che scarta lavoro senza dirlo è indistinguibile da una
|
|
43
|
+
* funzione mai cablata. Ogni verdetto negativo NOMINA il motivo, e il chiamante
|
|
44
|
+
* lo logga.
|
|
45
|
+
*
|
|
46
|
+
* Puro: nessun bus, nessun orologio, nessuna config. La scelta di QUALI classi
|
|
47
|
+
* ascoltare è della banda (`bandTriggerSources`); qui si decide solo se
|
|
48
|
+
* l'evento è una detection utilizzabile e di che macro classe è.
|
|
49
|
+
*/
|
|
50
|
+
/** Type guard, non cast: `event.data` è `unknown` finché non passa di qui. */
|
|
51
|
+
function isDetectionEventData(value) {
|
|
52
|
+
if (typeof value !== "object" || value === null) return false;
|
|
53
|
+
if (!("deviceId" in value) || typeof value.deviceId !== "number") return false;
|
|
54
|
+
if (!("kind" in value) || typeof value.kind !== "string") return false;
|
|
55
|
+
if (!("timestamp" in value) || typeof value.timestamp !== "number") return false;
|
|
56
|
+
if (!Number.isFinite(value.timestamp) || value.timestamp <= 0) return false;
|
|
57
|
+
if (!("className" in value) || typeof value.className !== "string") return false;
|
|
58
|
+
if ("source" in value && value.source !== void 0 && typeof value.source !== "string") return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
function qualifyObjectTrigger(data) {
|
|
62
|
+
if (!isDetectionEventData(data)) return {
|
|
63
|
+
qualified: false,
|
|
64
|
+
reason: "malformed"
|
|
65
|
+
};
|
|
66
|
+
if (data.kind !== "object") return {
|
|
67
|
+
qualified: false,
|
|
68
|
+
reason: "not-object"
|
|
69
|
+
};
|
|
70
|
+
if ((data.source ?? "pipeline") !== "pipeline") return {
|
|
71
|
+
qualified: false,
|
|
72
|
+
reason: "not-pipeline"
|
|
73
|
+
};
|
|
74
|
+
const className = data.className.trim().toLowerCase();
|
|
75
|
+
if (!require_dist.isFirstLevelMacroClass(className)) return {
|
|
76
|
+
qualified: false,
|
|
77
|
+
reason: "not-a-macro"
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
qualified: true,
|
|
81
|
+
deviceId: data.deviceId,
|
|
82
|
+
macroClass: className,
|
|
83
|
+
atMs: data.timestamp
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/recorder/sensor-trigger.ts
|
|
88
|
+
/**
|
|
89
|
+
* Da `DeviceStateChanged` a "quali camere devono registrare".
|
|
90
|
+
*
|
|
91
|
+
* Due responsabilità, entrambe in RAM e nessuna durevole:
|
|
92
|
+
* - la MEMORIA del fronte, per `(deviceId, capName)`, che rende `false→true`
|
|
93
|
+
* distinguibile da una ri-emissione. Il predicato è `evaluateSensorEdge`
|
|
94
|
+
* (`@camstack/types`) — la stessa tabella `SOURCE_CAP_ACTIVE_FIELD` del
|
|
95
|
+
* virtual-doorbell, non una copia;
|
|
96
|
+
* - l'INDICE INVERSO sorgente→camere, uno stato rispecchiato aggiornato FUORI
|
|
97
|
+
* dal percorso dell'evento (D49): `setBindings` è chiamato al boot dalle
|
|
98
|
+
* config già lette e a ogni `onConfigChanged`, che è un'RPC. Una lettura
|
|
99
|
+
* fallibile sul percorso del trigger potrebbe rispondere "nessuno ascolta"
|
|
100
|
+
* e perdere l'episodio, che è il fallimento contro cui D49 è scritta.
|
|
101
|
+
*
|
|
102
|
+
* L'ordine dei controlli è deliberato: `DeviceStateChanged` viaggia a ritmo di
|
|
103
|
+
* bus su tutta la flotta (batteria, la `motion` nativa di ogni camera, la
|
|
104
|
+
* connettività). L'indice inverso è una `Map.get` senza allocazioni e va per
|
|
105
|
+
* primo; il fronte — che legge due tabelle e la slice — viene dopo. È la stessa
|
|
106
|
+
* scelta che post-analysis scrive per la sua sottoscrizione: *"the
|
|
107
|
+
* EVENT_KIND_BY_CAP gate runs FIRST so non-sensor cap churn exits before any
|
|
108
|
+
* async work"*.
|
|
109
|
+
*
|
|
110
|
+
* Puro rispetto al mondo: nessun bus, nessun logger, nessun orologio proprio.
|
|
111
|
+
* Il chiamante logga il verdetto — un ramo che non accende nulla lo DICE.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Type GUARD, not a cast: `event.data` is `unknown`, and a version-skewed
|
|
115
|
+
* emitter must leave this router untouched rather than route a `deviceId` of
|
|
116
|
+
* `undefined`. Same discipline as `parseTopologySnapshotNodes`.
|
|
117
|
+
*
|
|
118
|
+
* A missing or non-object `slice` is REFUSED rather than defaulted to `{}`:
|
|
119
|
+
* `evaluateSensorEdge` would read `non-boolean-value` from an empty object and
|
|
120
|
+
* that would look like a sensor reporting nonsense, when what actually
|
|
121
|
+
* happened is that there was nothing to read.
|
|
122
|
+
*/
|
|
123
|
+
function parseSensorStateChanged(data) {
|
|
124
|
+
if (typeof data !== "object" || data === null) return null;
|
|
125
|
+
if (!("deviceId" in data) || typeof data.deviceId !== "number") return null;
|
|
126
|
+
if (!("capName" in data) || typeof data.capName !== "string") return null;
|
|
127
|
+
if (!("slice" in data) || typeof data.slice !== "object" || data.slice === null) return null;
|
|
128
|
+
const slice = { ...data.slice };
|
|
129
|
+
return {
|
|
130
|
+
deviceId: data.deviceId,
|
|
131
|
+
capName: data.capName,
|
|
132
|
+
slice
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* sourceDeviceId → cameras whose config names it.
|
|
137
|
+
*
|
|
138
|
+
* From EVERY band, not only the one active now: the index only changes on a
|
|
139
|
+
* config write, while the active band changes with the clock, and an index
|
|
140
|
+
* that followed the clock would lose the first trigger after every band edge.
|
|
141
|
+
* Filtering by band is already the gate's job — `bandTriggerSources` reads the
|
|
142
|
+
* band active at the instant of evaluation.
|
|
143
|
+
*
|
|
144
|
+
* A disabled camera is skipped: it records nothing whatever a sensor does, and
|
|
145
|
+
* it re-enters through `onConfigChanged`, which rebuilds this.
|
|
146
|
+
*/
|
|
147
|
+
function buildSensorTriggerBindings(configs) {
|
|
148
|
+
const index = /* @__PURE__ */ new Map();
|
|
149
|
+
for (const [cameraId, config] of configs) {
|
|
150
|
+
if (config.enabled !== true) continue;
|
|
151
|
+
for (const band of config.bands ?? []) for (const sourceDeviceId of band.triggers?.sensorDeviceIds ?? []) {
|
|
152
|
+
const cameras = index.get(sourceDeviceId) ?? /* @__PURE__ */ new Set();
|
|
153
|
+
cameras.add(cameraId);
|
|
154
|
+
index.set(sourceDeviceId, cameras);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return index;
|
|
158
|
+
}
|
|
159
|
+
var SensorTriggerRouter = class {
|
|
160
|
+
/** sourceDeviceId → camere la cui config lo nomina. */
|
|
161
|
+
bindings = /* @__PURE__ */ new Map();
|
|
162
|
+
/** Ultimo booleano osservato, per `${deviceId}:${capName}`. */
|
|
163
|
+
lastValues = /* @__PURE__ */ new Map();
|
|
164
|
+
now;
|
|
165
|
+
startedAtMs;
|
|
166
|
+
freshnessMs;
|
|
167
|
+
constructor(options) {
|
|
168
|
+
this.now = options.now;
|
|
169
|
+
this.startedAtMs = options.startedAtMs;
|
|
170
|
+
this.freshnessMs = options.firstSightingFreshnessMs ?? 3e4;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Sostituisce l'indice inverso. NON tocca `lastValues`: un sensore tolto e
|
|
174
|
+
* rimesso in una banda deve ritrovare il suo livello precedente, altrimenti
|
|
175
|
+
* la prima slice dopo il rientro sarebbe una "prima osservazione" e un
|
|
176
|
+
* contatto rimasto aperto tutto il tempo diventerebbe un fronte alto.
|
|
177
|
+
*/
|
|
178
|
+
setBindings(bindings) {
|
|
179
|
+
this.bindings = bindings;
|
|
180
|
+
}
|
|
181
|
+
/** Quali sorgenti l'indice contiene ora — per la riga di log al boot. */
|
|
182
|
+
listenedSourceIds() {
|
|
183
|
+
return [...this.bindings.keys()];
|
|
184
|
+
}
|
|
185
|
+
onStateSlice(deviceId, capName, slice) {
|
|
186
|
+
const cameras = this.bindings.get(deviceId);
|
|
187
|
+
if (cameras === void 0 || cameras.size === 0) return {
|
|
188
|
+
fired: [],
|
|
189
|
+
skipped: "not-listened"
|
|
190
|
+
};
|
|
191
|
+
const key = `${deviceId}:${capName}`;
|
|
192
|
+
const verdict = require_dist.evaluateSensorEdge({
|
|
193
|
+
capName,
|
|
194
|
+
slice,
|
|
195
|
+
prior: this.lastValues.get(key),
|
|
196
|
+
startedAtMs: this.startedAtMs,
|
|
197
|
+
nowMs: this.now(),
|
|
198
|
+
firstSightingFreshnessMs: this.freshnessMs
|
|
199
|
+
});
|
|
200
|
+
if (verdict.edge === "none") {
|
|
201
|
+
if (verdict.value !== null) this.lastValues.set(key, verdict.value);
|
|
202
|
+
return {
|
|
203
|
+
fired: [],
|
|
204
|
+
skipped: verdict.reason
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
this.lastValues.set(key, true);
|
|
208
|
+
return {
|
|
209
|
+
fired: [...cameras],
|
|
210
|
+
skipped: null
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
//#endregion
|
|
36
215
|
//#region src/recorder/event-map.ts
|
|
37
216
|
var EventMap = class {
|
|
38
217
|
byDevice = /* @__PURE__ */ new Map();
|
|
@@ -7743,17 +7922,47 @@ function eventsBandCanEverDemand(band) {
|
|
|
7743
7922
|
return bandTriggerSources(band).length > 0 && resolveBandBufferMs(band).postMs > 0;
|
|
7744
7923
|
}
|
|
7745
7924
|
/**
|
|
7925
|
+
* La chiave sotto cui una sorgente conserva le sue finestre. È anche la stringa
|
|
7926
|
+
* che compare nei log — quattro sorgenti che aprono la stessa finestra senza
|
|
7927
|
+
* dire chi è stato rendono impossibile rispondere a "perché questa camera
|
|
7928
|
+
* registra tanto" — quindi è leggibile per progetto.
|
|
7929
|
+
*/
|
|
7930
|
+
function triggerKey(source) {
|
|
7931
|
+
switch (source.kind) {
|
|
7932
|
+
case "motion": return "motion";
|
|
7933
|
+
case "audio": return "audio";
|
|
7934
|
+
case "object": return `object:${source.macroClass}`;
|
|
7935
|
+
case "sensor": return `sensor:${source.sourceDeviceId}`;
|
|
7936
|
+
}
|
|
7937
|
+
}
|
|
7938
|
+
/**
|
|
7746
7939
|
* LE sorgenti che questa banda ascolta — l'unico posto dove i `triggers` di
|
|
7747
|
-
* una banda diventano `TriggerSource[]`.
|
|
7748
|
-
*
|
|
7749
|
-
*
|
|
7940
|
+
* una banda diventano `TriggerSource[]`.
|
|
7941
|
+
*
|
|
7942
|
+
* Prima erano CINQUE copie dello stesso if-ladder motion/audio
|
|
7943
|
+
* (`eventsBandCanEverDemand`, `eventsBandDemanded`, `segmentRetainedForEvents`,
|
|
7944
|
+
* `segmentMissedByMs`, `eventsWindowCloseMs`), che con quattro sorgenti
|
|
7945
|
+
* sarebbero diventate cinque scale a quattro rami. `RecordingController`
|
|
7946
|
+
* (`reportUnrecordable`, la riconciliazione durevole) legge la stessa lista.
|
|
7947
|
+
*
|
|
7948
|
+
* Una chiave in {@link UNFED_TRIGGER_KEYS} non produce sorgenti: la banda che
|
|
7949
|
+
* ascolta solo quella "non può mai chiedere", ed è così che il recorder la
|
|
7950
|
+
* denuncia invece di restare zitto.
|
|
7750
7951
|
*/
|
|
7751
7952
|
function bandTriggerSources(band) {
|
|
7752
7953
|
const t = band.triggers;
|
|
7753
7954
|
if (t === void 0) return [];
|
|
7754
7955
|
const sources = [];
|
|
7755
|
-
if (t.motion === true) sources.push("motion");
|
|
7756
|
-
if (t.audioThresholdDbfs !== void 0) sources.push("audio");
|
|
7956
|
+
if (t.motion === true) sources.push({ kind: "motion" });
|
|
7957
|
+
if (t.audioThresholdDbfs !== void 0) sources.push({ kind: "audio" });
|
|
7958
|
+
for (const macroClass of t.objectClasses ?? []) sources.push({
|
|
7959
|
+
kind: "object",
|
|
7960
|
+
macroClass
|
|
7961
|
+
});
|
|
7962
|
+
for (const sourceDeviceId of t.sensorDeviceIds ?? []) sources.push({
|
|
7963
|
+
kind: "sensor",
|
|
7964
|
+
sourceDeviceId
|
|
7965
|
+
});
|
|
7757
7966
|
return sources;
|
|
7758
7967
|
}
|
|
7759
7968
|
/**
|
|
@@ -7782,10 +7991,7 @@ function audioLevelQualifies(band, dbfs) {
|
|
|
7782
7991
|
return threshold !== void 0 && dbfs >= threshold;
|
|
7783
7992
|
}
|
|
7784
7993
|
/** No trigger has been seen for this device yet. */
|
|
7785
|
-
var EMPTY_TRIGGER_STATE = {
|
|
7786
|
-
motion: [],
|
|
7787
|
-
audio: []
|
|
7788
|
-
};
|
|
7994
|
+
var EMPTY_TRIGGER_STATE = { windows: /* @__PURE__ */ new Map() };
|
|
7789
7995
|
/**
|
|
7790
7996
|
* How long a window is retained PAST the end of its own keep span
|
|
7791
7997
|
* (`lastMs + postBufferSec`).
|
|
@@ -7797,18 +8003,21 @@ var EMPTY_TRIGGER_STATE = {
|
|
|
7797
8003
|
* room to spare, while bounding a busy camera to a handful of windows.
|
|
7798
8004
|
*/
|
|
7799
8005
|
var TRIGGER_HISTORY_MARGIN_MS = 12e4;
|
|
7800
|
-
/** The windows for a source, in the order they opened.
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
8006
|
+
/** The windows for a source, in the order they opened. Empty when the source
|
|
8007
|
+
* has never fired — an absent key and a source with no history are the same
|
|
8008
|
+
* fact, and only one of them is ever stored. */
|
|
8009
|
+
function triggerWindowsFor(state, source) {
|
|
8010
|
+
return state.windows.get(triggerKey(source)) ?? [];
|
|
8011
|
+
}
|
|
8012
|
+
/** Replace one source's windows. An EMPTY list deletes the key rather than
|
|
8013
|
+
* storing a zero-length array: that is what bounds the map when an operator
|
|
8014
|
+
* removes a sensor from a band. */
|
|
7804
8015
|
function withWindows(state, source, windows) {
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
audio: windows
|
|
7811
|
-
};
|
|
8016
|
+
const next = new Map(state.windows);
|
|
8017
|
+
const key = triggerKey(source);
|
|
8018
|
+
if (windows.length === 0) next.delete(key);
|
|
8019
|
+
else next.set(key, windows);
|
|
8020
|
+
return { windows: next };
|
|
7812
8021
|
}
|
|
7813
8022
|
/**
|
|
7814
8023
|
* Fold one qualifying trigger into the history, immutably. It EXTENDS the newest
|
|
@@ -7820,7 +8029,7 @@ function withWindows(state, source, windows) {
|
|
|
7820
8029
|
* predates the episode, so the keep span can only ever grow.
|
|
7821
8030
|
*/
|
|
7822
8031
|
function recordTrigger(state, source, atMs, mergeGapMs) {
|
|
7823
|
-
const windows =
|
|
8032
|
+
const windows = triggerWindowsFor(state, source);
|
|
7824
8033
|
const newest = windows[windows.length - 1];
|
|
7825
8034
|
const merged = newest !== void 0 && atMs - newest.lastMs <= mergeGapMs && atMs >= newest.firstMs - mergeGapMs ? [...windows.slice(0, -1), {
|
|
7826
8035
|
firstMs: Math.min(newest.firstMs, atMs),
|
|
@@ -7843,18 +8052,18 @@ function recordTrigger(state, source, atMs, mergeGapMs) {
|
|
|
7843
8052
|
*/
|
|
7844
8053
|
function pruneTriggerHistory(state, postMs, nowMs) {
|
|
7845
8054
|
const cutoffMs = nowMs - postMs - TRIGGER_HISTORY_MARGIN_MS;
|
|
7846
|
-
const
|
|
7847
|
-
|
|
7848
|
-
const
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
};
|
|
8055
|
+
const next = /* @__PURE__ */ new Map();
|
|
8056
|
+
let changed = false;
|
|
8057
|
+
for (const [key, windows] of state.windows) {
|
|
8058
|
+
const live = windows.filter((w) => w.lastMs >= cutoffMs);
|
|
8059
|
+
if (live.length !== windows.length) changed = true;
|
|
8060
|
+
if (live.length > 0) next.set(key, live);
|
|
8061
|
+
}
|
|
8062
|
+
return changed ? { windows: next } : state;
|
|
7854
8063
|
}
|
|
7855
8064
|
/** Most recent trigger for a source, or null when none is retained. */
|
|
7856
8065
|
function latestTriggerMs(state, source) {
|
|
7857
|
-
const windows =
|
|
8066
|
+
const windows = triggerWindowsFor(state, source);
|
|
7858
8067
|
return windows[windows.length - 1]?.lastMs ?? null;
|
|
7859
8068
|
}
|
|
7860
8069
|
/**
|
|
@@ -7864,10 +8073,10 @@ function latestTriggerMs(state, source) {
|
|
|
7864
8073
|
*/
|
|
7865
8074
|
function eventsBandDemanded(band, triggers, atMs) {
|
|
7866
8075
|
const { postMs } = resolveBandBufferMs(band);
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
8076
|
+
return bandTriggerSources(band).some((source) => {
|
|
8077
|
+
const lastMs = latestTriggerMs(triggers, source);
|
|
8078
|
+
return lastMs !== null && atMs - lastMs <= postMs;
|
|
8079
|
+
});
|
|
7871
8080
|
}
|
|
7872
8081
|
/**
|
|
7873
8082
|
* Should recording (any mode) be active for this device at `at`? The live
|
|
@@ -7938,9 +8147,7 @@ function segmentRetainedForEvents(segStartMs, segEndMs, band, triggers, attach)
|
|
|
7938
8147
|
if (segStartMs <= window.lastMs + postMs) return true;
|
|
7939
8148
|
return attach.attachedAtMs <= window.lastMs + postMs && segStartMs <= deadlineMs;
|
|
7940
8149
|
};
|
|
7941
|
-
|
|
7942
|
-
if (band.triggers?.audioThresholdDbfs != null && triggers.audio.some(overlaps)) return true;
|
|
7943
|
-
return false;
|
|
8150
|
+
return bandTriggerSources(band).some((source) => triggerWindowsFor(triggers, source).some(overlaps));
|
|
7944
8151
|
}
|
|
7945
8152
|
/**
|
|
7946
8153
|
* By how many ms a discarded segment missed being kept — its start past the
|
|
@@ -7962,7 +8169,7 @@ function segmentMissedByMs(segStartMs, band, triggers, attach) {
|
|
|
7962
8169
|
const windowEndMs = window.lastMs + postMs;
|
|
7963
8170
|
return attach.attachedAtMs <= windowEndMs ? Math.max(windowEndMs, deadlineMs) : windowEndMs;
|
|
7964
8171
|
};
|
|
7965
|
-
const considered =
|
|
8172
|
+
const considered = bandTriggerSources(band).flatMap((source) => [...triggerWindowsFor(triggers, source)]);
|
|
7966
8173
|
if (considered.length === 0) return null;
|
|
7967
8174
|
return segStartMs - Math.max(...considered.map(latestKeptStart));
|
|
7968
8175
|
}
|
|
@@ -7996,10 +8203,10 @@ function foldDurableTriggers(state, source, timestamps, mergeGapMs) {
|
|
|
7996
8203
|
let recovered = 0;
|
|
7997
8204
|
let evicted = 0;
|
|
7998
8205
|
for (const atMs of rows) {
|
|
7999
|
-
const before =
|
|
8206
|
+
const before = triggerWindowsFor(next, source);
|
|
8000
8207
|
const folded = recordTrigger(next, source, atMs, mergeGapMs);
|
|
8001
8208
|
evicted += folded.evicted;
|
|
8002
|
-
const after =
|
|
8209
|
+
const after = triggerWindowsFor(folded.state, source);
|
|
8003
8210
|
if (folded.evicted > 0 || after.length !== before.length || after.some((w, i) => w.firstMs !== before[i]?.firstMs || w.lastMs !== before[i]?.lastMs)) recovered++;
|
|
8004
8211
|
next = folded.state;
|
|
8005
8212
|
}
|
|
@@ -8146,12 +8353,7 @@ function nextBandEdgeMs(config, nowMs) {
|
|
|
8146
8353
|
function eventsWindowCloseMs(band, triggers, nowMs) {
|
|
8147
8354
|
if (band.mode !== "events") return null;
|
|
8148
8355
|
const { postMs } = resolveBandBufferMs(band);
|
|
8149
|
-
const
|
|
8150
|
-
const motionMs = latestTriggerMs(triggers, "motion");
|
|
8151
|
-
const audioMs = latestTriggerMs(triggers, "audio");
|
|
8152
|
-
if (band.triggers?.motion === true && motionMs != null) ends.push(motionMs + postMs);
|
|
8153
|
-
if (band.triggers?.audioThresholdDbfs != null && audioMs != null) ends.push(audioMs + postMs);
|
|
8154
|
-
const open = ends.filter((ms) => ms >= nowMs);
|
|
8356
|
+
const open = bandTriggerSources(band).map((source) => latestTriggerMs(triggers, source)).filter((ms) => ms !== null).map((ms) => ms + postMs).filter((ms) => ms >= nowMs);
|
|
8155
8357
|
if (open.length === 0) return null;
|
|
8156
8358
|
return Math.max(...open) + 1;
|
|
8157
8359
|
}
|
|
@@ -9417,44 +9619,78 @@ var RecordingController = class {
|
|
|
9417
9619
|
* of it is discarded and the footage is gone for ever — durable state resting
|
|
9418
9620
|
* on telemetry, which D8/D11 forbid.
|
|
9419
9621
|
*
|
|
9420
|
-
*
|
|
9421
|
-
*
|
|
9422
|
-
*
|
|
9622
|
+
* ## Which sources it covers, and which it does NOT
|
|
9623
|
+
*
|
|
9624
|
+
* MOTION and OBJECT-DETECTION. Both have a durable counterpart at the same
|
|
9625
|
+
* granularity the bus carries — `pipelineAnalytics.getMotionEvents` and
|
|
9626
|
+
* `getObjectEvents` — so a dropped event is recoverable from rows.
|
|
9627
|
+
*
|
|
9628
|
+
* AUDIO and SENSOR are NOT covered, and that is a stated gap, not an
|
|
9629
|
+
* oversight:
|
|
9630
|
+
* - audio has no per-window durable row the recorder can ask for;
|
|
9631
|
+
* - `SensorEvent` rows exist but are LEVEL, not EDGE (a contact closing
|
|
9632
|
+
* writes a row exactly like one opening), and they carry the taxonomy
|
|
9633
|
+
* `kind`, not the `capName` that `SOURCE_CAP_ACTIVE_FIELD` is indexed by.
|
|
9634
|
+
* The inversion was MEASURED on 2026-08-27 rather than eyeballed:
|
|
9635
|
+
* `CAP_TO_KIND` (`types/capabilities/sensor-event-kinds.ts`) has no two
|
|
9636
|
+
* caps sharing a kind, so `kind → capName` is invertible — but `binary`,
|
|
9637
|
+
* a source cap, has NO entry in it at all, so a `binary` sensor's edges
|
|
9638
|
+
* never reach the `SensorEvent` table and could never be recovered. A
|
|
9639
|
+
* reconcile covering nine source caps out of ten reads as covering all
|
|
9640
|
+
* ten, which is the failure this whole comment exists to avoid.
|
|
9641
|
+
*
|
|
9642
|
+
* A reconcile that silently covered some sources and not others would read as
|
|
9643
|
+
* covering all of them, so it is named here and the un-covered sources are
|
|
9644
|
+
* simply skipped — never faked.
|
|
9423
9645
|
*
|
|
9424
9646
|
* Never throws: this runs at the head of the reconcile beat and an escape
|
|
9425
9647
|
* here would cancel the evaluate for the whole device.
|
|
9426
9648
|
*/
|
|
9427
9649
|
async reconcileTriggerHistory(deviceId) {
|
|
9428
|
-
const
|
|
9429
|
-
|
|
9650
|
+
const loadMotion = this.deps.loadMotionEvents;
|
|
9651
|
+
const loadObject = this.deps.loadObjectEvents;
|
|
9652
|
+
if (loadMotion === void 0 && loadObject === void 0 || this.stopped) return;
|
|
9430
9653
|
try {
|
|
9431
9654
|
const config = await this.deps.loadConfig(deviceId);
|
|
9432
9655
|
if (config.enabled !== true) return;
|
|
9433
9656
|
const nowMs = this.now();
|
|
9434
9657
|
const band = activeBandAt({ bands: config.bands ?? [] }, new Date(nowMs));
|
|
9435
|
-
if (!band || band.mode !== "events"
|
|
9658
|
+
if (!band || band.mode !== "events") return;
|
|
9436
9659
|
const { postMs } = resolveBandBufferMs(band);
|
|
9437
9660
|
const sinceMs = nowMs - postMs - TRIGGER_HISTORY_MARGIN_MS;
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
const
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9661
|
+
/** Durable rows for one source, or null when that source has no durable
|
|
9662
|
+
* half (audio, sensor) or its loader was not injected. */
|
|
9663
|
+
const durableRowsFor = async (source) => {
|
|
9664
|
+
if (source.kind === "motion") return loadMotion === void 0 ? null : await loadMotion(deviceId, sinceMs, nowMs);
|
|
9665
|
+
if (source.kind === "object") return loadObject === void 0 ? null : await loadObject(deviceId, source.macroClass, sinceMs, nowMs);
|
|
9666
|
+
return null;
|
|
9667
|
+
};
|
|
9668
|
+
for (const source of bandTriggerSources(band)) {
|
|
9669
|
+
if (this.stopped) return;
|
|
9670
|
+
const rows = await durableRowsFor(source);
|
|
9671
|
+
if (rows === null || rows.length === 0) continue;
|
|
9672
|
+
if (this.stopped) return;
|
|
9673
|
+
const folded = foldDurableTriggers(pruneTriggerHistory(this.triggersFor(deviceId), postMs, this.now()), source, rows, postMs);
|
|
9674
|
+
this.triggers.set(deviceId, folded.state);
|
|
9675
|
+
if (folded.recovered > 0) this.deps.logger.info("recorder: trigger windows recovered from the durable rows — the bus had not delivered them", {
|
|
9676
|
+
tags: { deviceId },
|
|
9677
|
+
meta: {
|
|
9678
|
+
source: triggerKey(source),
|
|
9679
|
+
rows: rows.length,
|
|
9680
|
+
recovered: folded.recovered,
|
|
9681
|
+
sinceMs,
|
|
9682
|
+
postMs
|
|
9683
|
+
}
|
|
9684
|
+
});
|
|
9685
|
+
if (folded.evicted > 0) this.deps.logger.warn("recorder: trigger history full during reconcile — oldest window(s) evicted", {
|
|
9686
|
+
tags: { deviceId },
|
|
9687
|
+
meta: {
|
|
9688
|
+
source: triggerKey(source),
|
|
9689
|
+
evicted: folded.evicted,
|
|
9690
|
+
maxWindows: 32
|
|
9691
|
+
}
|
|
9692
|
+
});
|
|
9693
|
+
}
|
|
9458
9694
|
} catch (err) {
|
|
9459
9695
|
this.deps.logger.warn("recorder: trigger reconcile failed — retries on the next beat", {
|
|
9460
9696
|
tags: { deviceId },
|
|
@@ -9621,7 +9857,7 @@ var RecordingController = class {
|
|
|
9621
9857
|
if (receivedLagMs > TRIGGER_LAG_WARN_MS) this.deps.logger.warn("recorder: trigger arrived late — part of its window is already spent", {
|
|
9622
9858
|
tags: { deviceId },
|
|
9623
9859
|
meta: {
|
|
9624
|
-
source,
|
|
9860
|
+
source: triggerKey(source),
|
|
9625
9861
|
atMs,
|
|
9626
9862
|
receivedLagMs
|
|
9627
9863
|
}
|
|
@@ -9634,7 +9870,7 @@ var RecordingController = class {
|
|
|
9634
9870
|
this.deps.logger.warn("recorder: trigger attach deferred — stream not available yet (retries on next broker ready/reconcile)", {
|
|
9635
9871
|
tags: { deviceId },
|
|
9636
9872
|
meta: {
|
|
9637
|
-
source,
|
|
9873
|
+
source: triggerKey(source),
|
|
9638
9874
|
atMs,
|
|
9639
9875
|
error: require_dist.errMsg(err)
|
|
9640
9876
|
}
|
|
@@ -9676,7 +9912,7 @@ var RecordingController = class {
|
|
|
9676
9912
|
return;
|
|
9677
9913
|
}
|
|
9678
9914
|
if (!audioLevelQualifies(band, dbfs)) return;
|
|
9679
|
-
await this.onTrigger(deviceId, "audio", atMs);
|
|
9915
|
+
await this.onTrigger(deviceId, { kind: "audio" }, atMs);
|
|
9680
9916
|
}
|
|
9681
9917
|
/**
|
|
9682
9918
|
* The post-buffer that governs this device's trigger history right now: it is
|
|
@@ -9712,7 +9948,7 @@ var RecordingController = class {
|
|
|
9712
9948
|
if (evicted > 0) this.deps.logger.warn("recorder: trigger history full — oldest window(s) evicted, their footage may be discarded", {
|
|
9713
9949
|
tags: { deviceId },
|
|
9714
9950
|
meta: {
|
|
9715
|
-
source,
|
|
9951
|
+
source: triggerKey(source),
|
|
9716
9952
|
atMs,
|
|
9717
9953
|
postMs,
|
|
9718
9954
|
evicted,
|
|
@@ -10157,14 +10393,10 @@ var RecordingController = class {
|
|
|
10157
10393
|
profile,
|
|
10158
10394
|
startMs,
|
|
10159
10395
|
durMs,
|
|
10160
|
-
|
|
10161
|
-
firstMs: w.firstMs,
|
|
10162
|
-
lastMs: w.lastMs
|
|
10163
|
-
})),
|
|
10164
|
-
audioWindows: triggers.audio.map((w) => ({
|
|
10396
|
+
triggerWindows: Object.fromEntries(bandTriggerSources(band).map((source) => [triggerKey(source), triggerWindowsFor(triggers, source).map((w) => ({
|
|
10165
10397
|
firstMs: w.firstMs,
|
|
10166
10398
|
lastMs: w.lastMs
|
|
10167
|
-
})),
|
|
10399
|
+
}))])),
|
|
10168
10400
|
postMs,
|
|
10169
10401
|
preMs,
|
|
10170
10402
|
attachedAtMs: attach.attachedAtMs,
|
|
@@ -11855,6 +12087,28 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
11855
12087
|
* down the same way, idempotent re-entry included.
|
|
11856
12088
|
*/
|
|
11857
12089
|
audioTriggerUnsub = null;
|
|
12090
|
+
/**
|
|
12091
|
+
* Unsubscribe handle for the `PipelineAnalyticsDetectionEvent` subscription —
|
|
12092
|
+
* the feed behind `RecordingTriggers.objectClasses` (Traccia A of the same
|
|
12093
|
+
* plan). Same guard/teardown discipline as the two above.
|
|
12094
|
+
*/
|
|
12095
|
+
detectionTriggerUnsub = null;
|
|
12096
|
+
/**
|
|
12097
|
+
* Unsubscribe handle for the `DeviceStateChanged` subscription — the feed
|
|
12098
|
+
* behind `RecordingTriggers.sensorDeviceIds` (Traccia B).
|
|
12099
|
+
*/
|
|
12100
|
+
sensorTriggerUnsub = null;
|
|
12101
|
+
/**
|
|
12102
|
+
* Edge memory + reverse index (source device → cameras) for the sensor
|
|
12103
|
+
* trigger. Constructed once per addon instance: `startedAtMs` is the floor a
|
|
12104
|
+
* first-sighting rise must beat, and a fresh instance per boot is exactly
|
|
12105
|
+
* what makes a runner respawn err towards silence rather than record 30 s
|
|
12106
|
+
* per camera on every hydrated contact.
|
|
12107
|
+
*/
|
|
12108
|
+
sensorRouter = new SensorTriggerRouter({
|
|
12109
|
+
now: () => Date.now(),
|
|
12110
|
+
startedAtMs: Date.now()
|
|
12111
|
+
});
|
|
11858
12112
|
/** Resolved recordings locations (id + root). Refreshed on boot + rescan.
|
|
11859
12113
|
* Already ALIAS-GUARDED: a writable same-type duplicate of another
|
|
11860
12114
|
* location's physical root arrives here demoted to read-only. */
|
|
@@ -12070,6 +12324,29 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12070
12324
|
projection: "slim"
|
|
12071
12325
|
})).map((event) => event.timestamp);
|
|
12072
12326
|
},
|
|
12327
|
+
/**
|
|
12328
|
+
* The DURABLE half of the OBJECT source. Same shape as `loadMotionEvents`
|
|
12329
|
+
* — SQLite rows instead of a broadcast, one call per macro class because
|
|
12330
|
+
* `TriggerState` keys per class and the store filters server-side.
|
|
12331
|
+
*
|
|
12332
|
+
* `projection: 'full'` and NOT `'slim'`, deliberately: `SLIM_OBJECT_COLUMNS`
|
|
12333
|
+
* (`addon-post-analysis/.../store/event-store.ts`) does not carry `source`,
|
|
12334
|
+
* and the filter below reads an absent `source` as `pipeline` — so a slim
|
|
12335
|
+
* read would fold ONBOARD rows, re-opening from SQL exactly the windows
|
|
12336
|
+
* `qualifyObjectTrigger` refuses on the live path. Two truths about one
|
|
12337
|
+
* detection, which is what this whole track exists to avoid. The extra
|
|
12338
|
+
* cost is bounded: only bands that actually list `objectClasses` reach
|
|
12339
|
+
* here, `classFilter` narrows to one class, and `limit` caps the rows.
|
|
12340
|
+
*/
|
|
12341
|
+
loadObjectEvents: async (deviceId, macroClass, sinceMs, untilMs) => {
|
|
12342
|
+
return (await this.ctx.api.pipelineAnalytics.getObjectEvents.query({
|
|
12343
|
+
deviceId,
|
|
12344
|
+
since: sinceMs,
|
|
12345
|
+
until: untilMs,
|
|
12346
|
+
classFilter: macroClass,
|
|
12347
|
+
limit: TRIGGER_RECONCILE_ROW_LIMIT
|
|
12348
|
+
})).filter((event) => (event.source ?? "pipeline") === "pipeline").map((event) => event.timestamp);
|
|
12349
|
+
},
|
|
12073
12350
|
locations: () => this.resolvedLocations,
|
|
12074
12351
|
placeProfile: (deviceId, profile) => this.placeProfile(deviceId, profile),
|
|
12075
12352
|
onPlacementTick: (deviceIds) => this.recomputePlacement(deviceIds),
|
|
@@ -12137,7 +12414,10 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12137
12414
|
calendar: this.calendar,
|
|
12138
12415
|
mfraFor: (deviceId, profile, startMs) => this.mfraTables.get(deviceId, profile, startMs),
|
|
12139
12416
|
hydrateWindow: (deviceId, fromMs, toMs) => hydrateWindowFromStorage(this.index, deviceId, fromMs, toMs, this.resolvedLocations, this.ctx.logger),
|
|
12140
|
-
onConfigChanged: (deviceId) =>
|
|
12417
|
+
onConfigChanged: async (deviceId) => {
|
|
12418
|
+
await this.refreshSensorTriggerBindings();
|
|
12419
|
+
await (this.controller?.onConfigChanged(deviceId) ?? Promise.resolve());
|
|
12420
|
+
},
|
|
12141
12421
|
pauseForStorageMigration: (leaseId) => this.pauseForStorageMigration(leaseId),
|
|
12142
12422
|
resumeForStorageMigration: (leaseId) => this.resumeForStorageMigration(leaseId),
|
|
12143
12423
|
refreshStorageLocationsForMigration: (leaseId) => this.refreshStorageLocationsForMigration(leaseId),
|
|
@@ -12328,6 +12608,10 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12328
12608
|
this.eventUnsub = null;
|
|
12329
12609
|
this.audioTriggerUnsub?.();
|
|
12330
12610
|
this.audioTriggerUnsub = null;
|
|
12611
|
+
this.detectionTriggerUnsub?.();
|
|
12612
|
+
this.detectionTriggerUnsub = null;
|
|
12613
|
+
this.sensorTriggerUnsub?.();
|
|
12614
|
+
this.sensorTriggerUnsub = null;
|
|
12331
12615
|
await this.controller?.stop();
|
|
12332
12616
|
this.controller = null;
|
|
12333
12617
|
this.segmentStore = null;
|
|
@@ -12399,7 +12683,7 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12399
12683
|
padPreMs: MARKER_PAD_PRE_MS,
|
|
12400
12684
|
padPostMs: MARKER_PAD_POST_MS,
|
|
12401
12685
|
onMotion: (deviceId, atMs) => {
|
|
12402
|
-
this.controller?.onTrigger(deviceId, "motion", atMs);
|
|
12686
|
+
this.controller?.onTrigger(deviceId, { kind: "motion" }, atMs);
|
|
12403
12687
|
}
|
|
12404
12688
|
});
|
|
12405
12689
|
if (this.audioTriggerUnsub === null) this.audioTriggerUnsub = this.ctx.eventBus.subscribe({ category: require_dist.EventCategory.PipelineAudioInferenceResult }, (event) => {
|
|
@@ -12407,6 +12691,48 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12407
12691
|
if (dbfs === void 0) return;
|
|
12408
12692
|
this.controller?.onAudioLevel(event.data.deviceId, dbfs, event.data.frame.timestamp);
|
|
12409
12693
|
});
|
|
12694
|
+
if (this.detectionTriggerUnsub === null) this.detectionTriggerUnsub = this.ctx.eventBus.subscribe({ category: require_dist.EventCategory.PipelineAnalyticsDetectionEvent }, (event) => {
|
|
12695
|
+
const verdict = qualifyObjectTrigger(event.data);
|
|
12696
|
+
if (!verdict.qualified) {
|
|
12697
|
+
this.ctx.logger.debug("recorder: detection event did not qualify as a trigger", { meta: { reason: verdict.reason } });
|
|
12698
|
+
return;
|
|
12699
|
+
}
|
|
12700
|
+
this.controller?.onTrigger(verdict.deviceId, {
|
|
12701
|
+
kind: "object",
|
|
12702
|
+
macroClass: verdict.macroClass
|
|
12703
|
+
}, verdict.atMs);
|
|
12704
|
+
});
|
|
12705
|
+
if (this.sensorTriggerUnsub === null) {
|
|
12706
|
+
await this.refreshSensorTriggerBindings();
|
|
12707
|
+
this.sensorTriggerUnsub = this.ctx.eventBus.subscribe({ category: require_dist.EventCategory.DeviceStateChanged }, (event) => {
|
|
12708
|
+
const parsed = parseSensorStateChanged(event.data);
|
|
12709
|
+
if (parsed === null) return;
|
|
12710
|
+
const atMs = event.timestamp instanceof Date ? event.timestamp.getTime() : Date.now();
|
|
12711
|
+
const result = this.sensorRouter.onStateSlice(parsed.deviceId, parsed.capName, parsed.slice);
|
|
12712
|
+
for (const cameraId of result.fired) {
|
|
12713
|
+
this.ctx.logger.info("recorder: sensor rising edge opened a recording window", {
|
|
12714
|
+
tags: { deviceId: cameraId },
|
|
12715
|
+
meta: {
|
|
12716
|
+
sourceDeviceId: parsed.deviceId,
|
|
12717
|
+
capName: parsed.capName
|
|
12718
|
+
}
|
|
12719
|
+
});
|
|
12720
|
+
this.controller?.onTrigger(cameraId, {
|
|
12721
|
+
kind: "sensor",
|
|
12722
|
+
sourceDeviceId: parsed.deviceId
|
|
12723
|
+
}, atMs);
|
|
12724
|
+
}
|
|
12725
|
+
if (result.skipped === null || result.skipped === "not-listened") return;
|
|
12726
|
+
const level = result.skipped === "baseline-seeded-stale-active" ? "warn" : "debug";
|
|
12727
|
+
this.ctx.logger[level]("recorder: sensor state change opened no window", {
|
|
12728
|
+
tags: { deviceId: parsed.deviceId },
|
|
12729
|
+
meta: {
|
|
12730
|
+
capName: parsed.capName,
|
|
12731
|
+
reason: result.skipped
|
|
12732
|
+
}
|
|
12733
|
+
});
|
|
12734
|
+
});
|
|
12735
|
+
}
|
|
12410
12736
|
try {
|
|
12411
12737
|
await this.segmentHours?.load();
|
|
12412
12738
|
this.segmentHours?.hydrateIndex(this.index);
|
|
@@ -12420,6 +12746,7 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12420
12746
|
this.ctx.logger.warn("recorder: reading persisted device configs failed — skipping hydrate", { meta: { error: require_dist.errMsg(err) } });
|
|
12421
12747
|
return;
|
|
12422
12748
|
}
|
|
12749
|
+
this.applySensorTriggerBindings(configs);
|
|
12423
12750
|
this.warmToday([...configs.keys()]);
|
|
12424
12751
|
this.ctx.logger.info("recorder: full-archive index walk skipped", { meta: {
|
|
12425
12752
|
reason: "on-demand-windows",
|
|
@@ -12438,6 +12765,39 @@ var RecorderV2Addon = class extends require_dist.BaseAddon {
|
|
|
12438
12765
|
this.retentionSweeper?.start();
|
|
12439
12766
|
}
|
|
12440
12767
|
/**
|
|
12768
|
+
* Rebuild the sensor trigger's reverse index from the persisted configs.
|
|
12769
|
+
*
|
|
12770
|
+
* D49: this is a MIRROR refreshed off the event path — at boot and on every
|
|
12771
|
+
* config write (an RPC that cannot be dropped), never from a fallible read
|
|
12772
|
+
* while a `DeviceStateChanged` is being routed.
|
|
12773
|
+
*
|
|
12774
|
+
* A failed read leaves the PREVIOUS index standing and says so. An index that
|
|
12775
|
+
* emptied itself on a transient store failure would answer "nobody listens"
|
|
12776
|
+
* to every sensor edge until the next config write — silently, and that is
|
|
12777
|
+
* precisely the "a read that fails changes nothing" half of D49.
|
|
12778
|
+
*/
|
|
12779
|
+
async refreshSensorTriggerBindings() {
|
|
12780
|
+
try {
|
|
12781
|
+
this.applySensorTriggerBindings(await readDeviceConfigs(this.configStore()));
|
|
12782
|
+
} catch (err) {
|
|
12783
|
+
this.ctx.logger.warn("recorder: sensor trigger index NOT refreshed — config read failed, the previous index stands", { meta: { error: require_dist.errMsg(err) } });
|
|
12784
|
+
}
|
|
12785
|
+
}
|
|
12786
|
+
/** Apply an already-read config map to the sensor index. Logs only when the
|
|
12787
|
+
* set of listened sources CHANGED — a config write that touches something
|
|
12788
|
+
* else must not print a line that reads as a rewiring. */
|
|
12789
|
+
applySensorTriggerBindings(configs) {
|
|
12790
|
+
const before = [...this.sensorRouter.listenedSourceIds()].toSorted((a, b) => a - b);
|
|
12791
|
+
const bindings = buildSensorTriggerBindings(configs);
|
|
12792
|
+
this.sensorRouter.setBindings(bindings);
|
|
12793
|
+
const after = [...bindings.keys()].toSorted((a, b) => a - b);
|
|
12794
|
+
if (before.length === after.length && before.every((id, i) => id === after[i])) return;
|
|
12795
|
+
this.ctx.logger.info("recorder: sensor trigger index rebuilt", { meta: {
|
|
12796
|
+
sourceDeviceIds: after,
|
|
12797
|
+
cameras: configs.size
|
|
12798
|
+
} });
|
|
12799
|
+
}
|
|
12800
|
+
/**
|
|
12441
12801
|
* Resume interrupted exports and arm the expiry sweep.
|
|
12442
12802
|
*
|
|
12443
12803
|
* The resume itself lives in `export-reconcile.ts` — pure, tested, and loud
|