diagnose-tui-pty

Diagnose: TUI PTY scrollback duplicates last chunk after window resize

Metadata

Statusdone
Assignedagent-1038
Agent identityf51439356729d112a6c404803d88015d5b44832c6c584c62b96732b63c2b0c7e
Modelclaude:opus
Created2026-04-29T00:23:23.137908711+00:00
Started2026-04-29T00:31:08.791962346+00:00
Completed2026-04-29T00:40:14.034476444+00:00
Tagsbug,tui,pty, eval-scheduled
Eval score0.93
└ blocking impact0.92
└ completeness0.98
└ constraint fidelity0.85
└ coordination overhead0.90
└ correctness0.95
└ downstream usability0.88
└ efficiency0.85
└ intent fidelity0.75
└ style adherence0.95

Description

Description

User reports: in the wg TUI, the PTY scrollback buffer redraws when the PTY window is resized. After resize, the last chunk of the scrollback is sometimes duplicated — i.e., the most recent N lines appear twice in the rendered scrollback area.

User quote: 'the scroll back buffer in the PTY, if you change the dimensions of the PTY window, it can redraw. But it seems that sometimes it ends up not redrawing the last part properly. You get like a duplication of the last chunk. ... Basically duplication is a thing.'

Repro path (start here)

  1. Open the wg TUI
  2. Run a command in a chat / spawn output that fills more than one screen of scrollback
  3. Resize the TUI window (drag terminal corner, or send a SIGWINCH equivalent)
  4. Scroll back through the buffer
  5. Observe: the last chunk (last screen-worth-ish of lines) appears duplicated

Goal

Reproduce + identify root cause. Likely candidates:

  • The redraw path is appending the visible region a second time instead of replacing it
  • Wrap-rewrap logic on resize miscomputes the new line count and emits trailing lines that overlap with the existing tail
  • The scrollback buffer's tail pointer isn't updated after re-wrap, so subsequent renders read past the real end
  • Cursor / last-line position is not snapshotted before resize, so the post-resize render duplicates whatever was 'below' the old cursor

Files likely involved (start here, do NOT chase widely):

  • src/tui/ — anything mentioning pty / scrollback / resize / SIGWINCH
  • Recent commits in fix-pty-output, tui-live-log, tui-chat-bar may have touched this code path

Validation

  • Reproduction confirmed and described step-by-step in the task log (wg log)
  • Root cause identified — specific file + function + line range, with explanation of why duplication happens
  • If the bug is intermittent: identify the trigger condition (specific resize direction? specific buffer fill state?) so the fix task can write a deterministic test
  • Recommended fix approach noted (e.g., 'snapshot tail pointer before re-wrap, restore after' or 'replace render-append with render-replace')
  • No source modifications — diagnose only

Depends on

Required by

Log