fix(tui): suppress verbose CLI logging on Windows alt-screen#2295
fix(tui): suppress verbose CLI logging on Windows alt-screen#2295aboimpinto wants to merge 5 commits into
Conversation
…I leak, restore on cleanup On Windows, stderr cannot be redirected to the log file (no dup2). Suppress verbose CLI logging once the alt-screen is active so eprintln! calls from crate::logging don't leak into the TUI buffer. Also restores verbose logging on all cleanup paths after leaving alt-screen.
There was a problem hiding this comment.
Code Review
This pull request introduces changes to suppress verbose CLI logging on Windows when the alternate screen is active, preventing stderr leaks into the TUI buffer, and restoring the logging state when leaving the alternate screen. The reviewer identified two critical issues where querying the environment via env_requests_verbose_logging() in emergency_restore_terminal() and TerminalCleanupGuard::drop introduces deadlock risks during panics or signal handling due to memory allocation and lock acquisition. It is recommended to remove these calls from the emergency and cleanup paths.
aboimpinto
left a comment
There was a problem hiding this comment.
Addressed the review feedback in the associated threads and pushed the fixes.
aboimpinto
left a comment
There was a problem hiding this comment.
Removed the cleanup-path restore from the review comments and kept the final exit behavior aligned with the panic-safe path.
This PR is the cleaned replacement for the old
#1910branch.It carries the same Windows alt-screen verbose-leak fix, but rebased onto current
mainso the review starts from a clean history instead of the stale DeepSeek-era workspace snapshot.What changed:
Validation:
cargo fmt --allcargo check -p codewhale-tui --all-features --lockedReference:
#1910, especially the maintainer note explaining that the broader Windows verbose-leak work was being split into defense-in-depth layers (#2259and#2262). This PR keeps only the alt-screen suppression fix and replays it cleanly on currentmain.The old PR branch was superseded by this clean cherry-pick on top of
main.Paulo Aboim Pinto
Greptile Summary
This PR suppresses verbose CLI logging on Windows while the TUI alt-screen is active, replacing the approach from #1910 with a snapshot/restore pattern that correctly preserves the pre-suppression verbose state (including
--verboseCLI flags) across alt-screen entry and exit.logging.rsgainssnapshot_verbose_state/restore_verbose_statebacked by aVERBOSE_SNAPSHOTatomic;ui.rscalls these at every alt-screen enter/leave site (run_tui,pause_terminal,resume_terminal), all correctly guarded insideif use_alt_screen.#[cfg(windows)]to the wholemod testsblock silently drops the cross-platformlog_value_parser_accepts_common_rust_log_directivestest from Linux/macOS CI runs; only the new snapshot/restore tests need the Windows gate.Confidence Score: 5/5
Safe to merge; the core suppress/restore logic is correct and properly scoped to alt-screen sessions.
The suppress/restore pairs are consistently placed inside if use_alt_screen guards across all changed call sites, and the snapshot correctly captures the full verbose state including CLI flags rather than re-reading the environment. The only issue is a test-module attribute that drops cross-platform coverage for an existing test, which does not affect runtime behavior.
crates/tui/src/logging.rs — the #[cfg(windows)] gate on the test module needs to be narrowed so the cross-platform parser test keeps running on Linux/macOS.
Important Files Changed
Sequence Diagram
sequenceDiagram participant main participant run_tui participant logging participant pause_terminal participant resume_terminal main->>run_tui: "run_tui(use_alt_screen=true)" run_tui->>logging: snapshot_verbose_state() [Windows] run_tui->>logging: set_verbose(false) [Windows] Note over run_tui: TUI event loop running... run_tui->>pause_terminal: "pause_terminal(use_alt_screen=true)" pause_terminal->>logging: restore_verbose_state() [Windows] Note over pause_terminal: LeaveAlternateScreen pause_terminal-->>run_tui: Ok Note over run_tui: child process running... run_tui->>resume_terminal: "resume_terminal(use_alt_screen=true)" Note over resume_terminal: EnterAlternateScreen resume_terminal->>logging: set_verbose(false) [Windows] resume_terminal-->>run_tui: Ok Note over run_tui: TUI event loop running... run_tui->>logging: restore_verbose_state() [Windows, normal exit] run_tui-->>main: OkComments Outside Diff (2)
crates/tui/src/tui/ui.rs, line 626-628 (link)TerminalCleanupGuard::dropskipsrestore_verbose_stateon WindowsThe drop handler is the safety net for every early-return path between guard creation (line ~338) and
defused = true(line ~558). On Windows withuse_alt_screen = true, it leaves the alt-screen correctly but never callscrate::logging::restore_verbose_state(). Any?-propagated error that escapesrun_tuibefore the normal cleanup will leaveVERBOSEpermanently cleared, silencing all subsequentcrate::logging::info/warncalls in the same process — including any post-TUI diagnostics or retry logic in the caller.crates/tui/src/tui/ui.rs, line 616-637 (link)TerminalCleanupGuard::dropis the safety net for all early-return paths between guard creation andcleanup_guard.defused = true. On Windows withuse_alt_screen = true, the drop correctly issuesLeaveAlternateScreen, but never callscrate::logging::restore_verbose_state(). Any?-propagated error that escapesrun_tuibefore line 558 will leaveVERBOSEpermanently cleared — silencing all subsequentcrate::logging::info/warncalls in the same process, including any post-TUI diagnostics in the caller.The fix is to add the same
#[cfg(windows)]restore call that the normal-exit path already has, inside theif self.use_alt_screen { … }branch ofDrop::drop.Reviews (5): Last reviewed commit: "test(tui): cover windows verbose state r..." | Re-trigger Greptile