Files
codewhale/crates
Hunter Bown b59012e765 fix(tui): forward resize dimensions to ratatui viewport
@imakid reported on Windows PowerShell that clicking the OS restore
button (maximize → windowed) during a long task turns the entire
terminal black, unrecoverable until Ctrl+C. The "refreshing context"
chip in the footer indicates the freeze coincides with a compaction
summary call (engine state `CoherenceState::RefreshingContext`).

Hypothesis (no Windows dev box, awaiting @imakid confirmation):

* Symptom 1 — "transcript stops refreshing" — is the expected
  no-stream window during the side-channel compaction summary call.
  Tokens don't stream until the summary returns and the next assistant
  turn resumes. That's not a bug, but the UI doesn't currently surface
  the distinction well.

* Symptom 2 — "black screen on restore-from-maximized" — most likely
  comes from a Windows ConHost transient: `crossterm::terminal::size()`
  briefly returns stale (maximized) dimensions during the
  maximize→windowed transition, while the `Event::Resize(w, h)`
  payload itself already carries the correct post-restore size. The
  current handler does `terminal.clear() + terminal.draw()` and
  relies on ratatui's internal autoresize, which calls
  `crossterm::terminal::size()` — meaning we paint a frame sized to
  the stale dimensions into the post-restore viewport, leaving most
  of the visible area unpainted (the user-reported black screen).

The change forwards the event-reported `(w, h)` to ratatui via
`Terminal::resize(Rect)` before the clear+draw, so the viewport
commit always uses the OS-truthful new size regardless of whether
`crossterm::terminal::size()` has caught up. This is a defensive
change everywhere — the event payload is authoritative on every
platform — and it specifically addresses the Windows ConHost stale-
size race.

Also widens the resize tracing event to include `coherence_state`
and `use_alt_screen` so the next user bug report includes the
context we'd ask for in triage.

Tests
=====

`chat_widget_renders_cleanly_after_resize_during_refreshing_context`
pins the renderer-side invariant: a resize cycle that arrives while
`coherence_state == RefreshingContext` must produce non-empty frames
at every cycled width, and must not mutate the engine's
coherence_state. The actual fix lives in the event-handler size
forwarding; the test guards the renderer's no-empty-buffer contract
so a future regression that gates layout on coherence state would be
caught immediately.

What this PR does NOT change
============================

* No platform-specific code path. The fix is universal — passing the
  event-reported size to ratatui is correct everywhere; Windows just
  happens to be where the bug manifests today.
* No change to the freeze symptom directly. If symptom 1 is the
  expected compaction-summary no-stream window, the right
  follow-up is a UX cue ("compacting context, please hold") rather
  than a bugfix.

@imakid — please test by installing this branch:

    cargo install --git https://github.com/Hmbown/DeepSeek-TUI.git \\
        --branch fix/582-powershell-resize

Then run a long task, click the OS restore button mid-task, and
confirm whether the black-screen symptom is gone. If it still
reproduces, please run with `RUST_LOG=deepseek_tui=debug` and post
the resize lines from the log so we can see the dimensions
crossterm/ratatui actually saw.

Verification
============

* `cargo fmt --all -- --check` clean.
* `cargo clippy -p deepseek-tui --bin deepseek-tui --all-features
  --locked -- -D warnings` clean.
* `cargo test -p deepseek-tui --bin deepseek-tui --locked` →
  2029 passed, 2 ignored.

Refs #582.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 17:29:00 -05:00
..
2026-05-06 11:06:00 -05:00
2026-05-06 11:06:00 -05:00
2026-05-06 11:06:00 -05:00
2026-05-06 11:06:00 -05:00