szn

Bug 401 — Render errors permanently lose updates

401. Render errors permanently lose updates: diff cache committed to last_cells before bytes are emitted, and dirty flags cleared despite the error

Severity: HIGH Status: ✅ RESOLVED

renderContent writes the new cell into the client’s diff baseline the moment it is examined — before that cell’s escape bytes are produced:

lc.items[cell_idx] = cell;   // render.zig:529 — committed pre-emit

If renderAll returns an error mid-frame (render-buffer capture OOM, Screen.init OOM, moveTo OOM), server.zig:3113-3116 catches it, logs a warning, and continues without setting all_flushed = false — so at :3133-3138 self.dirty and every p.dirty are cleared for a frame that was never queued. The next frame diffs against the already-committed cache and skips exactly the cells that were lost: a client terminal stays permanently stale (missing regions) until a manual redraw. force_clear is consumed destructively before delivery (pb.pane.screen.force_clear = false, render.zig:186), so a dropped forced repaint is never retried. The comment at server.zig:2972-2975 (“the diff state only advances once the buffered frame is fully flushed”) holds only for EAGAIN backpressure, not for render errors.

Fix: commit lc.items[...] after the successful append of the cell’s bytes (or snapshot/restore last_cells on error); on render error set all_flushed = false and restore force_clear.