Maintenance: shut down for a move and come back by itself (#9453)
Prepare. An admin opens /maintenance (linked from Resilience), the terminal's Maintenance command
(src/tui/screens/maintenance.ts: p prepare, c check again, e end; admins only), or calls
POST /api/v1/admin/maintenance/prepare (admin-scope token) or MCP
maintenance {action: "prepare"}. The forge then:
- holds releases (an owner hold,
keeper/hold.ts); - pauses the crew: the dispatcher starts nothing while
maintenance.jsonstands in the data directory; vitals reads the queue as held by "planned maintenance"; - takes a fresh snapshot (
actions/backups_now.ts); - reports the drain:
GET /api/v1/admin/maintenancesaysdrainingwhile runs or checks still go,readywhen the backup is taken and nothing runs. Power off onready; a SIGTERM drains the rest as in a release.
The page says plainly what stops: releases, new crew runs, then the forge, its apps and previews when the host powers off.
The restore drill line. Under the status line, /maintenance and the terminal's Maintenance screen
(src/tui/screens/maintenance.ts, admins only, hidden on the calm "For information" view) read the last
restore drill in one sentence from drillLine (src/maintenance/drill_line.ts): "Last restore drill:
restored in 4 minutes, passed, 2 days ago." or "failed after 10 minutes, 2 days ago: <cause>." (the cause is
one line, at most 200 characters, no raw milliseconds). With no drill yet it reads "No restore drill has run
yet." Spans come from durationWords (src/system/format.ts). Tests: test/maintenance-drill.test.ts.
The page. /maintenance answers one question first: one status line, "Healthy: nothing needs you" or
"Needs you" with what waits (maintenance on, a failed return, overdue or paused duties, stale pulls; needsYou
in src/web/pages/maintenance.ts). Below it, each part is a disclosure with a count in its summary:
Duties, Budgets, Prepare for a power-off (or Maintenance state while on), Last return. A fold opens by
itself only when something in it needs a person. Pulls untouched for 14 days are a fold too, open, with their
count, only when there are some; /system keeps them as a section under its own heading. While maintenance is
on, "End maintenance now" sits under the status line. The forge's looks picture it as the owner (the slot was
/repos'). Tests: test/maintenance-calm.test.ts, test/maintain-stale-web.test.ts.
Disk line (#15999). Under the heading /maintenance and the terminal's Maintenance screen say "Disk: N percent free" for the data volume (diskLine() in src/maintenance/disk_line.ts, one function for both; N is the share rounded down, and the same figure is compared). Under 15 percent the page turns the line amber with an alert icon and adds what to do: remove old backups, previews and merged branches, or grow the volume; the terminal says the same sentence and lists it under "Needs you" (l), and plain under "For information". Nothing is filed and nothing alarms; a volume that reports no size shows no line. To read it, open /maintenance as an admin. Tests: test/maintenance-disk-line.test.ts.
Duties. /maintenance, the terminal's Maintenance screen and the duties of MCP maintenance {action: "status"}
list each nightly job and the radar in one line (src/maintenance/duties.ts, one function for all three doors):
when it last ran (UTC), what it found: each issue or pull it filed is a link on the page (plain owner/name#N in the terminal), a finding that names none ends "nothing filed", and a reference to a repository you cannot read reads "something you cannot read", never its name, and "overdue". A duty is
overdue when now is past its last slot plus one day plus 6 hours of grace (a night may run long); one
that never ran says so and gives its slot, and is not overdue.
Quiet duties fold. A duty that ran on time and found nothing is quiet; splitDuties in
src/maintenance/duties.ts decides it from NOTHING_FOUND, the same constant the duty's found is built
from. On /maintenance the quiet ones sit behind one closed fold, "All 3 duties ran, nothing to report" (or
"2 other duties ran, ..." when some have rows), and list their names when opened. Never-run, overdue,
unfinished and finding duties keep their rows. The terminal's Maintenance screen folds them into one line
the same way, naming the duties. Tests: test/maintenance-calm.test.ts.
Come back. On boot resumeAtBoot acts only when the host has restarted since the prepare
(/proc/sys/kernel/random/boot_id differs from the one stored); a release roll of the process on
the same host boot keeps what the admin prepared. It then lifts the hold, unpauses the crew and
records a line (shown on /maintenance, in the status, and as the
maintenance.ended event) with every check and its result (src/maintenance/checks.ts,
one plain function each: database, hold, dispatcher, apps, nightly lines, queue, and at boot
the tunnel, which must answer /healthz on the public address (asked again every 3 s for up to
30 s, since it often comes up after the process; the listener is already up when this runs), and the
runner, whose checks lane must hand out a slot within 2 s: that proves the lane is not wedged, not that
a check would run). A failed check reads FAILED as a badge on a dl row of /maintenance, first
in the terminal screen; the status reads "Back, NOT healthy" with healthy: false; the hold is lifted
regardless. Admins with a
notification address are told what is healthy and what is not. An admin can also press
"End maintenance now" (no outside probes then). The nightly jobs show on Resilience.
No Kubernetes is asked anything; the state is one file.
While it is off. bun scripts/standby.ts 8080 serves the calm 503 page
(src/maintenance/page.ts) from the droplet; point the tunnel's or
Cloudflare's origin at it for the move, and back after. A Cloudflare Worker can
return the same HTML with status 503 and Retry-After.
Is the standby up? Set MAINTENANCE_STANDBY_URL (an http(s) URL, e.g. http://127.0.0.1:8080/) in
the forge's environment. /maintenance and GET /api/v1/admin/maintenance (field standby) then fetch
that one URL server-side (2 s timeout, no redirects) and say whether it answers 503 with the maintenance
page. The URL is never taken from a request. When ready, the line reads "Ready, standby answering",
"Ready, standby not answering" or "Ready, no standby". Unset, the page says how to start one:
bun scripts/standby.ts 8080 on the droplet, then point the tunnel or Cloudflare origin at it.
Size of a standby. For reads or a whole forge: disk for the data (38 GB now, apps 13 GB) plus one snapshot and headroom, so 64 GB; 4 GB of memory free for the forge alone, 8 GB with apps running. The 16 GB droplet cannot hold it.
Take over reads (#9657). On a second machine of that size, with the backup
store's variables (S3_*, or FORGE_SNAPSHOT_DIR) and FORGE_SNAPSHOT_PASSPHRASE:
bun scripts/standby-restore.ts latest /srv/standby # or a snapshot name; the directory must be empty FORGE_READ_ONLY=1 FORGE_DATA=/srv/standby PORT=3000 bun run src/main.ts
The script restores the snapshot (src/snapshot/restore.ts), runs SQLite's
integrity check and confirms every repository the database lists is on disk;
it exits 1 and names what is wrong otherwise. With FORGE_READ_ONLY=1 the forge
serves pages, the API's reads and git clone/fetch from that directory. One guard
at the front of the request path (src/http/read_only.ts) answers every other
method, a WebSocket upgrade and the push door (git-receive-pack) with a plain
503 "read-only standby", so a route added later is covered. Nothing past the
listener starts: no terminal, apps, crew, checks, releases, mirrors, snapshots
or nightly jobs, and not even the boot's reconcile or any timer. The
standby knows no one: a session or token of the main forge is read as signed
out, so it shows public pages only, and sign-in (a POST) is refused. Opening
the database still migrates it forward, on the restored copy only. Point the tunnel's origin at it for the move.
Test: test/standby-restore.test.ts.
Not done
- Writes on the standby, and switching back: the standby is a copy as of its snapshot, so anything written on the main forge after it is not there, and nothing carries standby-time changes back (there are none; it takes no writes). Nothing replicates continuously; re-restore into a new directory to catch up.
- The page is not pushed to Cloudflare automatically;
standby.tsis started by hand (the forge only checks it). - The admin is told on the page, event and status, and by the notification address they saved (
/account); no mail. - Where the kernel gives no boot id, any restart ends maintenance.
Stale issues (#13592)
The stale-issues duty runs once a day and files one issue, "Open issues untouched for 60 days with no
pull and no blocker", naming up to 20 open issues of the forge's own repository whose last comment or
edit is over 60 days old, that no open pull says it closes (Closes #n) and that wait for no open
blocker (oldest first; the rest are counted). While that report is open, later nights file none; closing
it lets the next night file a fresh list. The duty never comments on, labels or closes an issue it names.
It shows as the stale-issues row on /maintenance. Test: test/maintain-stale-issues.test.ts.
Flaky tests (#13937)
The flaky-tests duty runs once a day and names each test file whose tests failed and then passed
alone on the same commit in the last 7 days, with the count, distinct tests and commits. It reads
check_flake, which stores a test name, its file and the commit (no finer per-test data), so the report
is per file. A quiet week reports nothing; it files no issue. It shows as the flaky-tests row on
/maintenance. Test: test/maintain-flaky-tests.test.ts.
Red apps (#13938)
The red-apps duty runs once a day. An app is red when the latest finished check of its default branch
has failed and the first failure of that unbroken streak (no passing check since) finished 3 or more
days ago; an app whose latest check passed, or that has none, is not. For each red app it files one defect
issue, labelled bug (made if missing), in the app's own repository, titled "The latest build of
owner/name has been red for 3 days", naming the failing check, the run and the commit. One issue stays
open at a time: while it is open no second is filed, and closing it while the check is still red lets the
next day file a fresh one. The duty never comments on or closes an issue. It shows as the red-apps row
on /maintenance. Test: test/maintain-red-apps.test.ts.
Untested sources (#14125)
The untested-sources duty runs weekly and reads the forge's own checkout: each .ts file under src/
that no file under test/ imports by path, minus ENTRY_POINTS (one array, a reason each). It files one
finding with the first ten names and the count of the rest, never one per file, and none when the list is
empty. Matching is by import path in the text, so a dynamic import built at run time is missed; every
finding says so in its footer. It shows as the untested-sources row on /maintenance. Test:
test/maint-untested.test.ts.
Chapter stall (#14057)
The chapter-stall duty runs once a day. For each repository with an open chapter it lists the chapter's
open issues whose last sign of work is 24 or more hours old: a run on the issue, a pull whose description
closes it, or the moment it entered the open chapter (or the chapter was opened). Each gets one defect
issue, labelled bug, in its repository, titled "#N in chapter X has had no run and no pull for 24 hours";
while one is open no second is filed. Draft and closed chapters, and repositories with no chapter, are left
alone. Shows as the chapter-stall row on /maintenance. Test: test/maintenance-chapter-stall.test.ts.
Slow tests (#13966)
The slow-tests duty runs weekly and names the five test files that took longest in the forge's own last
finished check (state ok or failed). It reads that check's stored run log, never runs a test: a file's
seconds is the sum of its tests' own [12.3ms] times, the tests' time and not the file's wall clock, so
load and teardown are not in it. It files one finding with the five names and seconds, and a measurement
of the slowest file's seconds; it changes nothing. Only the last 512 KB of a log is stored, so when the
log was cut the finding says earlier files are missing; where the log has no per-test times, or no
finished check is stored, the run says so and names nothing it did not read. It shows as the slow-tests
row on /maintenance. Test: test/maintain-slow-tests.test.ts.
Filter by level (#14544). /maintenance?level=needs-you or ?level=fyi narrows the board to the sections that wait on a person or the calm ones; anything else shows all. The three links (All, Needs you, For information) are the seg() component with plain words, no counts, since a count of sections would read as a count of findings; the current one is marked aria-current, and each is 44px tall on a phone (.levels, docs/design/areas/maintenance.md). A level with nothing in it says "Nothing here needs you." The "For information" view leaves out the status line, which speaks for the whole board. A section's level is fixed except Duties (needs-you while one is overdue or paused), the state fold (needs-you while maintenance is on) and Last return (needs-you when it failed): the same rule as the status line. The terminal's Maintenance screen has the same filter: l cycles all, Needs you, For information (maintenanceLines, nextLevel in src/maintenance/level.ts); there overdue duties count as needing you, paused ones are not listed. Tests: test/maintenance-level.test.ts.
Quiet a finding for a day (#14557)
Each row of the stale-pull, merged-branch and preview-data cards on /maintenance has a small "Quiet for a day" button: a
same-origin POST for a forge admin who is a person, receipted in the maintenance runs under its own duty name, quieted-findings, so no card's duty looks as if it ran
(maintenance_quiet holds the row). The undo is on the Quieted row, not on the receipt or the flash. The finding leaves the card and is listed under "Quieted" with the time it is back and a "Bring back" button
that undoes it, also receipted. Nothing expires by job: after 24 hours the row is simply in the past, and the finding
shows again if it still holds. The terminal's maintenance screen does the same for an admin who is a person: z quiets a numbered finding, b brings a numbered quieted one back, through the same quiet()/unquiet(). Tests: test/maintenance-quiet.test.ts, test/tui-maintenance-quiet.test.ts.