Skip to content

An open-source, faster Devin alternative

TypeScript

computer: age /tmp after 7 days instead of Ubuntu's 30 (#1082)

opencomputer-app[bot]d87598afb4e3
diff --git a/computer/deploy/vm/provision.sh b/computer/deploy/vm/provision.sh
index 5559da61..f3659b97 100755
--- a/computer/deploy/vm/provision.sh
+++ b/computer/deploy/vm/provision.sh
@@ -644,6 +644,11 @@ log "systemd units"
# The entries live in sp-host.sh (`run_dirs`), which also writes them on migrate and revert.
AGENT_USER="$AGENT_USER" SP_RUN="$SP_RUN" bash "$SP_CURRENT/deploy/vm/sp-host.sh" run-dirs
+# /tmp ages after 7 days, not Ubuntu's 30: runners share TMPDIR=/tmp, and it
+# filled the root disk (deploy/vm/tmp.conf replaces /usr/lib/tmpfiles.d/tmp.conf).
+# No clean here: the daily systemd-tmpfiles-clean.timer does the first one, not a deploy.
+install -m 0644 "$SP_CURRENT/deploy/vm/tmp.conf" /etc/tmpfiles.d/tmp.conf
+
# Lingering keeps the agent's systemd user manager (user@$AGENT_UID) running
# without a login, so the host agent can start runners as transient user units
# (`systemd-run --user`). Chosen over system-level systemd-run: letting a
diff --git a/computer/deploy/vm/tmp.conf b/computer/deploy/vm/tmp.conf
new file mode 100644
index 00000000..c1b4ccc5
--- /dev/null
+++ b/computer/deploy/vm/tmp.conf
@@ -0,0 +1,23 @@
+# Installed by deploy/vm/provision.sh as /etc/tmpfiles.d/tmp.conf.
+# Runners share TMPDIR=/tmp (src/host/launch.ts), and Ubuntu's 30 days left
+# 44 GB there on a 61 GB root disk. Same name as /usr/lib/tmpfiles.d/tmp.conf,
+# so this file replaces it (its one line was `D /tmp 1777 root root 30d`).
+#
+# D as Ubuntu has it: emptied at boot as before, mode and owner unchanged.
+# Entries untouched (atime, mtime, and ctime for non-directories) for 7 days
+# go when systemd-tmpfiles-clean.timer runs (daily). A directory goes only once
+# it is empty and itself old: anything recent inside keeps it.
+D /tmp 1777 root root 7d
+
+# The host's own: Slack attachments a session may still read (src/runner/attachments.ts).
+x /tmp/slack-presence
+# Claude Code's per-user temp dir (/tmp/claude-<uid>), held open by live sessions' processes.
+x /tmp/claude-*
+# Other services' private /tmp and desktop sockets; their packages age them.
+x /tmp/systemd-private-*
+x /tmp/snap-private-tmp
+x /tmp/.X11-unix
+x /tmp/.ICE-unix
+x /tmp/.XIM-unix
+x /tmp/.font-unix
+x /tmp/.Test-unix
diff --git a/computer/src/host/vm-tmp.test.ts b/computer/src/host/vm-tmp.test.ts
new file mode 100644
index 00000000..959f9a7d
--- /dev/null
+++ b/computer/src/host/vm-tmp.test.ts
@@ -0,0 +1,68 @@
+// /tmp's aging lives in a tmpfiles.d file (deploy/vm/tmp.conf, installed by
+// provision.sh); this runs the real systemd-tmpfiles --clean on it in a scratch
+// root, next to Ubuntu's own tmp.conf, and checks what goes and what stays.
+import { execFileSync } from 'node:child_process';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { afterEach, describe, expect, it } from 'vitest';
+
+const CONF = path.resolve(import.meta.dirname, '../../deploy/vm/tmp.conf');
+const tmpfiles = (() => {
+ try {
+ execFileSync('systemd-tmpfiles', ['--version'], { stdio: 'ignore' });
+ return true;
+ } catch {
+ return false;
+ }
+})();
+
+const DAY = 24 * 60 * 60;
+let root = '';
+afterEach(() => root && fs.rmSync(root, { recursive: true, force: true }));
+
+/** Runs the clean on a root holding `files` (path under /tmp → age in days), and returns what is left under /tmp. */
+function clean(files: Record<string, number>, dirs: Record<string, number>): string[] {
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'vm-tmp-'));
+ const etc = path.join(root, 'etc/tmpfiles.d');
+ const usr = path.join(root, 'usr/lib/tmpfiles.d');
+ fs.mkdirSync(etc, { recursive: true });
+ fs.mkdirSync(usr, { recursive: true });
+ fs.writeFileSync(path.join(usr, 'tmp.conf'), 'D /tmp 1777 root root 30d\n'); // Ubuntu 24.04's
+ // Birth and change times cannot be set back, so the test ages by access and modification only.
+ const conf = fs.readFileSync(CONF, 'utf8');
+ expect(conf).toMatch(/^D \/tmp 1777 root root 7d$/m);
+ fs.writeFileSync(path.join(etc, 'tmp.conf'), conf.replace(/^(D \/tmp .*) 7d$/m, '$1 amAM:7d'));
+ const tmp = path.join(root, 'tmp');
+ const now = Date.now() / 1000;
+ for (const f of Object.keys(files)) {
+ fs.mkdirSync(path.dirname(path.join(tmp, f)), { recursive: true });
+ fs.writeFileSync(path.join(tmp, f), '');
+ }
+ for (const d of Object.keys(dirs)) fs.mkdirSync(path.join(tmp, d), { recursive: true });
+ for (const [f, days] of Object.entries(files)) fs.utimesSync(path.join(tmp, f), now - days * DAY, now - days * DAY);
+ // Deepest first, so setting a child's times does not touch its parent's afterwards.
+ for (const [d, days] of Object.entries(dirs).sort(([a], [b]) => b.length - a.length)) fs.utimesSync(path.join(tmp, d), now - days * DAY, now - days * DAY);
+ execFileSync('systemd-tmpfiles', ['--clean', `--root=${root}`], { stdio: 'pipe' });
+ return (fs.readdirSync(tmp, { recursive: true }) as string[]).sort();
+}
+
+describe.skipIf(!tmpfiles)('deploy/vm/tmp.conf', () => {
+ it('removes week-old scratch and keeps recent entries', () => {
+ expect(clean({ 'old.txt': 8, 'new.txt': 1, 'ws-prompt-1': 30 }, { 'session-test-1': 10, 'track-i': 2 })).toEqual(['new.txt', 'track-i']);
+ });
+
+ it('keeps an old directory while anything inside is recent, and empties old files out of a recent one', () => {
+ const left = clean(
+ { 'oc-src/new.ts': 1, 'oc-src/sub/old.ts': 9, 'vid/old.mp4': 9 },
+ { 'oc-src': 20, 'oc-src/sub': 20, vid: 1 },
+ );
+ expect(left).toEqual(['oc-src', 'oc-src/new.ts', 'vid']);
+ });
+
+ it('never ages the host’s attachments, Claude Code’s temp dir or other services’ private /tmp', () => {
+ const keep = ['slack-presence/s-1/F1-a.png', 'claude-1500/cwd-x', 'systemd-private-abc-x/tmp/f', 'snap-private-tmp/f', '.X11-unix/X0', '.ICE-unix/1'];
+ const left = clean(Object.fromEntries(keep.map((f) => [f, 20])), Object.fromEntries(keep.map((f) => [path.dirname(f), 20])));
+ for (const f of keep) expect(left).toContain(f);
+ });
+});