Windows: app exits with CallbackFailed while another process is reading snapshot.txt
On Windows, an app built with -Dautomation=true exits with nothing but error: CallbackFailed if another process has snapshot.txt open at the moment the app publishes a frame. I hit this while driving an app with native automate and reading the automation files from PowerShell.
Repro on main (ff108d0a), Windows 11 26200, Zig 0.16.0, with examples/ui-inbox:
# terminal 1 (the app's stderr doesn't show up in the console for me unless it's redirected)
cd examples/ui-inbox
zig build run -Dautomation=true *> run.log
# terminal 2, same directory: keep reading the snapshot
while ($true) { $null = Get-Content .zig-cache\native-sdk-automation\snapshot.txt -Raw }
# terminal 3, same directory: keep the app publishing
$w = 820; do { native automate resize $w 640; $w = 1720 - $w } while ($LASTEXITCODE -eq 0)
After a few resizes the window disappears, zig build exits, and terminal 3 times out with the app never consumed resize. The log has:
> Select-String -Path run.log -Pattern '^error'
run.log:104:error: CallbackFailed
run.log:107:error: process exited with error code 1
run.log:114:error: the following build command failed with exit code 1:
Without the redirect, terminal 1 only shows process exited with error code 1.
It's a race, but in all my runs it went down within the first six commands. Without terminal 2 the same loop gets through a couple hundred resizes, and polling with native automate snapshot instead of Get-Content doesn't trigger it.
As far as I can tell this comes from #712: writePathAtomic now publishes each file with createFileAtomic + replace, i.e. a rename over the existing file. On Windows that rename fails with STATUS_SHARING_VIOLATION (0xc0000043) whenever another handle is open on the destination without FILE_SHARE_DELETE, and Zig surfaces it as error.Unexpected. I checked this outside Native with a few lines of Zig doing the same createFileAtomic/replace while another process held the file: Get-Content, .NET File.Open without FileShare.Delete, and Python open() all make it fail. Node's fs and Zig's own file APIs open with delete sharing, which is why native automate snapshot is fine. (tools/windows-truth/lib.ps1 reads snapshot.txt with Get-Content too.)
The error then goes up through publishAutomation in Runtime.frame, and RunState.emit drops it and stops the host, so the process exits with CallbackFailed and no mention of the file. #43 ran into the same swallowed error on Linux.
I'd expect a failed publish to be logged and retried rather than take the app down. Happy to open a PR if that sounds like the right direction.