Skip to content

fix(ui-tui): heal same-dimension alt-screen resize drift#18499

Closed
luoyuctl wants to merge 1 commit into
NousResearch:mainfrom
luoyuctl:codex/fix-tui-resize-heal
Closed

fix(ui-tui): heal same-dimension alt-screen resize drift#18499
luoyuctl wants to merge 1 commit into
NousResearch:mainfrom
luoyuctl:codex/fix-tui-resize-heal

Conversation

@luoyuctl

@luoyuctl luoyuctl commented May 1, 2026

Copy link
Copy Markdown

Summary

  • Treat same-dimension resize events in alt-screen mode as a repaint signal, because terminal hosts can reflow or restore the physical buffer without changing columns/rows.
  • Ensure pending resize erases are emitted even when the virtual diff is empty, so stale physical glyphs are still cleared.
  • Add a focused regression test for same-dimension alt-screen resize healing.

Root cause

The TUI renderer tracks a virtual previous frame and normally writes only the cells that changed. After a terminal resize, focus restore, or host-side reflow, the physical terminal buffer can contain stale glyphs that do not exist in Ink's virtual frame. If the next virtual frame has no diff, the old code skipped the erase/repaint path, leaving those physical cells visible.

Related issues

Validation

  • npm test -- --run packages/hermes-ink/src/ink/ink-resize.test.ts packages/hermes-ink/src/ink/log-update.test.ts
  • npm run type-check
  • npm test
  • npm run build
  • git diff --check

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels May 1, 2026
@luoyuctl luoyuctl force-pushed the codex/fix-tui-resize-heal branch from e0c7880 to 3d2e254 Compare May 3, 2026 16:14
@luoyuctl

luoyuctl commented May 3, 2026

Copy link
Copy Markdown
Author

Pushed two small improvements after review:

  1. Defensive clearTimeout in prepareAltScreenResizeRepaint() — handleResize already clears the settle timer before calling this method, but adding a self-contained clear makes the method safe if it's ever called from other code paths (e.g., a future resume handler).

  2. Restored the "same-dimension" comment with updated rationale — the original code had a comment explaining same-dimension events are no-ops; since this PR intentionally breaks that rule for alt-screen mode, replaced it with a comment explaining why (terminal host reflow / buffer restore can leave stale glyphs without changing cols/rows).

Test still passes: npm test -- --run .../ink-resize.test.ts

- Treat same-dimension resize events in alt-screen mode as a repaint
  signal, because terminal hosts can reflow or restore the physical
  buffer without changing columns/rows.
- Ensure pending resize erases are emitted even when the virtual diff
  is empty, so stale physical glyphs are still cleared.
- Extract alt-screen resize repaint into prepareAltScreenResizeRepaint()
  for readability.
- Add defensive clearTimeout in prepareAltScreenResizeRepaint so rapid
  resize bursts don't stack redundant delayed repaints.
- Add a focused regression test for same-dimension alt-screen resize
  healing.

Addresses NousResearch#18449
Related to NousResearch#17961
@luoyuctl luoyuctl force-pushed the codex/fix-tui-resize-heal branch from 3d2e254 to 59d89f8 Compare May 4, 2026 03:14
@luoyuctl

luoyuctl commented May 7, 2026

Copy link
Copy Markdown
Author

@teknium1 here's background
Clipboard_Screenshot_1778162720

@liw71750-dotcom

Copy link
Copy Markdown

This PR addresses one specific symptom of a broader issue: the CLI/TUI does not reflow content on terminal resize. There are 34+ open bugs about various manifestations of this problem.

I've opened a tracking feature request (#24164) that proposes a comprehensive solution — a SIGWINCH handler triggering full re-render at new viewport dimensions, comparable to how opencode and Claude Code handle resize smoothly.

If this PR gets merged, please consider whether the underlying architecture supports full reflow, or if we still need a systematic fix. The tracking issue consolidates all related work:

#24164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants