Skip to content

Suspend (ctrl + z) pauses api calls for all opencode instances #5043

Closed

Description

@Eric162

Description

I was running about 3 instances of opencode, i suspended 1 of them with ctrl+z and the other 2 stopped sending/receiving data.

When i fg they all resume where they left off.

OpenCode version

1.0.128

Steps to reproduce

  1. run opencode in in shell 1
  2. open new terminal tab (shell 2) in another folder
  3. run opencode in shell 2
  4. send message in shell 2
  5. switch to shell 1
  6. send message in shell-1
  7. press ctrl + z to suspend shell 1
  8. switch back to shell 2
  9. observe shell 2 responses hanging

Screenshot and/or share link

No response

Operating System

MacOS Sequoia Version 15.7.2 (24G325)

Terminal

WezTerm, Cursor

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 4, 2025
  2. github-actions commented on Dec 4, 2025

    @github-actions
    Contributor

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

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

  3. Eric162 commented on Dec 4, 2025

    @Eric162
    ContributorAuthor

    opencode investigating found this:

    Findings

    • ctrl+z is wired to the terminal_suspend command in the shipped config (packages/opencode/src/config/config.ts:447), so hitting ctrl+z inside OpenTUI always runs that command rather than letting the terminal driver handle job control.
    • The command handler (added in 6afdb5c) lives in packages/opencode/src/cli/cmd/tui/app.tsx:366-377. It suspends the renderer and then calls process.kill(0, "SIGTSTP") to emulate “send the job to the background.” As the in-line comment notes, passing 0 targets the entire process group.
    • When you have multiple opencode TUIs that share the same process group (which is common whenever they’re launched from the same terminal session/multiplexer—WezTerm tabs, Cursor panes, tmux windows, or multiple opencode attach clients pointing at a single opencode spawn server), every process in that group receives the signal. That means the worker thread hosting the local Bun server plus any other TUIs in that group are also SIGTSTP’d, so their event loops stop processing API/network IO. They appear “hung” until a SIGCONT arrives, which matches the user’s observation that everything resumes right after they fg the instance they suspended.
    • The resume logic already hooks SIGCONT (app.tsx:371-373), so once the foreground job is continued, the renderer wakes up and the HTTP server continues accepting requests, letting all other instances drain their pending network work immediately.
      Why the issue occurs
      The new suspend implementation broadcasts SIGTSTP too broadly by signaling the whole process group (pid 0). In practice that group includes every OpenCode process launched from the same terminal session, so suspending one client inadvertently pauses the Bun worker/server that the other clients depend on, which freezes their request/response traffic until SIGCONT.
      Next steps
    1. Change the suspend handler to signal only the current job (e.g., process.kill(process.pid, "SIGTSTP") or explicitly target just the worker/TUI PIDs) instead of pid 0, or ensure each opencode invocation runs in its own process group (setpgid) before wiring ctrl+z.
    2. Add a regression test/manual QA note: run multiple TUIs simultaneously (including in tmux/WezTerm/Cursor panes) and verify suspending one instance no longer stalls the others.
      This should prevent the cascade pause described in issue Suspend (ctrl + z) pauses api calls for all opencode instances #5043 while keeping the “ctrl+z to background” feature.
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

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions