diff --git a/scripts/activate_simulation_worker_release.ps1 b/scripts/activate_simulation_worker_release.ps1 new file mode 100644 index 00000000..1f6bd399 --- /dev/null +++ b/scripts/activate_simulation_worker_release.ps1 @@ -0,0 +1,74 @@ +param( + [Parameter(Mandatory=$true)][ValidatePattern('^[a-f0-9]{16}$')][string]$Release, + [Parameter(Mandatory=$true)][ValidatePattern('^[a-f0-9]{16}$')][string]$ExpectedCurrentRelease, + [string]$EvidenceRoot, + [switch]$Apply +) +# Runtime-only update of an already installed service. Installation, firewall, +# principal, task settings, credentials and tunnel configuration are preserved. +$ErrorActionPreference='Stop' +$root='D:\NDC_MISSIONCORE\runtime\simulation' +$name='ndc-ai-polygon-worker' +if(Test-Path "$root\state\active.json") { throw 'Active episode prevents update' } +$task=Get-ScheduledTask -TaskName $name +if(@($task.Actions).Count -ne 1) { throw 'Expected one installed worker action' } +$old=$task.Actions[0] +$releaseMatches=[regex]::Matches($old.Arguments,'ai-polygon-([a-f0-9]{16})[\\/]+simulation[\\/]+ai-polygon[\\/]+realtime_worker\.py') +if($releaseMatches.Count -ne 1 -or $releaseMatches[0].Groups[1].Value -ne $ExpectedCurrentRelease) { + throw 'Installed worker identity changed' +} +$source="$root\releases\ai-polygon-$Release" +$manifestPath="$root\releases\ai-polygon-$Release.manifest.json" +$digest=(Get-FileHash $manifestPath -Algorithm SHA256).Hash.ToLower() +if(!$digest.StartsWith($Release)) { throw 'Manifest identity mismatch' } +$manifest=Get-Content $manifestPath -Raw | ConvertFrom-Json +$count=0 +foreach($entry in $manifest.PSObject.Properties) { + $path=[IO.Path]::GetFullPath((Join-Path $source $entry.Name)) + if(!$path.StartsWith($source+'\',[StringComparison]::OrdinalIgnoreCase) -or + (Get-FileHash $path -Algorithm SHA256).Hash.ToLower() -ne $entry.Value) { + throw "Source identity mismatch: $($entry.Name)" + } + $count++ +} +if($count -eq 0) { throw 'Empty release' } +$arguments=$old.Arguments.Replace('ai-polygon-'+$ExpectedCurrentRelease,'ai-polygon-'+$Release) +if($EvidenceRoot) { + $EvidenceRoot=[IO.Path]::GetFullPath($EvidenceRoot) + if($EvidenceRoot -notmatch '^[A-Za-z]:\\' -or $EvidenceRoot -match '[&|<>^%!"\r\n]') { + throw 'Evidence storage must be an explicit local Windows directory' + } + if($arguments -match '--evidence-root') { throw 'Review existing evidence storage before replacing it' } + $arguments+=' --evidence-root "'+$EvidenceRoot+'"' +} +$action=New-ScheduledTaskAction -Execute $old.Execute -Argument $arguments -WorkingDirectory $old.WorkingDirectory +$report=[ordered]@{utc=[DateTime]::UtcNow.ToString('o'); task=$name; previous=$ExpectedCurrentRelease; + release=$Release; manifest_sha256=$digest; verified_files=$count; applied=$false; + network_changed=$false; credentials_changed=$false; principal_changed=$false} +if($EvidenceRoot) { $report['evidence_root']=$EvidenceRoot } +if($Apply) { + if($EvidenceRoot) { New-Item -ItemType Directory -Force -Path $EvidenceRoot | Out-Null } + $backup="$root\preparations\worker-activation-$Release" + New-Item -ItemType Directory -Path $backup -ErrorAction Stop | Out-Null + Export-ScheduledTask -TaskName $name | Set-Content -Encoding UTF8 "$backup\previous-task.xml" + $oldPattern="ai-polygon-$ExpectedCurrentRelease[\\/]+simulation[\\/]+ai-polygon[\\/]+realtime_worker\.py" + try { + Stop-ScheduledTask -TaskName $name + $deadline=[DateTime]::UtcNow.AddSeconds(10) + while(@(Get-CimInstance Win32_Process | Where-Object {$_.CommandLine -match $oldPattern}).Count) { + if([DateTime]::UtcNow -ge $deadline) { throw 'Old worker did not stop' } + Start-Sleep -Milliseconds 200 + } + Set-ScheduledTask -TaskName $name -Action $action | Out-Null + Start-ScheduledTask -TaskName $name + $report.applied=$true + } catch { + Set-ScheduledTask -TaskName $name -Action $old | Out-Null + Start-ScheduledTask -TaskName $name + $report['error']=$_.Exception.Message + $report | ConvertTo-Json | Set-Content -Encoding UTF8 "$backup\activation.json" + throw + } + $report | ConvertTo-Json | Set-Content -Encoding UTF8 "$backup\activation.json" +} +$report | ConvertTo-Json diff --git a/simulation/ai-polygon/nav2/check_http_integration.py b/simulation/ai-polygon/nav2/check_http_integration.py index d9ecbc5d..1091a934 100644 --- a/simulation/ai-polygon/nav2/check_http_integration.py +++ b/simulation/ai-polygon/nav2/check_http_integration.py @@ -63,12 +63,13 @@ def main(): def controls(): try: while running.is_set(): - with condition:current=dict(state) - packet=dict(execution_inputs_sha256=inputs['sha256'],pose=original['pose'], - measured_twist=[0.,0.,0.],speed_mps=0.,pose_age_seconds=.01, - perception_age_seconds=0.,**current) - result=request('/control',packet) - responses.append(result) + with condition: + current=dict(state) + packet=dict(execution_inputs_sha256=inputs['sha256'],pose=current.pop('pose',original['pose']), + measured_twist=[0.,0.,0.],speed_mps=0.,pose_age_seconds=.01, + perception_age_seconds=0.,**current) + result=request('/control',packet) + responses.append(result) time.sleep(.05) except BaseException as error:errors.append(error) @@ -183,6 +184,72 @@ def main(): restored=request('/plan',value) assert restored['status']=='path' and restored['controller_goal'][0]=='path',restored with condition:state['observation_id']=value['observation_id'] + # A separate synthetic, stationary floor checks the actual BackUp -> + # rover-gate integration. It does not qualify motion on the city scene. + with condition: + state.update(enabled=False,pose=[0.,0.,.37,0.,0.,0.,1.]) + assert request('/reset',{})['reset'] + ready() + floor=[[i*.05,j*.05,0.] for i in range(-40,41) for j in range(-40,41)] + front=[p for p in floor if p[0]>.75] + retreat=copy.deepcopy(original) + retreat.update(pose=[0.,0.,.37,0.,0.,0.,1.],goal=[1.,0.,0.], + max_speed_mps=.1,allow_reverse=False,translation_allowed=True, + recovery_orientation=False,orientation_target=None,arrival_target=None, + detection_point_indices=[],unlocalized_rear_detection=False, + geometry_age_seconds=0.,detection_age_seconds=0.,semantic_points=[]) + retreat['range_rays']=dict(origins=[[0.,0.,.37],[0.,0.,.37]], + ends=floor,origin_indices=[0]*len(floor)) + retreat['semantic_observations']=[dict(frame_id='retreat-floor',age_seconds=0., + samples=[[*p,1.] for p in floor])] + retreat['points']=floor + deadline=time.monotonic()+15 + while True: + retreat['observation_id']='retreat-bootstrap' + result=request('/plan',retreat) + if result['status']=='path':break + assert time.monotonic()