You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Hermetic temp directories (seeded auth/store databases) are left behind on SIGINT/SIGTERM, unhandled rejection or MCP runner kill #977
Severity: low. Found in an adversarial review of #947 and #970.
Runtime revision and environment
origin/main ba9f3204, Node 26.10, macOS.
What happens
The hermetic temp directories (urlcode-hermetic-*, holding the throwaway auth, store and audit SQLite files: seeded test accounts with hashed passwords and fixture data) and urlcode-data-* are removed only in the CLI's finally (packages/core/src/cli.ts ~759) and in startRestartable's close() (packages/core/src/project-tests.ts ~46–60). Removal is skipped when:
SIGINT or SIGTERM reaches test, audit, validate or routes. Only dev, serve and studio install signal handlers. Reproduced.
An unhandled rejection hits the global handler, which calls process.exit(1) (cli.ts ~345). Reported by the reviewing agent; I did not re-run it.
The MCP runner SIGKILLs a child after 120 s (packages/core/src/mcp-authoring.ts ~145). Inferred from the code; not run.
The directories are 0700, so the exposure is low, but they accumulate on developer and CI machines.
Minimal reproduction
A project with one trusted function route /slow that awaits 60 s and a fixture [{"path":"/slow","status":200}], plus any composed host:
Observed: both directories remain after the process exits.
Suggested fix
For non-serving commands, install SIGINT/SIGTERM handlers that await the app's and the operator host's close(), and do the same best-effort close in the unhandled-rejection path.
In the MCP runner, send SIGTERM with a grace period before SIGKILL.
Optionally, sweep stale urlcode-hermetic-* directories.
Review of PR #987 (head af07d30): the temp-directory sweep.
What held up, run against the real sweepStaleRunDirectories and processExists:
A matching symlink in the temp root is neither followed nor removed.
Symlinks inside a stale directory are unlinked, and their targets are kept.
Also kept:
a directory whose pid is live;
pid 1 (EPERM counts as alive);
a file with a matching name;
a 0755 directory;
a young directory;
names that do not match the pattern.
createRunDirectory uses mkdtemp, and the sweep checks uid and 0700.
Two gaps:
The one-hour age guard reads the directory's own mtime (packages/core/src/temp-dirs.ts around line 84). That changes only when entries are added or removed, not when an existing file such as the SQLite database is written.
Repro: a matching directory aged 3 h (utimes), whose inner db.sqlite was rewritten just before the sweep, with a pid dead in this namespace, was removed: removed [ 'urlcode-data-99990-INUSE1', … ].
The PR says the age covers "a pid from another pid namespace sharing /tmp". It covers that only for runs shorter than an hour: a longer test/audit/benchmark, or an embedder's long-lived startServer({isolateData}), can lose its live directory to a sweep from another container that shares the temp dir and uid.
The container scenario itself is reasoned, not reproduced.
Options: touch the directory periodically while it is live, or document the one-hour limit.
Tests sweep the developer's real temp dir.test/hermetic-hardening.test.ts (and any in-process loadOperatorHost({hermetic: true}) or createRunDirectory) runs the first-use sweep on the real os.tmpdir(), because it has no root override. It removes only stale, owned, 0700, dead-pid URLCode directories, but a test run should not delete things outside its scratch area.
With TMPDIR pointed at scratch, the hermetic suites (34 tests) passed and left nothing behind.
Fixed in #987, commit 1d410c3. The sweep's age now comes from the newest entry in the directory (a bounded lstat walk that never follows links), so a directory with a fresh db.sqlite is kept. The test suites redirect TMPDIR, TEMP and TMP to a scratch directory. Summary: #987 (comment)
Activity
test(core): hermetic hardening tests are platform-aware on Windows (#977
jimhoyd commentedon Sep 30, 2026
Review of PR #987 (head af07d30): the temp-directory sweep.
What held up, run against the real
sweepStaleRunDirectoriesandprocessExists:createRunDirectoryusesmkdtemp, and the sweep checks uid and 0700.Two gaps:
mtime(packages/core/src/temp-dirs.ts around line 84). That changes only when entries are added or removed, not when an existing file such as the SQLite database is written.utimes), whose innerdb.sqlitewas rewritten just before the sweep, with a pid dead in this namespace, was removed:removed [ 'urlcode-data-99990-INUSE1', … ].test/audit/benchmark, or an embedder's long-livedstartServer({isolateData}), can lose its live directory to a sweep from another container that shares the temp dir and uid.test/hermetic-hardening.test.ts(and any in-processloadOperatorHost({hermetic: true})orcreateRunDirectory) runs the first-use sweep on the realos.tmpdir(), because it has no root override. It removes only stale, owned, 0700, dead-pid URLCode directories, but a test run should not delete things outside its scratch area.TMPDIRpointed at scratch, the hermetic suites (34 tests) passed and left nothing behind.fix(core): confirm each hermetic registration; age the sweep by a dir…
jimhoyd commentedon Sep 30, 2026
Fixed in #987, commit 1d410c3. The sweep's age now comes from the newest entry in the directory (a bounded lstat walk that never follows links), so a directory with a fresh db.sqlite is kept. The test suites redirect TMPDIR, TEMP and TMP to a scratch directory. Summary: #987 (comment)
fix(core): hermetic runs enforce the data handover and clean up their…
jimhoyd commentedon Sep 30, 2026
Fixed by #987 (merged), including the review follow-ups: per-registration hermetic confirmation and aging the sweep by a directory's newest entry.