Repository navigation
fix(backups): check app rows, generations and handoff parts against the journal - #564
Merged
Merged
Conversation
…he journal Backup validation compared only the installation rows with the native installation journal. Dependent rows, recorded generations and the new handoff parts were tied together by foreign keys or not checked. - Read installation rows, every installation referenced by the installation-scoped app tables and the handoff journal, and the highest generation per installation in one bounded query. Reject references outside the active inventory and a journal behind the database, which the next app registration would turn into a conflict. - Trial-decrypt every legacy feature handoff part with the backed-up app key, check its content hash, and require exactly parts 0..n-1 for an exported handoff and none for a committed one. Older schemas are recognized through to_regclass. - Re-run the journal comparison after the managed, offline and CLI restores applied the database and app state, before the restore journal completes, so a mismatch keeps the appliance stopped. - Use the journal comparison for new captures and resumed portable restores; the in-place pre-restore check still compares identities. - Report app state failures as BACKUP_VALIDATION=application_state. Refs #457 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backup validation already checks that
app_runtime_installationsmatches the native installation journal, but dependent app rows, recorded generations and the new handoff parts were only tied together by foreign keys or not checked at all. A restored appliance could therefore start with rows the journal does not govern, and a journal behind the database only surfaced later as aconflictwhen the app registered its next generation.This PR closes the four remaining backup gaps of #457. Every new check fails closed before any destructive restore step and reports
BACKUP_VALIDATION=application_state.installation_idreferenced by the twelve installation-scopedapp_runtime_*tables (grants, role permissions, secrets, events and the rest) pluslegacy_feature_handoffs, and the highest generation per installation. Each reference must belong to an active installation in the backup inventory, independent of whether the dump still carries its foreign keys.app_runtime_generations.generation. The app manager registers journal generation + 1 next, which the database would reject as a conflict.legacy_feature_handoff_partsrow with the backed-up app key and itslegacy-feature-handoff:v1:<domain>:<installationId>:<sequence>:<sha256>context, and checks the plaintext against the stored hash. Eachexportedhandoff must hold exactlypart_countparts with sequences0..part_count-1, acommittedhandoff none, and no part may lack its journal row. Older backups without the tables are recognized throughto_regclass.scripts/production-restore.tsre-run the rows-versus-journal check once the database and app state are applied, before the restore journal completes. A mismatch keeps the journal pending, so the appliance stays stopped until the operator resumes or investigates. The CLI step isverify restored application state; the backup agent and the CLIs share the newbackup-export.js --check-restored-app-inventoryentry point.application_statereason instead ofruntime_validation; the restore and smoke diagnostics allow it.Related issue
Refs #457. The issue stays open for the parallel handoff transport, upgrade preview and the follow-ups below.
Follow-ups that are intentionally not part of this PR:
scripts/production-backup.tsand the legacy guards inscripts/backup/volume-commands.ts).core/src/app_manager/portable_backup.rsrequires an empty target).Type of change
Testing
bun run typecheckoxlintandoxlint --config .oxlintrc.type-aware.jsonon all changed filescore/), with synthetic data only:validate-backup.test.ts,validate-backup.coverage.test.ts: one case per new rejection plus the positive paths for v4, v5 and v6 backupsbackup-app-validation.db.test.ts(new): runs the evidence query and handoff validation against a fully migrated database, including pagination over 20 parts, a dropped foreign key with an orphaned grant, a journal behind the database, a missing part, a sequence gap, a wrong key and parts of a committed handoffproduction-restore.test.ts,production-restore-stream.test.ts: command contract of the post-restore check, its position in the portable restore, and a mismatch that leaves the appliance stopped without completing the journalmaintenance-commands.test.ts,production-smoke-ci.test.ts: the new reason passes through, unknown reasons stay hiddenapp-state.test.ts,legacy-archive-migration.db.test.tsand all ofweb/src/tests/tooling/docker/production/, including the real-PostgreSQL backup orchestration round tripsChecklist
Breaking changes
None. Backups that previously validated still do, unless their app rows disagree with their own journal, which this PR rejects on purpose. App-related validation failures now report
application_stateinstead ofruntime_validation.Screenshots
None
🤖 Generated with Claude Code