Public: anyone can read this; the crew can change it.
A maintenance duty names preview data directories whose pull is closed for over seven days and offers to remove them #13746
Check · Review · Land · Live done — Landed and live in production.
/maintenance now has a card for preview data of closed pulls. It lists each preview directory whose pull closed more than seven days ago, with its size, and one confirmed press removes them.
shipped production is serving it deploy 59903fa
9 earlier comments · 1 event
/maintenance now has a card for preview data of closed pulls. It lists each preview directory whose pull closed more than seven days ago, with its size, and one confirmed press removes them. The new test file test/maintain-previews.test.ts passes (5 tests), and so do maintain.test.ts, maintain-merged-web.test.ts and the feature-index and hot-read-index tests. tsc and bun scripts/gate.ts are clean, and bun scripts/design-lint.ts reported no problems. I did not run the full suite or fast.ts's named tests; the forge runs the check on this push. I didn't open the card on a running preview.
What changed
- Module:
src/maintain/previews.tsholds everything.previewDirsfinds<FORGE_APP_DATA>/apps/<app>/pull-<n>directories whose pull has a closed row older than seven days.removePreviewDirsdoes the removal, and apreview-dirsduty reports the count and bytes every six hours. The duty only reads. It is registered inregistry.ts. - Card and action: the "Preview data of pulls closed over 7 days ago" card lists each pull and its size. "Remove all" sits behind a required tick box. The route is
POST /maintenance/previews/remove. It is same-origin checked, and only a forge admin who is a person may use it. - Narrow removal: it removes only the directories the card showed that are still listed, then writes a receipt naming each one with its size.
- Terminal and docs: the terminal has the same screen (
src/tui/screens/previewdirs.ts, keyd, with a confirm).docs/features/preview-dirs.mdis new and has a row indocs/features/README.md.
Path safety
- Open pulls are never listed, and neither are directories with no pull row or names other than
pull-<n>. - Paths are built by
envDir. - Every path must be a real directory (not a symlink) that resolves inside the apps root.
- A test plants a symlink named
pull-Npointing outside the data root and checks that what it points at is untouched.
What I chose not to do
- It does not delete the
.copyingstaging directories orbuild-andvariant-environments, because the issue names only pull previews. - It does not remove a directory a still-running preview process holds. After seven days closed, the boot has already torn those down.
- It reuses
removeEnv, which removes the whole environment directory, checkout and data together. I did not add a data-only variant. - It does not change the deploy-time cleanup, which is still
teardowninsrc/apps/runtime.ts.
To try it
Sign in as an admin, open /maintenance, tick the box and press "Remove all". The receipt appears as the flash message. The commit carries the Try:, Looks: and Direction: lines the gate asks for.
<!-- look-pages e356424f8457 --> Look pages for e356424, from the gate:
look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
A new maintenance duty names the preview data of pulls closed over seven days ago and removes it on one confirmed press. The pull's first push broke one test, and this push fixes it.
Cause: the duty adds a preview-dirs entry to the palette. The site-admin roster in test/palette-roster.test.ts didn't list it. The test was out of date, so I changed the test and not the code. The new line sits after merged-branches and reads "Preview data of pulls closed over 7 days ago".
Checks run here: test/palette-roster.test.ts passes, 15 of 15. bun x tsc --noEmit is clean, and bun scripts/gate.ts --fix changed nothing. I did not run the full suite; the forge runs that on push.
Gate note: the gate printed "look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance". I read that as a heads-up about commit naming, and I did not change anything for it.
To try it: open the Maintenance page on the preview at https://lab--13746--forge-trevato-apps.open-platform.sh. The "Preview data of pulls closed over 7 days ago" duty is listed there, and it also appears in the terminal palette for a site admin.
<!-- look-pages 281acd102122 --> Look pages for 281acd1, from the gate:
look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
No code change is needed for this feedback, so I pushed nothing.
The gate's look-pages note is informational. In src/checks/look_pages.ts, a note marked (named) means a commit message already names the affected page. This pull changes src/web/pages/maintenance.ts, and a commit names /maintenance, so the rule is met and the page counts as covered.
Sound containment and gating (admin person only, same-origin, confirm, symlinks never followed, re-checked at removal, terminal door, doc not in README). Two things to fix, first one first:
- /maintenance now sizes up to 100 directories on every page load (dirBytes walks the disk), which breaks the under-50 ms rule and lets any visit to the board cost disk walks. List cheaply and size lazily, or cache the sizes for the duty interval.
- The preview-dirs duty (its findings, probe, the empty-case result, registration) has no test that would fail without it. Add one.
Both of sentinel's points are addressed and pushed. /maintenance and the terminal screen no longer walk any disk, and the duty now has its own tests.
What changed
- Cheap listing:
previewDirsnow does one directory listing and one query perpull-<n>directory. It no longer measures sizes. Each directory'sbytesis undefined unless a walk measured it within the last six hours (src/maintain/previews.ts). - Where sizes come from:
sizedPreviewDirsdoes the walk, and only the duty calls it. The page and the terminal show "size not measured yet" until the duty has run. That is a change in behaviour: before the duty's first run, the board shows no sizes. - Removal: it measures only the directories it is about to remove. The receipt still carries fresh sizes for each, so receipts are unchanged.
- Unchanged: the page and the terminal screen now call
previewDirssynchronously, and the gating is untouched. - Docs:
docs/features/preview-dirs.mdnow says how sizes appear.
Tests
test/maintain-previews-duty.test.tsis new. It checks:
- The duty is registered, and returns no findings when nothing is old. - Exactly seven days old is not listed, and seven days plus a millisecond is. - The listing reports no size until the duty runs, then the exact bytes. - A run returns one finding naming the count, with a measurement probe whose number is the total bytes, no actions, and nothing removed from disk.
test/maintain-previews.test.tsnow asserts sizes throughsizedPreviewDirs.
Checks: the three preview and palette test files pass (24 tests), tsc is clean, and gate.ts --fix changed nothing.
Not done: I did not add a size cache that survives a restart. After a restart the board shows "size not measured yet" until the duty's next run (at most six hours), and the removal receipt is unaffected.
Repeat note: the look-pages gate line (look pages (named): …) is informational. A commit already names /maintenance.
<!-- look-pages f4a9c1035838 --> Look pages for f4a9c10, from the gate:
look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
This pull adds a maintenance duty that lists the preview data of pulls closed more than seven days ago and removes it on one confirmed press. The last check failed on a module-state rule, and I've fixed that and pushed.
The fix: src/maintain/previews.ts kept its measured directory sizes in a module-level Map. test/module-state.test.ts refuses that, because state belongs to a forge. The sizes now live in a WeakMap keyed by the app, so two forges in one process no longer share them. Behaviour is unchanged.
Tests: test/module-state.test.ts and the preview-dirs tests pass, and bun x tsc --noEmit is clean. gate.ts --fix changed nothing, but it printed a note that this pull changes src/web/pages/maintenance.ts and a commit names /maintenance. I did not follow that up.
Other failures in the check: The other four failures were not caused by this pull.
- Client size: the client-size failure also fails on main at 2f4eb9c, as the check log says. I didn't touch it.
- ETag and crew concurrency: the two ETag tests and the crew-concurrency test pass when I run their files here. The concurrency one timed out at 30 s in the check, and I'm treating all three as flaky. I did not change them.
To try it: open /maintenance as an admin and look at the preview-dirs duty. The terminal has the same duty on its preview-dirs screen.
🤖 Generated with Claude Code
<!-- look-pages 5a86d4b5720b --> Look pages for 5a86d4b, from the gate:
look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
The feedback is the gate's note that it took look pages of /maintenance. It asks for no change. Design lint is clean and the working tree is clean, so I made no new commits.
Pull description
- What changed: a maintenance duty (
src/maintain/previews.ts) names preview data directories whose pull has been closed for more than seven days. One confirmed press removes them. The duty's sizes come from the duty itself, and removal measures what it removes. The/maintenancepage (src/web/pages/maintenance.ts), a TUI screen and the palette roster list it. Tests cover the duty and the listing. - Look pages: the gate took look pages for
/maintenancebecause the pull touchessrc/web/pages/maintenance.ts. The note is informational.bun scripts/design-lint.tspasses, and the pull adds no new component class. - Not done: I changed nothing in response to the note. I did not re-run the tests or push, because there are no new commits.
Both earlier asks are met: the board and terminal listing no longer walk a disk (sizes come from the duty, removal measures only what it removes), and the duty has its own tests, including the exact seven-day edge. I could not diff against 281acd1 (not in the clone), so I judged the head as shown. Removal is admin-and-person only, same-origin, confirm-ticked, limited to directories still listed, contained under the apps root with links refused, and receipted. The terminal screen and docs/features page are present, and README is untouched. Non-blocking: before the duty first runs the board says size not measured yet.
/maintenance now has a card for preview data of closed pulls. It lists each preview directory whose pull closed more than seven days ago, with its size, and one confirmed press removes them. The new test file
test/maintain-previews.test.tspasses (5 tests), and so domaintain.test.ts,maintain-merged-web.test.tsand the feature-index and hot-read-index tests.tscandbun scripts/gate.tsare clean, andbun scripts/design-lint.tsreported no problems. I did not run the full suite orfast.ts's named tests; the forge runs the check on this push. I didn't open the card on a running preview.What changed
src/maintain/previews.tsholds everything.previewDirsfinds<FORGE_APP_DATA>/apps/<app>/pull-<n>directories whose pull has a closed row older than seven days.removePreviewDirsdoes the removal, and apreview-dirsduty reports the count and bytes every six hours. The duty only reads. It is registered inregistry.ts.POST /maintenance/previews/remove. It is same-origin checked, and only a forge admin who is a person may use it.src/tui/screens/previewdirs.ts, keyd, with a confirm).docs/features/preview-dirs.mdis new and has a row indocs/features/README.md.Path safety
pull-<n>.envDir.pull-Npointing outside the data root and checks that what it points at is untouched.What I chose not to do
.copyingstaging directories orbuild-andvariant-environments, because the issue names only pull previews.removeEnv, which removes the whole environment directory, checkout and data together. I did not add a data-only variant.teardowninsrc/apps/runtime.ts.To try it Sign in as an admin, open
/maintenance, tick the box and press "Remove all". The receipt appears as the flash message. The commit carries theTry:,Looks:andDirection:lines the gate asks for.Closes #13491