@trillboards/edge-sdk 0.2.200 → 0.2.203

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.
@@ -223,19 +223,266 @@ function Assert-QualificationModelGeneration($Before, $After) {
223
223
  throw 'The model configuration or producer generation changed during restart qualification'
224
224
  }
225
225
  }
226
- function Wait-QualificationModelReady($Evidence) {
226
+
227
+ function Get-QualificationConnectorTaskState {
228
+ $diagnostic = [ordered]@{ taskName='TrillboardsEdge'; taskPath='\'; cimEnabled=$null; cimEnabledType='unavailable'; rawTaskXml=$null }
229
+ try {
230
+ $task = Get-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop
231
+ $value = $task.Settings.Enabled
232
+ $diagnostic.cimEnabled = if ($value -is [bool]) { $value } else { $null }
233
+ $type = if ($null -eq $value) { 'null' } else { $value.GetType().FullName }
234
+ $diagnostic.cimEnabledType = $type.Substring(0, [Math]::Min(256, $type.Length))
235
+ if ($value -is [string]) {
236
+ $diagnostic.cimEnabledLength = $value.Length
237
+ $diagnostic.cimEnabledPreview = $value.Substring(0, [Math]::Min(256, $value.Length))
238
+ $diagnostic.cimEnabledPreviewTruncated = $value.Length -gt 256
239
+ }
240
+ $sid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
241
+ $expectedExe = Join-Path $env:WINDIR 'System32\wscript.exe'
242
+ $expectedArgs = '"' + (Join-Path $installDir 'bin\trillboards-edge-task.vbs') + '" "auto-sense"'
243
+ $actions = @($task.Actions)
244
+ $owner = [string]$task.Principal.UserId
245
+ if ($owner -notmatch '^S-1-') { $owner = (New-Object Security.Principal.NTAccount($owner)).Translate([Security.Principal.SecurityIdentifier]).Value }
246
+ if ($owner -ne $sid -or $actions.Count -ne 1 -or
247
+ [IO.Path]::GetFullPath([string]$actions[0].Execute) -ine $expectedExe -or
248
+ [string]$actions[0].Arguments -cne $expectedArgs -or
249
+ [IO.Path]::GetFullPath([string]$actions[0].WorkingDirectory) -ine $installDir -or
250
+ [string]$task.State -notin @('Ready','Running','Queued','Disabled')) { throw 'Cannot verify the fresh qualification connector task' }
251
+ # Export only after binding this fresh, unconfigured task's owner and action.
252
+ $rawXml = Export-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop
253
+ if ($rawXml -isnot [string]) { throw 'Unknown qualification task XML type' }
254
+ $diagnostic.rawTaskXml = $rawXml.Substring(0, [Math]::Min(65536, $rawXml.Length))
255
+ $diagnostic.rawTaskXmlTruncated = $rawXml.Length -gt 65536
256
+ $diagnostic.rawTaskXmlLength = $rawXml.Length
257
+ $xml = [xml]$rawXml
258
+ $namespace = $xml.DocumentElement.NamespaceURI
259
+ $diagnostic.namespace = $namespace.Substring(0, [Math]::Min(256, $namespace.Length))
260
+ $diagnostic.namespaceLength = $namespace.Length
261
+ if ($xml.DocumentElement.NamespaceURI -cne 'http://schemas.microsoft.com/windows/2004/02/mit/task') { throw 'Unknown qualification task definition' }
262
+ $ns = New-Object Xml.XmlNamespaceManager($xml.NameTable); $ns.AddNamespace('t', $xml.DocumentElement.NamespaceURI)
263
+ $settings = @($xml.SelectNodes('/t:Task/t:Settings', $ns))
264
+ $toggle = @($xml.SelectNodes('/t:Task/t:Settings/t:Enabled', $ns))
265
+ $principal = @($xml.SelectNodes('/t:Task/t:Principals/t:Principal/t:UserId', $ns))
266
+ $exec = @($xml.SelectNodes('/t:Task/t:Actions/t:Exec', $ns))
267
+ $diagnostic.settingsCount = $settings.Count; $diagnostic.enabledCount = $toggle.Count
268
+ $diagnostic.userIdCount = $principal.Count; $diagnostic.execCount = $exec.Count
269
+ $diagnostic.principalCount = $xml.SelectNodes('/t:Task/t:Principals/t:Principal', $ns).Count
270
+ $diagnostic.actionCount = $xml.SelectNodes('/t:Task/t:Actions/*', $ns).Count
271
+ $samples = @($toggle | Select-Object -First 2)
272
+ $diagnostic.xmlEnabledText = @($samples | ForEach-Object { $_.InnerText.Substring(0, [Math]::Min(256, $_.InnerText.Length)) })
273
+ $diagnostic.xmlEnabledLengths = @($samples | ForEach-Object { $_.InnerText.Length })
274
+ $diagnostic.xmlEnabledTextTruncated = $toggle.Count -gt 2 -or @($samples | Where-Object { $_.InnerText.Length -gt 256 }).Count -gt 0
275
+ if ($settings.Count -ne 1 -or $toggle.Count -gt 1 -or $principal.Count -ne 1 -or $exec.Count -ne 1 -or
276
+ $diagnostic.principalCount -ne 1 -or $diagnostic.actionCount -ne 1 -or
277
+ $task.Settings.Enabled -isnot [bool]) { throw 'Ambiguous qualification task definition' }
278
+ # The Task Scheduler settingsType schema defaults an omitted Enabled to true.
279
+ $xmlEnabled = $true
280
+ if ($toggle.Count -eq 1) {
281
+ try { $xmlEnabled = [Xml.XmlConvert]::ToBoolean($toggle[0].InnerText) }
282
+ catch { throw 'Ambiguous qualification task definition: invalid Enabled boolean' }
283
+ }
284
+ $diagnostic.effectiveXmlEnabled = $xmlEnabled
285
+ if ($task.Settings.Enabled -ne $xmlEnabled) { throw 'Ambiguous qualification task definition: Enabled disagreement' }
286
+ $xmlOwner = [string]$principal[0].InnerText
287
+ if ($xmlOwner -notmatch '^S-1-') { $xmlOwner = (New-Object Security.Principal.NTAccount($xmlOwner)).Translate([Security.Principal.SecurityIdentifier]).Value }
288
+ if ($xmlOwner -ne $sid -or [IO.Path]::GetFullPath([string]$exec[0].Command) -ine $expectedExe -or
289
+ [string]$exec[0].Arguments -cne $expectedArgs -or [IO.Path]::GetFullPath([string]$exec[0].WorkingDirectory) -ine $installDir) {
290
+ throw 'The qualification task changed during ownership inspection'
291
+ }
292
+ # Remove ONLY the mutable task-wide toggle, including its optional presence.
293
+ # Trigger Enabled nodes and every other definition field remain fingerprinted.
294
+ foreach ($node in $toggle) { [void]$node.ParentNode.RemoveChild($node) }
295
+ $sha = [Security.Cryptography.SHA256]::Create()
296
+ try { $fingerprint = [BitConverter]::ToString($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($xml.OuterXml))).Replace('-','').ToLowerInvariant() }
297
+ finally { $sha.Dispose() }
298
+ [pscustomobject]@{ Sid=$sid; Fingerprint=$fingerprint; Enabled=$task.Settings.Enabled; State=[string]$task.State }
299
+ } catch {
300
+ $failure = $_; $message = $_.Exception.Message
301
+ $diagnostic.failure = $message.Substring(0, [Math]::Min(1024, $message.Length))
302
+ $diagnostic.failureTruncated = $message.Length -gt 1024
303
+ try {
304
+ # Preserve the first refusal and any restoration refusal, without an unbounded log.
305
+ $path = $null
306
+ foreach ($index in 1..4) {
307
+ $candidate = Join-Path $root ('task-identity-refusal-' + $index + '.json')
308
+ if (-not (Test-Path -LiteralPath $candidate)) { $path = $candidate; break }
309
+ }
310
+ if (-not $path) { throw 'Task identity diagnostic limit reached' }
311
+ $diagnostic | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $path -Encoding UTF8
312
+ } catch {
313
+ $message = $_.Exception.Message
314
+ throw ($diagnostic.failure + '; task identity diagnostic failed: ' + $message.Substring(0, [Math]::Min(1024, $message.Length)))
315
+ }
316
+ throw $failure
317
+ }
318
+ }
319
+ function Invoke-QualificationServiceInspection([string]$Service) {
320
+ & (Join-Path $installDir 'bin\stop-local-ai.ps1') -Service $Service -Inspect
321
+ }
322
+ function Get-QualificationBootstrapActors($Context) {
323
+ if ($null -eq $Context.AllowedHosts) {
324
+ $Context.AllowedHosts = @()
325
+ foreach ($service in @('Model','Detector')) {
326
+ $null = Invoke-QualificationServiceInspection $service
327
+ $name = if ($service -eq 'Model') { 'TrillboardsLiteRtLm' } else { 'TrillboardsDetector' }
328
+ $task = Get-ScheduledTask -TaskName $name -TaskPath '\' -ErrorAction Stop
329
+ $actions = @($task.Actions); $owner = [string]$task.Principal.UserId
330
+ if ($owner -notmatch '^S-1-') { $owner = (New-Object Security.Principal.NTAccount($owner)).Translate([Security.Principal.SecurityIdentifier]).Value }
331
+ if ($owner -ne $Context.Task.Sid -or $actions.Count -ne 1 -or
332
+ [IO.Path]::GetFullPath([string]$actions[0].Execute) -ine (Join-Path $env:WINDIR 'System32\wscript.exe') -or
333
+ -not [string]$actions[0].Arguments) { throw 'Cannot bind the installed AI host during bootstrap isolation' }
334
+ $Context.AllowedHosts += [pscustomobject]@{ Exe=[string]$actions[0].Execute; Args=[string]$actions[0].Arguments }
335
+ }
336
+ }
337
+ $root = [IO.Path]::GetFullPath($installDir).TrimEnd('\') + '\'
338
+ $markers = @('bin\trillboards-edge-task.vbs','bin\run-connector.ps1','bin\trillboards-edge.cmd',
339
+ 'bin\setup-litertlm.ps1','bin\setup-detector.ps1','lib\edge-sdk\dist\cli.js') |
340
+ ForEach-Object { Join-Path $installDir $_ }
341
+ $processes = @(Get-CimInstance -ClassName Win32_Process -OperationTimeoutSec 5 -ErrorAction Stop)
342
+ $related = @{}
343
+ foreach ($process in $processes) {
344
+ $id = [int]$process.ProcessId
345
+ if ($id -eq $PID) { continue }
346
+ $command = [string]$process.CommandLine; $exe = [string]$process.ExecutablePath
347
+ if ($Context.Traced.ContainsKey($id) -or
348
+ ($exe -and $exe.StartsWith($root, [StringComparison]::OrdinalIgnoreCase)) -or
349
+ $command.IndexOf($root, [StringComparison]::OrdinalIgnoreCase) -ge 0) { $related[$id] = $process }
350
+ }
351
+ # Exclude only exact registered service hosts, before tracing bootstrap children.
352
+ # Inspect above is authority for their service trees; a generic --wait is not.
353
+ foreach ($id in @($related.Keys)) {
354
+ $process = $related[$id]; $allowed = $false
355
+ $Context.Candidates[$id] = [pscustomobject]@{ ProcessId=$id; ParentProcessId=[int]$process.ParentProcessId;
356
+ CreationDate=[string]$process.CreationDate; Exe=[string]$process.ExecutablePath; CommandLine=[string]$process.CommandLine;
357
+ Sid=$null; OwnershipVerified=$false; RoleVerified=$false }
358
+ if ([string]$process.CommandLine -match '^(?:"[^"]+"|\S+)\s*(.*)$') {
359
+ $tail = $Matches[1]
360
+ foreach ($hostAction in $Context.AllowedHosts) {
361
+ if ([string]$process.ExecutablePath -ieq $hostAction.Exe -and $tail -ceq $hostAction.Args) { $allowed = $true }
362
+ }
363
+ }
364
+ if (-not $allowed) { continue }
365
+ if (-not $process.CreationDate) { throw 'AI host generation is unavailable' }
366
+ $owner = Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid -OperationTimeoutSec 5 -ErrorAction Stop
367
+ $live = @(Get-CimInstance -ClassName Win32_Process -Filter ('ProcessId=' + $id) -OperationTimeoutSec 5 -ErrorAction Stop)
368
+ if ($live.Count -eq 0) { $related.Remove($id); continue }
369
+ if ($live.Count -ne 1 -or [string]$live[0].CreationDate -cne [string]$process.CreationDate -or
370
+ [string]$live[0].ExecutablePath -cne [string]$process.ExecutablePath -or [string]$live[0].CommandLine -cne [string]$process.CommandLine -or
371
+ $owner.ReturnValue -ne 0 -or $owner.Sid -ne $Context.Task.Sid) { throw 'AI host identity changed during bootstrap isolation' }
372
+ $Context.Candidates[$id].Sid = [string]$owner.Sid
373
+ $Context.Candidates[$id].OwnershipVerified = $true; $Context.Candidates[$id].RoleVerified = $true
374
+ $related.Remove($id)
375
+ }
376
+ # Descendants count only when observed beside a positively identified parent.
377
+ # Remember already observed children across polls; never infer a new orphan's lineage.
378
+ do {
379
+ $added = $false
380
+ foreach ($process in $processes) {
381
+ $id = [int]$process.ProcessId; $parent = [int]$process.ParentProcessId
382
+ if ($related.ContainsKey($id) -or $id -eq $PID) { continue }
383
+ if ($related.ContainsKey($parent)) { $related[$id] = $process; $added = $true }
384
+ elseif ($Context.Traced.ContainsKey($parent) -and -not $Context.Traced.ContainsKey($id)) {
385
+ throw 'A pending bootstrap descendant has unverifiable parent identity'
386
+ }
387
+ }
388
+ } while ($added)
389
+ $busy = @()
390
+ $ordered = @($related.Keys | Sort-Object {
391
+ $walk = [int]$_; $depth = 0; $seen = @{}
392
+ while ($related.ContainsKey($walk)) {
393
+ if ($seen.ContainsKey($walk)) { throw 'Bootstrap process ancestry is cyclic' }
394
+ $seen[$walk] = $true
395
+ $parent = [int]$related[$walk].ParentProcessId
396
+ if (-not $related.ContainsKey($parent)) { break }
397
+ $walk = $parent; $depth++
398
+ }
399
+ $depth
400
+ })
401
+ foreach ($id in $ordered) {
402
+ $process = $related[$id]
403
+ if (-not $Context.Candidates.ContainsKey($id)) {
404
+ $Context.Candidates[$id] = [pscustomobject]@{ ProcessId=$id; ParentProcessId=[int]$process.ParentProcessId;
405
+ CreationDate=[string]$process.CreationDate; Exe=[string]$process.ExecutablePath; CommandLine=[string]$process.CommandLine;
406
+ Sid=$null; OwnershipVerified=$false; RoleVerified=$false }
407
+ }
408
+ if (-not $process.CreationDate -or -not $process.ExecutablePath -or -not $process.CommandLine) { throw 'Bootstrap actor identity is unavailable' }
409
+ $identity = [string]$process.CreationDate + '|' + [string]$process.ExecutablePath + '|' + [string]$process.CommandLine
410
+ if ($Context.Traced.ContainsKey($id) -and $Context.Traced[$id] -cne $identity) { throw 'A bootstrap PID was replaced during isolation' }
411
+ try { $owner = Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid -OperationTimeoutSec 5 -ErrorAction Stop }
412
+ catch {
413
+ $remaining = @(Get-CimInstance -ClassName Win32_Process -Filter ('ProcessId=' + $id) -OperationTimeoutSec 5 -ErrorAction Stop)
414
+ if ($remaining.Count -eq 0) { continue }
415
+ throw
416
+ }
417
+ $live = @(Get-CimInstance -ClassName Win32_Process -Filter ('ProcessId=' + $id) -OperationTimeoutSec 5 -ErrorAction Stop)
418
+ if ($live.Count -eq 0) { continue }
419
+ if ($live.Count -ne 1 -or
420
+ ([string]$live[0].CreationDate + '|' + [string]$live[0].ExecutablePath + '|' + [string]$live[0].CommandLine) -cne $identity) {
421
+ throw 'Bootstrap actor changed during owner inspection'
422
+ }
423
+ if ($owner.ReturnValue -ne 0 -or $owner.Sid -ne $Context.Task.Sid) { throw 'A related bootstrap actor has foreign or unknown ownership' }
424
+ $Context.Candidates[$id].Sid = [string]$owner.Sid; $Context.Candidates[$id].OwnershipVerified = $true
425
+ $knownRoot = @($markers | Where-Object { ([string]$process.CommandLine).IndexOf($_, [StringComparison]::OrdinalIgnoreCase) -ge 0 }).Count -gt 0
426
+ $knownChild = $Context.Traced.ContainsKey($id) -or
427
+ ($related.ContainsKey([int]$process.ParentProcessId) -and $Context.Traced.ContainsKey([int]$process.ParentProcessId))
428
+ if ($related.ContainsKey([int]$process.ParentProcessId) -and
429
+ [DateTime]$process.CreationDate -lt [DateTime]$related[[int]$process.ParentProcessId].CreationDate) { throw 'Bootstrap parent generation is unverifiable' }
430
+ $exe = [IO.Path]::GetFullPath([string]$process.ExecutablePath)
431
+ # Windows creates this console child for the observed setup PowerShell host.
432
+ # It stays BUSY until natural exit; a root-marker/orphan or lookalike is not authority.
433
+ $consoleChild = [string]$process.Name -ieq 'conhost.exe'
434
+ if (($consoleChild -and (-not $knownChild -or $exe -ine (Join-Path $env:WINDIR 'System32\conhost.exe'))) -or
435
+ (-not $consoleChild -and ((-not $knownRoot -and -not $knownChild) -or [string]$process.Name -notin
436
+ @('powershell.exe','cmd.exe','wscript.exe','node.exe','uv.exe','python.exe','pythonw.exe','litert-lm.exe','trillboards-detector.exe','curl.exe')))) {
437
+ throw 'An unknown process belongs to the qualification bootstrap'
438
+ }
439
+ $windowsExe = @('System32\cmd.exe','SysWOW64\cmd.exe','System32\wscript.exe','SysWOW64\wscript.exe',
440
+ 'System32\WindowsPowerShell\v1.0\powershell.exe','SysWOW64\WindowsPowerShell\v1.0\powershell.exe','System32\curl.exe','System32\conhost.exe') |
441
+ ForEach-Object { Join-Path $env:WINDIR $_ }
442
+ $userTool = $exe.StartsWith((Join-Path $env:USERPROFILE '.local\bin\'), [StringComparison]::OrdinalIgnoreCase) -or
443
+ $exe.StartsWith((Join-Path $env:APPDATA 'uv\'), [StringComparison]::OrdinalIgnoreCase) -or
444
+ $exe.StartsWith((Join-Path $env:LOCALAPPDATA 'uv\'), [StringComparison]::OrdinalIgnoreCase)
445
+ if ([IO.Path]::GetFileName($exe) -ine [string]$process.Name -or
446
+ (-not ($windowsExe -icontains $exe) -and -not $exe.StartsWith($root, [StringComparison]::OrdinalIgnoreCase) -and -not $userTool)) {
447
+ throw 'The bootstrap actor executable is outside its owned runtime'
448
+ }
449
+ $Context.Traced[$id] = $identity
450
+ $Context.Candidates[$id].RoleVerified = $true
451
+ $Context.OwnedActors[$id] = $Context.Candidates[$id]
452
+ $busy += $Context.OwnedActors[$id]
453
+ }
454
+ return $busy
455
+ }
456
+
457
+
458
+ function Wait-QualificationModelReady($Evidence, $BootstrapContext = $null) {
227
459
  $started = Get-QualificationClockSeconds
460
+ if ($null -ne $BootstrapContext -and $null -ne $BootstrapContext.FirstStarted) {
461
+ $started = [double]$BootstrapContext.FirstStarted
462
+ $Evidence.startedAtUtc = $BootstrapContext.FirstStartedAtUtc
463
+ $BootstrapContext.FirstStarted = $null
464
+ }
228
465
  $barrier = New-QualificationSetupBarrier
229
466
  try {
230
467
  while (((Get-QualificationClockSeconds) - $started) -lt 120) {
231
468
  $held = $false
232
469
  try {
233
- try { $held = $barrier.WaitOne(0) } catch [Threading.AbandonedMutexException] { $held = $true; $Evidence.abandonedSetupOwner = $true }
234
- if ($held) {
235
- $Evidence.setupBarrierAcquired = $true
236
- $snapshot = Get-QualificationModelSnapshot
237
- $Evidence.lastReadinessSnapshot = $snapshot
238
- if ($snapshot.ready -and ((Get-QualificationClockSeconds) - $started) -lt 120) { return $snapshot }
470
+ $bootstrapReady = $true
471
+ if ($null -ne $BootstrapContext) {
472
+ $task = Get-QualificationConnectorTaskState
473
+ if ($task.Fingerprint -cne $BootstrapContext.Task.Fingerprint -or $task.Enabled) { throw 'Bootstrap ownership or disabled state changed during drain' }
474
+ $actors = @(Get-QualificationBootstrapActors $BootstrapContext)
475
+ $Evidence.bootstrapActors = $actors
476
+ $bootstrapReady = $task.State -notin @('Running','Queued') -and $actors.Count -eq 0 -and ((Get-QualificationClockSeconds) - $started) -lt 120
477
+ }
478
+ if ($bootstrapReady) {
479
+ try { $held = $barrier.WaitOne(0) } catch [Threading.AbandonedMutexException] { $held = $true; $Evidence.abandonedSetupOwner = $true }
480
+ if ($held) {
481
+ $Evidence.setupBarrierAcquired = $true
482
+ $snapshot = Get-QualificationModelSnapshot
483
+ $Evidence.lastReadinessSnapshot = $snapshot
484
+ if ($snapshot.ready -and ((Get-QualificationClockSeconds) - $started) -lt 120) { return $snapshot }
485
+ }
239
486
  }
240
487
  } finally { if ($held) { $barrier.ReleaseMutex() } }
241
488
  $remaining = 120 - ((Get-QualificationClockSeconds) - $started)
@@ -298,6 +545,91 @@ function Assert-RestartImageInference([string]$ServiceName) {
298
545
  }
299
546
  }
300
547
 
548
+
549
+ function Invoke-QualificationServiceRestarts {
550
+ # This is an isolated fresh-install AI test, not a paired sensing restart.
551
+ # Capture restoration authority before the first write; never stop a setup actor.
552
+ $bootstrapContext = [ordered]@{ Task=$null; AllowedHosts=$null; Traced=@{}; Candidates=@{}; OwnedActors=@{}; FirstStarted=(Get-QualificationClockSeconds); FirstStartedAtUtc=[DateTimeOffset]::UtcNow.ToString('o') }
553
+ $receipt.bootstrapIsolation = [ordered]@{ isolatedFreshAiOnly=$true; disabledVerified=$false; holdFailure=$null; afterRestarts=@(); restored=$false }
554
+ $failure = $null; $restoreFailure = $null
555
+ try {
556
+ if (Test-Path -LiteralPath (Join-Path $installDir 'trillboards.config.json')) { throw 'Bootstrap isolation refuses a configured connector' }
557
+ $bootstrapContext.Task = Get-QualificationConnectorTaskState
558
+ if (((Get-QualificationClockSeconds) - $bootstrapContext.FirstStarted) -ge 120) { throw 'Bootstrap inspection exceeded the existing 120-second readiness deadline' }
559
+ $receipt.bootstrapIsolation.originalEnabled = $bootstrapContext.Task.Enabled
560
+ $receipt.bootstrapIsolation.taskFingerprint = $bootstrapContext.Task.Fingerprint
561
+ if ($bootstrapContext.Task.Enabled) {
562
+ Disable-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop | Out-Null
563
+ }
564
+ $disabled = Get-QualificationConnectorTaskState
565
+ if ($disabled.Fingerprint -cne $bootstrapContext.Task.Fingerprint -or $disabled.Enabled) { throw 'The owned bootstrap task did not remain unchanged and disabled' }
566
+ $receipt.bootstrapIsolation.disabledVerified = $true
567
+ $powershell = Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'
568
+ foreach ($service in @(@{ Name = 'Model'; Task = 'TrillboardsLiteRtLm' }, @{ Name = 'Detector'; Task = 'TrillboardsDetector' })) {
569
+ $preStop = [ordered]@{ service = $service.Name; phase = 'before-stop-setup-completion'; passed = $false;
570
+ setupBarrierAcquired = $false; startedAtUtc = [DateTimeOffset]::UtcNow.ToString('o'); readinessDeadlineSeconds = 120 }
571
+ $receipt.serviceRestartPreparationChecks += $preStop
572
+ try {
573
+ # Completion precondition only; the existing waiter releases the mutex before stop/start.
574
+ $preStop.snapshot = Wait-QualificationModelReady $preStop $bootstrapContext
575
+ $preStop.passed = $true
576
+ } catch {
577
+ $preStop.failure = $_.Exception.Message
578
+ throw
579
+ } finally {
580
+ $preStop.completedAtUtc = [DateTimeOffset]::UtcNow.ToString('o')
581
+ }
582
+ $null = Invoke-QualificationProcess -File $powershell -Arguments @('-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File',
583
+ (Join-Path $installDir 'bin\stop-local-ai.ps1'), '-Service', $service.Name) -LogName ('stop-' + $service.Name + '.log') -TimeoutSeconds 90
584
+ Enable-ScheduledTask -TaskName $service.Task -TaskPath '\' -ErrorAction Stop | Out-Null
585
+ Start-ScheduledTask -TaskName $service.Task -TaskPath '\' -ErrorAction Stop
586
+ Assert-RestartImageInference -ServiceName $service.Name
587
+ if ($null -ne $bootstrapContext) {
588
+ $heldTask = Get-QualificationConnectorTaskState
589
+ $receipt.bootstrapIsolation.afterRestarts += [ordered]@{ service=$service.Name; atUtc=[DateTimeOffset]::UtcNow.ToString('o');
590
+ fingerprint=$heldTask.Fingerprint; enabled=$heldTask.Enabled; state=$heldTask.State }
591
+ if ($heldTask.Fingerprint -cne $bootstrapContext.Task.Fingerprint -or $heldTask.Enabled) {
592
+ $receipt.bootstrapIsolation.holdFailure = 'Bootstrap isolation was lost during restart acceptance'
593
+ throw $receipt.bootstrapIsolation.holdFailure
594
+ }
595
+ }
596
+ }
597
+ } catch {
598
+ $failure = $_
599
+ $receipt.bootstrapIsolation.failure = $_.Exception.Message
600
+ } finally {
601
+ $receipt.bootstrapIsolation.actorCandidates = @($bootstrapContext.Candidates.Values)
602
+ $receipt.bootstrapIsolation.ownedActorsSeen = @($bootstrapContext.OwnedActors.Values)
603
+ if ($null -ne $bootstrapContext.Task) {
604
+ try {
605
+ $current = Get-QualificationConnectorTaskState
606
+ if ($current.Fingerprint -cne $bootstrapContext.Task.Fingerprint) { throw 'The connector task was replaced; its enabled state was not changed' }
607
+ if ($receipt.bootstrapIsolation.disabledVerified -and $current.Enabled) {
608
+ if ($null -eq $receipt.bootstrapIsolation.holdFailure) { $receipt.bootstrapIsolation.holdFailure = 'Bootstrap isolation was lost before restoration' }
609
+ if ($null -eq $failure) {
610
+ $failure = [InvalidOperationException]::new($receipt.bootstrapIsolation.holdFailure)
611
+ $receipt.bootstrapIsolation.failure = $receipt.bootstrapIsolation.holdFailure
612
+ }
613
+ }
614
+ if ($current.Enabled -ne $bootstrapContext.Task.Enabled) {
615
+ if ($bootstrapContext.Task.Enabled) { Enable-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop | Out-Null }
616
+ else { Disable-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop | Out-Null }
617
+ }
618
+ $restored = Get-QualificationConnectorTaskState
619
+ if ($restored.Fingerprint -cne $bootstrapContext.Task.Fingerprint -or $restored.Enabled -ne $bootstrapContext.Task.Enabled) { throw 'The owned connector enabled state did not restore' }
620
+ $receipt.bootstrapIsolation.restored = $true
621
+ } catch {
622
+ $restoreFailure = $_
623
+ $receipt.bootstrapIsolation.restoreFailure = $_.Exception.Message
624
+ }
625
+ }
626
+ }
627
+ # Preserve both diagnostics, and retain the original failure when both occurred.
628
+ if ($null -ne $failure) { throw $failure }
629
+ if ($null -ne $restoreFailure) { throw $restoreFailure }
630
+ }
631
+
632
+
301
633
  try {
302
634
  if ([bool]$CustomerPackagePath -ne [bool]$ManifestPath) { throw 'Candidate package and manifest paths must be provided together' }
303
635
  $localCandidate = [bool]$CustomerPackagePath
@@ -369,27 +701,7 @@ try {
369
701
  Assert-ImageInference
370
702
  $receipt.repeatInstallPassed = $true; $receipt.phase = 'service-restart'; $receipt.serviceRestartChecks = @()
371
703
  $receipt.serviceRestartPreparationChecks = @()
372
- $powershell = Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'
373
- foreach ($service in @(@{ Name = 'Model'; Task = 'TrillboardsLiteRtLm' }, @{ Name = 'Detector'; Task = 'TrillboardsDetector' })) {
374
- $preStop = [ordered]@{ service = $service.Name; phase = 'before-stop-setup-completion'; passed = $false;
375
- setupBarrierAcquired = $false; startedAtUtc = [DateTimeOffset]::UtcNow.ToString('o'); readinessDeadlineSeconds = 120 }
376
- $receipt.serviceRestartPreparationChecks += $preStop
377
- try {
378
- # Completion precondition only; the existing waiter releases the mutex before stop/start.
379
- $preStop.snapshot = Wait-QualificationModelReady $preStop
380
- $preStop.passed = $true
381
- } catch {
382
- $preStop.failure = $_.Exception.Message
383
- throw
384
- } finally {
385
- $preStop.completedAtUtc = [DateTimeOffset]::UtcNow.ToString('o')
386
- }
387
- $null = Invoke-QualificationProcess -File $powershell -Arguments @('-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File',
388
- (Join-Path $installDir 'bin\stop-local-ai.ps1'), '-Service', $service.Name) -LogName ('stop-' + $service.Name + '.log') -TimeoutSeconds 90
389
- Enable-ScheduledTask -TaskName $service.Task -TaskPath '\' -ErrorAction Stop | Out-Null
390
- Start-ScheduledTask -TaskName $service.Task -TaskPath '\' -ErrorAction Stop
391
- Assert-RestartImageInference -ServiceName $service.Name
392
- }
704
+ Invoke-QualificationServiceRestarts
393
705
  $receipt.serviceRestartPassed = $true; $receipt.phase = 'uninstall'
394
706
  $receipt.uninstallerSha256 = Invoke-InstalledUninstaller -InstallDir $installDir -RunRoot $root -InheritPowerShellModulePath:($PowerShellModuleEnvironment -eq 'Inherited')
395
707
  foreach ($name in $taskNames) {
package/dist/EdgeAgent.js CHANGED
@@ -44,7 +44,7 @@ const edge_ads_1 = require("@trillboards/edge-ads");
44
44
  const CommandRouter_1 = require("./CommandRouter");
45
45
  const config_1 = require("./config");
46
46
  const dataDir_1 = require("./dataDir");
47
- const SDK_VERSION = '0.2.200';
47
+ const SDK_VERSION = '0.2.203';
48
48
  class EdgeAgent extends events_1.EventEmitter {
49
49
  constructor(config, deps) {
50
50
  super();
@@ -31,7 +31,7 @@ export interface DiagnosticReport {
31
31
  skipped: number;
32
32
  };
33
33
  }
34
- declare const SDK_VERSION = "0.2.200";
34
+ declare const SDK_VERSION = "0.2.203";
35
35
  declare function checkNodeVersion(): CheckResult;
36
36
  declare function checkPlatform(): CheckResult;
37
37
  declare function checkMemory(): CheckResult;
package/dist/diagnose.js CHANGED
@@ -63,7 +63,7 @@ const localNetworkAccess_1 = require("./localNetworkAccess");
63
63
  // ---------------------------------------------------------------------------
64
64
  // SDK version — mirrors package.json; kept in sync by CI
65
65
  // ---------------------------------------------------------------------------
66
- const SDK_VERSION = '0.2.200';
66
+ const SDK_VERSION = '0.2.203';
67
67
  exports._SDK_VERSION = SDK_VERSION;
68
68
  // ---------------------------------------------------------------------------
69
69
  // ANSI helpers (no external deps)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trillboards/edge-sdk",
3
- "version": "0.2.200",
3
+ "version": "0.2.203",
4
4
  "description": "Composable cross-platform Edge AI SDK for audience sensing on DOOH/CTV devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",