Skip to content

fix: harden fail-closed backup safety - #139

Merged
Serph91P merged 3 commits into
developfrom
fix/dv-fail-closed-backup-safety
Jul 11, 2026
Merged

Serph91P merged 3 commits into
developfrom
fix/dv-fail-closed-backup-safety

Conversation

@Serph91P

Copy link
Copy Markdown
Owner

Summary

  • persist an explicit failed sync row for every configured storage that omits an archive or key-sidecar result
  • wait for archive creation and restore extraction workers to finish before cancellation propagates and container restart cleanup begins
  • redact hook arguments, stdout, and stderr from application logs, backup logs, progress notifications, and raised messages

Fail-closed guarantees

  1. Local archives and key sidecars are deleted only after explicit success from every required storage.
  2. Cancellation cannot restart a stopped container while an archive or extraction worker is still touching data.
  3. Hook logs expose only the validated executable name and generic timeout or exit-status information.

Test evidence

RED against pre-remediation commit 3bfddb6:

pytest -o addopts='' -q tests/test_backup_engine.py -k '<seven new regression tests>'
7 failed, 41 deselected

The failures covered the missing executor helper, early archive cancellation, restore restart before worker completion, absent remote sync rows, an incorrectly completed missing key result, and hook marker leakage in exceptions and logs.

GREEN focused suite:

pytest -o addopts='' -q tests/test_backup_engine.py
48 passed, 1 warning in 1.38s

Full CI-equivalent backend suite:

pytest --cov=app --cov-report=xml --cov-report=html
126 passed, 4 warnings in 3.40s
Required test coverage of 34% reached. Total coverage: 38.69%

Hygiene:

ruff check app/ tests/test_backup_engine.py
All checks passed!
ruff format --check app/ tests/test_backup_engine.py
28 files already formatted
git diff --check
clean
U+2013/U+2014 count: 0
credential/private-key pattern matches in diff: 0

Remaining risk

The backend suite still emits four pre-existing warnings: three Starlette HTTP 422 deprecation warnings and one existing AsyncMock coroutine warning in test_create_backup. No real remote storage or live container cancellation was exercised; deterministic synchronized worker tests cover the ordering contract.

Closes #138

Serph91P added 3 commits July 10, 2026 14:36
Validate remote upload results before deleting local artifacts.
Require complete encryption output and clean partial files on failure.
Abort on container stop failures and retry required restarts.
Persist cancellation as a failed backup while preserving cancellation.

Fixes #134
Persist explicit failures for missing remote results, defer cancellation
until archive workers finish, and redact hook arguments and output.
@Serph91P

Copy link
Copy Markdown
Owner Author

Independent review found one blocking fail-closed gap.

BackupEngine._sync_to_remote only creates BackupStorageSync rows after backend initialization and archive upload complete (backend/app/backup_engine.py:1134-1149). If initialization, credential decryption, add_storage, or the archive-level sync_backup call raises (backend/app/backup_engine.py:1006-1065), control jumps to the outer handler at backend/app/backup_engine.py:1202-1215, which logs and reports progress but persists no result for any configured storage ID. This violates the issue requirement that every configured remote ID receive an explicit persisted result, including uninitialized storage.

Please initialize a fail-closed result for every required ID before fallible setup/upload work and persist those failures even when setup or the archive sync call raises. Add focused tests for an initialization exception and an archive sync_backup exception, asserting one failed row per configured ID and no local deletion.

Local verification otherwise passed: 48 focused tests, 126 full backend tests, Ruff check, Ruff format check, and git diff --check.

@Serph91P

Copy link
Copy Markdown
Owner Author

Independent review finding

Blocking: remote setup or archive-sync exceptions do not persist a result for every configured storage.

backend/app/backup_engine.py:1006-1056 initializes all backends inside one broad try, and backend/app/backup_engine.py:1060-1065 performs the archive sync before normalized_results is built. Any exception from configuration/decryption/backend construction or from sync_backup() jumps directly to backend/app/backup_engine.py:1202-1215, which only logs/notifies. No BackupStorageSync failure rows are inserted for the required IDs, violating the explicit persisted-result contract. Existing tests cover omitted entries in a returned map, but not initialization failure or a raised archive-sync call.

Focused remediation: handle initialization per storage ID and synthesize (False, <generic bounded reason>) for failed initialization; if archive sync raises, synthesize failures for all required IDs; then always run the common persistence/counting path. Add regressions for add_storage() failure and sync_backup() raising, asserting one failed row per configured ID, accurate failure progress, and no local deletion.

Local verification otherwise passed: focused backup engine suite 48 passed; complete backend suite 126 passed with 38.69% coverage; Ruff check and format verification passed; git diff --check passed. All current remote checks are green.

@Serph91P

Copy link
Copy Markdown
Owner Author

Independent review summary

Verdict: No blocking findings

Verified

  • Branch descends from current origin/develop; PR targets develop and is mergeable.
  • Complete diff and all three branch commits reviewed. Scope is limited to backup lifecycle safety in backend/app/backup_engine.py and its tests.
  • Every required storage ID is normalized into a persisted completed or failed row. Missing archive or key results remain failed, and local deletion requires explicit combined success for every required storage.
  • Archive creation and restore extraction use cancellation-safe executor waiting before restart cleanup.
  • Hook arguments and process output are absent from logs, progress, and raised errors.
  • Focused suite: 48 passed.
  • Complete backend suite: 126 passed, 4 known warnings, 38.69% coverage.
  • Ruff check: passed. Ruff format check: 28 files already formatted.
  • git diff --check and Unicode dash additions check: clean.
  • All current remote checks are successful.

GitHub does not allow the PR author account to formally approve its own PR, so this is recorded as the independent review result instead.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant