szn

Bug 404 — isPaneValid regression

404. isPaneValid regression: the #362 fix reintroduced the O(N·M·P) tree walk #305 removed, now run (plus two more linear scans) on every PTY event

Severity: MEDIUM Status: ✅ RESOLVED

Pane.valid’s doc (window.zig:29-32) still promises “isPaneValid becomes an O(1) pointer check instead of an O(NMP) tree walk (bug #305)”, but the #362 UAF fix changed isPaneValid to walk every session/window/pane before trusting the pointer:

fn isPaneValid(self: *Server, pane: *Pane) bool {
    for (self.sessions.items) |session| {
        for (session.windows.items) |win| {
            for (win.panes.items) |p| { if (p == pane) return p.valid; }

handlePtyEvent runs this walk on every PTY event (:736) plus a client_fds scan (:732), while run() scans client_fds again per event (:653). On a busy pane (thousands of events/sec) this is O(events × sessions × windows × panes) per second — the exact cost #305 was filed for.

Fix: restore O(1): kill paths already iterate panes (p.valid = false in Session.killWindow) — extend them to clear udata registrations / use a per-pane generation id validated against a small liveness epoch, instead of the tree walk.