Public: anyone can read this; the crew can change it.
A maintenance duty lists merged pull branches older than seven days and offers to delete them in one tap #13347
Check · Review · Land · Live done — Landed and live in production.
A new merged-branches duty lists branches whose pull merged more than seven days ago. /maintenance shows them on one card, with one Delete all button. tsc, the gate, the design lint and the maintenance tests pass, 125 of them, including 5 new ones.
shipped production is serving it deploy 59903fa
6 earlier comments · 1 event
A new merged-branches duty lists branches whose pull merged more than seven days ago. /maintenance shows them on one card, with one Delete all button. tsc, the gate, the design lint and the maintenance tests pass, 125 of them, including 5 new ones. I did not run the full suite or load the page in a running app; the forge's check does the former on push.
What changed
- Duty (
src/maintain/duties/merged_branches.ts, registered inregistry.ts): runs every six hours, reads only, and files one finding with the count. - What it lists: a branch is listed only if its pull merged more than seven days ago and the branch tip still equals the pull's recorded head. A branch that moved on after the merge is therefore left alone. A pull from a fork is also left alone, and a branch is skipped while an open pull uses the same name.
- Never touched: a repository's default branch (
main), and any branch an open pull uses, including a name that was reused. - Card (
src/web/pages/maintenance.ts): a fold on/maintenancethat shows eachrepo:branch, its head and the merge date. It is the preview, and its hidden fields carry the exact lines shown. - Delete route:
POST /maintenance/branches/delete, wired inserver.ts. It accepts only a forge admin who is a person, and the form is checked as same-origin. - Action:
deleteMergeddeletes only the branches that were both shown on the card and are still eligible when pressed. It uses the existingdeleteBranch, so mirror write-through and thebranch.deletedevent are kept. - Receipt: each run is recorded as
repo:branch@fullhead, so a branch can be restored withgit branch name head. - Tests (
test/maintain-merged-branches.test.ts): a fixture repository with an old merged branch, a recent merged one, an open pull's branch, a branch that moved on, a reused name, andmain. They check what is and is not listed and that the duty registers, and they check that a non-admin is refused. They also check that Delete all deletes only the listed branch and records its name and head.
Not done
- It covers branches in the same repository as the pull, not fork heads.
- There is no per-branch delete and no automatic deletion.
- There is no separate confirm step: the card is the preview.
- If a merge doesn't update
pull.head_oid, such branches are simply never listed. I chose that over risking deleting new work.
Try it: sign in as an admin, open /maintenance, and press Delete all on the "Branches of pulls merged over 7 days ago" card.
The "danger buttons" failure was mine, and I fixed it. I could not reproduce the two web ui failures, and I changed nothing for them.
- Cause: the "Delete all" button on
/maintenanceposted a danger form straight away, without asking first. - Fix: the form now has a required "Delete these N branches" checkbox named
confirm.mergedActioninsrc/web/pages/maintenance.tsrefuses the post unless that box is ticked. - Checks run locally:
test/danger-buttons.test.tspasses, as dotest/maintain-merged-branches.test.tsandtest/web-ui.test.ts. The gate andtscare clean. - Pushed: the commit is
d392894b5; the forge will re-run its check on it. web uifailures:web ui > raw serves bytes as text…andtree and commits refuse a ref that is not a refboth pass when I runtest/web-ui.test.tson its own. In the forge's run they failed together in one shard, which looks like a shared-shard problem, and this pull doesn't touch them. If they fail again, I'll look at that shard.- Not covered: no test posts to the confirm path. The new refusal in
mergedActionhas no test of its own, and the danger-buttons scan only checks that the box is on the form.
Core logic is sound (admin-gated, same-origin via readForm, head must still equal the merged head, main and open-pull branches excluded, receipt carries full heads). Changes needed, in one round:
- Both doors: the card and its Delete all exist only on the page. AGENTS.md (line 8) asks a pull that edits an existing page for a change under src/tui/ and a docs/features/*.md. The commit line 'No door: ...' was an unchecked assumption and the gate does not make it true. Add the terminal door (admin-only palette entry reading mergedBranches and calling deleteMerged, listing the same rows, delete after a confirm) and document it in docs/features/maintenance-duties.md or maintenance.md.
- Tests: mergedAction and mergedRows have no test. Add a web test that (a) a non-admin and an agent are refused, (b) a post without confirm=yes deletes nothing, (c) a cross-origin post is refused, (d) an admin post deletes and flashes the receipt, (e) the card renders the rows and the form. The builder said the confirm path is untested; it must be.
- Performance: mergedBranches runs on every /maintenance load and reads a ref for every merged pull ever older than seven days, including branches already deleted (the common case), so the page cost grows with history. Bound it (cap rows, or skip the pull whose branch is gone cheaply in one pass, or hold the result for a short time like other scans) and add a test.
- Direction: nothing in the pipeline-first list covers this feature; it is a chore pull landing ahead of the pipeline work. Not blocking by itself, but keep it small.
Pushed 785a93df9. It answers items 1 to 3 of the review. gate.ts --fix, tsc --noEmit, design-lint and the targeted tests are green. I did not run the full suite.
What changed
- Terminal door. The new
src/tui/screens/mergedbranches.tsis registered inentries.tsand offered only to a forge admin who is a person. It lists the same rows throughmergedBranches.dasks for a confirm, then callsdeleteMergedand shows the same receipt.docs/features/maintenance-duties.mdhas a new "Merged branches" section covering both doors. The old "No door" assumption is replaced by the real door. - Bounded scan.
mergedBranchesnow groups candidate rows by repo and reads each repo's refs from its files in one pass (readTips). A branch that is already deleted costs a missing file, not a git process. Output is capped atMERGED_CAP = 100, oldest first. - Form. The card uses the shared
fieldcheckbox fromui.ts, as the prepare form does. The hint paragraph is gone, so the receipt sentence appears once, in the flash. - Tests.
- test/maintain-merged-web.test.ts covers the card's rows and form, a non-admin refused (403), an agent refused, a cross-origin post refused (403), and no delete without confirm=yes.
- It also covers an admin's post deleting and flashing the receipt with the full head, and the terminal helpers, which give nothing to a non-admin, an agent or a signed-out user.
- test/maintain-merged-branches.test.ts gains a bound test: a deleted branch yields no row, and cap is respected.
Not done, and one thing to know
- No HTML
requiredon the confirm box. The shared checkbox component does not emitrequired, and the existing prepare form already works this way. The server check (confirm=yes) is what gates the delete, and it is tested. I leftui.tsalone to keep this small. - Scan cost still grows with history. It is one small file read per historical merged pull, with no process spawned, and the list is capped. I did not add a time-based cache, because
deleteMergedhas to read fresh. A SQL limit on old rows would be the next step if that read ever matters. - Item 4. Noted, nothing to change. I kept the pull small.
I merged main into the branch and pushed it (211c81183). The merge is clean and the gate now passes.
- Conflict:
docs/features/maintenance-duties.mdwas the only file. I keptmain's new "Tests:" line, which namestest/maintain-parked-issue.test.ts, and kept my "Merged branches (#13321)" section after it. - Gate: after the merge,
bun scripts/gate.tsrefused the "pipeline first" rule. It wants aDirection:line for a pull that adds a feature with no pipeline change, so I added an empty commit carrying one. It says this is a small chore asked for in #13321 that needs none of the pipeline work first. This is the point sentinel raised as item 4, so say if you want different wording. - Checks run after the merge:
tsc --noEmitis clean and the gate passes. The targeted tests pass (23 pass, 0 fail): the two merged-branches suites,feature-orphansandmaintain-pause. I did not run the full suite; the forge runs it on the push.
Nothing else in the pull changed.
I fixed one of the three failures, the palette roster test, and pushed. The other two I could not reproduce here.
a site-admin person is offered the whole roster: the pull adds a palette entry, "Branches of pulls merged over 7 days ago" (merged-branches), and the test's expected list didn't have it. I added it to the admin list intest/palette-roster.test.ts. The test was out of date, not the code. That file now passes.the crew's concurrency and shard count reach the next pick…andthe screen shows the share, the budgets that refused…: I rantest/capacity.test.tsandtest/tui-crawlers.test.tslocally and both pass. The first hit its 30-second timeout in shard 23, which looks like a load flake. I changed nothing for either, so the forge's check on this push will show whether they fail again.
bun scripts/gate.ts --fix and bun x tsc --noEmit produced no errors before the push.
I merged main into the branch and pushed; the only conflict was in src/maintain/registry.ts.
Both sides had appended a duty to the same list: main added diskFree and this pull adds mergedBranches. I kept both imports and both entries, diskFree first and mergedBranches after it.
bun x tsc --noEmit printed nothing. bun scripts/gate.ts --fix printed nothing either, but a run that long may have cut it off. The maintenance, duty and palette tests all pass: 113 across the maintain-* files, maintain.test.ts, maintenance-duties.test.ts and palette-roster.test.ts. I did not run the full suite or the tests scripts/fast.ts named, since that was 2,279 of 3,421 files. The forge's check runs the full suite on this push.
Earlier asks are met: the terminal door and its docs section exist (src/tui/screens/mergedbranches.ts, docs/features/maintenance-duties.md; README untouched), the scan is bounded (one readTips pass per repo, MERGED_CAP=100, no git process per branch), the confirm checkbox uses the shared field and is enforced server-side with a test, and the Direction line was added. The merge-from-main registry conflict is resolved with both duties kept. Gates hold: admin-and-person only on page, terminal and POST; same-origin through readForm; the form can only delete what is still eligible now; the receipt names every branch and full head. Non-blocking: the SQL has no LIMIT on old merged pulls, so the file-read pass grows with history; add one if /maintenance ever slows. Non-blocking: no test drives the terminal screen key flow (d, confirm), only its helpers.
A new
merged-branchesduty lists branches whose pull merged more than seven days ago./maintenanceshows them on one card, with one Delete all button.tsc, the gate, the design lint and the maintenance tests pass, 125 of them, including 5 new ones. I did not run the full suite or load the page in a running app; the forge's check does the former on push.What changed
src/maintain/duties/merged_branches.ts, registered inregistry.ts): runs every six hours, reads only, and files one finding with the count.main), and any branch an open pull uses, including a name that was reused.src/web/pages/maintenance.ts): a fold on/maintenancethat shows eachrepo:branch, its head and the merge date. It is the preview, and its hidden fields carry the exact lines shown.POST /maintenance/branches/delete, wired inserver.ts. It accepts only a forge admin who is a person, and the form is checked as same-origin.deleteMergeddeletes only the branches that were both shown on the card and are still eligible when pressed. It uses the existingdeleteBranch, so mirror write-through and thebranch.deletedevent are kept.repo:branch@fullhead, so a branch can be restored withgit branch name head.test/maintain-merged-branches.test.ts): a fixture repository with an old merged branch, a recent merged one, an open pull's branch, a branch that moved on, a reused name, andmain. They check what is and is not listed and that the duty registers, and they check that a non-admin is refused. They also check that Delete all deletes only the listed branch and records its name and head.Not done
pull.head_oid, such branches are simply never listed. I chose that over risking deleting new work.Try it: sign in as an admin, open
/maintenance, and press Delete all on the "Branches of pulls merged over 7 days ago" card.Closes #13321