@trillboards/edge-sdk 0.2.244 → 0.2.246
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/deploy/detector/bench/detect_frames.py +88 -0
- package/deploy/detector/bench/openvino_parity.py +152 -0
- package/deploy/detector/pyproject.toml +10 -1
- package/deploy/detector/tests/test_actor_tracking.py +32 -0
- package/deploy/detector/tests/test_actor_tracking_wire.py +11 -0
- package/deploy/detector/tests/test_openvino_engines.py +251 -0
- package/deploy/detector/tests/test_server.py +43 -0
- package/deploy/detector/tests/test_version_stamp.py +17 -4
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/actor_tracking.py +51 -0
- package/deploy/detector/trillboards_detector/cli.py +5 -0
- package/deploy/detector/trillboards_detector/detections.py +5 -0
- package/deploy/detector/trillboards_detector/execution.py +386 -0
- package/deploy/detector/trillboards_detector/loader.py +12 -1
- package/deploy/detector/trillboards_detector/registry.py +6 -0
- package/deploy/detector/trillboards_detector/server.py +41 -0
- package/deploy/detector/trillboards_detector/session.py +81 -3
- package/deploy/detector/trillboards_detector/track_records.py +113 -0
- package/deploy/windows/ci/test-alert-window-field.ps1 +28 -6
- package/deploy/windows/ci/test-detector-looks-field.ps1 +31 -7
- package/deploy/windows/ci/test-detector-reinstall.ps1 +474 -0
- package/deploy/windows/setup-detector.ps1 +122 -29
- package/dist/ActorTracking.d.ts +38 -0
- package/dist/ActorTracking.d.ts.map +1 -1
- package/dist/ActorTracking.js +40 -0
- package/dist/ActorTracking.js.map +1 -1
- package/dist/AlertClips.d.ts +12 -3
- package/dist/AlertClips.d.ts.map +1 -1
- package/dist/AlertClips.js +52 -11
- package/dist/AlertClips.js.map +1 -1
- package/dist/ChannelProber.d.ts +15 -0
- package/dist/ChannelProber.d.ts.map +1 -1
- package/dist/ChannelProber.js +61 -0
- package/dist/ChannelProber.js.map +1 -1
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +6 -1
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/ConnectorStatusClient.d.ts +9 -1
- package/dist/ConnectorStatusClient.d.ts.map +1 -1
- package/dist/ConnectorStatusClient.js +3 -0
- package/dist/ConnectorStatusClient.js.map +1 -1
- package/dist/DurableVlmCandidateSpool.d.ts +11 -0
- package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
- package/dist/DurableVlmCandidateSpool.js +31 -2
- package/dist/DurableVlmCandidateSpool.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/FrameGroupingShadow.d.ts +57 -0
- package/dist/FrameGroupingShadow.d.ts.map +1 -1
- package/dist/FrameGroupingShadow.js +123 -5
- package/dist/FrameGroupingShadow.js.map +1 -1
- package/dist/LocalDetectorClient.d.ts +25 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +60 -0
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/LocalVideoBuffer.d.ts +14 -2
- package/dist/LocalVideoBuffer.d.ts.map +1 -1
- package/dist/LocalVideoBuffer.js +23 -3
- package/dist/LocalVideoBuffer.js.map +1 -1
- package/dist/MainStreamRing.d.ts +246 -0
- package/dist/MainStreamRing.d.ts.map +1 -0
- package/dist/MainStreamRing.js +436 -0
- package/dist/MainStreamRing.js.map +1 -0
- package/dist/SensingProfileClient.d.ts +20 -0
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +13 -1
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/VideoSegmentUploader.d.ts +59 -8
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +143 -54
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/VlmCandidateBuffer.d.ts +13 -0
- package/dist/VlmCandidateBuffer.d.ts.map +1 -1
- package/dist/VlmCandidateBuffer.js.map +1 -1
- package/dist/autoSense.d.ts +4 -0
- package/dist/autoSense.d.ts.map +1 -1
- package/dist/autoSense.js +6 -0
- package/dist/autoSense.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/connectorUpdate.d.ts +9 -0
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +22 -13
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/continuousReview.d.ts +6 -2
- package/dist/continuousReview.d.ts.map +1 -1
- package/dist/continuousReview.js.map +1 -1
- package/dist/detectorBackendRelay.d.ts +24 -0
- package/dist/detectorBackendRelay.d.ts.map +1 -0
- package/dist/detectorBackendRelay.js +70 -0
- package/dist/detectorBackendRelay.js.map +1 -0
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +3 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +72 -3
- package/dist/localSensing.js.map +1 -1
- package/dist/pipelineSwitches.d.ts +59 -0
- package/dist/pipelineSwitches.d.ts.map +1 -0
- package/dist/pipelineSwitches.js +240 -0
- package/dist/pipelineSwitches.js.map +1 -0
- package/package.json +4 -4
- package/retained/RetainedCaptureClient.cjs +37 -2
- package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
- package/retained/__tests__/look-reuse.test.cjs +167 -0
- package/retained/manager.cjs +28 -2
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
<#
|
|
2
|
+
test-detector-reinstall.ps1 -- the detector reinstall a connector update runs
|
|
3
|
+
(install-update.ps1 Update-DetectorTask -> setup-detector.ps1), against a
|
|
4
|
+
detector that is SERVING, on a real Windows runner with real uv.
|
|
5
|
+
|
|
6
|
+
Why: `uv tool install --force` deletes the old venv and executable after it
|
|
7
|
+
resolves and before it downloads. Run with the service stopped, a WAN drop
|
|
8
|
+
during the download left a store PC with no detector at all (found from code
|
|
9
|
+
before the 0.2.246 install, 2026-11-17). setup-detector.ps1 now trial-installs
|
|
10
|
+
into a throwaway tool directory while the old service keeps serving, and only
|
|
11
|
+
then stops it and replaces it offline, from uv's cache.
|
|
12
|
+
|
|
13
|
+
The old detector is installed the way production 0.2.245 left it ([cpu], its
|
|
14
|
+
own version) and serves /health 200 on a stand-in ONNX with the shipped
|
|
15
|
+
RF-DETR Medium signature (the real artifact is behind presigned URLs).
|
|
16
|
+
|
|
17
|
+
(a) index unreachable: a cold uv cache and a dead proxy. Both trial rungs
|
|
18
|
+
fail; the old detector's process, executable and version are unchanged
|
|
19
|
+
and /health answers 200 from the same loaded model throughout.
|
|
20
|
+
(b) network cut right after the trial: a cold uv cache, uv's traffic through
|
|
21
|
+
a logging proxy that refuses every connection from the moment the
|
|
22
|
+
"trial install passed" line is written. The replacement must complete,
|
|
23
|
+
the proxy must see no connection attempt after the cut, and the old
|
|
24
|
+
detector must have answered 200 through the whole trial.
|
|
25
|
+
(c) the detector's down time inside (b): the old process's last /health 200
|
|
26
|
+
to the new process's first.
|
|
27
|
+
#>
|
|
28
|
+
[CmdletBinding()]
|
|
29
|
+
param()
|
|
30
|
+
|
|
31
|
+
$ErrorActionPreference = 'Stop'
|
|
32
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
33
|
+
|
|
34
|
+
$deploy = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
|
35
|
+
$detectorSource = (Resolve-Path (Join-Path $deploy '..\detector')).Path
|
|
36
|
+
$root = Join-Path $env:LOCALAPPDATA ('detector-reinstall-proof-' + [Guid]::NewGuid().ToString('N').Substring(0, 8))
|
|
37
|
+
$evidence = Join-Path $root 'evidence'
|
|
38
|
+
New-Item -ItemType Directory -Force -Path $evidence | Out-Null
|
|
39
|
+
if ($env:GITHUB_OUTPUT) { "artifact_path=$evidence" | Add-Content -LiteralPath $env:GITHUB_OUTPUT }
|
|
40
|
+
$setupLog = Join-Path $env:LOCALAPPDATA 'Trillboards\logs\detector-setup.log'
|
|
41
|
+
$healthUrl = 'http://127.0.0.1:9380/health'
|
|
42
|
+
$localBin = Join-Path $env:USERPROFILE '.local\bin'
|
|
43
|
+
$detectorExe = Join-Path $localBin 'trillboards-detector.exe'
|
|
44
|
+
$receipt = [ordered]@{ version = 1; startedAtUtc = [DateTimeOffset]::UtcNow.ToString('o'); passed = $false; cases = [ordered]@{} }
|
|
45
|
+
|
|
46
|
+
function Write-Receipt {
|
|
47
|
+
$receipt | ConvertTo-Json -Depth 12 | Set-Content -LiteralPath (Join-Path $evidence 'receipt.json') -Encoding utf8
|
|
48
|
+
}
|
|
49
|
+
function Write-Utf8NoBom([string]$Path, [string]$Text) {
|
|
50
|
+
[IO.File]::WriteAllText($Path, $Text, (New-Object Text.UTF8Encoding $false))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Copy-DetectorSource([string]$Destination, [string]$Version) {
|
|
54
|
+
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
|
55
|
+
& robocopy $detectorSource $Destination /E /XD tests bench __pycache__ .venv /NFL /NDL /NJH /NJS /NP | Out-Null
|
|
56
|
+
if ($LASTEXITCODE -ge 8) { throw "robocopy of the detector source failed ($LASTEXITCODE)" }
|
|
57
|
+
$global:LASTEXITCODE = 0
|
|
58
|
+
if ($Version) {
|
|
59
|
+
$pyproject = Join-Path $Destination 'pyproject.toml'
|
|
60
|
+
$text = [IO.File]::ReadAllText($pyproject)
|
|
61
|
+
$text = [Text.RegularExpressions.Regex]::Replace($text, '(?m)^version = "[^"]+"', ('version = "' + $Version + '"'))
|
|
62
|
+
Write-Utf8NoBom $pyproject $text
|
|
63
|
+
$versionPy = Join-Path $Destination 'trillboards_detector\_version.py'
|
|
64
|
+
$text = [IO.File]::ReadAllText($versionPy)
|
|
65
|
+
$text = [Text.RegularExpressions.Regex]::Replace($text, '(?m)^VERSION = "[^"]+"', ('VERSION = "' + $Version + '"'))
|
|
66
|
+
Write-Utf8NoBom $versionPy $text
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function Read-PackageVersion([string]$SourceDir) {
|
|
71
|
+
foreach ($line in [IO.File]::ReadAllLines((Join-Path $SourceDir 'pyproject.toml'))) {
|
|
72
|
+
if ($line -match '^\s*version\s*=\s*"([^"]+)"\s*$') { return $Matches[1] }
|
|
73
|
+
}
|
|
74
|
+
throw "no version in $SourceDir"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function Get-InstalledVersion {
|
|
78
|
+
if (-not (Test-Path -LiteralPath $detectorExe)) { return $null }
|
|
79
|
+
$out = & $detectorExe --version 2>$null
|
|
80
|
+
if ($LASTEXITCODE -ne 0 -or -not $out) { $global:LASTEXITCODE = 0; return $null }
|
|
81
|
+
return ([string]$out).Trim().Split(' ')[-1]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Get-HealthCode {
|
|
85
|
+
try {
|
|
86
|
+
$response = Invoke-WebRequest -Uri $healthUrl -NoProxy -SkipHttpErrorCheck -TimeoutSec 3
|
|
87
|
+
return [int]$response.StatusCode
|
|
88
|
+
} catch { return 0 }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function Wait-HealthCode([int]$Code, [int]$Seconds) {
|
|
92
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
93
|
+
while ($watch.Elapsed.TotalSeconds -lt $Seconds) {
|
|
94
|
+
if ((Get-HealthCode) -eq $Code) { return $watch.Elapsed.TotalSeconds }
|
|
95
|
+
Start-Sleep -Milliseconds 250
|
|
96
|
+
}
|
|
97
|
+
throw "/health did not answer $Code within $Seconds s (last: $(Get-HealthCode))"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function Get-ListenerPid {
|
|
101
|
+
$listener = @(Get-NetTCPConnection -LocalPort 9380 -State Listen -ErrorAction SilentlyContinue)
|
|
102
|
+
if (-not $listener.Count) { return $null }
|
|
103
|
+
return [int]$listener[0].OwningProcess
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function Get-LogLength {
|
|
107
|
+
if (-not (Test-Path -LiteralPath $setupLog)) { return 0 }
|
|
108
|
+
return (Get-Item -LiteralPath $setupLog).Length
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function Read-NewLogText([long]$Offset) {
|
|
112
|
+
if (-not (Test-Path -LiteralPath $setupLog)) { return '' }
|
|
113
|
+
$stream = [IO.File]::Open($setupLog, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
114
|
+
try {
|
|
115
|
+
$null = $stream.Seek($Offset, [IO.SeekOrigin]::Begin)
|
|
116
|
+
return (New-Object IO.StreamReader($stream)).ReadToEnd()
|
|
117
|
+
} finally { $stream.Dispose() }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# /health every 100 ms, in its own process, until the stop file appears. Each
|
|
121
|
+
# sample keeps the model's loaded_at, which identifies the serving process: a
|
|
122
|
+
# slow answer is not mistaken for the swap, and a 200 from a restarted process
|
|
123
|
+
# is not mistaken for the old one.
|
|
124
|
+
function Start-HealthPoller([string]$Samples, [string]$StopFile) {
|
|
125
|
+
Start-Job -ArgumentList $healthUrl, $Samples, $StopFile -ScriptBlock {
|
|
126
|
+
param($url, $samples, $stop)
|
|
127
|
+
while (-not (Test-Path -LiteralPath $stop)) {
|
|
128
|
+
$code = 0; $loadedAt = ''
|
|
129
|
+
try {
|
|
130
|
+
$response = Invoke-WebRequest -Uri $url -NoProxy -SkipHttpErrorCheck -TimeoutSec 3
|
|
131
|
+
$code = [int]$response.StatusCode
|
|
132
|
+
if ([string]$response.Content -match '"loaded_at":\s*([0-9.]+)') { $loadedAt = $Matches[1] }
|
|
133
|
+
} catch { $code = 0 }
|
|
134
|
+
Add-Content -LiteralPath $samples -Value ('{0},{1},{2}' -f [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds(), $code, $loadedAt)
|
|
135
|
+
Start-Sleep -Milliseconds 100
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function Stop-HealthPoller($Job, [string]$StopFile) {
|
|
141
|
+
New-Item -ItemType File -Force -Path $StopFile | Out-Null
|
|
142
|
+
$null = Wait-Job $Job -Timeout 30
|
|
143
|
+
Remove-Job $Job -Force
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function Read-HealthSamples([string]$Samples) {
|
|
147
|
+
@(Get-Content -LiteralPath $Samples | ForEach-Object {
|
|
148
|
+
$parts = $_.Split(',')
|
|
149
|
+
[pscustomobject]@{ atMs = [long]$parts[0]; code = [int]$parts[1]; loadedAt = $parts[2] }
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# Runs setup-detector.ps1 the way install-update.ps1 does (Windows PowerShell),
|
|
154
|
+
# with the given environment overrides, and returns what it appended to its log.
|
|
155
|
+
function Invoke-SetupDetector([string]$SourceDir, [hashtable]$Environment) {
|
|
156
|
+
$saved = @{}
|
|
157
|
+
foreach ($name in $Environment.Keys) {
|
|
158
|
+
$saved[$name] = [Environment]::GetEnvironmentVariable($name, 'Process')
|
|
159
|
+
[Environment]::SetEnvironmentVariable($name, $Environment[$name], 'Process')
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
$offset = Get-LogLength
|
|
163
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
164
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $deploy 'setup-detector.ps1') -SourcePath $SourceDir | Out-Host
|
|
165
|
+
$exit = $LASTEXITCODE
|
|
166
|
+
$global:LASTEXITCODE = 0
|
|
167
|
+
return [pscustomobject]@{ exit = $exit; seconds = [math]::Round($watch.Elapsed.TotalSeconds, 1); log = (Read-NewLogText $offset) }
|
|
168
|
+
} finally {
|
|
169
|
+
foreach ($name in $saved.Keys) { [Environment]::SetEnvironmentVariable($name, $saved[$name], 'Process') }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
$pythonProxy = @'
|
|
174
|
+
import os, socket, sys, threading, time
|
|
175
|
+
|
|
176
|
+
port, log_path, cut_path = int(sys.argv[1]), sys.argv[2], sys.argv[3]
|
|
177
|
+
lock = threading.Lock()
|
|
178
|
+
|
|
179
|
+
def log(line):
|
|
180
|
+
with lock, open(log_path, "a", encoding="utf-8") as f:
|
|
181
|
+
f.write("%d %s\n" % (int(time.time() * 1000), line))
|
|
182
|
+
|
|
183
|
+
def pipe(src, dst):
|
|
184
|
+
try:
|
|
185
|
+
while True:
|
|
186
|
+
data = src.recv(65536)
|
|
187
|
+
if not data:
|
|
188
|
+
break
|
|
189
|
+
dst.sendall(data)
|
|
190
|
+
except OSError:
|
|
191
|
+
pass
|
|
192
|
+
finally:
|
|
193
|
+
for s in (src, dst):
|
|
194
|
+
try:
|
|
195
|
+
s.shutdown(socket.SHUT_RDWR)
|
|
196
|
+
except OSError:
|
|
197
|
+
pass
|
|
198
|
+
|
|
199
|
+
def handle(client):
|
|
200
|
+
try:
|
|
201
|
+
head = b""
|
|
202
|
+
while b"\r\n\r\n" not in head:
|
|
203
|
+
chunk = client.recv(4096)
|
|
204
|
+
if not chunk:
|
|
205
|
+
client.close()
|
|
206
|
+
return
|
|
207
|
+
head += chunk
|
|
208
|
+
method, target = head.split(b"\r\n", 1)[0].decode("latin1").split(" ")[:2]
|
|
209
|
+
if os.path.exists(cut_path):
|
|
210
|
+
log("REFUSED %s %s" % (method, target))
|
|
211
|
+
client.sendall(b"HTTP/1.1 503 Service Unavailable\r\nContent-Length: 0\r\n\r\n")
|
|
212
|
+
client.close()
|
|
213
|
+
return
|
|
214
|
+
if method != "CONNECT":
|
|
215
|
+
log("REJECTED %s %s" % (method, target))
|
|
216
|
+
client.sendall(b"HTTP/1.1 405 Method Not Allowed\r\nContent-Length: 0\r\n\r\n")
|
|
217
|
+
client.close()
|
|
218
|
+
return
|
|
219
|
+
host, port_text = target.rsplit(":", 1)
|
|
220
|
+
upstream = socket.create_connection((host, int(port_text)), timeout=30)
|
|
221
|
+
upstream.settimeout(None)
|
|
222
|
+
log("CONNECT %s" % target)
|
|
223
|
+
client.sendall(b"HTTP/1.1 200 Connection Established\r\n\r\n")
|
|
224
|
+
threading.Thread(target=pipe, args=(upstream, client), daemon=True).start()
|
|
225
|
+
pipe(client, upstream)
|
|
226
|
+
except Exception as error:
|
|
227
|
+
log("ERROR %r" % (error,))
|
|
228
|
+
try:
|
|
229
|
+
client.close()
|
|
230
|
+
except OSError:
|
|
231
|
+
pass
|
|
232
|
+
|
|
233
|
+
server = socket.socket()
|
|
234
|
+
server.bind(("127.0.0.1", port))
|
|
235
|
+
server.listen(128)
|
|
236
|
+
log("LISTENING %d" % port)
|
|
237
|
+
while True:
|
|
238
|
+
connection, _ = server.accept()
|
|
239
|
+
threading.Thread(target=handle, args=(connection,), daemon=True).start()
|
|
240
|
+
'@
|
|
241
|
+
|
|
242
|
+
$pythonStandIn = @'
|
|
243
|
+
import sys
|
|
244
|
+
import onnx
|
|
245
|
+
from onnx import TensorProto, helper
|
|
246
|
+
|
|
247
|
+
# The shipped RF-DETR Medium export's signature (input [1,3,576,576], dets
|
|
248
|
+
# [1,300,4], labels [1,300,91]); every output constant, so the service's load
|
|
249
|
+
# probe completes and nothing is ever detected.
|
|
250
|
+
shape_dets = helper.make_tensor("shape_dets", TensorProto.INT64, [3], [1, 300, 4])
|
|
251
|
+
shape_labels = helper.make_tensor("shape_labels", TensorProto.INT64, [3], [1, 300, 91])
|
|
252
|
+
nodes = [
|
|
253
|
+
helper.make_node("ConstantOfShape", ["shape_dets"], ["dets"],
|
|
254
|
+
value=helper.make_tensor("zero", TensorProto.FLOAT, [1], [0.0])),
|
|
255
|
+
helper.make_node("ConstantOfShape", ["shape_labels"], ["labels"],
|
|
256
|
+
value=helper.make_tensor("low", TensorProto.FLOAT, [1], [-20.0])),
|
|
257
|
+
]
|
|
258
|
+
graph = helper.make_graph(
|
|
259
|
+
nodes, "rfdetr_medium_stand_in",
|
|
260
|
+
[helper.make_tensor_value_info("input", TensorProto.FLOAT, [1, 3, 576, 576])],
|
|
261
|
+
[helper.make_tensor_value_info("dets", TensorProto.FLOAT, [1, 300, 4]),
|
|
262
|
+
helper.make_tensor_value_info("labels", TensorProto.FLOAT, [1, 300, 91])],
|
|
263
|
+
initializer=[shape_dets, shape_labels])
|
|
264
|
+
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)])
|
|
265
|
+
model.ir_version = 8
|
|
266
|
+
onnx.checker.check_model(model)
|
|
267
|
+
for path in sys.argv[1:]:
|
|
268
|
+
onnx.save(model, path)
|
|
269
|
+
'@
|
|
270
|
+
|
|
271
|
+
$proxyProcess = $null
|
|
272
|
+
try {
|
|
273
|
+
$processor = @(Get-CimInstance Win32_Processor | Select-Object -First 1)
|
|
274
|
+
$receipt.runner = [ordered]@{ cpu = [string]$processor[0].Name; manufacturer = [string]$processor[0].Manufacturer
|
|
275
|
+
openVinoExpected = ([string]$processor[0].Manufacturer -match 'GenuineIntel') }
|
|
276
|
+
|
|
277
|
+
# --- uv, the way setup-detector.ps1 gets it --------------------------------
|
|
278
|
+
$env:PATH = "$localBin;$env:LOCALAPPDATA\uv\bin;$env:PATH"
|
|
279
|
+
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
|
|
280
|
+
# In its own process, exactly as setup-detector.ps1 runs it. Piped into
|
|
281
|
+
# Invoke-Expression here, the installer ran in THIS scope and replaced
|
|
282
|
+
# $receipt with its own install receipt (first runner without uv, 2026-11-17).
|
|
283
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'irm https://astral.sh/uv/install.ps1 | iex' | Out-Host
|
|
284
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing uv failed' }
|
|
285
|
+
$env:PATH = "$localBin;$env:LOCALAPPDATA\uv\bin;$env:PATH"
|
|
286
|
+
}
|
|
287
|
+
$uv = (Get-Command uv).Source
|
|
288
|
+
$receipt.uv = ((& $uv --version) | Out-String).Trim()
|
|
289
|
+
|
|
290
|
+
# --- two copies of the detector package: the field's and this release's ----
|
|
291
|
+
$oldSource = Join-Path $root 'detector-old'
|
|
292
|
+
$newSource = Join-Path $root 'detector-new'
|
|
293
|
+
Copy-DetectorSource $oldSource '0.2.0+src.000000000000'
|
|
294
|
+
Copy-DetectorSource $newSource $null
|
|
295
|
+
$oldVersion = Read-PackageVersion $oldSource
|
|
296
|
+
$newVersion = Read-PackageVersion $newSource
|
|
297
|
+
$receipt.oldVersion = $oldVersion; $receipt.newVersion = $newVersion
|
|
298
|
+
if ($oldVersion -eq $newVersion) { throw 'the old and new detector versions must differ' }
|
|
299
|
+
|
|
300
|
+
# --- the old detector, installed the way 0.2.245 left it --------------------
|
|
301
|
+
& $uv tool install --python 3.12 --managed-python --force --refresh-package trillboards-detector ($oldSource + '[cpu]') | Out-Host
|
|
302
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing the old detector failed' }
|
|
303
|
+
|
|
304
|
+
# --- a Python for the stand-in model and the proxy, beside the tool --------
|
|
305
|
+
$helperEnv = Join-Path $root 'helper-venv'
|
|
306
|
+
& $uv venv $helperEnv --python 3.12 --managed-python | Out-Host
|
|
307
|
+
if ($LASTEXITCODE -ne 0) { throw 'creating the helper venv failed' }
|
|
308
|
+
$py = Join-Path $helperEnv 'Scripts\python.exe'
|
|
309
|
+
& $uv pip install --python $py onnx | Out-Host
|
|
310
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing onnx into the helper venv failed' }
|
|
311
|
+
|
|
312
|
+
# --- the stand-in model, where the service looks for the real one ----------
|
|
313
|
+
# trillboards_detector/modelpath.py: HOME, else USERPROFILE, then
|
|
314
|
+
# .trillboards\models\rfdetr_medium\model.onnx. The task does not inherit this
|
|
315
|
+
# job's environment, so every HOME it could see gets a copy.
|
|
316
|
+
$homes = @($env:USERPROFILE, $env:HOME, [Environment]::GetEnvironmentVariable('HOME', 'User'),
|
|
317
|
+
[Environment]::GetEnvironmentVariable('HOME', 'Machine')) | Where-Object { $_ } | Select-Object -Unique
|
|
318
|
+
$modelPaths = @(foreach ($h in $homes) {
|
|
319
|
+
$dir = Join-Path $h '.trillboards\models\rfdetr_medium'
|
|
320
|
+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
321
|
+
Join-Path $dir 'model.onnx'
|
|
322
|
+
})
|
|
323
|
+
$standInScript = Join-Path $root 'stand_in.py'
|
|
324
|
+
Write-Utf8NoBom $standInScript $pythonStandIn
|
|
325
|
+
& $py -I $standInScript @modelPaths
|
|
326
|
+
if ($LASTEXITCODE -ne 0) { throw 'building the stand-in model failed' }
|
|
327
|
+
$receipt.modelPaths = $modelPaths
|
|
328
|
+
|
|
329
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $deploy 'register-detector-task.ps1') -DetectorPath $detectorExe -Port 9380 | Out-Host
|
|
330
|
+
if ($LASTEXITCODE -ne 0) { throw 'registering the old detector task failed' }
|
|
331
|
+
$receipt.oldReadySeconds = [math]::Round((Wait-HealthCode 200 180), 1)
|
|
332
|
+
if ((Get-InstalledVersion) -ne $oldVersion) { throw "the old detector reports $(Get-InstalledVersion), expected $oldVersion" }
|
|
333
|
+
Write-Receipt
|
|
334
|
+
|
|
335
|
+
$noProxy = '127.0.0.1,localhost'
|
|
336
|
+
|
|
337
|
+
# --- (a) index unreachable --------------------------------------------------
|
|
338
|
+
$case = [ordered]@{ name = 'index unreachable: cold uv cache, dead proxy' }
|
|
339
|
+
$receipt.cases.a = $case
|
|
340
|
+
$pidBefore = Get-ListenerPid
|
|
341
|
+
$hashBefore = (Get-FileHash -LiteralPath $detectorExe -Algorithm SHA256).Hash
|
|
342
|
+
$samples = Join-Path $evidence 'health-a.csv'
|
|
343
|
+
$poller = Start-HealthPoller $samples (Join-Path $root 'stop-a')
|
|
344
|
+
Start-Sleep -Seconds 2
|
|
345
|
+
$dead = 'http://127.0.0.1:9'
|
|
346
|
+
$run = Invoke-SetupDetector $newSource @{
|
|
347
|
+
UV_CACHE_DIR = (Join-Path $root 'uv-cache-a'); HTTPS_PROXY = $dead; HTTP_PROXY = $dead; ALL_PROXY = $dead; NO_PROXY = $noProxy }
|
|
348
|
+
Start-Sleep -Seconds 2
|
|
349
|
+
Stop-HealthPoller $poller (Join-Path $root 'stop-a')
|
|
350
|
+
Set-Content -LiteralPath (Join-Path $evidence 'setup-a.log') -Value $run.log -Encoding utf8
|
|
351
|
+
$health = Read-HealthSamples $samples
|
|
352
|
+
$case.setupExit = $run.exit; $case.setupSeconds = $run.seconds
|
|
353
|
+
$case.healthSamples = $health.Count
|
|
354
|
+
$case.healthNot200 = @($health | Where-Object { $_.code -ne 200 }).Count
|
|
355
|
+
$case.servingModelsSeen = @($health | ForEach-Object { $_.loadedAt } | Select-Object -Unique).Count
|
|
356
|
+
$case.pidBefore = $pidBefore; $case.pidAfter = Get-ListenerPid
|
|
357
|
+
$case.versionAfter = Get-InstalledVersion
|
|
358
|
+
$case.exeUnchanged = ((Test-Path -LiteralPath $detectorExe) -and (Get-FileHash -LiteralPath $detectorExe -Algorithm SHA256).Hash -eq $hashBefore)
|
|
359
|
+
$case.trialRefused = $run.log.Contains('the running detector was not touched and keeps serving')
|
|
360
|
+
$case.wentOnToReplace = $run.log.Contains('installing/repairing trillboards-detector')
|
|
361
|
+
$case.openVinoRetried = $run.log.Contains('retrying the same detector with ONNX Runtime only')
|
|
362
|
+
Write-Receipt
|
|
363
|
+
if ($run.exit -ne 0) { throw "(a) setup-detector exited $($run.exit)" }
|
|
364
|
+
if (-not $case.trialRefused) { throw '(a) the trial install did not report the refusal' }
|
|
365
|
+
if ($case.wentOnToReplace) { throw '(a) setup-detector went on to replace the detector' }
|
|
366
|
+
if ($receipt.runner.openVinoExpected -and -not $case.openVinoRetried) { throw '(a) the trial did not retry without OpenVINO' }
|
|
367
|
+
if ($case.healthSamples -lt 20) { throw "(a) only $($case.healthSamples) /health samples" }
|
|
368
|
+
if ($case.healthNot200 -ne 0) { throw "(a) /health answered other than 200 $($case.healthNot200) time(s)" }
|
|
369
|
+
if ($case.servingModelsSeen -ne 1) { throw "(a) /health was answered by $($case.servingModelsSeen) different model loads" }
|
|
370
|
+
if ($case.pidAfter -ne $pidBefore) { throw "(a) the detector process changed: $pidBefore -> $($case.pidAfter)" }
|
|
371
|
+
if (-not $case.exeUnchanged) { throw '(a) the detector executable changed or disappeared' }
|
|
372
|
+
if ($case.versionAfter -ne $oldVersion) { throw "(a) the detector reports $($case.versionAfter), expected $oldVersion" }
|
|
373
|
+
$case.passed = $true
|
|
374
|
+
Write-Receipt
|
|
375
|
+
|
|
376
|
+
# --- (b) network cut right after the trial, and (c) the down time ----------
|
|
377
|
+
$case = [ordered]@{ name = 'network cut after the trial install: cold uv cache, cuttable proxy' }
|
|
378
|
+
$receipt.cases.b = $case
|
|
379
|
+
$proxyScript = Join-Path $root 'proxy.py'
|
|
380
|
+
Write-Utf8NoBom $proxyScript $pythonProxy
|
|
381
|
+
$proxyLog = Join-Path $evidence 'proxy-b.log'
|
|
382
|
+
$cut = Join-Path $root 'cut-b'
|
|
383
|
+
$proxyPort = 18765
|
|
384
|
+
$proxyProcess = Start-Process -FilePath $py -ArgumentList @('-I', $proxyScript, $proxyPort, $proxyLog, $cut) -PassThru -WindowStyle Hidden
|
|
385
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
386
|
+
while (-not ((Test-Path -LiteralPath $proxyLog) -and (Get-Content -LiteralPath $proxyLog -Raw) -match 'LISTENING')) {
|
|
387
|
+
if ($watch.Elapsed.TotalSeconds -gt 20) { throw 'the proxy did not start' }
|
|
388
|
+
Start-Sleep -Milliseconds 200
|
|
389
|
+
}
|
|
390
|
+
$samples = Join-Path $evidence 'health-b.csv'
|
|
391
|
+
$poller = Start-HealthPoller $samples (Join-Path $root 'stop-b')
|
|
392
|
+
# The cut: the instant setup-detector logs that the trial passed.
|
|
393
|
+
$cutter = Start-Job -ArgumentList $setupLog, (Get-LogLength), $cut -ScriptBlock {
|
|
394
|
+
param($log, $offset, $cutFile)
|
|
395
|
+
$deadline = (Get-Date).AddMinutes(20)
|
|
396
|
+
while ((Get-Date) -lt $deadline) {
|
|
397
|
+
if (Test-Path -LiteralPath $log) {
|
|
398
|
+
$stream = [IO.File]::Open($log, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
399
|
+
try { $null = $stream.Seek($offset, [IO.SeekOrigin]::Begin); $text = (New-Object IO.StreamReader($stream)).ReadToEnd() }
|
|
400
|
+
finally { $stream.Dispose() }
|
|
401
|
+
if ($text.Contains('trial install passed')) {
|
|
402
|
+
Set-Content -LiteralPath $cutFile -Value ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
|
|
403
|
+
return
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
Start-Sleep -Milliseconds 25
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
Start-Sleep -Seconds 2
|
|
410
|
+
$via = "http://127.0.0.1:$proxyPort"
|
|
411
|
+
$run = Invoke-SetupDetector $newSource @{
|
|
412
|
+
UV_CACHE_DIR = (Join-Path $root 'uv-cache-b'); HTTPS_PROXY = $via; HTTP_PROXY = $via; ALL_PROXY = $null; NO_PROXY = $noProxy }
|
|
413
|
+
$null = Wait-HealthCode 200 120
|
|
414
|
+
Start-Sleep -Seconds 2
|
|
415
|
+
Stop-HealthPoller $poller (Join-Path $root 'stop-b')
|
|
416
|
+
$null = Wait-Job $cutter -Timeout 5; Remove-Job $cutter -Force
|
|
417
|
+
Set-Content -LiteralPath (Join-Path $evidence 'setup-b.log') -Value $run.log -Encoding utf8
|
|
418
|
+
$case.setupExit = $run.exit; $case.setupSeconds = $run.seconds
|
|
419
|
+
if (-not (Test-Path -LiteralPath $cut)) { throw '(b) the trial install never reported passing' }
|
|
420
|
+
$cutAtMs = [long]((Get-Content -LiteralPath $cut -Raw).Trim())
|
|
421
|
+
$proxyLines = @(Get-Content -LiteralPath $proxyLog | Where-Object { $_ -match '^\d+ (CONNECT|REFUSED|REJECTED|ERROR) ' })
|
|
422
|
+
$after = @($proxyLines | Where-Object { [long]($_.Split(' ')[0]) -gt $cutAtMs })
|
|
423
|
+
$case.connectionsBeforeCut = @($proxyLines | Where-Object { [long]($_.Split(' ')[0]) -le $cutAtMs -and $_ -match ' CONNECT ' }).Count
|
|
424
|
+
$case.attemptsAfterCut = $after.Count
|
|
425
|
+
$case.attemptsAfterCutLines = @($after | Select-Object -First 20)
|
|
426
|
+
$health = Read-HealthSamples $samples
|
|
427
|
+
$oldLoad = ($health | Where-Object { $_.code -eq 200 } | Select-Object -First 1).loadedAt
|
|
428
|
+
$beforeCut = @($health | Where-Object { $_.atMs -le $cutAtMs })
|
|
429
|
+
$case.healthSamplesThroughTrial = $beforeCut.Count
|
|
430
|
+
$case.trialNotServedByOld = @($beforeCut | Where-Object { $_.code -ne 200 -or $_.loadedAt -ne $oldLoad }).Count
|
|
431
|
+
$lastOld200 = $health | Where-Object { $_.code -eq 200 -and $_.loadedAt -eq $oldLoad } | Select-Object -Last 1
|
|
432
|
+
$firstNew200 = $health | Where-Object { $_.code -eq 200 -and $_.loadedAt -ne $oldLoad } | Select-Object -First 1
|
|
433
|
+
$firstNewAnswer = if ($lastOld200) { $health | Where-Object { $_.atMs -gt $lastOld200.atMs -and $_.code -ne 0 -and $_.loadedAt -ne $oldLoad } | Select-Object -First 1 } else { $null }
|
|
434
|
+
$case.oldServedUntilMsAfterCut = if ($lastOld200) { $lastOld200.atMs - $cutAtMs } else { $null }
|
|
435
|
+
$case.versionAfter = Get-InstalledVersion
|
|
436
|
+
$case.trialSeconds = if ($run.log -match 'trial install passed in ([0-9.]+) s with \[([^\]]+)\]') { [double]$Matches[1] } else { $null }
|
|
437
|
+
$case.extras = if ($run.log -match 'trial install passed in [0-9.]+ s with \[([^\]]+)\]') { $Matches[1] } else { $null }
|
|
438
|
+
$case.answeredAfterInstall = ($run.log -match 'detector is READY|detector is running and AWAITING ITS MODEL')
|
|
439
|
+
$receipt.cases.c = [ordered]@{
|
|
440
|
+
name = 'detector down time inside (b): the old process''s last /health 200 to the new process''s first'
|
|
441
|
+
downMs = if ($firstNew200 -and $lastOld200) { $firstNew200.atMs - $lastOld200.atMs } else { $null }
|
|
442
|
+
downToFirstAnswerMs = if ($firstNewAnswer -and $lastOld200) { $firstNewAnswer.atMs - $lastOld200.atMs } else { $null }
|
|
443
|
+
firstAnswerTo200Ms = if ($firstNew200 -and $firstNewAnswer) { $firstNew200.atMs - $firstNewAnswer.atMs } else { $null }
|
|
444
|
+
model = 'stand-in ONNX with the RF-DETR Medium signature; the shipped ~128 MB artifact adds its own load to this'
|
|
445
|
+
}
|
|
446
|
+
Write-Receipt
|
|
447
|
+
if ($run.exit -ne 0) { throw "(b) setup-detector exited $($run.exit)" }
|
|
448
|
+
if ($case.connectionsBeforeCut -lt 1) { throw '(b) the trial install never used the network, so the cut proves nothing' }
|
|
449
|
+
if ($case.attemptsAfterCut -ne 0) { throw "(b) $($case.attemptsAfterCut) connection attempt(s) after the cut" }
|
|
450
|
+
if ($case.healthSamplesThroughTrial -lt 20) { throw "(b) only $($case.healthSamplesThroughTrial) /health samples through the trial" }
|
|
451
|
+
if ($case.trialNotServedByOld -ne 0) { throw "(b) the old detector did not answer 200 through the trial ($($case.trialNotServedByOld) sample(s))" }
|
|
452
|
+
if (-not $lastOld200) { throw '(b) the old detector never answered' }
|
|
453
|
+
if ($case.versionAfter -ne $newVersion) { throw "(b) the detector reports $($case.versionAfter), expected $newVersion" }
|
|
454
|
+
if (-not $case.answeredAfterInstall) { throw '(b) setup-detector did not see the new detector answer' }
|
|
455
|
+
if ($null -eq $receipt.cases.c.downMs) { throw '(c) the new detector never answered 200' }
|
|
456
|
+
$case.passed = $true
|
|
457
|
+
$receipt.cases.c.passed = $true
|
|
458
|
+
$receipt.passed = $true
|
|
459
|
+
Write-Receipt
|
|
460
|
+
Write-Host ('PASS: (a) refused with the old detector serving; (b) {0} connection(s) before the cut, 0 after, [{1}] trial {2} s; (c) down {3} ms' -f
|
|
461
|
+
$case.connectionsBeforeCut, $case.extras, $case.trialSeconds, $receipt.cases.c.downMs)
|
|
462
|
+
} catch {
|
|
463
|
+
# Keep the first error: a failure to record it must not replace it.
|
|
464
|
+
$proofFailure = $_
|
|
465
|
+
try { $receipt['failure'] = $proofFailure.Exception.Message; Write-Receipt }
|
|
466
|
+
catch { Write-Host "could not record the failure in the receipt: $($_.Exception.Message)" }
|
|
467
|
+
throw $proofFailure
|
|
468
|
+
} finally {
|
|
469
|
+
if ($proxyProcess -and -not $proxyProcess.HasExited) { Stop-Process -Id $proxyProcess.Id -Force -ErrorAction SilentlyContinue }
|
|
470
|
+
if (Test-Path -LiteralPath $setupLog) { Copy-Item -LiteralPath $setupLog -Destination (Join-Path $evidence 'detector-setup.log') -ErrorAction SilentlyContinue }
|
|
471
|
+
$serviceLog = Join-Path $env:LOCALAPPDATA 'Trillboards\logs\detector.service.log'
|
|
472
|
+
if (Test-Path -LiteralPath $serviceLog) { Copy-Item -LiteralPath $serviceLog -Destination (Join-Path $evidence 'detector.service.log') -ErrorAction SilentlyContinue }
|
|
473
|
+
Write-Receipt
|
|
474
|
+
}
|
|
@@ -227,11 +227,6 @@ if (-not $source) {
|
|
|
227
227
|
# --refresh-package trillboards-detector, NOT --refresh: the latter also
|
|
228
228
|
# re-downloads the pinned ~250 MB onnxruntime wheel on a shop PC every time, for
|
|
229
229
|
# nothing - an exact pin cannot resolve to different bytes.
|
|
230
|
-
Log "installing/repairing trillboards-detector from $source with uv-managed Python $DetectorPython"
|
|
231
|
-
try { Stop-OwnedDetectorForRepair } catch {
|
|
232
|
-
Log "ERROR: detector service could not be safely stopped before repair: $($_.Exception.Message)"
|
|
233
|
-
exit 0
|
|
234
|
-
}
|
|
235
230
|
$runtimeExtra = 'cpu'
|
|
236
231
|
if ($Runtime -eq 'auto') {
|
|
237
232
|
try {
|
|
@@ -241,17 +236,130 @@ if ($Runtime -eq 'auto') {
|
|
|
241
236
|
if ($nvidia.Count) { $runtimeExtra = 'cuda' }
|
|
242
237
|
} catch { Log "WARN: GPU inventory unavailable; selecting CPU: $($_.Exception.Message)" }
|
|
243
238
|
}
|
|
244
|
-
|
|
239
|
+
# Plan v7 W8: an Intel host without NVIDIA also gets the pinned OpenVINO runtime
|
|
240
|
+
# ([openvino], beside [cpu]). It changes nothing by being installed: ONNX Runtime
|
|
241
|
+
# keeps answering until the server asks for OpenVINO (CCTV_DETECTOR_BACKEND) and
|
|
242
|
+
# the engine's own parity probe passes on this host. The Texas store PC (i7-7700,
|
|
243
|
+
# HD 630) is the case: its iGPU was idle under every model.
|
|
244
|
+
$openVinoExtra = $false
|
|
245
|
+
if ($runtimeExtra -eq 'cpu') {
|
|
246
|
+
try {
|
|
247
|
+
$processor = @(Get-CimInstance Win32_Processor -ErrorAction Stop | Select-Object -First 1)
|
|
248
|
+
if ($processor.Count -and [string]$processor[0].Manufacturer -match 'GenuineIntel') { $openVinoExtra = $true }
|
|
249
|
+
} catch { Log "WARN: processor inventory unavailable; OpenVINO is not installed: $($_.Exception.Message)" }
|
|
250
|
+
}
|
|
251
|
+
Log ("Selected detector runtime: $runtimeExtra" + $(if ($openVinoExtra) { ' + openvino (Intel CPU; serves only when the server asks and its parity probe passes)' } else { '' }))
|
|
252
|
+
$installFromStagedCache = $false
|
|
253
|
+
# ONE `uv tool install` per cache mode.
|
|
254
|
+
#
|
|
255
|
+
# ONLINE (the trial install below, and the repair rung): --refresh-package
|
|
256
|
+
# trillboards-detector, so the staged bytes are rebuilt rather than served from
|
|
257
|
+
# uv's cached wheel (see above).
|
|
258
|
+
#
|
|
259
|
+
# OFFLINE (the replacement, once the trial has passed): every byte it needs is in
|
|
260
|
+
# uv's cache, and --offline serves cached index pages at any age, so the step
|
|
261
|
+
# that begins by deleting the old venv cannot wait on or fail on the network. It
|
|
262
|
+
# carries NO refresh: current uv refuses the pair ("the argument `--offline`
|
|
263
|
+
# cannot be used with `--refresh`", uv 0.11.15), and it needs none - it installs
|
|
264
|
+
# the wheel the trial's --refresh-package just rebuilt. Measured 2026-11-17 on
|
|
265
|
+
# uv 0.11.15 with the network dead: same source path, version unchanged, new
|
|
266
|
+
# bytes installed.
|
|
267
|
+
function Invoke-DetectorToolInstall([string]$Extras) {
|
|
268
|
+
if ($script:installFromStagedCache) {
|
|
269
|
+
& $uvCmd.Source tool install --offline --python $DetectorPython --managed-python --force ($source + '[' + $Extras + ']') *>> $LogPath
|
|
270
|
+
} else {
|
|
271
|
+
& $uvCmd.Source tool install --python $DetectorPython --managed-python --force --refresh-package trillboards-detector ($source + '[' + $Extras + ']') *>> $LogPath
|
|
272
|
+
}
|
|
273
|
+
}
|
|
245
274
|
function Install-DetectorRuntime {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
275
|
+
$extras = if ($script:openVinoExtra) { $script:runtimeExtra + ',openvino' } else { $script:runtimeExtra }
|
|
276
|
+
Invoke-DetectorToolInstall $extras
|
|
277
|
+
if ($LASTEXITCODE -ne 0 -and ($script:openVinoExtra -or $script:runtimeExtra -eq 'cuda')) {
|
|
278
|
+
# ONE fallback rung: OpenVINO is only ever beside CPU, so it is either "the same
|
|
279
|
+
# detector without OpenVINO" or "CUDA's detector on the CPU".
|
|
280
|
+
if ($script:openVinoExtra) {
|
|
281
|
+
Log 'WARN: the OpenVINO runtime did not install; retrying the same detector with ONNX Runtime only'
|
|
282
|
+
$script:openVinoExtra = $false
|
|
283
|
+
} else {
|
|
284
|
+
Log 'WARN: CUDA runtime installation failed; retrying the same detector with CPU dependencies'
|
|
285
|
+
$script:runtimeExtra = 'cpu'
|
|
286
|
+
}
|
|
287
|
+
Invoke-DetectorToolInstall $script:runtimeExtra
|
|
251
288
|
}
|
|
252
289
|
return $LASTEXITCODE
|
|
253
290
|
}
|
|
291
|
+
function Get-StagedDetectorVersion {
|
|
292
|
+
param([string] $SourceDir)
|
|
293
|
+
$pyproject = Join-Path $SourceDir 'pyproject.toml'
|
|
294
|
+
if (-not (Test-Path -LiteralPath $pyproject)) { return $null }
|
|
295
|
+
foreach ($line in (Get-Content -LiteralPath $pyproject)) {
|
|
296
|
+
if ($line -match '^\s*version\s*=\s*"([^"]+)"\s*$') { return $Matches[1] }
|
|
297
|
+
}
|
|
298
|
+
return $null
|
|
299
|
+
}
|
|
300
|
+
function Get-InstalledDetectorVersion {
|
|
301
|
+
param([string] $Exe)
|
|
302
|
+
if (-not (Test-Path -LiteralPath $Exe)) { return $null }
|
|
303
|
+
# `--version` prints "trillboards-detector <version>"; take the last token.
|
|
304
|
+
$out = & $Exe --version 2>$null
|
|
305
|
+
if ($LASTEXITCODE -ne 0 -or -not $out) { return $null }
|
|
306
|
+
return ([string]$out).Trim().Split(' ')[-1]
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
# --- 2a. A trial install first, while the running detector keeps answering ----
|
|
310
|
+
# `uv tool install --force` RECREATES the tool venv (uv 0.10.10+: "Recreate Python
|
|
311
|
+
# environments under `uv tool install --force`"). It resolves first, so an index
|
|
312
|
+
# it cannot reach leaves the old venv alone. But once resolution succeeds it
|
|
313
|
+
# deletes the old venv AND trillboards-detector.exe, and only then downloads and
|
|
314
|
+
# installs; if that fails it deletes the new venv as well. With the service
|
|
315
|
+
# already stopped, a WAN drop during the download (the [openvino] wheel alone is
|
|
316
|
+
# 85 MB) left a store PC with NO detector: the finally below restarted a task
|
|
317
|
+
# whose executable uv had deleted, and nothing but the launcher's repair at the
|
|
318
|
+
# next connector start would bring it back (found from code before the 0.2.246
|
|
319
|
+
# install, 2026-11-17).
|
|
320
|
+
#
|
|
321
|
+
# So the identical install runs first into a THROWAWAY tool directory, while the
|
|
322
|
+
# old service keeps serving: it resolves, downloads, builds, and must report the
|
|
323
|
+
# staged version. If that fails with and without OpenVINO, this script exits
|
|
324
|
+
# without having touched the running detector. Only after it passes is the
|
|
325
|
+
# service stopped and the real venv replaced, offline, from what the trial just
|
|
326
|
+
# cached, with the extras that passed.
|
|
327
|
+
$stageRoot = Join-Path $env:LOCALAPPDATA 'Trillboards\detector-stage'
|
|
328
|
+
function Invoke-DetectorTrialInstall {
|
|
329
|
+
$saved = @{}
|
|
330
|
+
foreach ($name in @('UV_TOOL_DIR', 'UV_TOOL_BIN_DIR')) { $saved[$name] = [Environment]::GetEnvironmentVariable($name, 'Process') }
|
|
331
|
+
try {
|
|
332
|
+
[Environment]::SetEnvironmentVariable('UV_TOOL_DIR', (Join-Path $script:stageRoot 'tools'), 'Process')
|
|
333
|
+
[Environment]::SetEnvironmentVariable('UV_TOOL_BIN_DIR', (Join-Path $script:stageRoot 'bin'), 'Process')
|
|
334
|
+
if ((Install-DetectorRuntime) -ne 0) { return $false }
|
|
335
|
+
$trialVersion = Get-InstalledDetectorVersion -Exe (Join-Path $script:stageRoot 'bin\trillboards-detector.exe')
|
|
336
|
+
$packageVersion = Get-StagedDetectorVersion -SourceDir $source
|
|
337
|
+
if (-not $trialVersion -or ($packageVersion -and $trialVersion -ne $packageVersion)) {
|
|
338
|
+
Log "ERROR: the trial-installed detector reports '$trialVersion' but the package is '$packageVersion'"
|
|
339
|
+
return $false
|
|
340
|
+
}
|
|
341
|
+
return $true
|
|
342
|
+
} finally {
|
|
343
|
+
foreach ($name in $saved.Keys) { [Environment]::SetEnvironmentVariable($name, $saved[$name], 'Process') }
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
$trialWatch = [Diagnostics.Stopwatch]::StartNew()
|
|
347
|
+
Log "trial-installing trillboards-detector into $stageRoot while the running detector keeps serving"
|
|
348
|
+
if (-not (Invoke-DetectorTrialInstall)) {
|
|
349
|
+
Log "ERROR: the new detector runtime did not install (see above); the running detector was not touched and keeps serving"
|
|
350
|
+
Remove-Item -LiteralPath $stageRoot -Recurse -Force -ErrorAction SilentlyContinue
|
|
351
|
+
exit 0
|
|
352
|
+
}
|
|
353
|
+
Log ("trial install passed in {0:N1} s with [{1}]; replacing the running detector offline, from uv's cache" -f $trialWatch.Elapsed.TotalSeconds, $(if ($openVinoExtra) { $runtimeExtra + ',openvino' } else { $runtimeExtra }))
|
|
354
|
+
$installFromStagedCache = $true
|
|
355
|
+
|
|
356
|
+
Log "installing/repairing trillboards-detector from $source with uv-managed Python $DetectorPython"
|
|
357
|
+
try { Stop-OwnedDetectorForRepair } catch {
|
|
358
|
+
Log "ERROR: detector service could not be safely stopped before repair: $($_.Exception.Message)"
|
|
359
|
+
exit 0
|
|
360
|
+
}
|
|
254
361
|
$runtimeInstallExit = Install-DetectorRuntime
|
|
362
|
+
Remove-Item -LiteralPath $stageRoot -Recurse -Force -ErrorAction SilentlyContinue
|
|
255
363
|
if ($runtimeInstallExit -ne 0) {
|
|
256
364
|
Log "ERROR: trillboards-detector install failed; the cascade stays off (the VLM still runs every frame)"
|
|
257
365
|
exit 0
|
|
@@ -274,24 +382,6 @@ Log "trillboards-detector installed at $detectorPath"
|
|
|
274
382
|
# so this comparison is the only thing in the chain that can tell a real install
|
|
275
383
|
# from a convincing no-op. It reads the STAGED pyproject rather than a constant:
|
|
276
384
|
# a constant here would be a fourth place the same version is written down.
|
|
277
|
-
function Get-StagedDetectorVersion {
|
|
278
|
-
param([string] $SourceDir)
|
|
279
|
-
$pyproject = Join-Path $SourceDir 'pyproject.toml'
|
|
280
|
-
if (-not (Test-Path -LiteralPath $pyproject)) { return $null }
|
|
281
|
-
foreach ($line in (Get-Content -LiteralPath $pyproject)) {
|
|
282
|
-
if ($line -match '^\s*version\s*=\s*"([^"]+)"\s*$') { return $Matches[1] }
|
|
283
|
-
}
|
|
284
|
-
return $null
|
|
285
|
-
}
|
|
286
|
-
function Get-InstalledDetectorVersion {
|
|
287
|
-
param([string] $Exe)
|
|
288
|
-
if (-not (Test-Path -LiteralPath $Exe)) { return $null }
|
|
289
|
-
# `--version` prints "trillboards-detector <version>"; take the last token.
|
|
290
|
-
$out = & $Exe --version 2>$null
|
|
291
|
-
if ($LASTEXITCODE -ne 0 -or -not $out) { return $null }
|
|
292
|
-
return ([string]$out).Trim().Split(' ')[-1]
|
|
293
|
-
}
|
|
294
|
-
|
|
295
385
|
$wantVersion = Get-StagedDetectorVersion -SourceDir $source
|
|
296
386
|
$haveVersion = Get-InstalledDetectorVersion -Exe $detectorPath
|
|
297
387
|
if (-not $wantVersion) {
|
|
@@ -303,6 +393,9 @@ if (-not $wantVersion) {
|
|
|
303
393
|
Log "WARN: the installed detector reports '$haveVersion' but the staged package is '$wantVersion' - reinstalling from scratch"
|
|
304
394
|
Stop-OwnedDetectorForRepair
|
|
305
395
|
& $uvCmd.Source tool uninstall trillboards-detector *>> $LogPath
|
|
396
|
+
# Online, with --refresh-package: the offline replacement installed what the
|
|
397
|
+
# cache holds, so rebuild from the staged directory instead of asking it again.
|
|
398
|
+
$installFromStagedCache = $false
|
|
306
399
|
$runtimeInstallExit = Install-DetectorRuntime
|
|
307
400
|
$haveVersion = Get-InstalledDetectorVersion -Exe $detectorPath
|
|
308
401
|
if ($haveVersion -eq $wantVersion) {
|