Repository navigation
Description
Summary
Two related terminal-state defects surfaced during the 2026-09-18 'cricket' session when the TUI was rendered into a 57x1 pane:
Defect 1: index outside of buffer panic
thread '<unnamed>' panicked at ratatui-core-0.1.0/src/buffer/buffer.rs:250:13
index outside of buffer: the len is 57 but the index is 57
Buffer::index panics when called with (x, y) outside the buffer's Rect area. Upstream issue: ratatui/ratatui#2810.
Defect 2: resume-path terminal-mode corruption (CodeRabbit review 2026-10-05)
On the exec-resume path, init_tui_terminal_resume (src/cli/terminal.rs:623-645$) early-returns from the new L3 size gate (check_minimum_terminal_size()) without first restoring the inherited terminal modes that the *previous* jcode process preserved across the exec handoff via INHERITED_MODES_ENV/INHERITED_THEME_ENV`.
Consequence: when the new process aborts before claiming ownership via TuiRuntimeGuard, the user's terminal is left in raw mode + alternate screen + bracketed paste + focus events, with no one to clean it up. The panic hook doesn't cover this path because the gate returns an error rather than panicking.
Fix (PR #28)
KooshaPari/KCode#28 layers three defenses:
- L1 — dep bump ratatui 0.30.0 -> 0.30.2 (pulls upstream's bounds-check helper).
- L3 — pre-flight size gate in new
jcode-terminal-guardcrate: refuses to start TUI in terminals smaller than 60x20, and wrapsratatui::initincatch_unwind(AssertUnwindSafe(...))to convert any future bounds-check regression into ananyhow::Errorinstead of a panic. - Resume-path terminal-mode restoration (commit
1ac499c9donfeature/ratatui-buffer-guard): extracted a privaterestore_inherited_terminal_modes_quietly()helper from the inline cleanup that was duplicated in the panic hook + signal handler, and called it from the size-gate early-return path ininit_tui_terminal_resumebefore propagating the error. Single source of truth, no behavior change at the other call sites, idempotent and side-effect-safe on stderr.
Plus 5 regression tests in crates/jcode-tui/tests/ratatui_buffer_guard.rs + 1 unit test in src/cli/terminal.rs::tests.
Reproduction
# Resize pane to <60x20, then resume jcode via exec handoff
# -> panic on render, OR silent terminal corruption if size gate firesTest plan
cargo check --workspacecleancargo test -p jcode-tui --test ratatui_buffer_guard5/5 greencargo test --workspace --libno regressionscargo clippy --workspace -- -D warningsclean (pre-existing ratatui 0.30.2cell.set_skipdeprecations injcode-tui-mermaidare out of scope; caused by L1 dep bump)
Related
- Upstream: Buffer::index panics with index outside of buffer on degenerate Rect areas ratatui/ratatui#2810
- PR: fix(tui): guard against ratatui buffer overflow in degenerate terminals #28
- CodeRabbit review (2026-10-05): review id 5421574647 on PR fix(tui): guard against ratatui buffer overflow in degenerate terminals #28 —
CHANGES_REQUESTEDon Defect 2, resolved by1ac499c9d
Activity
fix(tui): restore inherited modes from INHERITED_MODES_ENV on resume-…
fix(tui): guard against ratatui buffer overflow in degenerate termina…
fix(tui): guard against ratatui buffer overflow in degenerate termina…
fix(cli): name kcode in every resume hint, not jcode (supersedes #319) (