Skip to content

fix: default agent TMPDIR to disk-backed home volume — /tmp tmpfs starves build scratch (#1098) - #1124

Merged
vybe merged 2 commits into
devfrom
feature/1098-tmpdir-home-volume
Jun 11, 2026
Merged

vybe merged 2 commits into
devfrom
feature/1098-tmpdir-home-volume

Conversation

@dolho

@dolho dolho commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

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 (rejects the naive "just enlarge the tmpfs", which costs host RAM per agent and leaves noexec).

Changes

  • services/agent_service/capabilities.py — new AGENT_TMPFS_MOUNT + AGENT_DEFAULT_TMPDIR constants (low-dep module, single source of truth).
  • crud.py (create) — TMPDIR in the env dict; tmpfs=AGENT_TMPFS_MOUNT.
  • lifecycle.py (recreate) — env_vars.setdefault('TMPDIR', …) so a template/user TMPDIR carried 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 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.

Acceptance criteria

  • Heavy install no longer hits No space left on device (150 MB scratch via TMPDIR succeeds; /tmp caps at 100 MB).
  • Default TMPDIR resolves to a disk-backed, exec-capable home-volume path, created on container start.
  • Applied at both provisioning sites (crud + lifecycle) — and the third (system agent); no drift (shared constants).
  • /tmp retains noexec,nosuid (security posture unchanged); scratch redirected via TMPDIR, not by loosening /tmp.
  • Existing agents pick up the default on restart/recreate (startup.sh mkdir + lifecycle env).
  • Templates with their own TMPDIR win (recreate uses setdefault).

Rollout note

Touches startup.sh → requires a base-image rebuild (scripts/deploy/build-base-image.sh, which start.sh runs). The env injection and the dir-creation ship together; recreate from the rebuilt image lands both. (A new-backend + old-image window where TMPDIR is set but the dir is missing is avoided by the standard rebuild-everything deploy.)

Verification (e2e on a fresh agent, rebuilt base image)

Check Result
Container env TMPDIR=/home/developer/.tmp (backend-injected)
Dir auto-created by startup.sh drwx------ developer developer /home/developer/.tmp
Scratch lands on disk tempfile.mkdtemp() → /home/developer/.tmp/..., on the 600 GB-free volume
150 MB scratch via TMPDIR ✅ success (4.5 GB/s)
150 MB into /tmp ❌ caps at exactly 100 MB (100+0 records out, no space) — the original symptom
/tmp posture still tmpfs ... noexec,nosuid,size=102400k

Throwaway test agent created + deleted; left environment clean.

Related to #1098

🤖 Generated with Claude Code

…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 || \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@dolho

dolho commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

🔎 Code review (high-effort, recall-biased) — no blocking bugs

Clean 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

  • Git pollution (the one I most expected) — refuted. /home/developer/.tmp is inside synced agents' git tree, but *.tmp (already in _GITIGNORE_PATTERNS, applied on init + every push) ignores the .tmp/ directory and its contents — empirically confirmed via git check-ignore .tmp/ and git status. Build scratch won't leak into auto-sync.
  • Shared mutable AGENT_TMPFS_MOUNT dict across three containers_run calls — docker-py treats tmpfs= read-only (builds HostConfig from it), no mutation. Safe.
  • Recreate image — agents run the trinity-agent-base:latest tag (Config.Image confirmed), and recreate reuses it, so a rebuilt latest reaches existing agents (AC: "pick up on recreate" holds).
  • /tmp posture unchanged (noexec,nosuid,size=100m via the constant — byte-identical to before).
  • setdefault in lifecycle correctly preserves a template/user TMPDIR across recreate.

Notes (non-blocking)

  1. Deploy-coupling (medium) — backend sets TMPDIR, but the dir is created by startup.sh in the base image. A backend deploy without a base-image rebuild → TMPDIR set, dir missing → startup.sh's own pip install + TMPDIR-honoring tools fail (worse than today). Mitigated by the standard start.sh/build-base-image.sh deploy + documented in the PR; flagging so rollout stays atomic. (inline)
  2. Nit — mkdir && chmod || echo: a chmod-only failure prints the "could not create" warning though the dir exists. Cosmetic. (inline)

✅ Ready to merge (rebuild the base image as part of the deploy).

Reviewed with the code-review skill.

@dolho
dolho requested a review from vybe June 10, 2026 09:36
@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

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 vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@vybe
vybe merged commit 7b1e567 into dev Jun 11, 2026
15 checks passed
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