Skip to content

Bash tool hangs with continuously-outputting background processes #22012

Description

@WanderWang

Description

The Bash tool hangs indefinitely when a command spawns a background process that continuously writes to stdout/stderr. This happens even though the foreground shell command itself has already finished executing.

PR #20901 (merged in v1.3.14) partially addressed this by switching from close to exit for process completion detection. However, that fix only covers background processes that do not produce output (e.g. sleep 10 &). If the background process keeps writing to stdout (e.g. uvicorn, npm run dev, docker compose up), the Bash tool's stdout stream collector never terminates, so the entire tool execution promise never resolves.

Plugins

oh-my-openagent

OpenCode version

1.4.3

Steps to reproduce

1. Create a minimal FastAPI file demo_server.py:

from fastapi import FastAPI
app = FastAPI()
@app.get("/health")
def health(): return {"status": "ok"}

2. Run the "dangerous" command inside OpenCode's Bash tool:

bash -c "uv run uvicorn demo_server:app --host 0.0.0.0 --port 9876 & sleep 2; curl -s http://localhost:9876/health; echo 'Foreground done'"

Expected behavior: The Bash tool should return after curl, echo, and sleep complete.
Actual behavior: The Bash tool remains in running state indefinitely until timeout kills it.

3. Run the "safe" command for comparison:

bash -c "nohup uv run uvicorn demo_server:app --host 0.0.0.0 --port 9877 > /dev/null 2>&1 & sleep 2; curl -s http://localhost:9877/health; echo 'Done'"

Expected behavior: Returns immediately as expected.
Actual behavior: Returns immediately as expected.

Screenshot and/or share link

No response

Operating System

Ubuntu 22 ( as a Docker Container)

Terminal

bash

Activity

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