szn

Bug 441 — Status cache invalidation lag and missing state change triggers causing delayed status bar updates

441. Status cache invalidation lag and missing state change triggers causing delayed status bar updates

Severity: HIGH
Status: Fixed

Following the introduction of second-granularity caching in Bug #425, the status line appeared noticeably delayed/laggy during interactive terminal sessions. Multiple state changes and lifecycle events updated underlying window/pane data without marking the status bar cache as dirty.


Root Cause Analysis

  1. Auto-Rename Process Detection (renderToDisplayClient): When getForegroundProcessName() detected a newly launched foreground process (e.g. vim, cat, cargo) or a return to shell (zsh), win.setName(proc_name_val) was called and self.dirty was set to true. However, self.status_dirty was never flagged. Within the active second, use_cache evaluated to true, and the status bar continued to display the previous process name until status-interval (default 15s) elapsed.

  2. OSC Title Escape Sequences (windowTitleCallback): When terminal programs emitted OSC 0 or OSC 2 window title sequences (\x1b]0;title\x07), windowTitleCallback updated window.name but did not notify the server of status dirtiness. The updated title was not rendered to the status line until the periodic interval timer fired.

  3. Pane Selection and Layout Operations: Switching active panes (select_pane_left/right/up/down, C-b o, mouse click via handleMouseFocus, select-pane), splitting panes, killing panes, and swapping panes did not set status_dirty = true. Formats relying on #{pane_title} or #{pane_index} lagged behind the actual active pane state.

  4. Auto-Rename Inspection Rate-Limiting Lag: getForegroundProcessName() was rate-limited to once every 1,000 ms. When the user pressed Enter to execute a command or when a child process exited (reapZombies), last_foreground_check_ms was not reset, adding up to 1,000 ms of latency before even polling the new process name.

  5. Command Dispatch Status Invalidation: dispatchCommand in src/server/dispatch.zig executed CLI / IPC commands but did not set server.status_dirty = true.


Solution

  1. Dirty Flag Propagation:
    • Added name_dirty: bool and active_pane_dirty: bool to Window, flagged in Window.setName and Window.setActivePane.
    • Added active_window_dirty: bool to Session, flagged in Session.setActiveWindow, Session.newWindow, Session.killWindow, and Session.rename.
    • Polled and consumed these dirty flags in renderToDisplayClient() to immediately set self.status_dirty = true.
  2. Immediate Foreground Process Detection:
    • Reset last_foreground_check_ms = 0 whenever Enter (\r or \n) is forwarded to a pane in processInput(), and whenever a child process terminates in reapZombies().
    • Marked self.status_dirty = true directly on win.setName(proc_name_val) inside renderToDisplayClient().
  3. Keybinding & Command Invalidation:
    • Marked self.status_dirty = true across executeAction() (splits, pane selections, copy mode, prompt, zoom, clock), handleMouseFocus(), and destroyPane().
    • Set server.dirty = true; server.status_dirty = true; on successful command execution in dispatchCommand().