@trillboards/edge-sdk 0.2.246 → 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 (78) hide show
  1. package/deploy/detector/pyproject.toml +1 -1
  2. package/deploy/detector/tests/test_actor_tracking.py +136 -0
  3. package/deploy/detector/tests/test_actor_tracking_wire.py +11 -0
  4. package/deploy/detector/tests/test_loader.py +25 -0
  5. package/deploy/detector/tests/test_registry.py +53 -0
  6. package/deploy/detector/trillboards_detector/_version.py +2 -2
  7. package/deploy/detector/trillboards_detector/actor_tracking.py +95 -9
  8. package/deploy/detector/trillboards_detector/loader.py +28 -0
  9. package/deploy/detector/trillboards_detector/registry.py +27 -1
  10. package/deploy/detector/trillboards_detector/server.py +6 -5
  11. package/deploy/windows/build-windows.ps1 +1 -0
  12. package/deploy/windows/ci/test-detector-looks-field.ps1 +15 -3
  13. package/deploy/windows/ci/test-detector-reinstall.ps1 +173 -2
  14. package/deploy/windows/ci/test-rollout-proofs.ps1 +3 -2
  15. package/deploy/windows/ensure-detector.ps1 +255 -0
  16. package/deploy/windows/install-update.ps1 +4 -3
  17. package/deploy/windows/stop-existing.ps1 +1 -0
  18. package/deploy/windows/trillboards-edge.cmd +10 -22
  19. package/dist/CloudSensingManager.d.ts +9 -0
  20. package/dist/CloudSensingManager.d.ts.map +1 -1
  21. package/dist/CloudSensingManager.js +46 -3
  22. package/dist/CloudSensingManager.js.map +1 -1
  23. package/dist/ConnectorStatusClient.d.ts +8 -0
  24. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  25. package/dist/ConnectorStatusClient.js +3 -0
  26. package/dist/ConnectorStatusClient.js.map +1 -1
  27. package/dist/EdgeAgent.js +1 -1
  28. package/dist/LocalDetectorClient.d.ts +19 -0
  29. package/dist/LocalDetectorClient.d.ts.map +1 -1
  30. package/dist/LocalDetectorClient.js +28 -4
  31. package/dist/LocalDetectorClient.js.map +1 -1
  32. package/dist/NativeReadiness.d.ts +21 -2
  33. package/dist/NativeReadiness.d.ts.map +1 -1
  34. package/dist/NativeReadiness.js +25 -6
  35. package/dist/NativeReadiness.js.map +1 -1
  36. package/dist/OrderedReviewClient.d.ts +3 -0
  37. package/dist/OrderedReviewClient.d.ts.map +1 -1
  38. package/dist/OrderedReviewClient.js +3 -0
  39. package/dist/OrderedReviewClient.js.map +1 -1
  40. package/dist/TemporalReviewClient.d.ts +3 -0
  41. package/dist/TemporalReviewClient.d.ts.map +1 -1
  42. package/dist/TemporalReviewClient.js +3 -0
  43. package/dist/TemporalReviewClient.js.map +1 -1
  44. package/dist/autoSense.d.ts.map +1 -1
  45. package/dist/autoSense.js +3 -0
  46. package/dist/autoSense.js.map +1 -1
  47. package/dist/cli.d.ts.map +1 -1
  48. package/dist/cli.js +3 -0
  49. package/dist/cli.js.map +1 -1
  50. package/dist/connectorUpdate.d.ts +18 -9
  51. package/dist/connectorUpdate.d.ts.map +1 -1
  52. package/dist/connectorUpdate.js +66 -3
  53. package/dist/connectorUpdate.js.map +1 -1
  54. package/dist/connectorUpdateApply.d.ts +20 -1
  55. package/dist/connectorUpdateApply.d.ts.map +1 -1
  56. package/dist/connectorUpdateApply.js +55 -1
  57. package/dist/connectorUpdateApply.js.map +1 -1
  58. package/dist/connectorUpdateApplyMac.d.ts +3 -1
  59. package/dist/connectorUpdateApplyMac.d.ts.map +1 -1
  60. package/dist/connectorUpdateApplyMac.js +6 -0
  61. package/dist/connectorUpdateApplyMac.js.map +1 -1
  62. package/dist/detectorEndpointState.d.ts +30 -0
  63. package/dist/detectorEndpointState.d.ts.map +1 -0
  64. package/dist/detectorEndpointState.js +125 -0
  65. package/dist/detectorEndpointState.js.map +1 -0
  66. package/dist/detectorLauncher.d.ts +23 -0
  67. package/dist/detectorLauncher.d.ts.map +1 -0
  68. package/dist/detectorLauncher.js +94 -0
  69. package/dist/detectorLauncher.js.map +1 -0
  70. package/dist/diagnose.d.ts +1 -1
  71. package/dist/diagnose.js +1 -1
  72. package/dist/localSensing.d.ts +69 -0
  73. package/dist/localSensing.d.ts.map +1 -1
  74. package/dist/localSensing.js +211 -28
  75. package/dist/localSensing.js.map +1 -1
  76. package/package.json +2 -2
  77. package/retained/ProfileAuthorityClient.cjs +4 -0
  78. package/retained/RetainedCaptureClient.cjs +4 -0
@@ -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");
@@ -454,8 +455,19 @@ class LocalSensingClient {
454
455
  this.cachedDeclaredProfileReview = false;
455
456
  this.nativeReadyKey = '';
456
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;
457
460
  this.nativeRetryAt = 0;
458
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 = '';
459
471
  this.cachedVlmFields = [];
460
472
  this.cachedCascadeArmed = false;
461
473
  /** This feed's parked-vehicle memory per gated field; losing it costs one question. */
@@ -899,11 +911,18 @@ class LocalSensingClient {
899
911
  return;
900
912
  }
901
913
  const key = JSON.stringify(request);
902
- if (this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil) {
914
+ const now = Date.now();
915
+ if (this.nativeProofCurrent(key, now)) {
903
916
  this.nativeFailure = undefined;
904
917
  this.applyReviewProfile(profile);
905
918
  return;
906
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
+ }
907
926
  if (profile.nativeFallback) {
908
927
  this.nativeFailure = undefined;
909
928
  this.applyReviewProfile(profile.nativeFallback);
@@ -911,6 +930,83 @@ class LocalSensingClient {
911
930
  else
912
931
  this.nativeFailure = new NativeReadiness_1.NativeReadinessError(undefined, 'unavailable');
913
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
+ }
914
1010
  async prepareNativeCapture() {
915
1011
  if (this.invalidWebsiteProfileAuthority || this.nativeAuthorityError)
916
1012
  return;
@@ -926,34 +1022,107 @@ class LocalSensingClient {
926
1022
  // A current proof is renewed in its last NATIVE_READINESS_RENEW_MS, in the background, by
927
1023
  // the next look: a lapse between two looks paused new evidence (and parked the feed on the
928
1024
  // health heartbeat) although the detector was ready throughout. A failed renewal proves
929
- // nothing new, so it revokes nothing: the current proof still lapses at its own expiry.
930
- const proven = this.nativeReadyKey === key && Date.now() < this.nativeReadyUntil;
931
- 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)
932
1030
  return;
933
- if (!this.nativePending || this.nativePending.key !== key) {
934
- if (this.nativeRetryKey === key && Date.now() < this.nativeRetryAt)
935
- return;
936
- const pending = { key, promise: Promise.resolve() };
937
- pending.promise = this.nativeReadinessProbe(request).then(until => {
938
- if (this.nativePending === pending) {
939
- this.nativeReadyKey = key;
940
- this.nativeReadyUntil = typeof until === 'number' && Number.isFinite(until) ? until : Date.now() + NativeReadiness_1.NATIVE_READINESS_TTL_MS;
941
- }
942
- }, () => { if (this.nativePending === pending) {
943
- this.nativeRetryKey = key;
944
- this.nativeRetryAt = Date.now() + 1000;
945
- } }).finally(() => {
946
- if (this.nativePending === pending)
947
- this.nativePending = undefined;
948
- // A delayed proof may select only the CURRENT profile, never a preceding policy.
949
- this.selectCaptureProfile();
950
- });
951
- 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;
952
1062
  }
953
- // A current proof never waits for its renewal. A valid authorized Gemma
954
- // projection never waits for a cold native session.
955
- if (!proven && !profile.nativeFallback)
956
- 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');
957
1126
  }
958
1127
  /**
959
1128
  * What the on-device runtime resolved about this host's accelerator (which
@@ -1017,7 +1186,16 @@ class LocalSensingClient {
1017
1186
  /** Explicit inactivity or invalid current native authority pauses new model work. */
1018
1187
  isReviewActive() {
1019
1188
  this.selectCaptureProfile();
1020
- 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';
1021
1199
  }
1022
1200
  usesWebsiteProfile() {
1023
1201
  return this.websiteManagedProfiles && this.reviewProfileState === 'active';
@@ -1046,6 +1224,9 @@ class LocalSensingClient {
1046
1224
  this.selectCaptureProfile();
1047
1225
  if (this.nativeFailure)
1048
1226
  throw this.nativeFailure;
1227
+ const unearned = this.unearnedNativeFallback();
1228
+ if (unearned)
1229
+ throw unearned;
1049
1230
  const selected = this.cachedModelSelection && !('invalid' in this.cachedModelSelection) ? this.cachedModelSelection : null;
1050
1231
  const actorTasks = (0, ActorActionProducer_1.hasSelectedActorActions)(selected);
1051
1232
  const actorOnly = actorTasks && !selected.models.some(model => model.format === 'litert-lm');
@@ -2005,6 +2186,8 @@ function buildLocalSensingLoops(config, deps) {
2005
2186
  */
2006
2187
  // Plan v7 W8: start from the pipeline switches this box last saw, before any feed is built.
2007
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));
2008
2191
  const videoRoot = path.join((0, dataDir_1.resolveDataDir)(config.dataDir), exports.VIDEO_SEGMENTS_DIRNAME);
2009
2192
  const recordingFeedByUrl = new Map();
2010
2193
  /** The recorder of each feed that records: an alert-supporting review hands it its receipt. */