Skip to content

Hidden stderr diagnostics duplicate mouse-enabled TUI frames #1879

Description

@code-yeongyu

Summary

Regular-mode mouse capture appends a duplicate full TUI frame when a diagnostic is redirected to the debug log and never reaches the terminal.

Reproduction

  1. Run the interactive source CLI in an isolated agent directory with terminal.mouse set to always.
  2. Execute a read sequence followed by grep when the optional native grep prebuild is unavailable.
  3. Grep emits its normal fallback diagnostic through console.warn; the interactive stderr guard stores that message in the debug log.
  4. Observe the previous user prompt/tool group remaining above a second complete copy of the working frame.

Expected

Hidden diagnostics must not invalidate terminal geometry. Real visible stdout/stderr, including the redacted stderr fallback when the diagnostic log cannot be written, must still invalidate mouse hit targets until geometry is recalibrated.

Actual and evidence

Runtime instrumentation records this call chain:

grep/select-engine.ts → writeHiddenConsoleDiagnostic → ProcessTerminal.installExternalStderrObserver → hidden diagnostic log.

The same run then records a second fullRender: first render, and the output stream contains the CRLF followed by a fresh non-clearing frame from TuiMainScreen.doRender.

The defect remains when the terminal emulator is connected before the CLI starts. It is not a delayed terminal-query response.

Root cause

The stderr observer wraps an already-redirected process.stderr.write and calls noteExternalWrite before the redirect decides whether any bytes reach the terminal. TuiMainScreen responds to that false visibility signal by preserving the old frame and appending a new one.

Scope and acceptance

  • Add a deterministic integration regression covering hidden diagnostics with mouse capture.
  • Preserve real-output invalidation and redacted visible fallback behavior.
  • Preserve stdout/stderr ownership and restoration through start/stop transitions.
  • Re-run the actual 80/120-column interactive scenario and verify only one current exploration group.

Related

Found during #1870. Mouse capture was introduced in #1651; diagnostic hiding predates it in #677. #1704 describes a different resize/focus-triggered replay symptom. Private runtime evidence is held locally.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions