a73x

Audit mid-flight waitIdleForShutdown sites for bounded semantics

open   by a73x

Labels: backlog

[claude 2026-04-18] Opened as follow-up to ab6c92f0 (Vulkan bounded waits).

The bounded-waits work migrated all 14 deviceWaitIdle / queueWaitIdle
sites to vk_sync.waitIdleForShutdown (which wraps vkd.deviceWaitIdle
with an unbounded wait and swallows errors to a log line). This
preserved existing behavior while satisfying the grep gate.

However, five of those sites are mid-flight or hot-ish paths — not
shutdown drains — where the driver could wedge exactly the way
ab6c92f0 documented:

- src/main.zig (scale_pending arm, formerly :424) — before rebuildFaceForScale
- src/main.zig (resize arm, grid-changed branch, formerly :462) — before recreateSwapchain
- src/main.zig (resize arm, grid-unchanged branch, formerly :479) — before recreateSwapchain
- src/main.zig (OutOfDateKHR arm in drawCells catch, formerly :681) — before recreateSwapchain
- src/renderer.zig uploadAtlas — formerly queueWaitIdle on graphics_queue (one-shot init/capture path; widening to deviceWaitIdle silently swallows DeviceLost during initial atlas upload)

All wait unbounded while the driver may be wedged. If the hang mode
from ab6c92f0 fires during a resize, scale change, or initial atlas
upload, we'll freeze again with the same symptoms.

Scope of this ticket:
1. Implement vk_sync.waitIdleBounded (currently a @compileError stub).
   The fence-based emulation: submit a no-op to the graphics queue,
   wait on its fence with a timeout. Return error.VkWaitTimeout on
   timeout.
2. Migrate the four mid-flight main.zig sites from waitIdleForShutdown
   to waitIdleBounded; handle the new timeout error in each caller.
3. Restore error propagation in uploadAtlas (currently `vk_sync.waitIdleForShutdown(self.vkd, self.device);` — needs a queue-bounded helper or equivalent fence-based pattern to surface DeviceLost during init).
4. Keep the ten remaining shutdown/init/bench sites as
   waitIdleForShutdown — those are correct as-is.

Priority: low. The NVIDIA 595 driver flake observed on 2026-04-18
was a fence-wait wedge in drawCells, not a resize/scale wedge.
Resize/scale/init paths have not been observed to hang. File so the
work isn't lost.