You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(backup): restore from a backup uploaded from another server - #3400
Related issue: #2313
Validation tasks: changes #1197 C1 (an uploaded restore set opens the same account restore, another web admin path that creates accounts); changes #1235 C1 and C2 (restoring accounts from an upload can replace notification preferences)
Selective restore works only with the backups a server took itself. Moving to
a new server, or recovering one server's settings and users onto another,
needs a way to bring another server's backup in. This lets an admin upload
another server's restore set and restore from it with the same preview and
rules.
Upload in parts: each part goes straight to the shared operational
store, and the session state lives in PostgreSQL, so any API server can
take any part. Each attempt is its own object, and a database row names the
copy that counts, so a late or failed attempt never replaces a good part.
Limits: 2 GiB per upload and three uploads in progress per server.
Space is reserved across servers before any byte is written. A part must
arrive within 2 minutes, and its storage write stops after 5.
Completion runs under the backup lock. It reads the parts through the
same hardened reader, freezes the SHA-256, and rejects a file that isn't a
restore set, comes from a newer Silo, or doesn't match a SHA-256 the upload
declared. Previews and restores are bound to the frozen digest.
Another SECRET_KEY: a restore set from a server with another key still
opens, but this server can't read its encrypted settings or plugin
configuration, so it never offers them (key_matches is false). An upload
is always unverified, so the admin confirms before the preview opens.
Cleanup: abandoned uploads go after 24 hours, and unused complete ones
after 7 days, never while a restore is queued from them.
UI: an upload dialog with progress, resume and clear errors, and an
"Uploaded backups" list.
Validation
Go: gofmt, build, go vet, and changed-line golangci-lint against the previous pull request: pass.
Web: tsc -b, eslint and prettier on changed files, and vitest: pass.
verify-route-inventory: pass.
Database tests against PostgreSQL 18: this pull request's contract tests pass (46 for the stack so far), covering parts sent to two servers, space reservation, deadlines, sweeping and hostile uploads.
Uploaded a 452 MB restore set from a development server to a fresh sandbox: 7 s to upload, 13 s to check, and the digest matched the downloaded file.
Revalidated on November 5, 2026 at the same head (the stack already sits on current main). On a sandbox built from feat(backup): restore accounts and profiles, and export your own data #3399, took a backup and downloaded its restore set. Rebuilt from this branch, uploaded it through the dialog, previewed it after confirming the unverified prompt, and restored a deleted account from it. Also checked that the browser and the server reject a file that isn't a restore set, that a declared SHA-256 mismatch is rejected, and that a request for 3 GiB gets 413. The test sandboxes share one SECRET_KEY, so the other-key case rests on TestRestoreFromUploadDB. The internal/backup and internal/adminjob database tests pass with PostgreSQL 18 client tools: 488 passed, none skipped.
Lock time: completion holds the backup lock for up to 10 minutes on a
slow store. A nightly run that starts then records a skip.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or says there is none.
AI Disclosure
Harness: T3 Code with Claude Code
Tool(s): Claude Code with subagents; OpenAI Codex CLI for independent review
Model(s): claude-opus-5-5; gpt-6.1-sol (review)
Involvement: Fully AI-generated. The maintainer tested the backups work it came from on a development server; the diff awaits human review.
Adversarial review: gpt-6.1-sol reviewed the backups work read-only in repeated rounds; every finding was fixed or answered before this branch was cut.
Add selective restore from backups uploaded from another server
Adds a full backup subsystem: nightly/manual backups via pg_dump streaming, restore sets (libraries, collections, settings, plugins, home sections, users), upload sessions for restore sets from other servers, and a restore job runner with fencing, cancellation, and progress reporting
Adds an admin Backups UI at /admin/backups with backup list, downloads, resumable restore-set upload, a multi-step restore chooser/review/report flow, and a Your Data page for profile export/import
Restores run per-item inside a caller transaction with planning previews, identity matching against local content, and safety rules: access-widening settings stay stricter, live credentials are never sent to a changed endpoint, signing keys rotate, and account/policy state is compared before apply
Adds PostgreSQL migrations for backup status, uploads, restore follow-ups, restored account/profile mappings, and restore item outcomes; the Docker images now install postgresql-client-18
Risk: restore path is new and large — key entry points to review are Service.ExecuteRestore in selective_apply.go, guardRoutes in selective_settings_routes.go, and the adminjob repository CTE changes in repository.go that alter Complete/Fail/CancelWithResult to also delete restore outcome rows
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
The pull request adds multipart restore-set uploads across backup storage, PostgreSQL, the admin API, and the web interface. Uploads can be validated, previewed, and used for selective restores. Upload records and parts are retained or swept according to upload status and restore activity.
Changes: Uploaded Restore Sets
Layer / File(s)
Summary
Upload storage and lifecycle migrations/sql/..., internal/backup/upload.go, internal/backup/upload_sweep.go, internal/backup/service.go, internal/backup/status.go
Adds upload sessions, part and attempt records, size and concurrency limits, space reservations, write and check deadlines, digest validation, expiry handling, and upload-aware active status.
Allows restore previews and jobs to use either a backup or an upload. Reports and active-operation metadata include the upload ID when relevant.
Admin API and schemas internal/apiv2/admin_backup_uploads.go, internal/apiv2/admin_backups.go, internal/apiv2/problem.go, internal/apiv2/router.go, contracts/api/v2/*, web/src/api/v2/*
Adds upload listing, creation, part transfer, completion, deletion, preview, and restore endpoints, with upload capability fields, request and response schemas, and upload-specific errors. The API contract files also add or revise declarations for AI, API-key, access-group, account, and Autoscan operations.
Admin web workflow web/src/App.tsx, web/src/api/v2/adminBackupUpload.ts, web/src/hooks/queries/admin/*, web/src/pages/AdminBackups.tsx, web/src/pages/AdminBackupRestore.tsx, web/src/pages/admin-backups/*
Adds upload controls, multipart progress and retry behavior, upload listing and deletion, and upload-aware restore routing and reporting.
Validation and supporting updates internal/backup/*_test.go, internal/apiv2/admin_backups_test.go, internal/api/testdata/media_routes.txt, scripts/ci/db-contracts.txt, internal/contractledger/ledger_test.go, docs/*
Adds upload lifecycle, timeout, storage, API, and restore tests. Updates route fixtures, retry-safety declarations, database contract entries, and backup documentation.
sequenceDiagram
participant Admin
participant WebUI
participant AdminBackupUploadRoutes
participant BackupService
participant PostgreSQL
participant Destination
Admin->>WebUI: Select restore-set file
WebUI->>AdminBackupUploadRoutes: Create upload and send parts
AdminBackupUploadRoutes->>BackupService: Create session and store parts
BackupService->>PostgreSQL: Record session and part state
BackupService->>Destination: Write part objects
WebUI->>AdminBackupUploadRoutes: Complete upload
AdminBackupUploadRoutes->>BackupService: Validate parts and restore set
BackupService->>Destination: Read ordered parts
BackupService->>PostgreSQL: Store digest and completion state
Admin->>WebUI: Preview or start restore
WebUI->>AdminBackupUploadRoutes: Request upload preview or restore
AdminBackupUploadRoutes->>BackupService: Read completed upload
Documented restore requests can fail, and uploads can expire sooner than documented. Resolve these issues before merging.
Security architecture risk: Low · up to 45930
Cross-server imports can affect sensitive configuration and account data. The inspected paths retain administrator authorization, explicit restore confirmation, checksum binding, and protection for queued restore sources. No material security regression was established, but deployment protections and end-to-end behavior were not fully verified.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — An administrator-accepted archive can influence selected server-wide configuration, plugins, libraries, collections, and accounts in the target installation. Its impact is therefore broader than the uploading account, but application remains downstream of the shared restore checks. Deployed tenant and environment isolation were not established.
Security Findings and Attack Paths
observed — External archive bytes reach the restore-set parser during administrator-authorized completion, before the separate confirmation required for preview or restore. Completion uses the existing bounded reader; it does not apply the archive. Later execution validates the frozen digest before state application.
Trust Boundaries and Controls
observed — The upload endpoints use the existing acting-admin operation factory. Its gate chain requires authentication, viewer access, and acting-admin authorization. Service-level source selection, consent, and digest checks remain in place independently of handler request translation.
observed — Resource controls include a 2 GiB upload limit, three active sessions across the shared database, four concurrent part attempts per upload, admission-time reservations, and per-part free-space checks. The free-space guarantee depends on the destination providing a capacity measurement.
Resilience and Maintainability Implications
observed — Queueing and deletion coordinate under the backup lock, and cleanup excludes the upload named by a queued or running restore. Failure to read active restore ownership prevents protected-source deletion. Orphan-object cleanup uses durable part and attempt references plus an age grace period.
inferred — A preview of an already-expired upload can lose a race between its lookup and retention timestamp update. This can fail the preview, but queued and running restores have separate lock-protected retention; the race does not establish a restore-integrity bypass.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 71.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title "feat(backup): restore from a backup uploaded from another server" matches the main change. The changeset adds multipart upload endpoints, upload storage, completion checks, and restore-from…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The pull request description clearly explains the backup upload, validation, restore, API, database, UI, testing, and risk changes covered by the changeset.
Full details: Title check
Explanation
The title "feat(backup): restore from a backup uploaded from another server" matches the main change. The changeset adds multipart upload endpoints, upload storage, completion checks, and restore-from-upload support, all tied to restoring from another server's backup. The title names the primary feature and does not list files.
Full details: Docstring Coverage
Explanation
Docstring coverage is 71.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 64 functions across 34 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
coderabbitaiBot
added
api-v2
API v2 / Huma migration program (epic #135); long-running, stacked by phase
evidence-required
Needs before-and-after evidence before the Evidence check passes
go
Pull requests that update go code
impact: usability
Core flow broken or severely blocked
javascript
Pull requests that update javascript code
needs-review
Needs maintainer review to resolve uncertain classification, scope, or changed evidence.
labels
Nov 2, 2026
Files not fully reviewed because their changes were unavailable: 2
contracts/api/v2/openapi.json
web/src/api/v2/schema.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Minor validation impact: the upload restore route reuses the selective Users restore flow and adds another web-admin path to create eligible restored accounts, affecting #1197 C1; invitation acceptance in C2 is unchanged. It can also import notification preferences when that data type is selected, adding a path that can change event preferences covered by #1235 C1 and C2. These are minor changes and need re-check after merge.
The PR body currently says Validation tasks: none. Suggested replacement:
Validation tasks: changes #1197 C1; changes #1235 C1 and C2
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Files skipped from review as they are similar to previous changes: 1
internal/api/backup_restore_wiring.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
The reason will be displayed to describe this comment to others. Learn more.
Follow-up Comments
Document the upload verification exception without splitting the existing sentence.
532-532: Minor · Maintainability & Code Quality · Quick win
Document the upload verification exception without splitting the existing sentence.
Upload completion decodes the restore set while computing its digest. When a declared SHA-256 is supplied, checkUpload compares it with the computed digest before the accepted digest is persisted. Preview and restore verify the archive before decoding its documents. Insert this paragraph after the existing verification paragraph, not after the trailing “The”.
📝 Suggested fix
-**Nothing inside a restore set is decoded before it is verified.** The-manifest records the restore set's digest and the digest of its index+**Nothing inside a restore set is decoded before it is verified, except at upload completion.**+The manifest records the restore set's digest and the digest of its index
...
+At upload completion, reading the restore set computes its digest and decodes+its documents. If a declared SHA-256 is supplied, the computed digest is+compared with it before the accepted digest is persisted. Preview and restore+verify the archive before they decode its documents.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 2fb25a3e-8600-47c1-81e0-f455566263f3
Commits
Reviewing files that changed from the base of the PR and between 97dda4a and 459301f.
Files selected for processing: 7
contracts/api/v2/breaking-approvals.json
docs/architecture/backups.md
internal/backup/lock_postgres_test.go
internal/backup/selective_apply_test.go
internal/backup/selective_plan.go
internal/backup/service.go
internal/backup/status.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
On CodeRabbit's review 5750373621 (docs/architecture/backups.md, "Nothing inside a restore set is decoded before it is verified"): fixed in 9369962. The code now keeps the invariant where it can, and the doc states the one exception.
With a declared SHA-256. Upload completion (checkUploadParts) hashes the whole staged file first and compares it with the declared value. Only a match is decoded. A mismatch is rejected as checksum before anything is decoded. The second pass is covered by the same check deadline, raised to 20 minutes.
Without a declared SHA-256. The set is decoded unverified. The reader's bounds alone apply: the tar guard, the entry and size caps, jsonsize before each document, and DecodeStrict with CheckBounds. Such a set can be restored only with the admin's confirmation that it is unauthenticated. The doc names this exception and these bounds.
Test.TestUploadRejectsHostileArchivesDB (the existing table) adds bytes that are neither a restore set nor the declared ones. They are rejected as checksum, which shows they were never decoded.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.
Adds uploads: an admin uploads another server's restore set in resumable
parts, the server checks it whole (hashing it first when a SHA-256 was
declared) under the backup lock, and the page previews and restores from
it like a local backup, with the admin's confirmation since nothing in an
upload can be authenticated. Abandoned uploads and checks are swept.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The completion's response deadline was 15 minutes while its check may
read the parts for 20, so a check that ran long finished after the
connection's deadline and its answer was lost. The deadline now derives
from backup.UploadCheckTimeout with two minutes to answer.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Interrupted upload checks cannot be retried from the uploads list
An interrupted completion can leave an upload in checking without a retry action. Allow fully received uploads in checking to be completed again; the backend serializes completion with the backup lock.
Prompt for LLM
File web/src/pages/admin-backups/UploadedBackups.tsx, lines 52-53:
Interrupted upload checks cannot be retried from the uploads list
An interrupted completion can leave an upload in `checking`, but this predicate hides the retry action, leaving the administrator unable to recover it from the list. Allow a fully received `checking` upload to be completed again; the backend serializes completion with the backup lock.
Suggested code:
return (upload.status === "uploading" || upload.status === "checking") && upload.received_parts === upload.part_count;
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
api-v2API v2 / Huma migration program (epic #135); long-running, stacked by phaseenhancementNew feature or requestevidence-requiredNeeds before-and-after evidence before the Evidence check passesgoPull requests that update go codeimpact: usabilityCore flow broken or severely blockedjavascriptPull requests that update javascript codeneeds-reviewNeeds maintainer review to resolve uncertain classification, scope, or changed evidence.priority: P2Limited scope, workaround exists, or polishsize/XXXL3000+ added + deleted lines (all files); change volume, not priority.stackedBase is another open PR; merge in stack order named in the body
1 participant
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.
Problem
Related issue: #2313
Validation tasks: changes #1197 C1 (an uploaded restore set opens the same account restore, another web admin path that creates accounts); changes #1235 C1 and C2 (restoring accounts from an upload can replace notification preferences)
Selective restore works only with the backups a server took itself. Moving to
a new server, or recovering one server's settings and users onto another,
needs a way to bring another server's backup in. This lets an admin upload
another server's restore set and restore from it with the same preview and
rules.
Stacked on #3399.
Approach
store, and the session state lives in PostgreSQL, so any API server can
take any part. Each attempt is its own object, and a database row names the
copy that counts, so a late or failed attempt never replaces a good part.
Space is reserved across servers before any byte is written. A part must
arrive within 2 minutes, and its storage write stops after 5.
same hardened reader, freezes the SHA-256, and rejects a file that isn't a
restore set, comes from a newer Silo, or doesn't match a SHA-256 the upload
declared. Previews and restores are bound to the frozen digest.
SECRET_KEY: a restore set from a server with another key stillopens, but this server can't read its encrypted settings or plugin
configuration, so it never offers them (
key_matchesis false). An uploadis always unverified, so the admin confirms before the preview opens.
after 7 days, never while a restore is queued from them.
"Uploaded backups" list.
Validation
go vet, and changed-line golangci-lint against the previous pull request: pass.verify-apiv2-openapi,-web-types,-fixtures,-contract(additive only),verify-migrations,verify-migration-ledger,verify-size-ratchet,verify-local-paths,verify-settings-bindings: pass.tsc -b, eslint and prettier on changed files, and vitest: pass.verify-route-inventory: pass.main). On a sandbox built from feat(backup): restore accounts and profiles, and export your own data #3399, took a backup and downloaded its restore set. Rebuilt from this branch, uploaded it through the dialog, previewed it after confirming the unverified prompt, and restored a deleted account from it. Also checked that the browser and the server reject a file that isn't a restore set, that a declared SHA-256 mismatch is rejected, and that a request for 3 GiB gets 413. The test sandboxes share oneSECRET_KEY, so the other-key case rests onTestRestoreFromUploadDB. Theinternal/backupandinternal/adminjobdatabase tests pass with PostgreSQL 18 client tools: 488 passed, none skipped.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3400/
Risks
backup_status. Additive.main, which stops a localwrite when its request is cancelled.
slow store. A nightly run that starts then records a skip.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Add selective restore from backups uploaded from another server
pg_dumpstreaming, restore sets (libraries, collections, settings, plugins, home sections, users), upload sessions for restore sets from other servers, and a restore job runner with fencing, cancellation, and progress reporting/admin/backupswith backup list, downloads, resumable restore-set upload, a multi-step restore chooser/review/report flow, and a Your Data page for profile export/importpostgresql-client-18Service.ExecuteRestorein selective_apply.go,guardRoutesin selective_settings_routes.go, and the adminjob repository CTE changes in repository.go that alterComplete/Fail/CancelWithResultto also delete restore outcome rowsMacroscope summarized b6f6b1a.