Operations
Commands below assume the pifi CLI. In the Docker image pifi is on PATH and PIFI_DATA_DIR=/data is set, so docker compose exec pifi pifi <args> (or docker exec <container> pifi <args>) works without flags; the image entrypoint is the CLI, so docker compose run --rm pifi <args> runs a one-off command. Elsewhere, install it with npm install -g @spencerboucher/pifi; from a source checkout use node packages/cli/dist/main.js <args>.
Data directory
| Path | Contents |
|---|---|
coordinator.db (+ -wal, -shm) |
SQLite database in WAL mode: identities (devices, hosts, passkeys), whether the server is set up, projects, tasks, runs, automations, the durable event log, push subscriptions, settings (including VAPID keys). |
admin.token |
Admin token for the local CLI (pair and local work commands), mode 0600. Grants full access. Not part of a database backup; a new one is created if it is missing. |
catalog-secrets/ |
GitHub Device Flow tokens. Protect and back up separately; SQLite backups do not include them. |
coordinator.lock |
Pid file written while a coordinator runs; a second coordinator on the same directory is refused, and restore checks it. |
cli-endpoint.json |
The local URL of the running coordinator, written by up and coordinator start for pair and local admin-token commands. |
host/ |
Local host agent config (host.json) and state in standalone mode (pifi up). |
Default locations are in deployment.md. In the Docker deployment this is the ./data bind mount at /data (the image sets PIFI_DATA_DIR=/data).
Backup
pifi coordinator backup <out> [--data-dir <dir>]docker compose exec pifi pifi coordinator backup /data/backups/coordinator-$(date +%F).dbThe backup uses SQLite VACUUM INTO, which produces a consistent, compacted copy and is safe while the coordinator is running. It refuses to overwrite an existing file. The backup includes who the owner is (the set-up marker and passkeys) and every device and host credential hash, so protect it like the data dir. Copying coordinator.db by hand while the coordinator runs is not safe because of the WAL; use the command.
A catalog backup without its matching catalog-secrets/ still restores project IDs and last-known membership, but the connection needs to be re-established to refresh or clone. Protect a copy of the keys separately and preserve the directory/file permissions. To retire an app credential, revoke it on GitHub.
Host state is separate. pifi host backup <out> copies host.db the same way (outbox, receipts, dispatches, interactions). Pi’s own session files and your repositories are not part of either backup. host.json and client.json (credentials) are not included; re-enroll if you lose them.
Restore
pifi coordinator restore <file> [--data-dir <dir>]Restore refuses to run while a live coordinator holds coordinator.lock, checks the backup’s integrity and schema level, and refuses a backup whose schema is newer than the running build (upgrade first). The previous database is kept as coordinator.db.bak-<timestamp> in the data dir.
In Docker, stop the service first, then restore from a file inside the data mount:
docker compose stop pificp coordinator-2026-11-02.db data/docker compose run --rm pifi coordinator restore /data/coordinator-2026-11-02.dbdocker compose up -dMigrations run at the next start if the backup is from an older schema. Hosts reconnect and replay their outboxes; clients behind the retained event window receive a snapshot.
Migrations
Schema changes are explicit numbered migrations applied automatically at coordinator start and recorded in schema_migrations. pifi coordinator migrate [--data-dir] applies them without starting the server. The current level and the latest known level are shown in diagnostics.
Retention
The durable event log keeps 30 days by default. A sweep runs at start and then hourly: it deletes events older than the window and records the highest deleted sequence as minRetainedSeq. A client reconnecting with a cursor older than that gets a full snapshot instead of an event replay. Host-side dedupe rows older than the window are removed in the same sweep.
The window is the retentionDays row in the coordinator’s settings table. There is no CLI flag, environment variable or API endpoint to change it in this version; the value in effect is reported under events.retentionDays in GET /api/diagnostics. Transcript items, tasks, runs and sessions are not subject to this sweep.
On each host, the outbox keeps acknowledged events for 24 hours (for diagnostics) and then prunes them, at most once a minute; unacknowledged events are never pruned. Panel updates are the exception to “every event is kept”: only a panel’s latest state matters, so an unacknowledged update is replaced by the next one for the same panel, and the coordinator’s event log keeps one event per panel. A generic Status or widget panel whose text only ticks (a countdown, a counter: digits change and nothing else) is sent at most every 30 seconds; any other change is sent at once.
Ended sessions
A session is Current until it is archived. It is archived in three ways:
- You let it go. You quit its Pi (
/quit, Ctrl+D), start a new session in its pane (/new,/resume, fork) or close its tab or pane (a herdr or tmux mirror, or the herdr pane of a Pi you started by hand). A Pi that ends because its terminal went away (SIGHUP/SIGTERM), a reboot, a crash or a host restart is not let go: the session stays Current so you can resume it. Archive in the web app always archives. - Its branch is finished. Its worktree was removed, or the pull request of its worktree branch merged.
- Nobody came back. The hourly sweep archives an ended top-level session with no activity for 3 days (7 when unread), and an ended subagent likewise, or whose parent is archived.
The primary session of a worktree branch that has not landed is never archived by letting it go or by time: the branch keeps it until it lands or its worktree is removed. A main checkout has no such protection, because each session there is its own task. Live sessions, task sessions and sessions with an open question are never archived this way. A pin does not keep a session: archiving removes it from every scope it was pinned to. An archived session is hidden, not deleted: it is under Archived in the Sessions list, and unarchived when its Pi comes back (resumed in a terminal) or from the session menu.
The host reports how each Pi ended as endedBy on the session: quit, replaced, reload, signal, stopped (PiFi stopped it), crashed or lost (the host agent restarted). A client that closes the place showing a session calls POST /api/sessions/:id/release, recorded as releasedAt. Older hosts report no endedBy; then only release, branch facts and time apply.
The thresholds are in Settings > Sessions (GET/PUT /api/settings/sessions): archiveEndedAfterDays (setting row sessionArchiveDays, default 3, 0 turns the time rule off), keepUnreadDays (sessionArchiveUnreadDays, default 7) and archiveWhenClosed (sessionArchiveOnLetGo, default on). GET /api/diagnostics reports them under sessions.
Before archiving, the sweep (and every coordinator start) clears what older releases left behind: questions of sessions whose Pi is gone expire and their “Needs input” attention is resolved, and scopes lose pins of archived sessions.
Logs
The coordinator writes structured JSON (pino) to stdout. Set the level with PIFI_LOG_LEVEL (default info).
docker compose logs -f pifiThese fields are redacted and appear as [redacted]: req.headers.authorization, req.headers.cookie, and any nested credential, token, keys, p256dh or auth field. Sign-in and enrollment links contain a single-use token and are never written to the log: pair and up print them to your terminal only. Device links expire after 10 minutes, host enrollments after 30. A server without single sign-on and with no device or passkey logs and prints only the hint to run pifi pair.
Webhooks
POST /api/hooks/<automationId> (bearer webhook token) fires a webhook automation. Each delivery becomes one occurrence, keyed for deduplication:
- With an
Idempotency-Keyheader (or GitHub’sX-GitHub-Delivery), the key is that value: a redelivery with the same value returns the original occurrence (duplicate: true) and fires nothing. - Without either header, the key is the SHA-256 of the JSON body plus the current 10-minute window (UTC, aligned to the epoch). A sender that retries the same body within the window gets the original occurrence back. Two identical bodies sent on purpose within one window are also treated as one delivery, and a retry that crosses a window boundary fires again; senders that need exact semantics should send an
Idempotency-Key.
Health
| Endpoint | Meaning |
|---|---|
GET /healthz |
Liveness. Returns {"ok":true} while the process serves requests. The Docker HEALTHCHECK uses it. |
GET /readyz |
Readiness. Runs a database query; returns {"ok":true} or 503 when the database is not ready. |
Both are unauthenticated.
Diagnostics
GET /api/diagnostics (authenticated) returns:
- versions (coordinator, protocol, Node, SQLite), the migration level and the latest known level, and the public URL;
- hosts with agent and Pi versions, Pi compatibility, connectivity, last seen time and unsupported capabilities;
- adapter diagnostics (the latest 100
diagnosticevents) and the adapters each host loaded; - the event sequence range (min, max, current,
minRetainedSeq, retention days); - push configuration (VAPID configured, subscription count);
- the number of connected client devices.
The web app shows this under Settings > Diagnostics.
pifi doctor runs local checks and prints PASS, WARN or FAIL per line; it exits non-zero when any check fails:
- Node >=24;
- Pi installed and in the supported range (>=1.4.0 <1.8.0);
- git available;
- the coordinator answers
/healthz; - a “Sign-in” line: PASS when single sign-on or a passkey is available (showing both), WARN when neither is;
- the client credential works (
/api/me); - a host link config (
host.json, or the standalone one in the data dir) exists, and the coordinator sees that host as connected; - push is configured (VAPID keys) and at least one device subscribed.
A missing Pi or git is a FAIL only on a machine with a host config; elsewhere (a pure client) it is a WARN. Not being signed in, an offline host and no push subscriptions are WARNs.
pifi host status reports this machine’s host link (--instance <name> with --config and --state-dir for a second agent). It asks the coordinator about the link only with a client credential for that coordinator.
Upgrading
- Back up (
coordinator backup). - Change the image tag in
deploy/compose.yaml(for exampleghcr.io/justmytwospence/pifi:0.11.0to the new release), thendocker compose pull && docker compose up -d(fromdeploy/). From source, pull, rebuild and restart. - Migrations apply automatically at start. If something goes wrong, stop the service and restore the backup with the previous image.
Repository catalog (schema 25). Before deploying this migration, take a coordinator backup. Existing project IDs, checkouts, worktrees and sessions are preserved. Connect the GitHub App and grant it repositories to put matching Projects back in the active list. A host’s one previous project folder becomes its checkout location; hosts with several previous folders need a location chosen in Settings. An old binary needs the pre-upgrade database to roll back. Restoring the database does not remove clones or undo changes made to a GitHub App installation.
To 0.21. Migration 23 merges views and trackers into scopes and renames terminals to clients (scopes.md, clients.md). It is one-way: an older coordinator cannot open the database afterwards, so back up first, and restore that backup to go back. Daemons and browser tabs from 0.20 keep working until you upgrade them (compatibility.md); every client takes one fresh snapshot after the upgrade. The herdr and tmux plugins moved from integrations/ to modules/: link or load them from the new path.
Upgrade the coordinator before its hosts and CLIs: a coordinator works with hosts and clients one release older, not newer. Hosts are upgraded separately: npm update -g @spencerboucher/pifi, then restart the installed service (launchctl kickstart -k gui/$(id -u)/com.pifi.host on macOS, systemctl --user restart pifi-host on Linux). Hosts and the coordinator reconnect on their own; running Pi sessions on a host stop when its agent restarts: sessions that were working show as interrupted until resumed; idle ones show as stopped and resume when you send to them.
For policy-protected launches, upgrade hosts and Pi to the supported policy-capable range (>=1.5.0 <1.8.0) and verify the session’s actual bridge protection state. Optional negotiation keeps older hosts browsable but does not protect their live Pi processes. Explicitly reload or restart old live sessions when appropriate; they are not silently replaced. Protected launches refuse unsupported hosts, and coordinator communication or policy evaluation failures block protected actions rather than allowing them. See policies.md.
For GitHub, connect a GitHub App or Personal Access Token in Settings > Projects on the coordinator; hosts do not need gh installed. See github.md.
Revoking devices and hosts
Revoke a lost browser, phone or terminal in Settings > Clients, and a retired host in Settings > Hosts; remove a passkey in Settings > Sign-in (see auth.md). A revoked device’s credential stops working, its push subscriptions are deleted and its open sockets receive force_logout. The local admin token cannot be revoked from the app; rotate it by stopping the coordinator and deleting admin.token (a new one is created at the next start).