Repository navigation
fix(codegen-ts): sweep scratch dirs left by dead processes - #704
Merged
Merged
Conversation
…tch area bun test never fires the exit event, so runGen's at-exit removal of meta-gen-state-<pid> never ran under test and every test process that generated with no project left up to ~120 MiB in DEV_SCRATCH. On the self-hosted runners ~900 of them filled the 16 GiB RAM scratch area and local-ci failed with ENOSPC. The first no-project run in a process now removes the dirs of processes that no longer exist, and ci-local.sh runs each invocation in its own DEV_SCRATCH subdirectory that it deletes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
runGenwith noprojectRootnow sweeps leftovermeta-gen-state-<pid>andmeta-gen-untracked-<pid>-…directories under the scratch root. It removes only directories owned by the current user, whose PID no longer exists and that have not changed for 15 minutes.removeTreeAtExitalone missed these becausebun testand signal-killed processes never fireexit.scripts/ci-local.shgives each run its ownmo-ci-scratch.<pid>.*directory under$DEV_SCRATCH, exports it asDEV_SCRATCH, and removes it inci_cleanup. Earlier runs' directories from dead PIDs are swept the same way.sweepDeadProcessDirstests inscratch-dir.test.ts, a changelog fragment, and a CONTRIBUTING note on per-run scratch cleanup.Validation
Risk Assessment
✅ Low: The change is a bounded cleanup fix, both round-1 fixes (owner check on the sweep, failing on mktemp error) hold in the current code, and this pass found no new defect beyond two wording corrections applied inline.
Testing
Driven live: (1) the ci-local.sh scratch guard, where a read-only DEV_SCRATCH makes mktemp fail and the script exits 1 with "cannot create a scratch directory under DEV_SCRATCH". (2) the scratch sweep, where a dead-PID directory aged past 15 minutes is removed and the live-PID directory is kept. The unit tests (5/5) pass but are not counted as live. The ownership skip is not driven live; it needs a directory owned by another uid.
Evidence: mktemp failure path transcript (ci-local.sh exits 1 with clear message)
Evidence: scratch-dir unit tests run (5 pass, not live)
Evidence: live sweep before/after listing
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
📌 **Review** - 4 infos left as notes at the round cap
server/typescript/packages/codegen-ts/src/scratch-dir.ts:125- sweepDeadProcessDirs deletes any matching directory regardless of owner. With DEV_SCRATCH unset the root is the shared /tmp, andsweepDeadProcessDirs(UNTRACKED_PREFIX)(runner.ts:435) runs on every runGen, including an ordinarymeta gen; the GEN_STATE_PREFIX sweep (runner.ts:424) is the sibling call. Sequence: another local user creates/tmp/meta-gen-state-<unused pid>/sub/, backdates its mtime, and while the victim (or root) walks it, swapssubfor a symlink to a victim directory. walkRemove lstatssubas a directory, then readdirSync and the child unlinks follow the swapped link, deleting the victim's files. Before this change only the process's own directory was ever removed. Fix: skip entries whosest.uiddiffers fromprocess.getuid()(where getuid exists). The sweep cannot normally remove another user's directory anyway.scripts/ci-local.sh:266- The result ofmktemp -dfor CI_SCRATCH is not checked, and the script runs withoutset -e. If it fails (scratch area out of inodes or not writable, the condition this change targets),export DEV_SCRATCH="$CI_SCRATCH"on line 267 exports an empty string. Every tool then silently falls back to the disk temp directory: mo_maven_private_repo (scripts/lib/maven-private-repo.sh:41), run-stryker.sh, and the test scratch helpers. stryker_run also drops back to the in-package sandbox. Fail the run with a message, or keep the original DEV_SCRATCH, when mktemp fails.server/typescript/packages/codegen-ts/src/scratch-dir.ts:79- Fixed inline: the SWEEP_MIN_AGE_MS comment said a live directory in another PID namespace "keeps a fresh mtime while it writes". A directory's mtime moves only when a direct entry is created, removed or renamed, not on writes deeper in the tree. The comment now says so and calls the age check a partial guard. No behaviour change.🔧 Fix applied.
📌 Review round cap reached: 4 infos left unresolved as notes (no further fix round):
scripts/ci-local.sh:266- The result ofmktemp -dfor CI_SCRATCH is not checked, and the script runs withoutset -e. If it fails (scratch area out of inodes or not writable, the condition this change targets),export DEV_SCRATCH="$CI_SCRATCH"on line 267 exports an empty string. Every tool then silently falls back to the disk temp directory: mo_maven_private_repo (scripts/lib/maven-private-repo.sh:41), run-stryker.sh, and the test scratch helpers. stryker_run also drops back to the in-package sandbox. Fail the run with a message, or keep the original DEV_SCRATCH, when mktemp fails.server/typescript/packages/codegen-ts/src/scratch-dir.ts:79- Fixed inline: the SWEEP_MIN_AGE_MS comment said a live directory in another PID namespace "keeps a fresh mtime while it writes". A directory's mtime moves only when a direct entry is created, removed or renamed, not on writes deeper in the tree. The comment now says so and calls the age check a partial guard. No behaviour change.scripts/ci-local.sh:255- Fixed inline: reworded the scratch-sweep comment, which said a killed run's directory is removed by the same user's "next run". A later run removes it, and only once its process is gone and it has been unchanged for 15 minutes. Comment only.changelog.d/codegen-ts-scratch-gen-state-sweep.md:6- Fixed inline: the changelog said only a run with no project sweeps both kinds of leftover. In runner.ts themeta-gen-untracked-*sweep is unconditional, so the first runGen of any kind in a process performs it. Themeta-gen-state-*sweep is limited to runs with no project. The text now says this.✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --affected --strict-toolchainsDEV_SCRATCH=<read-only dir> MO_CI_LIST_ONLY=1 scripts/ci-local.sh --affected --strict-toolchains(live, mktemp failure path)Live Bun driver callingsweepDeadProcessDirs("meta-gen-state-")from packages/codegen-ts/src/scratch-dir.ts against a temp DEV_SCRATCH holding a dead-PID old dir, a dead-PID young-mtime dir, and a live-PID (shell $$) old dircd server/typescript && bun test packages/codegen-ts/test/scratch-dir.test.ts(5 pass, 0 fail; unit level, not live)Temp dirs and driver script removed after runsthe machine-wide dev-scratch standard (outside this repo)- Global dev-scratch standard lives outside this repo, so it was not edited (workspace boundary). It should note that ci-local.sh now scopes DEV_SCRATCH per run and that codegen-ts sweeps dead-process dirs. The maintainer updated it separately.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.