File: src/screen.zig (addSixelImage / pending_sixel), src/server/server.zig (handlePtyEvent)
Severity: MEDIUM
Status: ✅ FIXED — when a sixel arrives before a measured cell size is known, addSixelImage now buffers the captured DCS bytes in pending_sixel instead of placing them with the built-in default (20×10) cell size. The server pauses that pane’s PTY feed (holding the shell’s subsequent output in the kernel buffer) until the cell_size response arrives, then replays the buffered image via flushPendingSixel at the correct footprint. Added unit tests addSixelImage buffers an image before cell size is known — bug #203 and addSixelImage replays a buffered image once cell size is known — bug #204.
The dynamic cell-size query (commit 7cc4d17) fixed the general “extra lines after img” case, but the first sixel still raced the measurement: addSixelImage ran with the default 20px cell height, computed too many cell rows, and advanced the cursor too far — leaving a blank gap after the image. The query only fires because the sixel was added, so its result lands a frame too late for that same image, and the cursor advance is already baked into the grid. Buffering the sixel (and pausing the PTY feed so the shell’s prompt can’t race in and land on top of where the image will go) means the very first image is also measured first, so its footprint and cursor advance are correct. A cell_size_wait_ms (2s) timeout force-replays with whatever size we have so a pane can never stall if the terminal never answers.