Repository navigation
fix(agent-server): remove the per-server TMUX_TMPDIR on shutdown - #5945
Conversation
When TMUX_TMPDIR is unset (or too long for a tmux socket path), the server creates <tempdir>/openhands-agent-server-<pid> for itself, but the lifespan shutdown only restored the environment variable, so every such start left a directory behind. Remove that directory at shutdown when this process created it; a user-provided TMUX_TMPDIR is never touched. Drops the known-bug marker from the F31.tmux-dir-cleanup map bullet. Fixes #5932 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Address the issue triage: removal stays best-effort but a failure is now logged instead of silently ignored, and tests cover the too-long TMUX_TMPDIR fallback (user value restored and kept, substitute removed) and the failure path. Fixes #5932 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: This change belongs in this repository. It touches agent-server lifecycle code (_ensure_server_tmux_tmpdir / api_lifespan in openhands-agent-server/openhands/agent_server/api.py), its unit tests, and the verify-agent-server feature map. It should not move repositories or be closed.
Why this stops for a decision: The PR body asks for it directly ("Decision needed ... A maintainer should confirm which gate they prefer"), and the two candidate gates are not behaviorally equivalent. Gating removal on "this process created the directory" leaves a pre-existing, same-named default directory behind, whereas the issue-triage suggestion (the env-restore guard) would remove it. That difference is real in the shared-/tmp-across-PID-namespaces case the linked issue (#5932) calls out, and it also decides whether acceptance criterion 1 of #5932 ("When the server defaulted its own TMUX_TMPDIR, a graceful shutdown removes that directory") is met as written or is being deliberately narrowed to directories this process created.
Choosing the removal-ownership policy is a maintainer call, so this review defers rather than recording an implementation verdict.
🛑 MAINTAINER DECISION REQUIRED
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands) on behalf of the requesting user.
Verdict: APPROVE.
Scope. Agent Server lifecycle/cleanup — belongs in this repo. shutil is stdlib, so no packaging change; _ensure_server_tmux_tmpdir is private with api_lifespan as its only caller, and no public API, default, or wire contract changes.
Decision gate resolved. The author's "Decision needed" (gate removal on a new created flag vs the env-restore guard) was answered by the maintainer (enyst, 2026-10-14 14:30): "Let's go with created though." The head implements that choice, so the open question is closed.
Verified at 4cecf3a4
uv run pytest -q tests/agent_server/test_api.py-> 51 passed (reproduced locally).- CI: all 53 check-runs on the head are success (
agent-server-tests,smoke-test,cross-tests,pre-commit,REST API (OpenAPI), ...). control-agent-server map check-> ok (34 files, 935 IDs, no problems);F31.tmux-dir-cleanuppasses with its# bugmarker removed.- Independent live before/after through the real entry point (
python -m openhands.agent_server, gracefulSIGTERM), reproducing the reported symptom:- baseline
main@6e7a853:<tmpdir>/openhands-agent-server-<pid>still exists after "Application shutdown complete."; - head
4cecf3a4: same workflow, the directory is removed.
This confirms the reported root cause and agrees with the PR's map-level xfail (baseline) -> pass (branch) proof.
- baseline
Behavior notes (non-blocking). Removal runs in the lifespan finally after the conversation services close, gated on the process having created the directory, matching the maintainer's choice; a failure is logged as a warning and shutdown continues (tested). A pre-existing same-named directory is intentionally kept, as the description states. The startup stale-session cleanup is unchanged.
No material correctness, security, compatibility, or architecture findings.
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-agent-server.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Decision needed
The issue triage suggests gating removal on the env-restore guard (
os.environ.get("TMUX_TMPDIR") == str(tmux_tmpdir)). This PR gates it instead on whether this server created the directory during this start (_ensure_server_tmux_tmpdirnow returns acreatedflag).openhands-agent-server-<pid>directory (for example,/tmpshared across PID namespaces) would be deleted under the env guard alone. Nothing in the server changesTMUX_TMPDIRafter startup.A maintainer should confirm which gate they prefer.
Why
When
TMUX_TMPDIRis unset (or too long for a tmux socket path), the agent server creates<tempdir>/openhands-agent-server-<pid>for itself. On a graceful shutdown,api_lifespanonly restored the environment variable and never deleted the directory, so every such start left one more directory in the temp dir (this sandbox had 241 of them).Summary
api_lifespanremoves the per-server tmux directory, but only when this process created it. Removal is best-effort: a failure is logged as a warning and shutdown continues. A user-providedTMUX_TMPDIR, or a default directory that already existed, is never removed. Env restoration is unchanged.TMUX_TMPDIRis kept;TMUX_TMPDIR, the user's value is restored and kept and the substitute is removed;# bugmarker and the "known bug" label fromF31.tmux-dir-cleanupand rewrites its prose as the expected behaviour.Issue Number
Fixes #5932
How to Test
uv run pytest -q tests/agent_server/test_api.py: 51 passed. The updated lifespan test fails on main (the directory still exists).AGENT_SERVER_VERIFY_HOME=/var/tmp/avs-tmux-dir-cleanup:control-agent-server map run --file F31 --only F31.tmux-dir-cleanup --fresh --repeat 2 --checkout <main checkout>givesxfail,xfail;--checkoutgivesxpass,xpass;control-agent-server map checkis ok, andmap run --file F31 --only F31.tmux-dir-cleanup --freshgivespass. It passed again after the second commit.uv run pre-commit run --files <changed files>: all checks pass.Video/Screenshots
n/a
Type
Notes
A same-named directory that already existed at startup is left alone, so it is left behind as before. See "Decision needed".
🤖 Generated with Claude Code
https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
🐳 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:4cecf3a-pythonRun
All tags pushed for this build
About Multi-Architecture Support
4cecf3a-python) is a multi-arch manifest supporting both amd64 and arm644cecf3a-python-amd64) are also available if needed