Repository navigation
feat: let users choose JSON or SQLite when profile copies diverge - #23278
Conversation
Replace the copy-a-command startup dialog for diverged JSON/SQLite profile state with Use SQLite / Use JSON buttons. The choice relaunches Orca into the locked recovery preflight, applies it, then starts normally. Adds a current-sqlite recovery selector (and --current-sqlite CLI flag) that archives the diverged JSON and republishes it from SQLite.
There was a problem hiding this comment.
ℹ️ Minor suggestions only.
Reviewed changes
This is a fresh review of the full 16-file diff at a93066b1bb (the PR's only commit). I traced the adoption path, the relaunch/lock ordering, and the CLI/spec wiring; two independent deep-dives confirmed there is no data-loss or lock-ordering defect in the change.
- Divergence tagging —
bootstrapProfileStateAuthoritytags the both-copies/no-marker error withdivergence: 'diverged-json', andisDivergedProfileStateFailureroutes only that case to the new choice dialog; every other ambiguous/unreadable state keeps the copy-command dialog. - Startup choice dialog + desktop relaunch —
index.tsshowschooseProfileStateCopy(SQLite/JSON/Quit with save times), thenapp.relaunchwithprofileStateDesktopRecoveryArgsand exits. The new--profile-state-desktop-recoveryflag applies the choice through the lock-owning preflight and relaunches ordinary startup, or shows an error dialog on failure. current-sqliterecovery —adoptCurrentDatabasevalidates SQLite, quarantines (copies) the database family and the diverged JSON, removes the JSON, and republishes it from SQLite via the compatibility export (which updates the acceptance marker), restoring the original JSON if the rewrite fails. The SQLite database itself is never removed.- CLI/spec parity —
--current-sqliteadded to the shared selector schema, CLI flag set, handlerparseSelector, command spec, andformatRollback;syncHttp1CompatibilityMarkerextracted for reuse.
The adoption path is safe against partial failure: the acceptance marker's accepted/pending hashes are always the SQLite export, never the diverged JSON, so a failure can only re-expose the same resolvable divergence or fall back to an intact SQLite-only startup. The three-process desktop flow cannot deadlock on locks — Electron's relauncher starts the replacement only after the current process has exited, so the dead process's participant owner is reclaimable and the single-instance lock is released before the recovery process acquires both. stripRecoveryArgs removes flag and payload, so there is no relaunch loop.
ℹ️ Nitpicks
src/main/index.ts:142usesapp.getPath('userData')for the recovery request, while the rest of the persistence/startup stack deliberately usesgetCanonicalUserDataPath()to dodge late-resolution differences afterapp.setName. It resolves to the same root today, but using the canonical accessor here would match the surrounding convention and remove the subtlety.- The two new
app.relaunchcalls bypassrelaunchApp(), so these relaunches record noapp_relaunch_requestedbreadcrumb, and the choice path exits with code1where theapp:relaunchhandler uses0. Passing custom args rules outrelaunchApp()as-is, but recording the breadcrumb (and exiting0when a relaunch is queued) would keep diagnostics consistent.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| try { | ||
| // Validate before archiving so an unreadable database leaves both copies untouched. | ||
| authority.readInitialState() | ||
| if (authority.revision === 0) { |
There was a problem hiding this comment.
This guard correctly refuses an empty SQLite, but the dialog recommends exactly this action: when both copies exist and SQLite is at revision 0 (no acceptance marker, so readAcceptedState returns undefined), the new divergence dialog shows and its default button "Use SQLite (Recommended)" guarantees this throw, bouncing the user through a relaunch plus error dialog before they can pick JSON.
Technical details
# Empty SQLite makes the recommended dialog choice a dead end
## Affected sites
- `src/main/persistence/profile-state/profile-state-recovery-command.ts:136-141` — throws on `authority.revision === 0`.
- `src/main/persistence/profile-state/profile-state-documents.ts:170-185` — `readAcceptedSnapshot` returns `undefined` whenever the marker is missing, so an empty (revision-0) database alongside any JSON classifies as `both` and reaches the divergence dialog.
- `src/main/persistence/profile-state/profile-state-startup-recovery-dialog.ts:81-88` — `defaultId: 0` presents "Use SQLite (Recommended)".
## Reachability
A user who launches this build once (creating and leaving an empty `profile-state.db`) and then opens the profile in an older build (which writes `orca-data.json`) lands in exactly this state: classification `both`, no acceptance marker, SQLite empty. Clicking the recommended button cannot succeed; the user must reopen Orca and choose JSON.
## Required outcome
Choosing "Use SQLite" on an empty database should not be a guaranteed failure. Either surface (or preselect) JSON when SQLite has no revision, or have the choice path treat an empty SQLite as the JSON selection so the user is not sent through a failed relaunch first.
## Open questions for the human
- Is an empty database alongside JSON genuinely expected `diverged-json` input, or should the bootstrap classify it separately so the dialog never offers SQLite?…ablyai#23278) Replace the copy-a-command startup dialog for diverged JSON/SQLite profile state with Use SQLite / Use JSON buttons. The choice relaunches Orca into the locked recovery preflight, applies it, then starts normally. Adds a current-sqlite recovery selector (and --current-sqlite CLI flag) that archives the diverged JSON and republishes it from SQLite. Co-authored-by: m4air <[email protected]>

ELI5
Sometimes a profile ends up with two saved copies that disagree — usually after opening it in an older version of Orca. Orca used to stop and show a wall of text plus a "copy recovery command" button, so the user had to go run a CLI command. Now it just asks: Use SQLite (Recommended) or Use JSON, and fixes it for you.
What Changed
Before: startup failed with "Orca cannot safely choose a profile-state authority…", listing several
orca profile state …commands and a "Copy recovery command" button (which actually copiedorca profile state exports, not the fix).After: for this specific case (both copies readable, JSON changed without SQLite accepting it), Orca shows a plain dialog explaining the two copies, with each copy's last-saved time, and three buttons: Use SQLite (Recommended), Use JSON, Quit. Picking one restarts Orca, applies the choice, and opens normally. If applying fails, Orca shows the reason and quits without starting.
Mechanism:
divergence: 'diverged-json') so only it gets the choice dialog; every other ambiguous/unreadable-state error keeps the existing copy-command dialog.--profile-state-desktop-recoveryflag. That runs the existing recovery preflight (which takes the profile maintenance lock and the single-instance lock), thenapp.relaunch()es with the original arguments.current-jsonrecovery.current-sqliterecovery: validate SQLite is readable, archive the database and the diverged JSON into a quarantine folder, then rewriteorca-data.jsonfrom SQLite via the normal compatibility export (which also updates the acceptance marker). If the rewrite fails, the original JSON is put back.orca profile state rollback --current-sqlite.Why
The user has to make this decision anyway; making them copy a command, quit, find a terminal and run it is needless friction. Recovery runs in a fresh relaunched process rather than in the failed one because the failed startup may still hold profile locks and partially-initialized state; the preflight path is already the audited, lock-owning recovery route the CLI uses.
Linked Issue
N/A (maintainer change)
Visual Proof
N/A — native Electron message box; not yet captured. Dialog content is asserted in
profile-state-startup-recovery-dialog.test.ts.Testing
New/updated tests:
profile-state-current-sqlite-command.test.ts(keep SQLite, unparseable JSON, unreadable SQLite leaves both untouched, JSON restored on export failure, admission refusal, error tagging), desktop relaunch/failure/malformed cases inprofile-state-recovery-preflight.test.ts, choice-dialog tests, CLI--current-sqlitehandler/spec tests.pnpm tc:node,pnpm tc:cli, oxlint and oxfmt pass. Not yet manually exercised end to end on a real diverged profile — the relaunch happening pre-readyis the main thing to eyeball. Threeprofile-state-backup-rotation.test.tstests time out locally on a cleanmaintree as well (pre-existing, unrelated).Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Cross-platform: uses
app.relaunch/dialog/path-based helpers only. SSH/remote: local profile startup only; no wire changes (the recovery selector is exchanged only between CLI and app of the same install). Serve/background launches never show the dialog.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)