Snapshot runbook: carrying manual review decisions¶
The app serves an offline-built snapshot that scripts/swap-snapshot.ps1 swaps over the live Quack file. Admin review
decisions (POST /api/admin/review/{versionId}) and the worker lyrics-content-check CLI write into the database they run
against. Without a carry step, the next build plus swap would replace the live file and silently drop every decision made
there. This runbook closes that gap. It adds no separate store and no gate on the public read path: lyrics still show when
the current version is model-approved and the song is keep-listed.
What records a decision¶
Every manual decision (approve, reject or keep, from the admin API or the CLI) appends one immutable row to
lyrics.ManualDecisions in the same transaction as the lyrics.Versions status change. The row holds the version ID, song
ID, stable song key, the version's content hash, the decision, the actor, the reviewer's note, the origin (admin or cli)
and the UTC time. It never holds lyric text. Automated model decisions are not manual and add no row.
The admin path is snapshot-only. It no longer needs ConnectionStrings:LyricsLiveState or lyrics_live.PublishPointers.
The offline Worker still keeps that pointer table as a derived projection, because the snapshot gates check it. Nothing on
the public read path reads it.
Commands¶
lyrics-decisions-export --out <export.json>
lyrics-decisions-replay --in <export.json> --report <report.json> [--gate-sql <table.sql>] [--accept-flagged <reason>]
- Export is read-only. It reads every
lyrics.ManualDecisionsrow and its version's resulting status from whatever database the Worker is configured for: a checkpointed copy of the live file, or the live database through Quack. A file that predates the migration exports zero rows withtablePresent: false. The export carries a SHA-256 digest of its decision list. - Replay writes only a LOCAL offline snapshot. It refuses Quack and pending migrations, and re-checks the digest. It is
idempotent: a decision already in the snapshot's history is reported as
already_appliedand never applied twice. A decision applies only to a version whose stored hash and recomputed line hash both equal the exported hash: the same version ID, or, when that ID is not in the snapshot, the one version whose song has the decision's stable song key and whose content hash matches (outcomeapplied, coderemapped, withtargetVersionIdin the report). Otherwise it is flagged for review with a fixed code and not applied. The codes areversion_missing(no ID and no key + hash match, or no stable key),remap_ambiguous(more than one key + hash match),content_changed,song_changed,not_pending,ineligible,outranked,no_stable_identity,duplicate_currentandrefused. Flagged and applied decisions alike are copied into the snapshot's ownlyrics.ManualDecisions, with their outcome inlyrics.ManualDecisionReplays. History therefore always moves forward. - A remap never guesses. A candidate on the decision's own song ID wins outright (exactly one, or
remap_ambiguous). Otherwise the same words under more than one song areremap_ambiguous, even when only one of those songs has the key. - Newest wins across both histories. A decision made on the candidate itself (CLI, never replayed) that is newer than an
exported decision on the same version (or, for an approval, a newer approval on the same song) supersedes it: the exported
decision is recorded with outcome
supersededand its effect is not applied. - A flagged decision is contained, never shipped as published. After the replay loop:
- a flagged reject holds its song. Every approved, current version of the song it names (by its version ID, its song ID
or a stable song key that resolves to a snapshot song which also carries the rejected text) goes back to pending,
stops being current, and is marked
replay-holdwithheld: flagged manual decision <id>. Independently, every approved, current version anywhere in the snapshot with the rejected text is held the same way, whatever its song. The model pass never re-checks a held version; a person must re-review it. Choosing "keep held" on a held version records the keep but leaves the hold marker in place; it still writes the version row, so a concurrent decision conflicts. - a flagged approve or keep leaves its exported version, and every version with its text on its version ID or on one of its songs (as above), pending rather than model-approved.
- the latest effective decision on that song (reject; for the hash hold, the held version's own song) or version (approve, keep) takes precedence when it is a newer approval. An approval a later decision revoked never excuses a flagged decision.
- a flagged decision the snapshot cannot locate is
unresolved: a reject with no matching version or song and no resolving key on a song with its text (a non-empty exported key alone locates nothing: a fresh import mints new IDs, a key can resolve to null, and a key can move to a different song); an approve or keep with no version carrying its text on its version ID or its songs (a surviving version ID whose text changed locates nothing). An unresolved approve or keep also holds every approved version with its text. Replay then exits 1 unless--accept-flagged "<reason>"records, in the replay report (acceptedFlaggedReason), an operator's explicit decision to ship anyway.unresolvedFlaggedRejectscounts all of them. - Replay then recomputes the pointer projection from the snapshot and reports the exact publication tuples. It exits 1 if the projection is not exact.
Building a snapshot¶
Every builder (build-snapshot.ps1 for 2b, build-snapshot-2c.ps1, build-snapshot-2d.ps1, and any later stage) takes exactly one of the
following. It refuses to start without one:
| Switch | Use |
|---|---|
-LiveDatabase <file> |
A checkpointed copy of the live file (no .wal). The builder exports from a private copy of it. |
-LiveDecisionsExport <json> |
An export the operator already took, for example through Quack. |
-NoLiveDecisions -NoLiveDecisionsReason "<why>" |
Explicit skip, for example when the live file predates the migration. It is recorded in the manifest. |
-AcceptFlaggedReason "<why>" (optional, any builder) is the only way to finish a build that has an unresolved flagged
rejection. It is passed to replay as --accept-flagged and recorded in the manifest.
Before the stage's gates, the builder exports (if given -LiveDatabase), replays, and then runs
scripts/snapshot-decisions-gate.sql with the DuckDB CLI. The gate fails the build unless all of these hold:
- every exported decision has the outcome
applied,already_applied,supersededorflagged; - every exported decision is in the snapshot's history, unchanged (including its song key and content hash);
- every applied, superseded or flagged outcome is recorded in
lyrics.ManualDecisionReplays; - every unflagged decision acts on a snapshot version with its content hash, on the same song: the same version ID on the same song ID, or a remapped version whose song's stable key (read afresh by the Worker) equals the decision's;
- no flagged reject leaves its song served, no approved, current version anywhere carries a flagged rejection's text, and no flagged approve or keep leaves its version approved, unless the latest effective decision on that version's song (reject) or on that version is a newer approval;
- no unresolved flagged decision passes without an accepted reason (the Worker lists, in
decision_key_songs, every snapshot song whose key resolves to a flagged decision's key; the gate counts one only when that song also has a version with the decision's text); - every superseded decision has a newer effective decision behind it;
- the latest effective decision (carried, or made on the candidate itself) on each version left it in that decision's state (approve = approved or held by a newer flagged decision, reject = rejected and not current, keep = pending), and the latest effective approval on each song (by the target's song in this snapshot) is its current version unless held;
- no song has more than one current approved version.
The builder then runs the exact tuple gate against the post-replay tuples. The manifest gains manualDecisions (the
status, export digest and time, the counts, the flagged IDs, codes and containment, containment: "v1",
unresolvedFlaggedRejects and any acceptedFlaggedReason) and publicationTuples.
A fresh 2b build gets fresh version IDs. A live decision then applies through the stable song key + content hash match
(remapped, counted as manualDecisions.remapped in the manifest) when exactly one rebuilt version carries the same text
for the same song. Re-imported text that changed, or an ambiguous match, stays flagged and visible in the manifest. 2c and
later stages (including 2d) copy their source snapshot, so the IDs match and decisions apply directly.
Getting the live export (operator)¶
Agents run read-only cloud verbs only. Either:
- With writers fenced, copy a checkpointed live file down (the swap's
/data/backups/v4v-<stamp>.duckdbis only as new as the last swap). Pass it as-LiveDatabase. - Or run
lyrics-decisions-exportwith the Worker configured for Quack (Quack__Uri,Quack__Token) over the IAP tunnel, and pass the JSON as-LiveDecisionsExport.
A stale export is safe. The swap's race guard refuses any decision the candidate lacks, so the worst case is a rebuild, not a loss.
Swapping¶
swap-snapshot.ps1 refuses a manifest that has no manualDecisions record (status replayed or skipped). Snapshots
built before this change must be re-finalized with a live export. It also refuses (scripts/snapshot-flagged-containment.ps1)
a manifest with a flagged decision that predates containment (containment missing), a flagged decision without a
containment result, an uncontained flagged approve or keep, or an unresolved flagged rejection without an accepted reason. On the VM, after stopping the service, checkpointing and
backing up the live file, swap-snapshot-remote.sh runs swap-snapshot-decisions.sql with the backup attached read-only.
It refuses the swap if the live file holds any lyrics.ManualDecisions row that the candidate lacks or that differs.
The pre-migration guard (swap-snapshot-legacy-decisions.sql) always runs, including when the live file has no
lyrics.ManualDecisions table. A decision made before that table existed lives only as a publish pointer and a version
status, so it derives decisions from those and refuses the swap while production holds a non-approved publish pointer, or a
rejection by a non-model actor, that no lyrics.ManualDecisions row carries. A row carries it only when it matches on all
three: a reject decision, the same content hash, and the same song (song ID, or the non-empty stable key the pointer
recorded; an empty key matches nothing). The
same text under another song, or an approve or keep of the same text, carries nothing. A read-only
check of the 2026-11-22 22:30Z production backup found 188 pointers, all approved and each matching an approved current
version, no lyrics.ManualDecisions table, and all 357 decided versions decided by the dual-checker model: nothing to carry. The race guard compares rows by set membership, not by timestamp, so a
decision taken between export and swap is always caught.
The live-state fingerprint now has a fourth line: the count and SHA-256 of lyrics.ManualDecisions. A decision made after
the swap therefore makes the fingerprint-guarded rollback refuse, instead of restoring the old backup over it. A
.fingerprint file written by an older script has three lines, so this script refuses to roll back with it (fail closed).
In that case, restore by hand as docs/snapshot-stage2a.md describes.
Publish pointers in production are no longer treated as an authority during the carry. A live rejection leaves a stale production pointer behind by design. Only the candidate's own pointers must be exact.
Tests¶
tests/Verse4Verse.Catalog.Tests/LyricsManualDecisionTests.cscovers the round trip (approve, reject, keep), idempotent replay, hash-mismatch and missing-version flags, tampered and conflicting exports, the gate SQL, the swap race-guard SQL, and the carry SQL with a stale production pointer. It also covers the CLI append, and the Worker export and replay commands through files (replay refuses Quack). Every SQL file runs as shipped, through DuckDB.NET.AdminReviewTests.Admin_decisions_append_manual_decision_rows_with_no_live_state_store_configuredruns the API withConnectionStrings:LyricsLiveStateunset.LyricsManualDecisionTestsalso covers flagged-decision containment, the unresolved-reject exit code and acceptance, superseded decisions, the hash and song-key binding, ambiguous remaps, concurrent approvals and the pre-migration guard.SnapshotScriptTestsruns the shipped PowerShell: the swap's containment refusal, the builder carry's unresolved refusal and-AcceptFlaggedReason, and the Bible allowlist agreement.scripts/test-swap-snapshot-carry.ps1andscripts/test-swap-snapshot.ps1need the DuckDB CLI.