Repository navigation
fix(workspace): don't pipe Apptainer server output nobody reads - #6619
Conversation
With detach_logs=False the agent server's stdout/stderr still went to a PIPE, but only the log-streaming thread reads it, so once ~64 KiB of logs filled the pipe buffer the server blocked on its next write. Send the output to DEVNULL when logs are not streamed.
Coverage Report •
|
||||||||||||||||||||
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In scope for this repository. ApptainerWorkspace lives in openhands-workspace, which this repo owns, and the change targets the exact item pinned in #6348 ("with detach_logs=False the server's stdout PIPE is never read, so it blocks once ~64 KiB of logs fill the pipe buffer"). The linked issue carries ready-for-dev and the tracked acceptance criteria for resource-lifecycle fixes are satisfied by this change.
Fix is correct: On origin/main the agent-server process is started with an unconditional stdout=subprocess.PIPE while the only reader, _stream_logs, is started only when detach_logs=True (the default). With detach_logs=False nothing drains the pipe, so the child blocks on a log write once the ~64 KiB OS pipe buffer fills — a real deadlock, not theoretical. The change to stdout=subprocess.PIPE if self.detach_logs else subprocess.DEVNULL eliminates the un-read pipe while preserving the existing streaming behavior unchanged on the detach_logs=True path. I verified there are no other consumers of _process.stdout in the file, and cleanup() does not depend on the pipe.
Parity claim checks out: DockerWorkspace runs docker run -d, so container output is managed by the Docker daemon and it has no equivalent undrained-pipe hazard; this change brings ApptainerWorkspace to the same "no logs streamed" behavior when detach_logs=False.
Verification on this head: uv run pytest tests/workspace/test_apptainer_workspace.py passes (8/8), including the new test_undrained_logs_do_not_block_server; the full tests/workspace/ suite passes (257 tests); pre-commit hooks (ruff format/lint, pycodestyle, pyright, import rules) pass on the changed files. GitHub Actions on 4a7a56d4 is green for all test workflows (workspace-tests, agent-server-tests, sdk-tests, cross-tests, windows-tests, pre-commit, etc.); the remaining pending jobs are image Build & Push and release-style checks unrelated to this diff, with no failures.
No material findings; no inline comments.
✅ APPROVED
HUMAN:
just fixing a bug
AGENT:
Why
ApptainerWorkspacestarts the agent server withstdout=subprocess.PIPE, stderr=STDOUT, and only the background_stream_logsthread reads that pipe. That thread is started only whendetach_logs=True. Withdetach_logs=Falsenothing drains the pipe, so after about 64 KiB of log output (the OS pipe buffer) the server blocks on its next log write and stops responding. That is the workspace hanging partway through a long run.Summary
stdout=subprocess.DEVNULLwhendetach_logsis off, the same "logs are not streamed" resultDockerWorkspacegets. Withdetach_logs=Truenothing changes.detach_logs=Falsethe server is no longer started with a pipe. The branch's original test needs real child-process fixtures that are not onmain.Issue Number
Part of #6348 (item: "with detach_logs=False the server's stdout PIPE is never read, so it blocks once ~64 KiB of logs fill the pipe buffer").
How to Test
test_undrained_logs_do_not_block_serverfails onmain(stdout is aPIPE) and passes here; the file passes (8).Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:4a7a56d-pythonRun
All tags pushed for this build
About Multi-Architecture Support
4a7a56d-python) is a multi-arch manifest supporting both amd64 and arm644a7a56d-python-amd64) are also available if needed