Skip to content

fix(tmp): replace the 1h /tmp reaper with configurable age and size l… - #1172

Merged
mensfeld merged 10 commits into
masterfrom
fix/tmp-cleanup-usage-based
Nov 27, 2026
Merged

mensfeld merged 10 commits into
masterfrom
fix/tmp-cleanup-usage-based

Conversation

@mensfeld

Copy link
Copy Markdown
Collaborator

…imits

The image removed every file in /tmp not used for an hour, checked every 15 minutes, so long-running agents lost their scratchpad and task output (Claude Code keeps them in /tmp/claude-).

Two limits replace it, both settable in [limits.disk] and profiles:

  • tmp_max_age (default 7d): systemd-tmpfiles-clean.timer, daily
  • tmp_max_size (default 4GiB): coi-tmp-cleanup.timer every 2 minutes removes the least recently used files until /tmp holds under 3/4 of it; files used in the last 15 minutes are kept

"0" turns a limit off. coi writes both at each session start (shell and run, fresh and restarted containers), and SANDBOX_CONTEXT.md names them.

…imits

The image removed every file in /tmp not used for an hour, checked every
15 minutes, so long-running agents lost their scratchpad and task output
(Claude Code keeps them in /tmp/claude-<uid>).

Two limits replace it, both settable in [limits.disk] and profiles:
- tmp_max_age (default 7d): systemd-tmpfiles-clean.timer, daily
- tmp_max_size (default 4GiB): coi-tmp-cleanup.timer every 2 minutes
  removes the least recently used files until /tmp holds under 3/4 of
  it; files used in the last 15 minutes are kept

"0" turns a limit off. coi writes both at each session start (shell and
run, fresh and restarted containers), and SANDBOX_CONTEXT.md names them.
…the limit

du walks the whole /tmp tree, so every 2 minutes was more than needed.
Cleaning down to half of tmp_max_size instead of three quarters leaves
room to grow, so the next cleanup is not due at once.
Check the real schedules in the built image (size every 15 minutes, age
daily with no override), and let both timers remove files without a
manual systemctl start: a drop-in makes each fire 1s after a restart and
then every 5s.
An empty OnUnitActiveSec= clears every timer of the unit, so the drop-in
cleared its own OnActiveSec=1s and left only OnUnitActiveSec=5s, which
never fires on a timer whose service has not run yet. The reset now goes
first. The off test compared the files in sort -V order, which puts
fresh before old1.
@mensfeld mensfeld self-assigned this Nov 27, 2026
@mensfeld mensfeld added the bug Something isn't working label Nov 27, 2026
They read a file from a workspace under pytest's /tmp. On GitHub's
ubuntu-24.04 runners on AWS that read never showed in the container's
io.stat, so the threshold never triggered (they pass on the Azure ones).
The workspace is now under the home directory, on the runner's disk, and
a failure also names the workspace's mount.
… tmp_max_size

An agent can leave a file in /tmp for longer than 15 minutes and still
need it; files go oldest first anyway, this is only the floor.
The code user cannot read the system journal, so the check for the
service's log line saw nothing although the timer had removed the files.
…t update

coi needs nothing from it, and its outage (403, "no longer signed")
failed apt-get update and with it the network and incus-lts-file lanes.
…st fails

The read tests discarded dd's output, so a failure on a runner where the
read never reached io.stat gave no reason.
…ytest workspace

The coi image is Ubuntu 26.04, whose dd is uutils'. On GitHub's runners
on AWS its iflag=direct read fails at once with "IO error: Invalid
input", so nothing is read and the threshold never triggers. The tests
now run gnudd when the image has it. This was the cause, not /tmp, so
the disk workspace fixture is gone again.
@mensfeld
mensfeld merged commit 82d8c4d into master Nov 27, 2026
40 checks passed
@mensfeld
mensfeld deleted the fix/tmp-cleanup-usage-based branch November 27, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant