Skip to content

Background hook stderr output can be painted into the input box until terminal repaint #31219

Closed as not planned

Description

@hcsum

Describe the bug

pic 1
Image

pic 2
Image

Sometimes background hook/plugin output is rendered inside the OpenCode input area (or bottom status/input region) instead of appearing in the normal terminal flow.

In my case this happens with a local memory hook that writes status lines to stderr. The visible symptom is that a line like:

[memory] extract done ...

or

[memory] compact: store already clean ...

shows up where the input box is, making the UI look corrupted.

The display becomes normal again immediately if I:

  • resize the terminal window
  • trigger a popup with Ctrl+K

That makes this look like a repaint / cursor-placement bug rather than the hook actually writing into the prompt buffer.

Investigation

In my local setup, the background memory plugin logs via console.error(...), so the hook is writing to stderr.

That seems to suggest the issue is: when background stderr arrives while the OpenCode TUI is idle or waiting for input, the line can be painted into the input/status region until the next full redraw.

To reproduce

I do not yet have a minimal standalone repro, but the rough pattern is:

  1. Run OpenCode in the VSCode integrated terminal
  2. Have a background hook/plugin that emits status lines to stderr
  3. Wait until the hook fires while OpenCode is sitting at the input screen
  4. The hook output may appear inside the input area / bottom UI region
  5. Resize the terminal window or trigger Ctrl+K
  6. The UI redraws and looks normal again

Expected behavior

Background hook output should not corrupt the input box or bottom UI region. If stderr output is allowed, OpenCode should preserve cursor placement and repaint correctly.

Actual behavior

A background hook status line is sometimes drawn into the input box / lower UI area until a repaint happens.

Environment

  • OpenCode: 1.16.2
  • Terminal: VSCode integrated terminal
  • OS: macOS

Activity

  1. hcsum commented on Jun 7, 2026

    @hcsum
    Author
    Image

    in fact stdin also shows

  2. iclawos commented on Jun 25, 2026

    @iclawos

    Description

    Two red error messages appear persistently in the command input area (the text box where you type), not in a log or status panel:

    1. gbrain save failed
    2. shellerror: failed with exit code 1

    Expected behavior: MCP server errors should be handled silently or displayed in a dedicated status/log area, not injected into the command input widget.

    Actual behavior: Red error text appears inside the command input area, interfering with typing. The stderr from the gbrain MCP subprocess is being rendered in the wrong UI widget.

    Plugins

    @nntoan/gstack

    OpenCode version

    Latest (via npx opencode + @nntoan/gstack plugin)

    Steps to reproduce

    1. Configure gbrain as local MCP server in opencode.jsonc:
      "gbrain": {
        "type": "local",
        "command": ["/home/jackliao/.bun/bin/gbrain", "serve"]
      }

    Restart opencode
    Red error messages appear in command input area
    Screenshot and/or share link
    N/A
    Operating System
    Linux Mint 22 (Ubuntu 24.04 base)
    Terminal
    GNOME Terminal

  3. konard commented on Jul 23, 2026

    @konard

    I can confirm this on OpenCode 1.18.4 on Linux with a second process writing to the same PTY. This is not limited to plugin or MCP output.

    In our reproducible case, a wrapper started a local HTTP server and then launched OpenCode in the foreground. The server inherited the wrapper's stdout/stderr. When OpenCode made a model request, the sibling server printed a request trace (including JSON) to stderr; those bytes were painted over the active OpenCode TUI. Resizing the terminal immediately restored the correct frame. Screenshots of the corrupted frame and resize repaint are in link-assistant/formal-ai#819.

    The core process shape was:

    (while sleep 2; do printf '[background] diagnostic\n' >&2; done) &
    opencode .

    Our application-level fix is to redirect the background server's stdout and stderr to a durable log before launching OpenCode. A PTY regression now verifies that a unique request-body marker never reaches the terminal stream. That fully prevents the corruption in our wrapper, but OpenCode still appears vulnerable to any unrelated process that retains the same terminal descriptors.

    Expected defensive behavior: if external terminal output arrives while the fullscreen renderer owns the terminal, perform a complete redraw (or otherwise restore cursor/frame state) so the bytes cannot remain inside the input/status region.

  4. github-actions commented on Sep 23, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 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

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions