Public: anyone can read this; the crew can change it.

Check run homes (/data/checks/*.home) are removed when their run ends or dies, not only at the next boot #7550

opened this

Merged 36d 0h ago, live in production

A check's run home (/data/checks/ .home) is now removed with its run, including when the cell left read-only files in it. The new test file test/checks-home-sweep.test.ts passes (4 tests), and tsc --noEmit is clean.

Notes

opened this

A check's run home (/data/checks/<id>.home) is now removed with its run, including when the cell left read-only files in it. The new test file test/checks-home-sweep.test.ts passes (4 tests), and tsc --noEmit is clean. scripts/fast.ts said the diff was too broad to name tests, so I ran three of the existing checks suites: checks-disk-red, checks-placement and checks-job-vanish. They pass (18 tests).

Cause. sweepCheckouts looked up getRun("<id>.home"), which never matches a run, so every home counted as orphaned. Each one was only collected at the next boot, and only because of that miss. The per-run rmSync also cannot unlink inside a read-only directory such as a bun cache, so a failed removal left the home behind. A forge killed mid-run never reaches its finally at all. That is the one case that still leaves a home until the next sweep.

What changed.

  • Sweep ownership. sweepCheckouts now treats <id>.home as belonging to run <id>. The lease check is untouched: a home survives only while its run is running with a live lease, so a roll sharing /data still leaves a live run's directory alone.
  • Timer. requeueAbandonedChecks now ends with sweepCheckouts. It already runs at boot and on the lease timer in main.ts, so homes are swept on the same timer as abandoned checks.
  • Removal. A new removeRunDir retries a failed removal after restoring permissions, and logs an error if it still fails. The run's own finally and the sweep both use it, so a failed removal is no longer swallowed.
  • Preview teardown. removeEnv already deletes the whole environment directory, which contains home. I made no change there and added a test that proves it.

Tests. The new tests cover a finished run's home, a home with no run, a lapsed run's home, and a read-only cache all being removed, and a live run's home surviving.

Not done. I did not add a timer of its own for the sweep, and I did not change the gate path's separate rmSync of its checkout directory. I did not clear the 99 homes already on disk (#7541); the first sweep after deploy should collect them.

Closes #7545

2 earlier comments
commented

A check's run home (/data/checks/<id>.home) is now removed with its run, including when the cell left read-only files in it. The new test file test/checks-home-sweep.test.ts passes (4 tests), and tsc --noEmit is clean. scripts/fast.ts said the diff was too broad to name tests, so I ran three of the existing checks suites: checks-disk-red, checks-placement and checks-job-vanish. They pass (18 tests).

Cause. sweepCheckouts looked up getRun("<id>.home"), which never matches a run, so every home counted as orphaned. Each one was only collected at the next boot, and only because of that miss. The per-run rmSync also cannot unlink inside a read-only directory such as a bun cache, so a failed removal left the home behind. A forge killed mid-run never reaches its finally at all. That is the one case that still leaves a home until the next sweep.

What changed.

  • Sweep ownership. sweepCheckouts now treats <id>.home as belonging to run <id>. The lease check is untouched: a home survives only while its run is running with a live lease, so a roll sharing /data still leaves a live run's directory alone.
  • Timer. requeueAbandonedChecks now ends with sweepCheckouts. It already runs at boot and on the lease timer in main.ts, so homes are swept on the same timer as abandoned checks.
  • Removal. A new removeRunDir retries a failed removal after restoring permissions, and logs an error if it still fails. The run's own finally and the sweep both use it, so a failed removal is no longer swallowed.
  • Preview teardown. removeEnv already deletes the whole environment directory, which contains home. I made no change there and added a test that proves it.

Tests. The new tests cover a finished run's home, a home with no run, a lapsed run's home, and a read-only cache all being removed, and a live run's home surviving.

Not done. I did not add a timer of its own for the sweep, and I did not change the gate path's separate rmSync of its checkout directory. I did not clear the 99 homes already on disk (#7541); the first sweep after deploy should collect them.

commented

Run homes (/data/checks/<id>.home) are now swept when their run ends or its lease lapses, on the forge's 30-second abandoned-checks timer. They are no longer left until the next boot. Read-only caches inside a home no longer block removal. The sweep leaves a live run's home alone, and tearing down a preview removes its home too.

This push addresses both review points:

  • Timer sweep test: a new test leaves a finished run's home and a live run's home on disk, calls requeueAbandonedChecks(app, STALE_AFTER_MS), and expects only the finished run's home to be gone. I confirmed it fails when the sweepCheckouts call at the end of requeueAbandonedChecks is removed. The test/checks-home-sweep.test.ts file now has 5 tests and passes, and tsc is clean.
  • removeRunDir: it no longer returns a boolean, since no caller read it, so there is no untested false path. A failed removal is still logged. When the first removal fails, the retry now sets 0o700 on directories only, so files are never made executable.

I did not add a test for the finally call in startChecks.

To try it, leave a <id>.home under FORGE_APP_DATA/checks for a finished run and wait for the timer, or call requeueAbandonedChecks.

commented

I merged main into the branch and pushed it. The forge's check will run on the push.

  • Conflict: the only one was the node:fs import line in src/checks/service.ts. My side added chmodSync and lstatSync for the run-home sweep, and main added readFileSync. I kept all of them.
  • Type check: bun x tsc --noEmit printed nothing.
  • Tests: test/checks-home-sweep.test.ts passes, 5 of 5. I did not run the rest of the suite here. scripts/fast.ts said the diff was too broad to name tests (it printed "over the 5m budget"), so I picked that file myself and left the full suite to the forge's check.
  • Stray test run: the combined command also started an unrestricted bun test run, which I stopped after a couple of minutes.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs