Repository navigation
fix: default agent TMPDIR to disk-backed home volume — /tmp tmpfs starves build scratch (#1098) - #1124
Conversation
…small for build scratch (#1098) Agent containers mount /tmp as a 100 MB RAM-backed tmpfs (noexec,nosuid). Heavy scratch — pip/npm install, compiling C extensions, ML wheels (torch/transformers) — overflows it with "No space left on device" even though the home volume has hundreds of GB free, and noexec breaks compile-and-exec-from-tmp. This blocks a core class of agent setup work. Fix: set a default TMPDIR=/home/developer/.tmp on the disk-backed, exec-capable home volume. pip/npm/most build tooling honor TMPDIR, so this redirects scratch onto real disk and dodges noexec in one move — while keeping /tmp's hardened noexec,nosuid posture unchanged. - New constants AGENT_TMPFS_MOUNT + AGENT_DEFAULT_TMPDIR in the low-dep capabilities.py (single source of truth). Wired into all three provisioning paths so create / recreate / system-agent can't drift: crud.py (create), lifecycle.py (recreate, setdefault so a template/user TMPDIR carried on the container wins), system_agent_service.py. - startup.sh creates the dir (idempotent, chmod 700) before its own pip install, so existing agents pick it up on restart/recreate and tools honoring TMPDIR land on disk. - architecture.md: note the TMPDIR redirect alongside the /tmp tmpfs claim. Requires a base-image rebuild (startup.sh change) — start.sh / build-base-image.sh handles it; env + startup.sh ship together. Verified e2e on a fresh agent (rebuilt base image): container env carries TMPDIR=/home/developer/.tmp; startup.sh auto-creates the dir (700, developer-owned) on the 600 GB-free home disk; tempfile.mkdtemp() lands there; 150 MB scratch succeeds via TMPDIR but caps at exactly 100 MB on /tmp ("No space left"); /tmp stays noexec,nosuid,size=100m. Related to #1098 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| # (idempotent) so tools that honor TMPDIR land there. Runs as `developer`, the | ||
| # UID-1000 owner of /home/developer. | ||
| AGENT_TMPDIR="${TMPDIR:-/home/developer/.tmp}" | ||
| mkdir -p "${AGENT_TMPDIR}" 2>/dev/null && chmod 700 "${AGENT_TMPDIR}" 2>/dev/null || \ |
There was a problem hiding this comment.
Deploy-coupling (medium): the backend injects TMPDIR (crud/lifecycle/system-agent) but this mkdir — the half that makes the dir actually exist — lives in the base image. The two are only in lockstep if the base image is rebuilt with the backend deploy. Since agents run/recreate on the trinity-agent-base:latest tag, a deploy that updates the backend without rebuilding latest gives newly created/recreated agents TMPDIR=/home/developer/.tmp pointing at a missing dir — and startup.sh's own pip install --user (line ~313, which now honors that TMPDIR) plus any TMPDIR-honoring tool fails. That's strictly worse than the status quo for that window.
Mitigated by the standard start.sh / build-base-image.sh deploy (and documented in the PR), so not a blocker — flagging so the rollout is treated as atomic (rebuild base image + backend together). A belt-and-suspenders option: have the backend tolerate a missing dir, or fall back in old images — though the old image can't be retroactively fixed, so deploy discipline is the real guard.
| # UID-1000 owner of /home/developer. | ||
| AGENT_TMPDIR="${TMPDIR:-/home/developer/.tmp}" | ||
| mkdir -p "${AGENT_TMPDIR}" 2>/dev/null && chmod 700 "${AGENT_TMPDIR}" 2>/dev/null || \ | ||
| echo "Warning: could not create TMPDIR ${AGENT_TMPDIR}; scratch will fall back to /tmp" |
There was a problem hiding this comment.
Nit: mkdir -p X && chmod 700 X || echo warning — if mkdir succeeds but chmod fails (e.g. dir pre-exists owned by another uid), the warning fires even though the dir exists, and conversely a successful mkdir on a pre-existing dir is the common restart path. Harmless, but the warning text ("could not create TMPDIR") is misleading when only the chmod failed. Minor.
🔎 Code review (high-effort, recall-biased) — no blocking bugsClean refactor (shared constants kill the create/recreate/system-agent drift) + verified e2e. No correctness bugs survived verification. 2 inline notes, both non-blocking. Checked & cleared
Notes (non-blocking)
✅ Ready to merge (rebuild the base image as part of the deploy). Reviewed with the |
|
Resolve by running |
Resolved docs/memory/architecture.md: dev's restructure collapsed Container Security into compact bullets; folded the #1098 TMPDIR redirect note into the tmpfs bullet. Code files auto-merged cleanly alongside the #1126 nano_cpus change (verified both coexist at all three provisioning sites). Co-Authored-By: Claude Fable 5 <[email protected]>
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr: TMPDIR redirect verified at all three provisioning sites via shared constants (no drift); /tmp posture unchanged (noexec,nosuid,100m); setdefault preserves template-supplied TMPDIR on recreate; coexistence with #1126 nano_cpus change verified post-merge. Architecture.md conflict resolved against dev restructure. Approving.
Summary
Agent containers mount
/tmpas a 100 MB RAM-backed tmpfs (noexec,nosuid). Heavy scratch —pip/npm install, compiling C extensions, ML wheels (torch/transformers) — overflows it withNo space left on deviceeven though the home volume has hundreds of GB free, andnoexecbreaks compile-and-exec-from-/tmp. This blocks a core class of agent setup work.Fix: set a default
TMPDIR=/home/developer/.tmpon the disk-backed, exec-capable home volume.pip/npm/most build tooling honorTMPDIR, so this redirects scratch onto real disk and dodgesnoexecin one move — while keeping/tmp's hardenednoexec,nosuidposture unchanged (rejects the naive "just enlarge the tmpfs", which costs host RAM per agent and leavesnoexec).Changes
services/agent_service/capabilities.py— newAGENT_TMPFS_MOUNT+AGENT_DEFAULT_TMPDIRconstants (low-dep module, single source of truth).crud.py(create) —TMPDIRin the env dict;tmpfs=AGENT_TMPFS_MOUNT.lifecycle.py(recreate) —env_vars.setdefault('TMPDIR', …)so a template/userTMPDIRcarried on the existing container wins;tmpfs=AGENT_TMPFS_MOUNT.system_agent_service.py— third provisioning site (not named in the issue, but had the identical literal) wired to the same constants — no drift.docker/base-image/startup.sh— creates the dir (idempotent,chmod 700) before its ownpip install, so existing agents pick it up on restart/recreate and tools honoringTMPDIRland on disk.architecture.md— note theTMPDIRredirect alongside the/tmptmpfs claim.Acceptance criteria
No space left on device(150 MB scratch viaTMPDIRsucceeds;/tmpcaps at 100 MB).TMPDIRresolves to a disk-backed, exec-capable home-volume path, created on container start./tmpretainsnoexec,nosuid(security posture unchanged); scratch redirected viaTMPDIR, not by loosening/tmp.TMPDIRwin (recreate usessetdefault).Rollout note
Touches
startup.sh→ requires a base-image rebuild (scripts/deploy/build-base-image.sh, whichstart.shruns). The env injection and the dir-creation ship together; recreate from the rebuilt image lands both. (A new-backend + old-image window whereTMPDIRis set but the dir is missing is avoided by the standard rebuild-everything deploy.)Verification (e2e on a fresh agent, rebuilt base image)
TMPDIR=/home/developer/.tmp(backend-injected)startup.shdrwx------ developer developer /home/developer/.tmptempfile.mkdtemp()→/home/developer/.tmp/..., on the 600 GB-free volumeTMPDIR/tmp100+0 records out, no space) — the original symptom/tmpposturetmpfs ... noexec,nosuid,size=102400kThrowaway test agent created + deleted; left environment clean.
Related to #1098
🤖 Generated with Claude Code