@trillboards/edge-sdk 0.2.245 → 0.2.253

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 (134) hide show
  1. package/deploy/detector/bench/detect_frames.py +88 -0
  2. package/deploy/detector/bench/openvino_parity.py +152 -0
  3. package/deploy/detector/pyproject.toml +10 -1
  4. package/deploy/detector/tests/test_actor_tracking.py +168 -0
  5. package/deploy/detector/tests/test_actor_tracking_wire.py +22 -0
  6. package/deploy/detector/tests/test_loader.py +25 -0
  7. package/deploy/detector/tests/test_openvino_engines.py +251 -0
  8. package/deploy/detector/tests/test_registry.py +53 -0
  9. package/deploy/detector/tests/test_server.py +43 -0
  10. package/deploy/detector/tests/test_version_stamp.py +17 -4
  11. package/deploy/detector/trillboards_detector/_version.py +2 -2
  12. package/deploy/detector/trillboards_detector/actor_tracking.py +139 -2
  13. package/deploy/detector/trillboards_detector/cli.py +5 -0
  14. package/deploy/detector/trillboards_detector/detections.py +5 -0
  15. package/deploy/detector/trillboards_detector/execution.py +386 -0
  16. package/deploy/detector/trillboards_detector/loader.py +40 -1
  17. package/deploy/detector/trillboards_detector/registry.py +33 -1
  18. package/deploy/detector/trillboards_detector/server.py +43 -1
  19. package/deploy/detector/trillboards_detector/session.py +81 -3
  20. package/deploy/detector/trillboards_detector/track_records.py +113 -0
  21. package/deploy/windows/build-windows.ps1 +1 -0
  22. package/deploy/windows/ci/test-detector-looks-field.ps1 +15 -3
  23. package/deploy/windows/ci/test-detector-reinstall.ps1 +645 -0
  24. package/deploy/windows/ci/test-rollout-proofs.ps1 +3 -2
  25. package/deploy/windows/ensure-detector.ps1 +255 -0
  26. package/deploy/windows/install-update.ps1 +4 -3
  27. package/deploy/windows/setup-detector.ps1 +122 -29
  28. package/deploy/windows/stop-existing.ps1 +1 -0
  29. package/deploy/windows/trillboards-edge.cmd +10 -22
  30. package/dist/ActorTracking.d.ts +38 -0
  31. package/dist/ActorTracking.d.ts.map +1 -1
  32. package/dist/ActorTracking.js +40 -0
  33. package/dist/ActorTracking.js.map +1 -1
  34. package/dist/AlertClips.d.ts +4 -2
  35. package/dist/AlertClips.d.ts.map +1 -1
  36. package/dist/AlertClips.js +24 -9
  37. package/dist/AlertClips.js.map +1 -1
  38. package/dist/CloudSensingManager.d.ts +9 -0
  39. package/dist/CloudSensingManager.d.ts.map +1 -1
  40. package/dist/CloudSensingManager.js +52 -4
  41. package/dist/CloudSensingManager.js.map +1 -1
  42. package/dist/ConnectorStatusClient.d.ts +8 -0
  43. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  44. package/dist/ConnectorStatusClient.js +3 -0
  45. package/dist/ConnectorStatusClient.js.map +1 -1
  46. package/dist/DurableVlmCandidateSpool.d.ts +11 -0
  47. package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
  48. package/dist/DurableVlmCandidateSpool.js +31 -2
  49. package/dist/DurableVlmCandidateSpool.js.map +1 -1
  50. package/dist/EdgeAgent.js +1 -1
  51. package/dist/FrameGroupingShadow.d.ts +57 -0
  52. package/dist/FrameGroupingShadow.d.ts.map +1 -1
  53. package/dist/FrameGroupingShadow.js +123 -5
  54. package/dist/FrameGroupingShadow.js.map +1 -1
  55. package/dist/LocalDetectorClient.d.ts +44 -1
  56. package/dist/LocalDetectorClient.d.ts.map +1 -1
  57. package/dist/LocalDetectorClient.js +88 -4
  58. package/dist/LocalDetectorClient.js.map +1 -1
  59. package/dist/LocalVideoBuffer.d.ts +14 -2
  60. package/dist/LocalVideoBuffer.d.ts.map +1 -1
  61. package/dist/LocalVideoBuffer.js +23 -3
  62. package/dist/LocalVideoBuffer.js.map +1 -1
  63. package/dist/NativeReadiness.d.ts +21 -2
  64. package/dist/NativeReadiness.d.ts.map +1 -1
  65. package/dist/NativeReadiness.js +25 -6
  66. package/dist/NativeReadiness.js.map +1 -1
  67. package/dist/OrderedReviewClient.d.ts +3 -0
  68. package/dist/OrderedReviewClient.d.ts.map +1 -1
  69. package/dist/OrderedReviewClient.js +3 -0
  70. package/dist/OrderedReviewClient.js.map +1 -1
  71. package/dist/SensingProfileClient.d.ts.map +1 -1
  72. package/dist/SensingProfileClient.js +3 -0
  73. package/dist/SensingProfileClient.js.map +1 -1
  74. package/dist/TemporalReviewClient.d.ts +3 -0
  75. package/dist/TemporalReviewClient.d.ts.map +1 -1
  76. package/dist/TemporalReviewClient.js +3 -0
  77. package/dist/TemporalReviewClient.js.map +1 -1
  78. package/dist/VideoSegmentUploader.d.ts +14 -7
  79. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  80. package/dist/VideoSegmentUploader.js +34 -38
  81. package/dist/VideoSegmentUploader.js.map +1 -1
  82. package/dist/VlmCandidateBuffer.d.ts +13 -0
  83. package/dist/VlmCandidateBuffer.d.ts.map +1 -1
  84. package/dist/VlmCandidateBuffer.js.map +1 -1
  85. package/dist/autoSense.d.ts +4 -0
  86. package/dist/autoSense.d.ts.map +1 -1
  87. package/dist/autoSense.js +7 -0
  88. package/dist/autoSense.js.map +1 -1
  89. package/dist/cli.d.ts.map +1 -1
  90. package/dist/cli.js +3 -0
  91. package/dist/cli.js.map +1 -1
  92. package/dist/connectorUpdate.d.ts +18 -9
  93. package/dist/connectorUpdate.d.ts.map +1 -1
  94. package/dist/connectorUpdate.js +66 -3
  95. package/dist/connectorUpdate.js.map +1 -1
  96. package/dist/connectorUpdateApply.d.ts +20 -1
  97. package/dist/connectorUpdateApply.d.ts.map +1 -1
  98. package/dist/connectorUpdateApply.js +55 -1
  99. package/dist/connectorUpdateApply.js.map +1 -1
  100. package/dist/connectorUpdateApplyMac.d.ts +3 -1
  101. package/dist/connectorUpdateApplyMac.d.ts.map +1 -1
  102. package/dist/connectorUpdateApplyMac.js +6 -0
  103. package/dist/connectorUpdateApplyMac.js.map +1 -1
  104. package/dist/continuousReview.d.ts +6 -2
  105. package/dist/continuousReview.d.ts.map +1 -1
  106. package/dist/continuousReview.js.map +1 -1
  107. package/dist/detectorBackendRelay.d.ts +24 -0
  108. package/dist/detectorBackendRelay.d.ts.map +1 -0
  109. package/dist/detectorBackendRelay.js +70 -0
  110. package/dist/detectorBackendRelay.js.map +1 -0
  111. package/dist/detectorEndpointState.d.ts +30 -0
  112. package/dist/detectorEndpointState.d.ts.map +1 -0
  113. package/dist/detectorEndpointState.js +125 -0
  114. package/dist/detectorEndpointState.js.map +1 -0
  115. package/dist/detectorLauncher.d.ts +23 -0
  116. package/dist/detectorLauncher.d.ts.map +1 -0
  117. package/dist/detectorLauncher.js +94 -0
  118. package/dist/detectorLauncher.js.map +1 -0
  119. package/dist/diagnose.d.ts +1 -1
  120. package/dist/diagnose.js +1 -1
  121. package/dist/localSensing.d.ts +72 -0
  122. package/dist/localSensing.d.ts.map +1 -1
  123. package/dist/localSensing.js +280 -31
  124. package/dist/localSensing.js.map +1 -1
  125. package/dist/pipelineSwitches.d.ts +59 -0
  126. package/dist/pipelineSwitches.d.ts.map +1 -0
  127. package/dist/pipelineSwitches.js +240 -0
  128. package/dist/pipelineSwitches.js.map +1 -0
  129. package/package.json +4 -4
  130. package/retained/ProfileAuthorityClient.cjs +4 -0
  131. package/retained/RetainedCaptureClient.cjs +41 -2
  132. package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
  133. package/retained/__tests__/look-reuse.test.cjs +167 -0
  134. package/retained/manager.cjs +28 -2
@@ -59,6 +59,7 @@ const ProfileReviewWork_1 = require("./ProfileReviewWork");
59
59
  const DetectorFieldProducer_1 = require("./DetectorFieldProducer");
60
60
  const SensingProfileClient_1 = require("./SensingProfileClient");
61
61
  const NativeReadiness_1 = require("./NativeReadiness");
62
+ const detectorEndpointState_1 = require("./detectorEndpointState");
62
63
  const detectorCountReview_1 = require("./detectorCountReview");
63
64
  const jpegFrameSize_1 = require("./jpegFrameSize");
64
65
  const ScopedVlmReview_1 = require("./ScopedVlmReview");
@@ -74,6 +75,7 @@ const SceneMarks_1 = require("./SceneMarks");
74
75
  const CloudSensingManager_1 = require("./CloudSensingManager");
75
76
  const localInferenceSchema_1 = require("./localInferenceSchema");
76
77
  const legacyRecorderProfile_1 = require("./legacyRecorderProfile");
78
+ const pipelineSwitches_1 = require("./pipelineSwitches");
77
79
  const ReviewPriority_1 = require("./ReviewPriority");
78
80
  const ActorActionClient_1 = require("./ActorActionClient");
79
81
  const ActorActionProducer_1 = require("./ActorActionProducer");
@@ -453,8 +455,19 @@ class LocalSensingClient {
453
455
  this.cachedDeclaredProfileReview = false;
454
456
  this.nativeReadyKey = '';
455
457
  this.nativeReadyUntil = 0;
458
+ /** When the current proof was actually proven: a refusal after it suspends it (plan v7 W8 item 2). */
459
+ this.nativeReadyProvenAt = 0;
456
460
  this.nativeRetryAt = 0;
457
461
  this.nativeRetryKey = '';
462
+ /**
463
+ * The key whose /ready is failing now, since when, and whether its last failure may pass on
464
+ * retry (nothing listening, reset, timeout, 503). Cleared by that key's next proof.
465
+ */
466
+ this.nativeFailKey = '';
467
+ this.nativeFailSince = 0;
468
+ this.nativeFailTransient = false;
469
+ /** A key whose bounded wait ended without a proof: its looks take the fallback at once until it is proven. */
470
+ this.nativeWaitSkipKey = '';
458
471
  this.cachedVlmFields = [];
459
472
  this.cachedCascadeArmed = false;
460
473
  /** This feed's parked-vehicle memory per gated field; losing it costs one question. */
@@ -585,6 +598,7 @@ class LocalSensingClient {
585
598
  */
586
599
  this.activeFieldSet = 'audience';
587
600
  this.retainedApiBaseUrl = options.retainedApiBaseUrl;
601
+ this.feedName = options.feedName;
588
602
  if (this.retainedApiBaseUrl !== undefined)
589
603
  (0, continuousReview_1.assertRetainedReviewReceiver)(this.getEndpoint(), this.retainedApiBaseUrl);
590
604
  this.profileClient = options.profileClient;
@@ -897,11 +911,18 @@ class LocalSensingClient {
897
911
  return;
898
912
  }
899
913
  const key = JSON.stringify(request);
900
- if (this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil) {
914
+ const now = Date.now();
915
+ if (this.nativeProofCurrent(key, now)) {
901
916
  this.nativeFailure = undefined;
902
917
  this.applyReviewProfile(profile);
903
918
  return;
904
919
  }
920
+ // Plan v7 W8 item 2: a detector seen working within the restart grace is restarting or
921
+ // preparing. Its failing key pauses and retries; it does not hand the box to Gemma.
922
+ if (this.nativeRestartPaused(key, now)) {
923
+ this.nativeFailure = new NativeReadiness_1.NativeReadinessError('Native readiness: the detector is restarting', 'unavailable');
924
+ return;
925
+ }
905
926
  if (profile.nativeFallback) {
906
927
  this.nativeFailure = undefined;
907
928
  this.applyReviewProfile(profile.nativeFallback);
@@ -909,6 +930,83 @@ class LocalSensingClient {
909
930
  else
910
931
  this.nativeFailure = new NativeReadiness_1.NativeReadinessError(undefined, 'unavailable');
911
932
  }
933
+ /**
934
+ * A proof from this feed's own /ready, inside its expiry, with no refused or reset connection to
935
+ * the detector since: a refusal means the process that loaded those models is gone.
936
+ */
937
+ nativeProofCurrent(key, now) {
938
+ if (this.nativeReadyKey !== key || now >= this.nativeReadyUntil)
939
+ return false;
940
+ const base = this.nativeReadinessProbe.endpointBase;
941
+ return !base || (0, detectorEndpointState_1.detectorEndpointState)(base).refusedAt <= this.nativeReadyProvenAt;
942
+ }
943
+ /**
944
+ * The restart grace (plan v7 W8 item 2): this key's /ready failed in a way that may pass on
945
+ * retry, the detector answered or proved something within NATIVE_RESTART_GRACE_MS (kept on disk
946
+ * across a connector restart), and this key has been failing for less than that. A definite
947
+ * refusal (409, 400, 500, an invalid proof) never pauses: that key takes its fallback as before.
948
+ */
949
+ nativeRestartPaused(key, now) {
950
+ const base = this.nativeReadinessProbe.endpointBase;
951
+ if (!base || this.nativeFailKey !== key || !this.nativeFailTransient)
952
+ return false;
953
+ const { goodAt } = (0, detectorEndpointState_1.detectorEndpointState)(base);
954
+ return goodAt > 0 && now - goodAt < NativeReadiness_1.NATIVE_RESTART_GRACE_MS && now - this.nativeFailSince < NativeReadiness_1.NATIVE_RESTART_GRACE_MS;
955
+ }
956
+ /** The current website profile's native key, or '' when it needs no proof (or cannot be built). */
957
+ currentNativeKey() {
958
+ if (this.invalidWebsiteProfileAuthority || this.nativeAuthorityError)
959
+ return '';
960
+ const profile = this.desiredReviewProfile;
961
+ if (!profile || !this.websiteManagedProfiles || profile.profileState === 'inactive'
962
+ || profile.nativeReadiness?.state === 'unavailable')
963
+ return '';
964
+ try {
965
+ const request = (0, NativeReadiness_1.nativeReadinessRequest)(profile);
966
+ return request ? JSON.stringify(request) : '';
967
+ }
968
+ catch {
969
+ return '';
970
+ }
971
+ }
972
+ startNativeProbe(key, request) {
973
+ if (this.nativePending?.key === key)
974
+ return this.nativePending.promise;
975
+ if (this.nativeRetryKey === key && Date.now() < this.nativeRetryAt)
976
+ return undefined;
977
+ const pending = { key, promise: Promise.resolve() };
978
+ pending.promise = this.nativeReadinessProbe(request).then(until => {
979
+ if (this.nativePending !== pending)
980
+ return;
981
+ const now = Date.now(), known = typeof until === 'number' && Number.isFinite(until);
982
+ this.nativeReadyKey = key;
983
+ this.nativeReadyUntil = known ? until : now + NativeReadiness_1.NATIVE_READINESS_TTL_MS;
984
+ // A coalesced proof was made when its expiry says, not when this feed heard of it.
985
+ this.nativeReadyProvenAt = known ? Math.min(now, until - NativeReadiness_1.NATIVE_READINESS_TTL_MS) : now;
986
+ if (this.nativeFailKey === key)
987
+ this.nativeFailKey = '';
988
+ if (this.nativeWaitSkipKey === key)
989
+ this.nativeWaitSkipKey = '';
990
+ }, error => {
991
+ if (this.nativePending !== pending)
992
+ return;
993
+ const now = Date.now();
994
+ this.nativeRetryKey = key;
995
+ this.nativeRetryAt = now + 1000;
996
+ if (this.nativeFailKey !== key) {
997
+ this.nativeFailKey = key;
998
+ this.nativeFailSince = now;
999
+ }
1000
+ this.nativeFailTransient = error?.transient === true;
1001
+ }).finally(() => {
1002
+ if (this.nativePending === pending)
1003
+ this.nativePending = undefined;
1004
+ // A delayed proof may select only the CURRENT profile, never a preceding policy.
1005
+ this.selectCaptureProfile();
1006
+ });
1007
+ this.nativePending = pending;
1008
+ return pending.promise;
1009
+ }
912
1010
  async prepareNativeCapture() {
913
1011
  if (this.invalidWebsiteProfileAuthority || this.nativeAuthorityError)
914
1012
  return;
@@ -924,34 +1022,107 @@ class LocalSensingClient {
924
1022
  // A current proof is renewed in its last NATIVE_READINESS_RENEW_MS, in the background, by
925
1023
  // the next look: a lapse between two looks paused new evidence (and parked the feed on the
926
1024
  // health heartbeat) although the detector was ready throughout. A failed renewal proves
927
- // nothing new, so it revokes nothing: the current proof still lapses at its own expiry.
928
- const proven = this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil;
929
- if (proven && Date.now() < this.nativeReadyUntil - NativeReadiness_1.NATIVE_READINESS_RENEW_MS)
1025
+ // nothing new, so it revokes nothing: the current proof still lapses at its own expiry
1026
+ // (or at a refused connection, which means the detector process went away).
1027
+ const now = Date.now();
1028
+ const proven = this.nativeProofCurrent(key, now);
1029
+ if (proven && now < this.nativeReadyUntil - NativeReadiness_1.NATIVE_READINESS_RENEW_MS)
930
1030
  return;
931
- if (!this.nativePending || this.nativePending.key !== key) {
932
- if (this.nativeRetryKey === key && Date.now() < this.nativeRetryAt)
933
- return;
934
- const pending = { key, promise: Promise.resolve() };
935
- pending.promise = this.nativeReadinessProbe(request).then(until => {
936
- if (this.nativePending === pending) {
937
- this.nativeReadyKey = key;
938
- this.nativeReadyUntil = typeof until === 'number' && Number.isFinite(until) ? until : Date.now() + NativeReadiness_1.NATIVE_READINESS_TTL_MS;
939
- }
940
- }, () => { if (this.nativePending === pending) {
941
- this.nativeRetryKey = key;
942
- this.nativeRetryAt = Date.now() + 1000;
943
- } }).finally(() => {
944
- if (this.nativePending === pending)
945
- this.nativePending = undefined;
946
- // A delayed proof may select only the CURRENT profile, never a preceding policy.
947
- this.selectCaptureProfile();
948
- });
949
- this.nativePending = pending;
1031
+ const pending = this.startNativeProbe(key, request);
1032
+ // A current proof never waits for its renewal. A valid authorized Gemma projection never
1033
+ // waits for a cold native session here; a look waits, bounded, in awaitNativeProof. A feed
1034
+ // paused for a detector restart waits, so its retry resolves on the proof.
1035
+ if (!proven && (!profile.nativeFallback || this.nativeRestartPaused(key, now)))
1036
+ await pending;
1037
+ }
1038
+ /**
1039
+ * Plan v7 W8 item 2, called by a look before it captures. A proof that is not current (or
1040
+ * lapses within 2 s) is re-proven by a real /ready, waiting at most NATIVE_PROOF_WAIT_MS:
1041
+ * a 16.5 s gap between looks, or the first look after start, no longer hands the look to
1042
+ * Gemma. Undefined when there is nothing to wait for (no microtask hop on the common path).
1043
+ * Never rejects. A wait that ends without a proof, on a key that is not paused for a
1044
+ * detector restart, lets later looks take the fallback at once until the key is proven.
1045
+ */
1046
+ awaitNativeProof() {
1047
+ const key = this.currentNativeKey();
1048
+ if (!key || this.nativeWaitSkipKey === key)
1049
+ return undefined;
1050
+ const now = Date.now();
1051
+ if (this.nativeProofCurrent(key, now) && now < this.nativeReadyUntil - 2000)
1052
+ return undefined;
1053
+ // A paused key belongs to the feed's own 2 s retry, not to a look.
1054
+ if (this.nativeRestartPaused(key, now))
1055
+ return undefined;
1056
+ let request;
1057
+ try {
1058
+ request = (0, NativeReadiness_1.nativeReadinessRequest)(this.desiredReviewProfile);
1059
+ }
1060
+ catch {
1061
+ return undefined;
950
1062
  }
951
- // A current proof never waits for its renewal. A valid authorized Gemma
952
- // projection never waits for a cold native session.
953
- if (!proven && !profile.nativeFallback)
954
- await this.nativePending?.promise;
1063
+ if (!request)
1064
+ return undefined;
1065
+ const pending = this.startNativeProbe(key, request);
1066
+ if (!pending)
1067
+ return undefined;
1068
+ return new Promise(resolve => {
1069
+ let done = false;
1070
+ const finish = () => {
1071
+ if (done)
1072
+ return;
1073
+ done = true;
1074
+ clearTimeout(timer);
1075
+ const at = Date.now();
1076
+ if (!this.nativeProofCurrent(key, at) && !this.nativeRestartPaused(key, at))
1077
+ this.nativeWaitSkipKey = key;
1078
+ resolve();
1079
+ };
1080
+ const timer = setTimeout(finish, NativeReadiness_1.NATIVE_PROOF_WAIT_MS);
1081
+ timer.unref?.();
1082
+ pending.then(finish, finish);
1083
+ });
1084
+ }
1085
+ /**
1086
+ * True while this feed waits out a detector restart (plan v7 W8 item 2): keep its camera
1087
+ * session live and retry every 2 s, so its first look follows the detector's first answer.
1088
+ */
1089
+ isNativePaused() {
1090
+ const key = this.currentNativeKey();
1091
+ const now = Date.now();
1092
+ return !!key && !this.nativeProofCurrent(key, now) && this.nativeRestartPaused(key, now);
1093
+ }
1094
+ /**
1095
+ * True while this feed's native key has no current proof because the detector is not answering
1096
+ * (refused, reset, timed out or 503: a failure that may pass on retry), inside the restart grace
1097
+ * or after it. The camera wants its looks and the local detector is not giving them, so its
1098
+ * health says `waiting_for_capacity`, not `idle`: the look-stall sweep then judges a detector
1099
+ * that hangs past the grace (a native-only alert camera has no Gemma fallback, so it simply stops
1100
+ * looking) as a camera trying to review, the case a box restart can help. A definite refusal
1101
+ * (409, 400, 500, an invalid proof) stays `idle`, as before.
1102
+ */
1103
+ isNativeDetectorDown() {
1104
+ const key = this.currentNativeKey();
1105
+ return !!key && this.nativeFailKey === key && this.nativeFailTransient && !this.nativeProofCurrent(key, Date.now());
1106
+ }
1107
+ /**
1108
+ * Plan v7 W8 (Windows field run 44153992974, 15 Gemma calls in a swap): a look checks its proof
1109
+ * (awaitNativeProof) before it captures, but the proof can lapse, or be revoked by a refused
1110
+ * connection another feed saw, while the frame is read. When the look then takes its contract,
1111
+ * selectCaptureProfile finds this feed's proven key without a current proof and without a failure
1112
+ * of its own, and hands the look the Gemma fallback. On a proven key the fallback is a look's only
1113
+ * when it was earned: this key failed and is not paused (a definite refusal, or failing past the
1114
+ * restart grace), or a look's bounded wait ended without a proof outside a restart pause.
1115
+ * Otherwise this one look is skipped, as a detector-only camera's is, and the next re-proves the
1116
+ * key before it captures. A key never proven keeps its authorized fallback while its first
1117
+ * preparation is pending, as before.
1118
+ */
1119
+ unearnedNativeFallback() {
1120
+ const key = this.currentNativeKey();
1121
+ if (!key || !this.desiredReviewProfile?.nativeFallback || this.nativeReadyKey !== key)
1122
+ return undefined;
1123
+ if (this.nativeFailKey === key || this.nativeWaitSkipKey === key || this.nativeProofCurrent(key, Date.now()))
1124
+ return undefined;
1125
+ return new NativeReadiness_1.NativeReadinessError('Native readiness: re-proving the detector before this look', 'unavailable');
955
1126
  }
956
1127
  /**
957
1128
  * What the on-device runtime resolved about this host's accelerator (which
@@ -1015,7 +1186,16 @@ class LocalSensingClient {
1015
1186
  /** Explicit inactivity or invalid current native authority pauses new model work. */
1016
1187
  isReviewActive() {
1017
1188
  this.selectCaptureProfile();
1018
- return !this.invalidWebsiteProfileAuthority && !this.nativeAuthorityError && !this.nativeFailure && this.reviewProfileState !== 'inactive';
1189
+ return !this.invalidWebsiteProfileAuthority && !this.nativeAuthorityError && (!this.nativeFailure || this.nativeReprovable()) && this.reviewProfileState !== 'inactive';
1190
+ }
1191
+ /**
1192
+ * A detector-only key whose proof lapsed without its /ready failing: still active, because the
1193
+ * next look re-proves it before capturing (awaitNativeProof). Parking it on a lapse cost a
1194
+ * camera-health heartbeat although the detector was ready throughout.
1195
+ */
1196
+ nativeReprovable() {
1197
+ const key = this.currentNativeKey();
1198
+ return !!key && this.nativeFailKey !== key && this.nativeFailure?.kind === 'unavailable';
1019
1199
  }
1020
1200
  usesWebsiteProfile() {
1021
1201
  return this.websiteManagedProfiles && this.reviewProfileState === 'active';
@@ -1044,6 +1224,9 @@ class LocalSensingClient {
1044
1224
  this.selectCaptureProfile();
1045
1225
  if (this.nativeFailure)
1046
1226
  throw this.nativeFailure;
1227
+ const unearned = this.unearnedNativeFallback();
1228
+ if (unearned)
1229
+ throw unearned;
1047
1230
  const selected = this.cachedModelSelection && !('invalid' in this.cachedModelSelection) ? this.cachedModelSelection : null;
1048
1231
  const actorTasks = (0, ActorActionProducer_1.hasSelectedActorActions)(selected);
1049
1232
  const actorOnly = actorTasks && !selected.models.some(model => model.format === 'litert-lm');
@@ -1339,6 +1522,21 @@ class LocalSensingClient {
1339
1522
  throw Error('Invalid saved detector count result');
1340
1523
  }
1341
1524
  }
1525
+ // Plan v7 W8 (CCTV_LOOK_REUSE=live): a live look answered from the camera's newest
1526
+ // model-reviewed frame, every question scope unchanged against it. The spool re-bound
1527
+ // it to THIS image; only a plain detector answer may stand (WebsiteAdmissionCaptureClient
1528
+ // liveSafeContext), and everything that belongs to this look is decided below.
1529
+ const sceneReuse = saved?.reuseMethod === 'unchanged_scene';
1530
+ if (sceneReuse && (typeof saved.reusedFromEvidenceId !== 'string' || !saved.reusedFromEvidenceId
1531
+ || typeof saved.sourceCapturedAtMs !== 'number' || !Number.isFinite(saved.sourceCapturedAtMs)
1532
+ || typeof saved.sourceReviewedAtMs !== 'number' || !Number.isFinite(saved.sourceReviewedAtMs)
1533
+ || saved.sourceCapturedAtMs >= capturedAtMs || saved.sourceCapturedAtMs > saved.sourceReviewedAtMs
1534
+ || capturedAtMs > saved.reviewedAtMs || request.reviewWindowMs === undefined
1535
+ || saved.reviewedAtMs - saved.sourceCapturedAtMs > request.reviewWindowMs
1536
+ || saved.analysisMethod !== undefined || saved.scopeReviews !== undefined || saved.actorReview !== undefined
1537
+ || detectorCounts || scopedReview || actorActions || context?.mixedModelExecution !== undefined)) {
1538
+ throw new Error('Invalid unchanged-scene answer provenance');
1539
+ }
1342
1540
  if (saved?.reuseMethod === 'exact_recent' && (typeof saved.reusedFromEvidenceId !== 'string' || !saved.reusedFromEvidenceId ||
1343
1541
  typeof saved.sourceCapturedAtMs !== 'number' || !Number.isFinite(saved.sourceCapturedAtMs) ||
1344
1542
  typeof saved.sourceReviewedAtMs !== 'number' || !Number.isFinite(saved.sourceReviewedAtMs) ||
@@ -1611,6 +1809,42 @@ class LocalSensingClient {
1611
1809
  ...(alertPositive ? { alertPositive: true } : {}),
1612
1810
  };
1613
1811
  }
1812
+ if (sceneReuse && saved.evidenceImage === undefined) {
1813
+ // The reused answer is this look's answer: its onset against the camera's previous live
1814
+ // look, and its photo, are decided exactly as for a fresh one, once, and saved with it.
1815
+ const absence = context ? new Set(context.absenceWatchedFields) : this.cachedAbsenceWatchedFields;
1816
+ let alertOnset;
1817
+ let alertPositive = false;
1818
+ try {
1819
+ const positives = alertPositiveKeys({ structured: saved.structured, alertFields: this.cachedAlertFields,
1820
+ absenceWatchedFields: absence, hasSignal: isAlertWorthy(saved.structured, absence), actorReview: null });
1821
+ alertOnset = !positives ? undefined
1822
+ : this.cachedAlertFields === null ? positives.size > 0 : isAlertOnset(positives, this.lastAlertPositives);
1823
+ alertPositive = !!positives && positives.size > 0 && this.cachedAlertFields !== null;
1824
+ if (positives && request.reviewSchedule?.slot !== 'backlog') {
1825
+ this.lastAlertPositives = positives;
1826
+ if (positives.size === 0)
1827
+ this.continuationRefused = false;
1828
+ }
1829
+ }
1830
+ catch {
1831
+ alertOnset = undefined;
1832
+ this.lastAlertPositives = null;
1833
+ }
1834
+ const evidenceImage = request.reviewWindowMs === undefined ? undefined : evidenceImageReason({
1835
+ structured: saved.structured, alertFields: this.cachedAlertFields, absenceWatchedFields: absence,
1836
+ imagelessAccepted: this.imagelessReview, actorReview: false,
1837
+ followUp: request.reviewSchedule?.slot === 'follow_up', capturedAtMs,
1838
+ lastSampleCapturedAtMs: this.lastEvidenceSampleAtMs,
1839
+ continuationImageless: this.continuingImagelessReview && !this.continuationRefused
1840
+ && request.reviewSchedule?.slot !== 'backlog',
1841
+ alertOnset,
1842
+ });
1843
+ if (evidenceImage === 'sample')
1844
+ this.lastEvidenceSampleAtMs = capturedAtMs;
1845
+ saved = { ...saved, ...(evidenceImage ? { evidenceImage } : {}),
1846
+ ...(alertOnset !== undefined ? { alertOnset } : {}), ...(alertPositive ? { alertPositive: true } : {}) };
1847
+ }
1614
1848
  // Also retry a previously failed disk commit before any upload. The spool
1615
1849
  // keeps that answer in memory while disk recovers; inference is not repeated.
1616
1850
  if (usedCachedAnalysis && (actorActions || saved.actorReview !== undefined || saved.actorActionRuns !== undefined || saved.actorPerceptionSha256 !== undefined))
@@ -1635,8 +1869,8 @@ class LocalSensingClient {
1635
1869
  if (review && typeof saved.reusedFromEvidenceId === 'string') {
1636
1870
  review.reusedFromEvidenceId = saved.reusedFromEvidenceId;
1637
1871
  }
1638
- if (review && saved.reuseMethod === 'exact_recent') {
1639
- review.reuseMethod = 'exact_recent';
1872
+ if (review && (saved.reuseMethod === 'exact_recent' || saved.reuseMethod === 'unchanged_scene')) {
1873
+ review.reuseMethod = saved.reuseMethod;
1640
1874
  review.sourceCapturedAtMs = saved.sourceCapturedAtMs;
1641
1875
  review.sourceReviewedAtMs = saved.sourceReviewedAtMs;
1642
1876
  }
@@ -1677,7 +1911,9 @@ class LocalSensingClient {
1677
1911
  && saved.scopeReviews?.some(trace => trace.fields.includes(f.field) && !trace.customVisualDeferred))
1678
1912
  .map(f => [f.field, { contract: f.alert_intent.contract, revision: f.alert_intent.revision }])),
1679
1913
  } : {}),
1680
- localInferenceTrace: (0, LocalInferenceTrace_1.localInferenceTrace)(saved, context?.scopedVlmReview?.detectorFields),
1914
+ localInferenceTrace: { ...(0, LocalInferenceTrace_1.localInferenceTrace)(saved, context?.scopedVlmReview?.detectorFields),
1915
+ // Plan v7 W8: the capture, look-reuse, detector-engine and clock facts of this look.
1916
+ pipeline: (0, pipelineSwitches_1.pipelineTrace)(this.feedName, request.lookReuse) },
1681
1917
  // The boxes behind each box-decided yes, so the owner's mark on its alert can be learned (SceneMarks.ts).
1682
1918
  ...(review && (0, SceneMarks_1.readSceneCauses)(saved.detectorCauses) ? { detectorCauses: { version: 1,
1683
1919
  fields: (0, SceneMarks_1.readSceneCauses)(saved.detectorCauses) } } : {}),
@@ -1729,7 +1965,12 @@ class LocalSensingClient {
1729
1965
  ...(review ? { evidenceId, evidenceSha256 } : {}),
1730
1966
  };
1731
1967
  const withJpeg = { ...uploadOptions, jpeg: request.jpeg, evidenceId, evidenceSha256 };
1968
+ const sentAtMs = Date.now();
1732
1969
  let response = await this.uploadClient.analyzePreAnalyzed(result, attachJpeg ? withJpeg : uploadOptions);
1970
+ // The server's clock on its acknowledgement, against this box's: the 1.7 s
1971
+ // completion-to-receipt gap (plan v7 W8) is either this offset or the path.
1972
+ if (review && response.ok)
1973
+ (0, pipelineSwitches_1.noteServerClock)(sentAtMs, Date.now(), response.body?.serverNowMs);
1733
1974
  if (review && !attachJpeg && this.attachEvidenceFrame && response.statusCode === 422
1734
1975
  && response.body?.reason === exports.EVIDENCE_IMAGE_REQUIRED) {
1735
1976
  if (saved.evidenceImage === 'continuing')
@@ -1943,6 +2184,10 @@ function buildLocalSensingLoops(config, deps) {
1943
2184
  * server has answered once. Segments live under the connector's data root,
1944
2185
  * the one directory the Linux unit grants write access to.
1945
2186
  */
2187
+ // Plan v7 W8: start from the pipeline switches this box last saw, before any feed is built.
2188
+ (0, pipelineSwitches_1.restorePipelineSwitches)((0, dataDir_1.resolveDataDir)(config.dataDir));
2189
+ // Plan v7 W8 item 2: a connector restarted in the middle of a detector swap still knows the detector worked.
2190
+ (0, detectorEndpointState_1.restoreDetectorEndpointState)((0, dataDir_1.resolveDataDir)(config.dataDir));
1946
2191
  const videoRoot = path.join((0, dataDir_1.resolveDataDir)(config.dataDir), exports.VIDEO_SEGMENTS_DIRNAME);
1947
2192
  const recordingFeedByUrl = new Map();
1948
2193
  /** The recorder of each feed that records: an alert-supporting review hands it its receipt. */
@@ -1997,6 +2242,9 @@ function buildLocalSensingLoops(config, deps) {
1997
2242
  outputFormat: feed.outputFormat ?? 'jpeg',
1998
2243
  },
1999
2244
  });
2245
+ // Plan v7 W8: the server's capture switch reaches every persistent session,
2246
+ // and each of this feed's looks reports how its frame was made.
2247
+ (0, pipelineSwitches_1.bindCapturePipeline)(feed.name, provider);
2000
2248
  const urlKey = recordingUrlKey(feed.rtspUrl);
2001
2249
  if (attachVideo && !feed.crop && urlKey !== null && !recordingFeedByUrl.has(urlKey)) {
2002
2250
  // Recording is an addition to a feed, never a condition of it: a
@@ -2090,6 +2338,7 @@ function buildLocalSensingLoops(config, deps) {
2090
2338
  name: feed.name,
2091
2339
  camera,
2092
2340
  client: new LocalSensingClient(localProviderFactory(feed), uploadClientFactory(feed), {
2341
+ feedName: feed.name,
2093
2342
  websiteManagedProfiles: deps?.websiteManagedProfiles,
2094
2343
  retainedApiBaseUrl,
2095
2344
  profileClient: profileClientFactory(feed),