Skip to content

Background logs are printed to the TUI #8639

Closed

Description

@wudanzy

Description

After a while, the logs from background threads are printed to the TUI. Currently I can resize the window to clear it, but still would like to fix it.

Plugins

oh-my-opencode

OpenCode version

Not a publish version, commit id is 66f9bda

Steps to reproduce

opencode --print-logs --log-level DEBUG .

Wait for 1 hour

Screenshot and/or share link

Image

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Jan 15, 2026
  2. github-actions commented on Jan 15, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    All of these share the common pattern of TUI output corruption or unwanted background content appearing in the interface that can be cleared by window resize events.

    Feel free to ignore if none of these address your specific case.

  3. wudanzy commented on Jan 15, 2026

    @wudanzy
    Author

    If this is the first time this bug gets discovered, I am willing to fix it. (I have discussed opencode and get some idea)

  4. blackas commented on Feb 5, 2026

    @blackas

    Root Cause Analysis: Debug console.log Statements in TUI Code + disableStdoutInterception()

    I did a deep source code analysis and found the root cause of this issue extends beyond --print-logs mode. The TUI corruption happens even in normal mode due to debug console.log statements left in production TUI code.

    Architecture

    Main Thread (TUI)                    Worker Thread (Backend)
    @opentui/solid renderer (60 FPS)     Sessions, Tools, MCP, Sub-agents
    → renders to process.stdout           → shares stdout/stderr fd with main
    → disableStdoutInterception()         → Log system → file (after init)
    → console.log → DIRECTLY to terminal  → Bus events → RPC → TUI events
    

    Root Cause Chain

    1. renderer.disableStdoutInterception() is called in App() component (src/cli/cmd/tui/app.tsx:190). This disables @opentui/core's built-in stdout protection, meaning ANY console.log or process.stdout.write bypasses the TUI framework and goes raw to the terminal.

    2. Multiple debug console.log statements remain in TUI code:

    File Line Code Trigger
    app.tsx 214 console.log(JSON.stringify(route.data)) Every route change (in createEffect!)
    route.tsx 34 console.log("navigate", route) Every navigation
    sync.tsx 332 console.log("bootstrapping") During data sync
    theme.tsx 319 console.log("resolveSystemTheme") Theme resolution
    theme.tsx 325 console.log(colors.palette) Palette detection
    clipboard.ts 79-149 console.log("clipboard: using ...") Clipboard operations
    1. Sub-agent execution amplifies the problem: When sub-agents run, heavy event activity (PartUpdated, MessageUpdated) flows from Worker → RPC → TUI EventSource → Solid.js reactivity → createEffect fires → console.log writes raw text to stdout → interleaves with renderer's ANSI escape sequences → visual corruption.

    Minimal Reproduction (no --print-logs needed)

    1. Start opencode normally (no flags)
    2. Navigate to a session
    3. Trigger a sub-agent task
    4. As events flow, app.tsx:214's createEffect(() => { console.log(JSON.stringify(route.data)) }) fires, writing raw JSON to stdout mid-render

    Suggested Fix

    Immediate (high impact, trivial effort): Remove all console.log/console.error debug statements from TUI code:

    • app.tsx:214 — This single line causes the most corruption
    • route.tsx:34
    • sync.tsx:332
    • theme.tsx:319, 325
    • clipboard.ts:79, 88, 97, 110, 125, 149

    Medium-term: Consider re-enabling stdout interception or routing TUI-internal logs through renderer.console instead of raw console.log.

    Related Issues

    This analysis also explains the symptoms reported in:

    Environment

    • OpenCode version: 1.1.51
    • Source analyzed: anomalyco/opencode latest main branch
    • TUI framework: @opentui/solid 0.1.77 + @opentui/core 0.1.77
  5. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentuiwindows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions