Skip to content

P1: restore.sh safety — five defects (no-owner/no-acl, public-only check, RDB beside AOF, workers restarted, writers not proven stopped); phase 1 = design + isolated tests #508

Open

Description

@Alajmah

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, public and gitwire_auth, not a public-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_executed on 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

Activity

  1. Alajmah commented on Nov 23, 2026

    @Alajmah
    ContributorAuthor

    #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

    # Requirement
    R1 Restore PostgreSQL with ownership, privileges and default privileges intact; the six roles exist before pg_restore runs
    R2 Verification counts both schemas (public and gitwire_auth), plus rows, views, sequences and constraints
    R3 The Redis state source is explicit: either AOF (live history) or the restored RDB (point-in-time), never "whatever the server happens to load"
    R4 No service restarts until the restore is verified; workers are gated separately (the barrier of #10-R1)
    R5 Every writer capable of touching PostgreSQL or Redis is stopped, and its absence is verified, before any data is replaced

    The safe sequence (spec)

    Phase Steps
    0. Preflight refuse to run unless: no deploy in progress; the backup pair's sha256 matches the manifest; the Redis engine reads the backup's RDB format version (format 12 needs ≥ 7.4); disk headroom ≥ 2× the database size
    1. Quiesce stop app, executor-service, dashboard, bot, demo, docs, landing, tunnel? (tunnel keeps serving static reads — but it proxies API writes, so stop it), then verify: no gitwire-* container except postgres and redis is running; postgres and redis stay up for the data replacement
    2. Postgres drop/recreate; create the six roles NOLOGIN; pg_restore WITHOUT --no-owner/--no-acl; verify: both schemas, 77 tables, row counts per table, 0 invalid indexes, owners = gitwire
    3. Redis explicit source flag: --redis-source=rdb (delete appendonlydir/ first, then place dump.rdb) or --redis-source=aof (refuse a stale AOF by comparing its mtime with the RDB's) — never both unattended
    4. Verify level-2 checks of the real-data trial: row counts, key families, queue sets
    5. Gate stop. Print the classification reminder and REFUSE to start workers until #10-R1's classification has run (confirmed never again; uncertain manual; not_executed on positive evidence)
    6. Resume out of scope for the script; an operator procedure with the classification evidence is a separate approval

    The isolated synthetic tests (real deliverables of phase 1)

    Test Proves Venue
    redis-rdb-vs-aof-precedence-proof.mjs (drafted) with appendonly yes, a restored dump.rdb beside an existing AOF is ignored — defect 3's mechanics study branch, CI, no secrets
    roles-first restore on a scratch cluster without the six roles pg_restore fails at the first privilege statement; with them it completes (already observed in the real-data trial — now pinned as an automated test) scratch PostgreSQL in CI
    both-schema verification catches what public-only misses a seed where gitwire_auth fails to restore must fail the verifier scratch PostgreSQL in CI
    version-rejection gate an RDB of format 12 against a 7.0 server is refused before any data is replaced scratch Redis in CI
    the barrier with the barrier present, compose up -d of the workers is refused; without it, the synthetic trial's re-run set is exactly the active-or-waiting snapshot set synthetic queue, CI

    Measured 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.

  2. Alajmah commented on Nov 23, 2026

    @Alajmah
    ContributorAuthor

    Defect 3's mechanics proven: with appendonly yes, a restored dump.rdb is 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.mjs runs two scenarios:

    1. RDB-only: a server with AOF off loads dump.rdb and its state is exactly the seeded state → a restored RDB loads when it is the only source.
    2. RDB + AOF: the same dump.rdb placed beside an existing AOF with appendonly yes → the AOF state wins and the restored dump.rdb is 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.

  3. Alajmah commented on Nov 24, 2026

    @Alajmah
    ContributorAuthor

    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:

    1. roles-first restore (scratch PostgreSQL: without the six roles the restore must fail; with them it completes with correct owners and both schemas)
    2. both-schema verification (a seed whose gitwire_auth fails to restore must fail the verifier; a public-only verifier must NOT catch the same broken seed)
    3. the RDB version-rejection gate (a format-12 RDB against a 7.0 server refused before any data is replaced)
    4. the worker-resumption barrier (reference semantics: with the barrier, worker start is refused; without it, the re-run set equals the active-or-waiting snapshot set)

    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.

  4. Alajmah commented on Nov 24, 2026

    @Alajmah
    ContributorAuthor

    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.sh edit, 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 — and pg_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.sh copies 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)

    # Test Rejection path Success path
    1 roles-first restore without the roles, pg_restore fails at the first ownership/privilege statement with the roles restored to their declared properties, the restore completes and the authorization model verifies
    2 both-schema verification a seed whose gitwire_auth fails to restore passes a public-only verifier (the current defect) and must FAIL the both-schema verifier a good seed passes the declaration-driven verifier
    3 RDB version gate a format-12 RDB against a Redis 7.0 server is refused before any data is replaced the same RDB loads on a ≥7.4 server
    4 writer-present block (new) with a live writer connected, the restore refuses before touching any data with no writer, the restore proceeds
    5 worker barrier workers refused on missing / incomplete / uncertain classification evidence; the state survives a simulated restore crash with complete positive evidence, workers are allowed

    The barrier test implements the fail-closed marker semantics; the queue re-run equivalence itself remains covered by the earlier synthetic trial (comment 7092268545).

  5. Alajmah commented on Nov 24, 2026

    @Alajmah
    ContributorAuthor

    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.

    Test Rejection proven Success proven
    1. roles-first restore pg_restore without the roles → exit 1 with the roles on a fresh cluster: restore completes; owners = gitwire (tables + schema), membership gitwire_app→gitwire verified, gitwire stays NOLOGIN; counts compared against the fixture's declaration, not hard-coded
    2. both-schema verification the public-only verifier passed a seed whose gitwire_auth was emptied — the current defect, demonstrated the declaration-driven both-schema verifier failed the broken seed and passed the good seed
    3. RDB version gate Redis 7.0 refused a format-12 RDB (written by 7.4) and loaded nothing the same RDB loaded on 7.4 (positive control)
    4. active-writer block with a live writer transaction open, the keeper refused and the data stayed untouched once the writer was gone, the destructive step proceeded and replaced the data
    5. worker barrier refused on: no marker, incomplete classification, any uncertain; the marker survived a simulated restore crash (fresh instance re-reads disk) opened only on complete positive evidence

    Failures 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.sh remains untouched and every hold stands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions