szn

Bug 371 — Reflow bypasses the history limit

371. Unbounded growth that scrollUp’s cap was supposed to prevent

File: src/grid.zig:906-924 Severity: HIGH Status: ✅ FIXED

Fix (applied)

After the reflow history rebuild, overflow past history_limit is trimmed: evicted lines release their cell buffers and fire notifyEvict (keeping sixel refcounts consistent), then the list is compacted — mirroring scrollUp’s cap.

Test: setSize enforces history_limit after rewrap — bug #371 (five soft-wrapped lines at limit 5; narrowing to half width keeps historyLen() <= 5). Related: #360 (eviction doesn’t reclaim), grid.zig:75 (limit default 2000)

Problem

const h_count = total_len - height;
...
hist_list.appendSliceAssumeCapacity(new_lines.items[0..h_count]);
self.history = hist_list;

Rebuilt history absorbs all overflow without enforcing history_limit and without firing the on_line_evict callback used for sixel refcounts elsewhere. Shrinking width multiplies line counts (text wraps into more rows), so repeated narrow resizes grow history arbitrarily.

Fix (proposed)

After rebuilding, trim to history_limit from the front and invoke the evict callback for released lines (keeps sixel refcounts consistent). Also guard the raw subtraction at grid.zig:720 with the existing historyLen() helper (bug #293 pattern).