Skip to content

FLT-281 Stage 2a snapshot runbook

Stage 2a serves the verified Christian keep-list catalog and WEB/BSB Bibles. It imports no lyrics, writes no content-check decisions and carries no publish pointers. Automated lyric review remains Stage 2b. This change authorizes local build/test work only; no cloud swap has been run or authorized by these scripts.

The builder runs production import-release, then conservatively downgrades legacy BOOST artist-only approvals outside SongKeepList or flagged secular to PendingReview (enum 1). It never grants new approvals. Manifest field approvalsRestrictedToKeepList records that count; lyric versions, decisions and pointers remain zero.

Before a later operator-run window

Clahadore is the sole swap operator. Fence every staff takedown/content-check command before backup; keep the fence through transfer, restart, smoke and any rollback. There is no Cloud Run writer. -WritersFenced records that operational assertion; it is not a distributed writer lock. The VM also holds an exclusive local swap lock.

Use the API revision corresponding to this checkout's migration scripts, pointed at v4v-quack in verse4verse-prod, zone us-central1-a. Verify the API URI's deployment/backend relationship and recycle/drain stale database connections before the window. The HTTP smoke alone cannot establish which backend a URL uses. The base revision already defers missing live-state configuration inside the lyrics fail-closed filter; the new endpoint tests verify hidden, not merely HTTP 200. No lyrics reader change/new revision is required for that behavior.

The snapshot and manifest are C:\v4v-night\snapshot\v4v_snapshot.duckdb and manifest.json. The swap validates manifest SHA-256/size and refuses a candidate WAL. Candidate and backup must have the exact migration histories expected by this checkout. An older/incompatible production database blocks this swap; do not bypass the check.

Linux prerequisites: /opt/duckdb/duckdb v2.0.0, quack.service, Bash, Python 3 standard library, runuser, flock, coreutils and operator sudo access. Python and runuser availability are checked before stopping service. Checkpoints execute as quack; fingerprint, compatibility and gate queries open databases read-only, preventing root-owned live WAL files. The requested PowerShell interface orchestrates Windows/IAP; Bash manages Linux service/file operations; Python supplies structured HTTP/JSON checks and narrowly scoped retention. These helpers avoid requiring an unprovided .NET/F# runtime on the VM.

Local preview and verification

pwsh -NoProfile -File scripts/swap-snapshot.ps1 -DryRun prints the fenced sequence without executing gcloud, making network requests or touching the VM. scripts/test-swap-snapshot.ps1 checks that path with a gcloud tripwire, requires the writer fence, runs real DuckDB fingerprint SQL against synthetic state, and executes the shipped Bash rollback function with mocked service/DB adapters. It tests changed state, unreadable state and incompatible backup refusal, plus unchanged-state restore. These are local tests, not live IAP/systemd/production verification.

python -O scripts/test-swap-snapshot-smoke.py exercises the shipped HTTP checker against mocked HTTP 200 responses with no network. It verifies hidden/missing statuses pass, found/unknown statuses fail, malformed/empty catalog and Bible responses fail, and both Bibles contain JHN 3:16 with nonempty text. Gates remain active under Python optimization.

A real invocation would additionally require -WritersFenced and an explicit credential-free HTTPS -ApiBaseUri. Do not run it until a separate cloud execution authorization exists. The wrapper uses only gcloud compute ssh/scp --tunnel-through-iap, and checks free space in both /data and the upload filesystem before copying payloads. Linux text payloads are normalized to LF.

Swap and failure behavior

Manual review decisions (all stages). The swap refuses a manifest without a manualDecisions carry record. On the VM it refuses if the fenced live file holds any lyrics.ManualDecisions row the candidate lacks. The fingerprint has a fourth line covering those rows, so rollback cannot restore over a decision made after the swap. Production publish pointers are no longer an authority during carry. See docs/snapshot-manual-decisions.md for the export, replay and gate steps every build now runs.

After stopping the active service, checkpoint production and require zero production publish pointers. Any nonzero count blocks 2a before replacement, preventing silent unpublication. With zero lyric versions and zero production pointers there are zero matching tuples to carry and zero unmatched pointers dropped; both counts are logged. Copy every takedown and audit row from the backup into the candidate, then compare full live-state fingerprints. The fingerprint includes counts and SHA-256 of ordered complete takedown, audit and pointer rows; no text or identities are printed.

Run Bible/catalog/keep-list/no-lyrics/no-pointers and migration gates using the VM's DuckDB CLI after transfer. Checkpoint and atomically rename the gated candidate over /data/v4v.duckdb, restart service, then check catalog nonempty, WEB and BSB JHN 3, and sample lyrics status equal to hidden or missing. Response bodies are never logged. Keep only the newest two generated backups after successful smoke and remove that successful upload's snapshot file; failures retain forensic backups, candidate/restore copies and staging evidence for deliberate operator cleanup after investigation. Backup paths are generated from a fixed /data prefix, UTC timestamp and numeric process ID; they are not caller-supplied SQL paths.

Before any restore, compare the running file's live-state fingerprint against the backup-time fingerprint and recheck backup compatibility. DuckDB cannot open the file from another process while Quack holds its writer lock, so comparison briefly stops the service. A changed or unreadable fingerprint refuses rollback, preserves the current database/WAL and restarts the current file. No automatic restore discards newer state. Unchanged state permits a temporary backup copy and atomic restore, followed by restart.

On refusal, keep writers fenced. Preserve /data/v4v.duckdb, its WAL, the named backup and .fingerprint evidence. Compare takedown/audit/pointer rows offline in protected storage, reconcile newer rows into a compatible recovery candidate, rerun every gate, and arrange a separately authorized atomic recovery. Never overwrite newer state with the old backup. If service restart itself fails, inspect systemd status while retaining those files; do not repeatedly rerun the swap.

After successful API smoke, rollback is disarmed before upload cleanup or backup retention. A housekeeping failure exits 43, leaves the healthy candidate running, and prints manual cleanup instructions. Inspect the upload and newest two backups; do not rerun the swap or restore production merely to finish cleanup.

Crash recovery

The supplied startup unit opens /data/v4v.duckdb as quack using /opt/duckdb/duckdb -bail /data/v4v.duckdb -init /run/quack/serve.sql; it attaches no other database. Both replacement names are on /data, so atomic rename exposes either the complete old file or the fully gated candidate. The next boot serves whichever file occupies that name; it does not automatically restore a backup. A crash before post-restart smoke still requires operator verification before releasing the fence.