Pause and resume a maintenance duty (#11205)
Each duty the forge's maintenance runner runs (src/maintain/registry.ts) has an on/off switch, kept in maintenance_duty_state. A paused duty is skipped by every tick. After three errored runs in a row (it threw, timed out or had a finding refused) the runner pauses the duty itself and says why: "paused after 3 errors in a row; last error: …". Resuming starts the count again, so one more error does not pause it at once. The pause also files one issue on the forge's own repository (FORGE_REPO) naming the duty and its last error (src/maintain/park.ts); it carries a Maintenance key: parked/<duty> line, so while it is open no second is filed, restarts included. Closed, the next park files a new one.
All doors are for a forge admin and call one function, switchDuty in src/maintain/pause.ts, so they say the same words.
- On the web.
/maintenancelists each duty once; the ones the runner runs carry their state ("on", or "paused by … 3 h ago; why") then when it last ran and is next due ("on; ran 2h ago; next in 4h", "due now"; a paused duty says only when it ran, since its state already says paused; a late badge once the due time was missed by twice the interval; #14674,src/maintain/schedule.ts,dutySchedules), and one Pause / Resume button (POST /maintenance/duties/:name, same-origin only, form body bounded,pausedisyesorno). - In the terminal. Ctrl-K, Pause, resume or dismiss a maintenance duty (an admin who is a person):
j/kchoose, Enter or Space flips,ddismisses its finding for seven days (see duty-dismiss.md), Esc closes. Each line ends with the same schedule in brackets, "(ran 2h ago; next in 4h)", "; late" when late, "(ran 4d ago)" when paused. It writes the same row, so a web viewer sees it on its next load. - Over the API.
GET /api/v1/maintenance/dutieslists the states;POST /api/v1/maintenance/duties/:namewith{"paused": true|false}needs anadmin-scope token. - In the MCP. The
maintenancetool:pause-dutyandresume-dutywithduty.
An unknown duty name is 404 (a flash on the page); a paused that is not a boolean is 422.
Tests: test/maintain-parked-issue.test.ts (one issue for three failures and a fourth tick), test/maintain-pause.test.ts (the three errors, resume from the API, the page and the terminal, the gates).
Merged branches (#13321)
The merged-branches duty finds branches of pulls that merged over seven days ago and whose tip is still the head they merged with. Never listed: the default branch, a branch an open pull uses, a branch that moved since, a fork's branch. It reads refs from the repository's files in one pass (no git process per branch) and lists at most 100 (MERGED_CAP), oldest first.
- On the web.
/maintenancefolds the list (name, short head, merge day) with a required confirm box and Delete all (POST /maintenance/branches/delete, same-origin, a forge admin who is a person). A branch not on the list any more is left alone; the flash receipt names each deleted branch with its full head. - In the terminal. Ctrl-K, Branches of pulls merged over 7 days ago: the same rows;
ddeletes them all after a confirm, with the same receipt.
Tests: test/maintain-merged-branches.test.ts, test/maintain-merged-web.test.ts.
Wait split (#13635)
The wait-split duty finds where a slow public page waits. Every six hours, from the forge's own host, it does three things for each of /healthz, /, /pricing, /terms and /privacy: it times a TCP+TLS handshake with the public origin (the edge), a GET of the public URL (to first byte and to the last byte), and a GET of the same path on 127.0.0.1:<port>, which skips the edge and the tunnel. It also reads the app;dur= the forge wrote in Server-Timing. src/maintain/wait_split.ts splits the first-byte time into edge = connect, tunnel = first byte − connect − loopback, accept = loopback − app, and app. The largest share names the layer. A page under 1 s waits in none. It sends GET only, and its timeout is the proof's own 15 s. A slow or unanswered page is a finding, and every page is one line on /maintenance. Inside a cell, the bare handshake cannot pass the egress proxy: that line says so and counts the handshake as 0 ms.
Tests: test/maintain-wait-split.test.ts.
Edge kept (#14663)
The edge-kept duty notices when the edge is not keeping the pages the forge marks shareable. Hourly, it sends two signed-out GETs (no cookie) to each of / and /explore, and only at config.url (the forge's own public origin), never a host from a request. If the forge marked the answer shareable (Cache-Control: public with a positive s-maxage) and the cf-cache-status header says the edge went to the forge both times (DYNAMIC, MISS or BYPASS), it files one issue per page, once, and leaves it open. A HIT, STALE or REVALIDATED on either read counts as kept. No edge header, an unshared page, a non-200 answer, a host the forge's gate refuses, or a forge with no FORGE_URL say nothing but an action line; so does a forge without its own repository row, which has nowhere to file. The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on Cookie, Authorization. The duty's lines (one per page) show on the maintenance runs lists (/api/v1/maintenance/runs, the terminal) after its first run, an hour after boot.
Tests: test/maintain-edge-kept.test.ts.
Account purge (#15620)
The account-purge duty erases a closed account once its grace has run. A person asks to close their account on /settings/password (#15619). For 7 days Keep my account undoes it. After that, the hourly duty erases at most 20 accounts a run. For each one it:
- asks again what stands in front of closing (the forge's only admin is never erased);
- checks every repository the person owns and stops, deleting nothing, if any is a fork that is the head of a pull into another repository (no one may delete such a fork);
- deletes the person's repositories, ends every browser, and removes the person's own rows in one transaction.
What they wrote in other people's repositories stays, as "a former member". So do events whose payload named them: the username, the id and the person's name/repo paths are rewritten to the placeholder's.
The audit is admins-only events. account.purged carries counts only. account.purge_failed names the account and why, and is written once a reason, not once each daily retry. A held account is tried again a day later. Every run also lists the held accounts and their reasons as a finding on /maintenance, and the person's own settings page says "It is held, and an admin will look." For a held fork, an admin transfers it to an owner who keeps it (the repository's settings, Transfer), and the next try erases the rest. If a repository fails to delete partway, the reason says how many went before it, and the next try goes on from there.
Try it: close a test account, set its close_requested_at back 8 days, and wait for the next run (or run the duty from /maintenance).
Tests: test/account-purge.test.ts, test/account-close.test.ts.
Duty idle (#13406)
The duty-idle duty watches the other duties for silence. Hourly, it looks at when each duty last started (budget stops do not count as a start). A duty whose last start is more than twice its interval ago is idle; exactly 2x is not. A duty that has never run is skipped, because there is no last run to name. The watcher never watches itself.
For each idle duty it files one issue, once (an open one is not filed again), titled The maintenance duty <name> has not run in twice its interval. The body gives the last run time and the interval. It spends no money.
There is no terminal screen for it: it files an issue, and both doors (the web and the terminal) already show issues.
Tests: test/duty-idle.test.ts.
Adding a duty (#14355)
A duty is one file in src/maintain/duties/ that exports duty (a Duty, see src/maintain/duty.ts). src/maintain/registry.ts lists that directory when it loads and builds the roster from it, so a pull that adds a duty adds that file and edits no shared list; scripts/unreached.ts counts every file there as reached. A file that does not export duty stops boot with an error naming it. duty_idle.ts is the one exception: it watches the others and is appended last.
The roster is in file-name order, and that is the order the runner ticks the duties and /maintenance lists them (it used to be a hand-picked order). To place a duty, name its file for where it should sit. Tests: test/duty-roster.test.ts.