Skip to content

fix(workspace): don't pipe Apptainer server output nobody reads - #6619

Merged
VascoSch92 merged 1 commit into
mainfrom
vasco/apptainer-undrained-logs
Nov 7, 2026
Merged

VascoSch92 merged 1 commit into
mainfrom
vasco/apptainer-undrained-logs

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

just fixing a bug


AGENT:

Why

ApptainerWorkspace starts the agent server with stdout=subprocess.PIPE, stderr=STDOUT, and only the background _stream_logs thread reads that pipe. That thread is started only when detach_logs=True. With detach_logs=False nothing 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

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

uv run pytest tests/workspace/test_apptainer_workspace.py

test_undrained_logs_do_not_block_server fails on main (stdout is a PIPE) and passes here; the file passes (8).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

🐳 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:4a7a56d-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-4a7a56d-python \
  ghcr.io/openhands/agent-server:4a7a56d-python

All tags pushed for this build

ghcr.io/openhands/agent-server:4a7a56d-golang-amd64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-golang-amd64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-golang-amd64
ghcr.io/openhands/agent-server:4a7a56d-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:4a7a56d-golang-arm64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-golang-arm64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-golang-arm64
ghcr.io/openhands/agent-server:4a7a56d-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:4a7a56d-java-amd64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-java-amd64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-java-amd64
ghcr.io/openhands/agent-server:4a7a56d-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:4a7a56d-java-arm64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-java-arm64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-java-arm64
ghcr.io/openhands/agent-server:4a7a56d-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-amd64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-amd64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-arm64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-arm64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-minimal-amd64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-minimal-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-minimal-arm64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-minimal-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-slim-amd64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-slim-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:4a7a56d-python-slim-arm64
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-slim-arm64
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:4a7a56d-golang
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-golang
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-golang
ghcr.io/openhands/agent-server:4a7a56d-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:4a7a56d-java
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-java
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-java
ghcr.io/openhands/agent-server:4a7a56d-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:4a7a56d-python-minimal
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-minimal
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-minimal
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-minimal
ghcr.io/openhands/agent-server:4a7a56d-python-slim
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python-slim
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python-slim
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime-slim
ghcr.io/openhands/agent-server:4a7a56d-python
ghcr.io/openhands/agent-server:4a7a56d410df9999d5a4d56c5c0adf719f9f1941-python
ghcr.io/openhands/agent-server:vasco-apptainer-undrained-logs-python
ghcr.io/openhands/agent-server:4a7a56d-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 4a7a56d-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 4a7a56d-python-amd64) are also available if needed

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.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-workspace/openhands/workspace/apptainer
   workspace.py1816664%162, 171, 174–175, 182, 195, 227–228, 230, 233–235, 237–239, 241, 244, 250–252, 256–257, 265, 270–272, 332–333, 337–347, 349–352, 356–357, 359–365, 368, 370, 375–376, 380, 401, 410–417
TOTAL537552665150% 

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@VascoSch92
VascoSch92 merged commit fac5e9e into main Nov 7, 2026
49 of 50 checks passed
@VascoSch92
VascoSch92 deleted the vasco/apptainer-undrained-logs branch November 7, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants