File: src/server/server.zig:1602, 1616, 1643, 1742, 1746, 1791
Severity: MEDIUM
Status: ✅ FIXED
All six raw history.items.len - history_start subtractions in the
mouse/copy-mode handlers replaced with the underflow-guarded
grid.historyLen() (grep now reports zero raw sites in server.zig).
Test: mouse scroll uses guarded historyLen even with corrupt
history_start — bug #380 (corrupts the ring-buffer invariant, then drives a
wheel-up event through processInput — panicked with the old code).
const hist_len: u32 = @intCast(press_pane.screen.grid.history.items.len - press_pane.screen.grid.history_start);
Grid.historyLen() (grid.zig:117-120) guards history_start > items.len
(added by bug #293 after a real underflow panic). These six sites — added
around the copy-mode mouse handling — repeat the unguarded subtraction. Safe
only while scrollUp’s compaction invariant holds; latent panic otherwise.
Replace all six with @intCast(grid.historyLen()) and add a debug assert in
historyLen so violations surface immediately.