Repository navigation
Description
Someone who runs fctl's control plane in their own container or cluster gets a health check that only says the Worker answers. They get logs without requests, no metrics to alert on, and backups that mean stopping the server. The control plane is one replica by design (ADR 0026), with no failover, so how long an outage lasts comes down to how soon they notice and how fast they restore. fctl should give them metrics to alert on, a readiness check that means something, backups taken while it runs, and a restore they've practised.
How it works now
- Health.
GET /api/v1/healthanswers{"ok": true, "version": …}(crates/fctl-control/src/lib.rs) without touching D1 or any Durable Object: anonymous requests skip storage (auth::authenticate). The image'sHEALTHCHECK(deploy/standalone/Dockerfile) uses it, and so do all three of the Kubernetes example's probes (deploy/standalone/kubernetes.yaml), so its readiness probe says no more than its liveness one. - When workerd stops answering.
deploy/standalone/server.mjsasks/api/v1/healthevery 30 s, with a 10 s timeout. After four misses in a row it logs "The control plane stopped answering: exiting" and exits 1, for Docker or Kubernetes to start it again. Miniflare restarts a crashed workerd itself, "but not forever" (ADR 0026). The server listens only once D1's migrations are applied and Miniflare is ready. If a server stalls for over 30 s, another can take over itsserver.lock(lib/lock.mjs), and the first exits when it notices. - Logs. The server writes its own lines, and passes on the Worker's console output with warnings and errors on stderr (
handleStructuredLogs). Miniflare logs at warning level, andlogRequestsis off, so there's no request log. - Metrics: none. The numbers exist. D1 has
sessions.status, indexed (sessions_status), andd1_migrations. FleetDO'squeuegives each waiting session'sreason: the sentencefctl_domain::schedule::Wait::reasonwrites, not a kind. Itsrunnerstable hasconnected,draining_since,disk_available_mband the hello with capacity (crates/fctl-control/src/do_fleet.rs). Each workspace's HooksDO keeps ahealthtable withfailing_sinceanddropped(crates/fctl-control/src/do_hooks.rs). - The data directory.
FCTL_DATA_DIR(/datain the image) holdsmaster-key(unlessFCTL_MASTER_KEYis set),server.lock, andstate/(mode 0700). There Miniflare keeps D1 instate/v3/d1/miniflare-D1DatabaseObject/<hash>.sqlite, and each Durable Object instate/v3/do/fctl-control-<Class>/<id>.sqlite.crates/fctl-control/wrangler.tomlhas seven SQLite-backed classes, so there's a file per session, project, person and workspace. - Measured in this session. The Miniflare that
deploy/standalonepins (wrangler 4.156.1) ran a D1 database and a SQLite Durable Object, persisted tostate/v3asserver.mjsdoes. Every file was in WAL mode, with-waland-shmbeside it, and each class'smetadata.sqliteheld a_cf_ALARMtable. Checkpoints were rare: after a few hundred writes, the D1 file was 4 KiB and its WAL 3 MiB. A copy of the.sqlitewithout its-walhad no tables at all. Meanwhile, another process'ssqlite3 .backup, andVACUUM INTOthrough Node'snode:sqlite, made copies that passedPRAGMA integrity_checkwhile workerd kept writing. - Backups. docs/self-hosting.md#operating-it says "Stop the server and copy it, or snapshot its volume", with a
busybox tarof the volume, and ADR 0026 says the same. Nothing says why a copy of a running server's directory is unsafe, or how to restore. Nothing says the master key must come along either, thoughmasterKey(deploy/standalone/lib/config.mjs) refuses any key but the one inmaster-key. - A restored copy is live. A copy started anywhere runs the instance's alarms: HooksDO posts pending webhook deliveries, NotifyDO sends notifications, and ScheduleDO starts schedules (docs/architecture.md#data).
- Cloudflare. D1 Time Travel restores D1, in place, to any minute in the last 30 days (7 on the Free plan) (Cloudflare's docs). docs/self-hosting.md's Cloudflare section says event logs and search indexes live in Durable Object storage. SQLite-backed objects have 30 days of point-in-time recovery too, but only from each object's own code (
ctx.storage.getBookmarkForTime,onNextSessionRestoreBookmark), and not in local development (Cloudflare's docs). fctl calls neither, so none of the Durable Objects' state can be restored today: event logs, attachments, webhook deliveries, notifications, FleetDO's queue and runners, and the schedules' alarm.
What should happen
-
GET /api/v1/metricsanswers in Prometheus' text format, behind a metrics token, on both kinds of deployment. - The standalone server adds its own numbers: requests by status, workerd restarts, data size and free disk, and the last backup. It hands them to the Worker through a service binding of its own.
-
GET /api/v1/readychecks D1 (a query, and every migration the Worker was built with) and FleetDO, and answers 503 with what failed. The Dockerfile and the Kubernetes example use it for readiness, and keep health for liveness. - The standalone server backs up while it runs, on a schedule and on demand, copying each file through SQLite, with a manifest.
- A restore command in the image restores into a stopped server's data directory.
- A drill mode runs a restored copy with its outbound effects off.
- Admin shows the instance's health, metrics tokens and backups, as do
fctl admin healthandfctl admin metrics-tokens. - An optional request log at the front door,
lib/proxy.mjs, without query strings. - The operating guide says plainly that there's one replica and no failover. It covers the data's layout, three ways to back up, restoring, a drill, and what recovery takes, with times measured in the drill. For Cloudflare it says what Time Travel covers and what it doesn't.
Metrics.
fctl_build_info{version="0.38.0"} 1
fctl_d1_migrations{state="applied"} 72
fctl_d1_migrations{state="expected"} 72
fctl_sessions{status="working"} 14
fctl_sessions_waiting{workspace="acme",reason="busy"} 3
fctl_runners{state="online"} 6 # also offline, draining, low_disk, driver_not_ready, disabled
fctl_runner_sessions 14
fctl_runner_capacity 24
fctl_webhooks_failing{workspace="acme"} 1
fctl_housekeeping_last_success_seconds 1795436220
# The standalone server adds:
fctl_server_requests_total{method="GET",code="2xx"} 51234
fctl_server_runtime_restarts_total 0 # Miniflare's unsafeHandleRuntimeRestart
fctl_server_data_bytes 2254857830
fctl_server_disk_free_bytes 40265318400
fctl_backup_last_success_seconds 1795402800
A scrape costs one indexed D1 count and one FleetDO request. HooksDO writes failing_since through to D1, in a new webhooks column, so that no scrape wakes a workspace's object. FleetDO's queue keeps a stable kind beside the sentence (Wait::kind, a new column through add_column). The token is a new kind, fctl_met_ (fctl_domain::tokens), which instance admins make. D1 keeps its hash, and it reaches /api/v1/metrics alone. The standalone server gives the Worker a service binding, FCTL_SERVER, answered by a function in Node: server.mjs already gives it FCTL_WEBHOOK_NETWORK, and the pinned Miniflare takes functions as bindings. Through it the Worker reads the server's numbers (the front door counts requests) and the backups, and asks for a backup now. So Node checks no credentials, and on Cloudflare, where the binding is absent, those parts don't show.
Readiness. {"ready": false, "d1": "ok", "migrations": "71 of 72 applied", "fleet": "didn't answer in 5 s"} with 503.
Backups. FCTL_BACKUP_DIR turns them on, FCTL_BACKUP_EVERY sets how often (6 hours) and FCTL_BACKUP_KEEP how many stay (14). A job like the hourly one (lib/schedule.mjs) writes each SQLite file under state/v3 with VACUUM INTO, through node:sqlite (Node 22.5 and later, and the image runs Node 22). It writes into a new directory, adds manifest.json (fctl's version, migrations, time, and each file's size and SHA-256), then renames the directory into place. Durable Objects go first and D1 last, so that D1 never names what they lack. A backup made this way isn't one instant across files. A volume snapshot is (a Kubernetes VolumeSnapshot, LVM, ZFS, a cloud disk's), and SQLite recovers it as it would after a power cut, so the docs recommend it where the platform has one. On demand: docker exec fctl node deploy/standalone/server.mjs backup.
Restore. docker run --rm -v fctl-data:/data -v /srv/fctl-backups:/backups ghcr.io/hyperstructure/fctl-control:0.38.0 restore /backups/2026-11-23T03-00Z restores a backup. It refuses while a server holds server.lock, when the backup is from a newer fctl, and when the master key doesn't match. It moves state/ aside as state.before-2026-11-23T09-12Z, copies the backup in, checks each file's integrity and prints the next step.
Drill. FCTL_DRILL=1, with another FCTL_PUBLIC_URL, starts a restored copy whose outbound fetches go to a service that refuses them (Miniflare's outboundService), and which lets no runner in. Its restored alarms fire into nothing, and the app shows a banner: "A drill: this copy sends nothing and runs no sessions."
Cloudflare. /api/v1/metrics and /api/v1/ready work the same there. A restore of one session's event log or one project's files could call a Durable Object's own point-in-time recovery (a decision below). Until fctl does that, the docs say what can't come back.
Design and UX
An operator should know within a minute whether the instance is well. They should be able to restore last night's backup by following one page, without learning where Miniflare keeps its files.
Admin's header gets a status line: "fctl 0.38.0 · ready · last backup 3 hours ago". It has a dot in the accent when all is well, amber for a problem and red when not ready, and each part links to its section of Admin → Settings.
Health (Admin → Settings) lists checks as sentences: "The database answers in 4 ms, with all 72 migrations". "6 runners online (1 draining); 14 sessions working, 3 waiting for a runner in Acme, all busy". "Housekeeping ran 11 minutes ago". Problems are amber and name who acts: "Deploys in Acme has failed since 12:04: its workspace's admins see it under Acme → Webhooks."
Monitoring, before there's a token:
- Headline: "Alerts before anyone notices".
- Lead: "Prometheus, or anything that reads its format, scrapes https://fctl.acme.dev/api/v1/metrics. It gets sessions by status, sessions waiting for a runner and why, runners online, busy and draining, failing webhooks, migrations and the version."
- Preview: a few metric lines with this instance's values.
- Primary action: "Make a metrics token".
Once one is made, the token shows once in an amber box ("Copy it now: whoever has it reads the instance's metrics"), then two CodeBoxes. One holds a scrape configuration with the address and token filled in, and the other example alerts (sessions waiting 10 minutes, no runner online, not ready, the newest backup older than a day). The token list shows each token's name, who made it and "scraped 15 seconds ago", or "not scraped yet: its first scrape shows here".
Backups, standalone, before they're on:
- Headline: "Last night's state, ready to restore".
- Lead: "Acme factory keeps everything in /data: its database, every session's transcript, attached files. With FCTL_BACKUP_DIR set to a volume of its own, the server copies them there every 6 hours while it runs."
- Preview: three drawn backups.
- The setting belongs to the deployment, so instead of a button there are CodeBoxes for Compose and Kubernetes.
Once backups are on:
- The newest seven show ("Today 03:00 · 2.1 GB · took 48 s"), then "Show 23 older".
- "Back up now" is the primary action. While it runs: "Backing up: 312 of 1,904 files".
- Each backup has "How to restore it", which opens the steps with its name filled in.
- A failure is red: "Last night's backup failed: /backups has 2.0 GB free and it needed 2.1 GB."
On Cloudflare, the section says what there is: "Cloudflare keeps 30 days of D1's history (Time Travel). Transcripts, attachments and webhook deliveries live in Durable Objects, which fctl can't restore yet."
CLI:
$ fctl admin health
✓ ready: fctl 0.38.0 at https://fctl.acme.dev
✓ database: answers in 4 ms, all 72 migrations applied
✓ fleet: 6 runners online (1 draining); 14 sessions working, 3 waiting for a runner (Acme: busy)
✓ housekeeping: ran 11 minutes ago
✕ webhooks: Deploys in Acme has failed since 12:04 (connection refused)
its workspace's admins see it under Acme → Webhooks
· backups: newest at 03:00 (2.1 GB) in /backups, next at 09:00
$ fctl admin metrics-tokens create Prometheus
fctl_met_…
Shown once: whoever has it reads Acme factory's metrics. Scrape https://fctl.acme.dev/api/v1/metrics with it as the bearer token.
fctl admin health --json gives the same checks as fields, and fctl admin metrics-tokens list and revoke round the tokens out.
States. Loading: Health's checks show as skeletons of their own size. Errors: "Couldn't ask the database: D1_ERROR …", with the readiness check's own words. Waiting: a backup in progress, and a metrics token not scraped yet. Partial setups: backups on but never succeeded; a token made but never used. Long lists: older backups fold, and so do revoked tokens.
- Follow hyperstructure/design's docs:
docs/principles.md;docs/web-app/explaining.mdfor pages that set something up (a headline that names the outcome, a lead built from this place's facts, a preview of the result, one primary action, and who can act);docs/web-app/kit.mdfor controls. - Design every state before building it: the first visit, loading, errors and refusals, waiting, partial setups and long lists.
- Say what happens, plainly, and never leave someone at a disabled control without saying who can act.
- Prototype the main screens with realistic data (
cargo xtask demo's world) and review them before building the rest. - Check both themes, a phone's width, the keyboard, screen readers and reduced motion, and show screenshots in each pull request.
- Give the CLI the same care: readable output,
--json, and errors that say what to do next. - Add or update the pages of hyperstructure/design's docs for each new component, with the reasons behind its choices.
Compatibility
- D1. New migration files: the metrics tokens' table and
webhooks.failing_since. FleetDO's newqueuecolumn goes throughadd_column, which is safe on an already-migrated schema. - Protocol. The health, readiness and metrics-token types go in
crates/fctl-proto, thencargo xtask gen. Methods go incrates/fctl-client, and commands incrates/fctl. Hosts and agents don't change. - Release. The control plane and the standalone image (
server.mjs, the Dockerfile,kubernetes.yaml). The Standalone image workflow runs on changes todeploy/standalone. - An ADR records online backups and the drill mode, in place of ADR 0026's "copy the data directory while the server is stopped".
- Docs.
docs/self-hosting.md(both Operating it sections, and the Settings table for the new variables) anddocs/organizations.md(Oversight).docs/architecture.md(Data, Deployment),docs/cli.mdanddocs/llms.txt. - Privacy policy. Metrics carry workspaces' slugs. If app.fctl.sh sent them to a monitoring provider, fctl-site's
legal/privacy.mdwould list that provider. Backups kept longer than Cloudflare's 30 days would change its "Backups" line.
Decisions for a person
- Is the metrics token its own kind, a
FCTL_METRICS_TOKENvariable for deployments, or an admin token? - Do metrics carry a workspace label by default? It costs cardinality on large instances and puts workspaces' names in the monitoring system.
- Are backups built into the server, with a schedule and retention, or only a command and the docs? Do they ever include the master key?
- Which consistency is enough: online copies file by file (not one instant), pausing writes while they run, or volume snapshots only?
- Should
fctl admin backupstream the instance's whole data over HTTP, to the primary instance owner after confirming it's them? Or isdocker execenough? - On Cloudflare, does fctl build restores of Durable Objects from their point-in-time recovery, or document the gap?
- Is the drill mode part of this issue, or a follow-up?
Session: https://app.fctl.sh/s/ses_01M8450BECFP8DN88R0ZP0N0MS
Activity