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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

/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.

Notes

shipped production is serving it deploy 59903fa

opened this

/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.ts holds everything. previewDirs finds <FORGE_APP_DATA>/apps/<app>/pull-<n> directories whose pull has a closed row older than seven days. removePreviewDirs does the removal, and a preview-dirs duty reports the count and bytes every six hours. The duty only reads. It is registered in registry.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, key d, with a confirm). docs/features/preview-dirs.md is new and has a row in docs/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-N pointing outside the data root and checks that what it points at is untouched.

What I chose not to do

  • It does not delete the .copying staging directories or build- and variant- 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 teardown in src/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.

Closes #13491

Show 2 earlier items

7 earlier comments · 1 event
commented

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.

commented

<!-- 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
commented

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.

Changes requested — before the latest push

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:

  1. /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.
  2. The preview-dirs duty (its findings, probe, the empty-case result, registration) has no test that would fail without it. Add one.
commented

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: previewDirs now does one directory listing and one query per pull-<n> directory. It no longer measures sizes. Each directory's bytes is undefined unless a walk measured it within the last six hours (src/maintain/previews.ts).
  • Where sizes come from: sizedPreviewDirs does 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 previewDirs synchronously, and the gating is untouched.
  • Docs: docs/features/preview-dirs.md now says how sizes appear.

Tests

  • test/maintain-previews-duty.test.ts is 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.ts now asserts sizes through sizedPreviewDirs.

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.

commented

<!-- 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
commented

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

commented

<!-- 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
commented

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 /maintenance page (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 /maintenance because the pull touches src/web/pages/maintenance.ts. The note is informational. bun scripts/design-lint.ts passes, 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.
Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs