← Back to PRs

#17677: fix(tui): prevent crash when rendered line exceeds terminal width

by Phineas1500 open 2026-02-16 02:40 View on GitHub →
stale size: S
## Summary Fixes #17525 — the TUI crashes with `Rendered line N exceeds terminal width (X > Y)` when any rendered line overshoots the terminal width by even 1 character. - Adds a `SafeContainer` class that extends `Container` and truncates any overwide line after rendering, using pi-tui's own `visibleWidth()` / `truncateToWidth()` — the same truncation technique pi-tui already applies to overlay compositing - Replaces the TUI root container with `SafeContainer` so **all** components are protected regardless of source - No behavior change for lines that fit within the terminal width ## AI Disclosure AI-assisted (Claude). Fully tested — build, lint, format, and unit tests pass. The fix was verified at the unit level (Container passes overwide lines through → crash; SafeContainer truncates them → no crash), though the exact end-to-end crash from #17525 could not be reproduced on the test environment (Linux/ARM vs reporter's macOS/Node v24). ## Test plan - [x] `pnpm build` passes - [x] `pnpm check` passes (lint + format) - [x] New unit tests pass (4 cases: ASCII overflow, CJK boundary, ANSI-styled overflow, passthrough for normal lines) - [ ] Manual: run TUI, resize terminal to odd width, have agent output long lines — should not crash <!-- greptile_comment --> <h3>Greptile Summary</h3> Introduces a `SafeContainer` class that wraps the TUI root container to prevent pi-tui's hard crash when any rendered line exceeds the terminal width. The fix uses pi-tui's own `visibleWidth()` and `truncateToWidth()` utilities — the same approach already used in `searchable-select-list.ts` — to silently truncate overwide lines before they reach pi-tui's render verification. - Adds `SafeContainer` extending `Container` with a `render()` override that truncates overwide lines - Replaces the root container in `tui.ts` with `SafeContainer`, protecting all child components - Includes 4 unit tests covering ASCII overflow, CJK boundary, ANSI-styled overflow, and passthrough for normal lines - Note: overlays rendered via `tui.showOverlay()` bypass the root container and are not protected by this fix, though overlay components already handle truncation internally <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — it adds a defensive truncation layer with no behavioral change for lines that fit the terminal width. - The change is minimal (18 lines of implementation + 75 lines of tests), uses well-established pi-tui utilities already employed elsewhere in the codebase, and is a purely defensive fix. The SafeContainer only alters behavior for lines that would otherwise crash pi-tui, making it a strict improvement with no risk of regression. No logic, syntax, or style issues found. - No files require special attention. <sub>Last reviewed commit: 5dba97b</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs