fix(brain-repo): allow restore wizard to list snapshots before connect#77
Open
mt-alarcon wants to merge 1 commit into
Open
Conversation
The restore wizard ran before BrainRepoConfig was persisted, so /api/brain-repo/snapshots and /api/brain-repo/restore/start aborted with "Brain repo not connected". The only workaround was inserting config directly via Python (see [C]contabo-brain-restore.py). Both endpoints now accept an optional token + repo_url pair (query string on snapshots, JSON body on restore/start). When provided they bypass the persisted-config requirement; when absent the legacy fallback to BrainRepoConfig is preserved, so /settings/brain-repo and reconnect flows are unaffected. Wizard now propagates the PAT from RestoreSelectRepo through RestoreFlow into both RestoreSelectSnapshot and RestoreExecute. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Reviewer's GuideBackend brain-repo restore endpoints now accept an explicit token + repo_url so the onboarding restore wizard can list and restore snapshots before a BrainRepoConfig is persisted, while preserving the previous behavior when overrides are not provided. The frontend restore wizard threads token and repoUrl through all steps and attaches them to the snapshots and restore/start API calls. Sequence diagram for restore wizard token and repo_url propagationsequenceDiagram
actor User
participant RestoreFlow
participant RestoreSelectRepo
participant RestoreSelectSnapshot
participant RestoreExecute
participant Backend as BrainRepoBackend
User->>RestoreFlow: start restore wizard
RestoreFlow->>RestoreSelectRepo: render select-repo
User->>RestoreSelectRepo: selectRepo(html_url) + token
RestoreSelectRepo->>RestoreFlow: onNext(repoUrl, token)
RestoreFlow->>RestoreSelectSnapshot: render select-snapshot(repoUrl, token)
RestoreSelectSnapshot->>Backend: api.get(/brain-repo/snapshots?token&repo_url)
Backend-->>RestoreSelectSnapshot: SnapshotData
RestoreSelectSnapshot->>RestoreFlow: onNext(snapshot)
RestoreFlow->>RestoreExecute: render execute(snapshot, token, repoUrl)
RestoreExecute->>Backend: fetch(/api/brain-repo/restore/start, {ref, include_kb, token, repo_url})
Backend-->>RestoreExecute: stream restore steps
RestoreExecute-->>User: onComplete()
Flow diagram for snapshots and restore_start override vs config fallbackflowchart TD
A[Request to /api/brain-repo/snapshots or /api/brain-repo/restore/start] --> B{token and repo_url provided?}
B -- Yes --> C[Use override_token and override_repo_url]
C --> D[get_repo_info or _resolve_repo]
D --> E[list_snapshots or start_restore]
B -- No --> F[_get_config]
F --> G{config and github_token_encrypted?}
G -- No --> H[abort 400 Brain repo not connected]
G -- Yes --> I[_decrypt_token]
I --> J{token decrypted?}
J -- No --> K[abort 400 Could not decrypt stored token]
J -- Yes --> L[Use config.repo_url and decrypted token]
L --> E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Problem
The restore wizard runs before `BrainRepoConfig` is persisted (it's a first-run / reconfigure flow). However, `/api/brain-repo/snapshots` and `/api/brain-repo/restore/start` both require a persisted config — they abort with `400 "Brain repo not connected"`.
This creates a catch-22: users selecting a repo via the wizard cannot list its snapshots, blocking the entire restore flow.
Solution
Both endpoints now accept an optional `token` + `repo_url` pair (query string on `/snapshots`, JSON body on `/restore/start`). When provided, they bypass the persisted-config requirement. When absent, the legacy fallback to `BrainRepoConfig` is preserved.
This mirrors the same opt-in token override that `/api/brain-repo/detect` already accepts.
Changes
Backend (`dashboard/backend/routes/brain_repo.py`):
Frontend (`dashboard/frontend/src/pages/onboarding/restore/*.tsx`):
Verification
Impact
Unblocks the wizard restore flow for any user setting up a new EvoNexus instance from an existing brain repo (disaster recovery, new server migration, etc.).
Summary by Sourcery
Allow the restore wizard to list and execute brain repo snapshots using an explicit token and repo URL before a BrainRepoConfig is persisted.
New Features: