Skip to content

fix(tui): route console output to log file to protect TUI display - #48517

Open
thomas-bw wants to merge 1 commit into
anomalyco:devfrom
thomas-bw:tui-console-guard
Open

fix(tui): route console output to log file to protect TUI display#48517
thomas-bw wants to merge 1 commit into
anomalyco:devfrom
thomas-bw:tui-console-guard

Conversation

@thomas-bw

@thomas-bw thomas-bw commented Sep 11, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #48520

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

#31002 reports Ajv's unknown format "uint64" ignored warnings from Rust/schemars MCP schemas reaching the terminal via console.warn and polluting the TUI. PR #48331 fixes that specific source by disabling Ajv's logger through the MCP SDK's ClientOptions seam.

This PR is a complementary, systemic guardrail for the same problem: any library console.* output — Ajv today, plugin dependencies or anything else tomorrow — writes raw lines straight into the TUI's alternate screen and corrupts the display. A small ConsoleGuard is installed in every TUI entrypoint (tui, attach, run) and the server worker, redirecting console.debug/info/log/warn/error into the opencode log file while respecting the minimum log level (OPENCODE_LOG_LEVEL). Non-TUI entrypoints (serve, mcp list, ...) keep normal console behavior.

The two fixes are orthogonal: #48331 removes the Ajv warning at its source; this PR guarantees the TUI survives stray console output no matter where it comes from. Neither alone covers the full class of bug behind #31002.

How did you verify your code works?

  • Two unit tests in packages/opencode/test/util/console-guard.test.ts: console output lands in the log file as a service=console line, and entries below the minimum level are suppressed while errors still get logged.
  • bun test and bun typecheck pass in packages/opencode.
  • Manual repro: start the TUI with an MCP server whose schemas contain uint32/uint64 formats. Before: Ajv warnings overwrite the display. After: they only appear in opencode.log.

Screenshots / recordings

Before:

grafik

After:

grafik

Log file:

grafik

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Library console output (Ajv compiling third-party MCP schemas, plugin
dependencies, ...) wrote raw lines into the TUI's alternate screen and
corrupted the display. In TUI mode the console methods are now redirected
into the opencode log file in all TUI entrypoints and the server worker,
respecting OPENCODE_LOG_LEVEL.

anomalyco#31002
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. fix(mcp): silence Ajv unknown format warnings from MCP tool schemas #48331 - fix(mcp): silence Ajv unknown format warnings from MCP tool schemas

  2. fix(tui): contain stray stdio writes #43065 - fix(tui): contain stray stdio writes

Conclusion: These are related PRs addressing similar TUI protection concerns, but they're complementary fixes rather than duplicates. #48517 is distinct in focusing on console output redirection to log files with log-level filtering across all TUI entrypoints.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: library console output corrupts alternate screen display

1 participant