Repository navigation
Description
Scope (approved by the maintainer, 2026-11-23)
An independent P1 unit for the safety of scripts/restore.sh. Phase 1 is design and isolated tests, then independent review. Implementation needs its own approval. This issue does not authorize editing or running the production restore script, changing production Redis, or rebuilding the validator image.
The five defects to address
| # | Defect | Evidence | Severity if the script were used in a real recovery |
|---|---|---|---|
| 1 | Ownership and privileges dropped | --no-owner --no-acl (lines 63–70): the dump's 64 privilege and 49 default-privilege entries are skipped |
high |
| 2 | Verification covers public only |
lines 72 and 110 count public tables; the 15 tables of gitwire_auth are not counted |
high |
| 3 | RDB restored beside a live AOF | lines 80–85 copy dump.rdb into the volume while compose runs --appendonly yes; which state the server loads is unsettled |
critical for the recovery path |
| 4 | Everything restarted at once | line 96 docker compose up -d starts the workers on the restored queue |
critical |
| 5 | Only the app is stopped first | line 55 docker compose stop gitwire-app; other writers (executor, workers) are not proven stopped before the data is replaced |
critical |
Defect 5 was added by the maintainer's review of the script on 2026-11-23.
What the unit covers
- A restore sequence that provably prevents writes during the restore, with writers stopped and their absence verified before any data is replaced.
- How the six roles the dump names (
gitwire,gitwire_admission,gitwire_app,gitwire_auth_fn_owner,gitwire_executor,gitwire_operator) are created, and how ownership and privileges are restored. - Verification of both schemas,
publicandgitwire_auth, not apublic-only count. - A test of Redis's RDB-versus-AOF precedence when both exist, in isolation only.
- Pinning the Redis version requirement: the backup RDB is format version 12, written by Redis 7.4.9; Redis 7.0.15 rejects it (
Can't handle RDB format version 12). The restore needs Redis 7.4 or later. - An explicit separation between restoring data and resuming work: a barrier that refuses to start any worker on a restored queue until its jobs are classified (
confirmed: never again;uncertain: manual, never automatic;not_executedon positive evidence: eligible; insufficient evidence:uncertain). - Negative tests proving the restore refuses to proceed when a requirement is not met (writers running, roles missing, Redis too old for the RDB, barrier absent).
Measured facts this unit builds on
From the real-data trial of 2026-11-23 (PR #464, comment 7094211093): the backup of 20261123_030001 restores with exit 0 once the six roles exist — 77 tables, 928,895 rows, 429 MB, 0 invalid indexes; the RDB loads 12,163 keys into Redis 7.4.9 in 0.42 s and is rejected by 7.0.15. The synthetic trial (comment 7092268545) showed which jobs a restored queue re-runs: exactly those active or waiting at the snapshot.
The gate that does not move
No worker starts on a restored Redis merely because the RDB loaded. This is a blocking barrier, not an operational warning. Until this unit's outcome is approved, scripts/restore.sh remains unauthorized as a routine production recovery procedure.
Out of scope, kept separate
- Backup files: gitops_hub.dump is created with mode 644 in a 755 directory (backup.sh runs without a restrictive umask) #502 (backup file modes): touches how backups are created, not how they are restored.
- The Node 24 stages: separate deploys.
- The strip, the migration and the AOF rewrite of docs(runbook): repository ID reconciliation procedure #10-R1: on hold.
Activity
Alajmah commentedon Nov 23, 2026
#508 — Phase 1 design: the safe restore sequence (DESIGN + ISOLATED TESTS; no production change)
Phase 1 of the restore-safety unit, as scoped by the review of 2026-11-23 and extended by the review of 2026-11-24. This spec defines the safe restore sequence, its contract surfaces, and its negative tests. Nothing here touches
scripts/restore.sh, production Redis, or the validator image.The five defects, restated as requirements
pg_restorerunspublicandgitwire_auth), plus rows, views, sequences and constraintsThe safe sequence (spec)
gitwire-*container except postgres and redis is running; postgres and redis stay up for the data replacementpg_restoreWITHOUT--no-owner/--no-acl; verify: both schemas, 77 tables, row counts per table, 0 invalid indexes, owners =gitwire--redis-source=rdb(deleteappendonlydir/first, then placedump.rdb) or--redis-source=aof(refuse a stale AOF by comparing its mtime with the RDB's) — never both unattendedconfirmednever again;uncertainmanual;not_executedon positive evidence)The isolated synthetic tests (real deliverables of phase 1)
redis-rdb-vs-aof-precedence-proof.mjs(drafted)appendonly yes, a restoreddump.rdbbeside an existing AOF is ignored — defect 3's mechanicspg_restorefails at the first privilege statement; with them it completes (already observed in the real-data trial — now pinned as an automated test)public-only missesgitwire_authfails to restore must fail the verifiercompose up -dof the workers is refused; without it, the synthetic trial's re-run set is exactly the active-or-waiting snapshot setMeasured inputs this design rests on
Real-data trial (comment 7094211093): 77 tables / 928,895 rows / 429 MB restore in 25 s with the six roles present; RDB format 12 loads in 0.42 s on 7.4.9 and is rejected by 7.0.15. Synthetic trial (comment 7092268545): a restored queue re-runs exactly the active-or-waiting set.
What phase 1 does NOT include
No change to
scripts/restore.sh, no production run, no production Redis change, no AOF rewrite, no validator rebuild, no worker start on any restored copy.Evidence so far
The RDB-vs-AOF precedence proof script is drafted (
scripts/redis-rdb-vs-aof-precedence-proof.mjs) and will run on a study branch in CI; its run is the evidence for defect 3's mechanics. The remaining four tests follow the same pattern: synthetic data, scratch engines, no secrets.Alajmah commentedon Nov 23, 2026
Defect 3's mechanics proven: with
appendonly yes, a restoreddump.rdbis ignored (2026-11-24)Evidence for #508 phase 1 (design + isolated tests), the RDB-vs-AOF precedence defect. Synthetic, isolated, no secrets, no production change — the script ran in CI (run 45274433121, SUCCESS) on the study branch
study/redis-rdb-vs-aof.The scenarios and what they prove
The proof spawns throwaway redis-server processes on 127.0.
scripts/redis-rdb-vs-aof-precedence-proof.mjsruns two scenarios:dump.rdband its state is exactly the seeded state → a restored RDB loads when it is the only source.dump.rdbplaced beside an existing AOF withappendonly yes→ the AOF state wins and the restoreddump.rdbis ignored.Scenario 2 is defect 3's mechanics: restore.sh's current sequence leaves an existing AOF in place, so a restored RDB is dead weight. The restore delivers the point-in-time state only when the AOF directory is cleared — which is exactly what the phase-1 design's explicit-source requirement (R3,
--redis-source=rdb|aof) forces: never "whatever the server happens to load".Scope of the claim
Proven: the load-time precedence behaviour of the redis 7.x series in this exact configuration; the script pins the loaded state by comparing the sorted key set. Not proven here: every redis version; no production Redis was touched; no AOF rewrite ran. The four remaining phase-1 tests (roles-first restore, both-schema verification, version-rejection gate, worker barrier) are designed and listed in the design record.
Alajmah commentedon Nov 24, 2026
Phase-1 progress note: the four remaining isolated tests — authorized, deferred to the next session
The authorization is recorded: the four tests below run in isolation only, with their rejection paths tested alongside the success paths, and nothing here authorizes an edit to the production
restore.sh:gitwire_authfails to restore must fail the verifier; apublic-only verifier must NOT catch the same broken seed)This cycle's state: deferred. The session hit a generation-quality incident — two corrupted drafts of test 1 were caught in self-verification and deleted; no corrupted content reached any branch, commit, or this repository (the working tree on the unit's branch is clean). Per the quality guard, script writing stopped for the session rather than shipping unverified code. The dashboard stage-4 track consumed the session's remaining budget and is the maintainer's stated priority.
Alajmah commentedon Nov 24, 2026
Design amendment v2: the six review notes incorporated (2026-11-24)
This amends the phase-1 design (comment 7115073589) per the maintainer's six findings. Nothing here changes the holds: no production
restore.shedit, no production Redis mutation, no AOF deletion in the production space, no worker start on any restored copy.The amendments
R1 — roles are a contract, not a restore precondition only. The six roles are restored to their production properties, read from the backup's own catalog (login capability, superuser/createrole flags, memberships), not created blanket-
NOLOGIN. Post-restore verification asserts the authorization model — owners, memberships, login capability — andpg_restore's exit alone does not prove the model.R2 — no hard-coded counts. 77 tables was true for the tested backup; it is not a constant. Expected tables/rows/indexes/sequences/constraints derive from the backup's own declaration (manifest schema version + counts — depends on #512's manifest v2) and the verifier compares the restored state against that declaration.
R3 — Redis source: RDB-first, isolated. Restoring the RDB into a fresh, isolated storage area is the first path to prove. An AOF restore needs a known-integral source and its own independent test. File mtime is not accepted as a freshness or integrity signal. Deleting
appendonlydir/in the live production space is outside this design's authority.R5 — writers-stopped is proven, not listed. The design adds a mutual-exclusion operational lock across deploy / restore / backup so the paths cannot interleave, and verifies actual connections and write-capable processes against PostgreSQL and Redis — not a container list. New negative test: an active writer must block the restore before any data is modified.
The worker barrier is permanent and fail-closed. Its state lives outside the restored data (a host-side control marker carrying the restore id, independent of the restored Redis), so a crashed restore or a host reboot cannot clear the block. Workers start only on positive, complete classification evidence. Refusal cases tested: evidence missing, evidence incomplete, any
uncertain.R6 (new) — data restore is separated from config/secrets restore. The current
restore.shcopies the old env/compose files before stopping the app. The design separates the two: data restore and config/secrets re-adoption are distinct phases, and config/secrets re-adoption requires its own independent review — a restore must never resurrect a revoked executor token or reintroduce runtime settings that conflict with the deployed release.The isolated tests (now five)
pg_restorefails at the first ownership/privilege statementgitwire_authfails to restore passes apublic-only verifier (the current defect) and must FAIL the both-schema verifieruncertainclassification evidence; the state survives a simulated restore crashThe barrier test implements the fail-closed marker semantics; the queue re-run equivalence itself remains covered by the earlier synthetic trial (comment 7092268545).
Alajmah commentedon Nov 24, 2026
Phase-1 isolated tests EXECUTED: all five green in CI (run 45341379391)
The five tests of the amended design (comment 7123788794) ran on the study branch
study/restore-safety-tests-v3, CI run 45341379391 — scratch engines (docker postgres:16-alpine, redis 7.4/7.0-alpine), no secrets, no production contact. Each test proves its rejection path AND its success path.pg_restorewithout the roles → exit 1gitwire(tables + schema), membershipgitwire_app→gitwireverified,gitwirestays NOLOGIN; counts compared against the fixture's declaration, not hard-codedpublic-only verifier passed a seed whosegitwire_authwas emptied — the current defect, demonstratedFailures on the way (recorded for honesty)
Two earlier runs failed and were fixed: v1 (45340490377) — scenario A's failed restore left partial objects in the shared target cluster; v2 (45340901973) — the success scenario still restored into the rejection cluster (the dump push to the success cluster was missing). v3 gives each scenario its own cluster and pushes the dump to it. The tests are
study-branch-only deliverables for phase 1;restore.shremains untouched and every hold stands.