Make dev-watch confirm live reloads

This commit is contained in:
Meta Vens 2026-05-09 00:04:45 +01:00
commit de3b639bcf
6 changed files with 139 additions and 26 deletions

View file

@ -78,6 +78,12 @@ fingerprint is not retried until files change again.
It also watches the recorded script-owned process. If the visible window is
closed or the recorded process dies, the watcher relaunches from a fresh slot on
the next poll instead of sitting there with its hands folded like this is fine.
To reopen a closed visible window from the last good slot without rebuilding,
run the watcher with:
```powershell
.\scripts\dev-watch.ps1 -ReopenWhenClosed
```
Shader edits do not restart the process. The dev reload runner passes the
source `Aquarium.hlsl` path into the live app, and the renderer polls that file,
@ -91,8 +97,11 @@ assembly load context, while `dev-watch.ps1` builds live-only changes into
`artifacts\dev-reload\live-slots` and updates `live-current.txt`. The running
host sees the pointer change, loads and starts the new runtime first, then
disposes the old one only after the replacement is valid. A bad live DLL leaves
the previous runtime alive and reports the reload failure to stderr. Successful
reloads rehydrate through CultCache without restarting the window or D3D device.
the previous runtime alive and reports the reload failure to stderr. The watcher
waits for the host log to acknowledge the exact live DLL path before calling a
live reload successful; pointer updates without host acknowledgement are treated
as reload failures. Successful reloads rehydrate through CultCache without
restarting the window or D3D device.
Host, renderer, contract, project, script, and `src\Aquarium.Engine\Assets`
content changes still rebuild and restart the apphost. Runtime content belongs
to the process image; shader hot reload cannot make a running renderer discover

View file

@ -1,10 +1,12 @@
param(
[switch]$Headless,
[switch]$NoInitialLaunch,
[switch]$ReopenWhenClosed,
[switch]$Once,
[int]$IntervalMilliseconds = 1000,
[int]$DebounceMilliseconds = 350,
[int]$RetainSlots = 12
[int]$RetainSlots = 12,
[int]$LiveReloadAckTimeoutSeconds = 6
)
$ErrorActionPreference = "Stop"
@ -24,6 +26,10 @@ $ownedProcessStatePath = if ($Headless) { $headlessStatePath } else { $visibleSt
New-Item -ItemType Directory -Force -Path (Split-Path $watchLogPath) | Out-Null
New-Item -ItemType Directory -Force -Path $liveSlotRoot | Out-Null
if ($Headless -and $ReopenWhenClosed) {
throw "-ReopenWhenClosed is for the visible dev window; do not combine it with -Headless."
}
function Write-WatchLog([string]$message) {
$line = "$(Get-Date -Format o) $message"
Write-Host $line
@ -193,40 +199,75 @@ function Invoke-Reload {
}
}
function Get-OwnedProcessState {
if (-not (Test-Path $ownedProcessStatePath)) {
return $null
}
try {
return Import-Clixml -Path $ownedProcessStatePath
}
catch {
Write-WatchLog "Could not read script-owned process state. $($_.Exception.Message)"
return $null
}
}
function Test-OwnedProcessRunning {
if ($NoInitialLaunch) {
return $true
}
if (-not (Test-Path $ownedProcessStatePath)) {
$state = Get-OwnedProcessState
if (-not $state -or -not $state.pid -or -not $state.slot) {
return $false
}
$process = Get-Process -Id ([int]$state.pid) -ErrorAction SilentlyContinue
if (-not $process) {
return $false
}
$recordedPath = [string]$state.slot
$commandLine = $null
try {
$state = Import-Clixml -Path $ownedProcessStatePath
if (-not $state.pid -or -not $state.slot) {
return $false
}
$process = Get-Process -Id ([int]$state.pid) -ErrorAction SilentlyContinue
if (-not $process) {
return $false
}
$recordedPath = [string]$state.slot
$commandLine = $null
try {
$commandLine = (Get-CimInstance Win32_Process -Filter "ProcessId = $($process.Id)").CommandLine
}
catch {
$commandLine = $null
}
return [bool]($commandLine -and $commandLine -like "*$recordedPath*")
$commandLine = (Get-CimInstance Win32_Process -Filter "ProcessId = $($process.Id)").CommandLine
}
catch {
Write-WatchLog "Could not inspect script-owned process state; will relaunch. $($_.Exception.Message)"
return $false
$commandLine = $null
}
return [bool]($commandLine -and $commandLine -like "*$recordedPath*")
}
function Invoke-Reopen {
param([string]$reason)
if ($Headless) {
Invoke-Reload $reason
return
}
Write-WatchLog "Reopen requested: $reason"
$arguments = @(
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-File", $reloadScript,
"-Reopen",
"-RetainSlots", "$RetainSlots"
)
$process = Start-Process `
-FilePath "powershell" `
-ArgumentList $arguments `
-WorkingDirectory $repoRoot `
-Wait `
-PassThru `
-NoNewWindow
if ($process.ExitCode -ne 0) {
throw "dev-reload -Reopen failed with exit code $($process.ExitCode)."
}
}
@ -250,6 +291,53 @@ function Invoke-LiveReload {
Set-Content -Path $liveReloadPointerPath -Value $liveAssemblyPath -Encoding UTF8
Write-WatchLog "Live reload pointer updated: $liveAssemblyPath"
Wait-LiveReloadAcknowledged $liveAssemblyPath
}
function Wait-LiveReloadAcknowledged {
param([string]$liveAssemblyPath)
if ($NoInitialLaunch) {
Write-WatchLog "Live reload acknowledgement skipped: -NoInitialLaunch does not own a running process."
return
}
if (-not (Test-OwnedProcessRunning)) {
throw "live reload pointer was updated, but no script-owned process is running to load it."
}
$state = Get-OwnedProcessState
if (-not $state -or -not $state.stdoutLog) {
Write-WatchLog "Live reload acknowledgement skipped: no running process log is recorded."
return
}
$stdoutLog = [string]$state.stdoutLog
$stderrLog = if ($state.stderrLog) { [string]$state.stderrLog } else { $null }
$timeoutSeconds = [Math]::Max(1, $LiveReloadAckTimeoutSeconds)
$deadline = (Get-Date).AddSeconds($timeoutSeconds)
$appliedLine = "Live runtime reload applied: $liveAssemblyPath"
while ((Get-Date) -lt $deadline) {
if (Test-Path $stdoutLog) {
$stdoutTail = (Get-Content -Path $stdoutLog -Tail 120 -ErrorAction SilentlyContinue) -join "`n"
if ($stdoutTail.Contains($appliedLine)) {
Write-WatchLog "Live reload acknowledged by host: $liveAssemblyPath"
return
}
}
if ($stderrLog -and (Test-Path $stderrLog)) {
$stderrTail = (Get-Content -Path $stderrLog -Tail 120 -ErrorAction SilentlyContinue) -join "`n"
if ($stderrTail -match "Live runtime reload failed") {
throw "host reported live runtime reload failure. See $stderrLog"
}
}
Start-Sleep -Milliseconds 250
}
throw "live reload pointer was updated, but host did not acknowledge loading $liveAssemblyPath within $timeoutSeconds seconds. Check $stdoutLog and $stderrLog."
}
$lastGoodFingerprint = Wait-StableFingerprints
@ -275,7 +363,13 @@ do {
if (-not (Test-OwnedProcessRunning)) {
try {
Invoke-Reload "script-owned process is not running"
if ($ReopenWhenClosed) {
Invoke-Reopen "script-owned process is not running"
}
else {
Invoke-Reload "script-owned process is not running"
}
$lastGoodFingerprint = Wait-StableFingerprints
$lastFailedFingerprint = $null
$currentFingerprint = $lastGoodFingerprint

View file

@ -33,3 +33,4 @@
{"area":"renderer/taa","lesson":"TAA Gate 3J restores debug mode 1 to true raw scene color and stops final Grid pixels from blending previous color history. The current Grid renderer now uses analytic current Grid color for final output and writes that estimate into history; history age/weight/color remain diagnostics until a real transparent/volumetric composition contract needs color history again.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"}
{"area":"renderer/taa","lesson":"TAA Gate 3L disables projection jitter in the live frame by scaling Halton jitter to zero. Visible judder on Self/planet surfaces means the resolver is not yet hiding sample offsets; jitter should stay disabled until opaque and Grid paths both prove stable.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/D3D11Renderer.cs","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"}
{"area":"renderer/taa","lesson":"Removed the abandoned unjittered Grid retrace after projection jitter was disabled. The retrace was a temporary splint that solved the Grid surface twice; with live jitter at zero, Grid analytic final color can reconstruct from the existing current hit without adding renderer Jenga.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"}
{"area":"dev-loop/reload","lesson":"Live runtime reload must be end-to-end acknowledged. dev-watch now treats live-current.txt as a request, not success: after building a live slot and updating the pointer, it waits for the running host stdout to report the exact live DLL path or marks the reload failed. Visible dev windows can use dev-watch -ReopenWhenClosed to reopen the last good slot without rebuilding after the window is closed.","files":["scripts/dev-watch.ps1","README.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-watch.ps1 -NoInitialLaunch -Once -IntervalMilliseconds 10 -DebounceMilliseconds 10 -RetainSlots 4",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"}

View file

@ -14,6 +14,8 @@ current_model:
shader: src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl
overlay_text: src/Aquarium.Engine/Render/DirectWriteOverlay.cs
runtime_loader: src/Aquarium.Engine/Live/LiveRuntimeLoader.cs
dev_reload: scripts/dev-reload.ps1
dev_watch: scripts/dev-watch.ps1
live_runtime:
contracts: src/Aquarium.Engine.Contracts
implementation: src/Aquarium.Engine.Live
@ -44,6 +46,8 @@ invariants:
- Overlay text is DirectWrite final-pixel UI; scene text needs renderer-owned billboards.
- CultCache persists live app state through reload.
- Failed shader/live-runtime reloads must leave the last good frame alive.
- Live-runtime reload success requires host acknowledgement of the exact live DLL path, not merely a pointer update.
- Closed visible dev windows can be reopened from the last good slot without rebuilding.
renderer_state:
current:

View file

@ -74,7 +74,8 @@
"state_and_reload": [
"CultCache is the client memory organ. Runtime state, camera, renderer knobs, body state, UI state, and future Epiphany connection state should be typed Cult documents.",
"The current live document is epiphany.aquarium.live_state, stored through CultLib MessagePack backing. Direct runs can use --cache or AQUARIUM_CULTCACHE_PATH.",
"dev-reload builds disposable apphost slots so a running window does not lock normal build output. dev-watch hot reloads shaders and live runtime DLLs while preserving the last good process. Host/core/content changes, scripts, and src/Aquarium.Engine/Assets must rebuild and restart the apphost on demand. dev-watch must also relaunch if its recorded script-owned process is no longer running.",
"dev-reload builds disposable apphost slots so a running window does not lock normal build output. dev-watch hot reloads shaders and live runtime DLLs while preserving the last good process. Host/core/content changes, scripts, and src/Aquarium.Engine/Assets must rebuild and restart the apphost on demand. dev-watch must also relaunch if its recorded script-owned process is no longer running. For visible windows, dev-watch -ReopenWhenClosed reopens the last good visible slot without rebuilding.",
"Live runtime reload is not successful just because dev-watch wrote live-current.txt. The watcher must see the host acknowledge the exact live DLL path in stdout, or treat the update as failed and keep the previous runtime/process alive.",
"Shader reload failure must keep the previous good shader objects bound. Live-runtime reload failure must keep the previous runtime alive. Rehydrate from CultCache before claiming reload survival."
],
"salvage_without_baggage": [

View file

@ -96,3 +96,7 @@ prototype integrated along the camera ray before surface composition.
surfaces visibly juddered. Keep jitter disabled until opaque and Grid resolve
both hide the offset. Removed the abandoned unjittered Grid retrace; Grid
analytic final now uses the existing current hit while jitter is zero.
- Dev watcher correction: live runtime reload now waits for the host stdout log
to acknowledge the exact new live DLL path before declaring success. A pointer
write alone is not proof. `dev-watch.ps1 -ReopenWhenClosed` reopens the last
visible slot without rebuilding when the window has been closed.