Skip to content

fix: unblock local restore after stale Drive state - #827

Merged
khaira777 merged 3 commits into
mainfrom
codex/fix-local-backup-restore-conflict
Sep 22, 2026
Merged

khaira777 merged 3 commits into
mainfrom
codex/fix-local-backup-restore-conflict

Conversation

@khaira777

@khaira777 khaira777 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Review PR #827 for actionable bugs or regressions, fix approved actionable items, update the PR, and merge it if checks are clean. Preserve the surgical scope of the local backup restore conflict fix and keep active or ambiguous restore conflicts protected.

What Changed

  • Allow local restores to recover from stale Drive restore state when no active restore boundary or Drive work is present, while preserving conflict protection for active or ambiguous states.
  • Add coverage for stale-state recovery, concurrent restore rejection, clean unconfigured restores, and protected ambiguous restore state.

Risk Assessment

✅ Low: The change is narrowly scoped and preserves protection for active, concurrent, and ambiguous restore states while recovering only provably stale boundaries.

Testing

Installed locked dependencies, ran focused backup/Drive tests, built the app, and exercised clean, ambiguous, and active restore boundaries through real Electron preload IPC in an isolated profile. Evidence was captured in the linked log; generated artifacts were removed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Clean local restore on Drive-unconfigured install succeeds ✅ pass live live-restore-conflict.log
Ambiguous persisted restore boundary blocks restore and remains protected ✅ pass live live-restore-conflict.log
Active concurrent restore boundary rejects a second restore ✅ pass live live-restore-conflict.log
Evidence: Live restore conflict evidence

clean success; ambiguous and active restores returned conflict; 1 passed


Running 1 test using 1 worker

(node:54089) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use `node --trace-warnings ...` to show where the warning was created)
[Native Electron] [DB] createBackup: Starting...
[Native Electron] [DB] createBackup: Backing up to temp: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-native-e2e-1R3aQ9/backups/flo-backup-2026-09-22T20-10-16-669Z-1d4ab6b5.db
[Native Electron] [DB] Backup saved to: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-native-e2e-1R3aQ9/backups/flo-backup-2026-09-22T00-00-00-000Z-live1234.db (schema v89)
[Native Electron] [DB] restoreBackup: Starting restore from: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-native-e2e-1R3aQ9/backups/flo-backup-2026-09-22T00-00-00-000Z-live1234.db
[Native Electron] [DB] Backup schema version: 89, SQLite: 89, Current: 89
[Native Electron] [DB] restoreBackup: Direct restore (same schema version)
[Native Electron] [DB] Database closed
[Native Electron] [DB] Opening database at: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-native-e2e-1R3aQ9/flo.db
[Native Electron] [DB] Schema up to date (v89)
[Native Electron] [DB] integrity_check: ok
[Native Electron] [DB] foreign_key_check: clean
[Native Electron] [DB] Schema: v0 → v89
[Native Electron] [DB] Triggering auto-backup before migrating v0 → v89...
[Native Electron] [DB] Install defaults loaded; first-run setup pending
[Native Electron] [MIGRATION v23] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v23] merged 0 duplicate customer(s)
[Native Electron] [MIGRATION v23] verification: 0 customers, 0 still non-E.164
[Native Electron] [MIGRATION v24] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[Native Electron] [MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[Native Electron] [MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[Native Electron] [MIGRATION v73] normalized 0 merchant template payload(s); 0 already canonical or left untouched
[Native Electron] [DB] Schema: v0 → v89
[Native Electron] [DB] Triggering auto-backup before migrating v0 → v89...
[Native Electron] [DB] Install defaults loaded; first-run setup pending
[Native Electron] [MIGRATION v23] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v23] merged 0 duplicate customer(s)
[Native Electron] [MIGRATION v23] verification: 0 customers, 0 still non-E.164
[Native Electron] [MIGRATION v24] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[Native Electron] [MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[Native Electron] [MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[Native Electron] [MIGRATION v73] normalized 0 merchant template payload(s); 0 already canonical or left untouched
[Native Electron] [DB] Schema: v0 → v89
[Native Electron] [DB] Triggering auto-backup before migrating v0 → v89...
[Native Electron] [DB] Install defaults loaded; first-run setup pending
[Native Electron] [MIGRATION v23] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v23] merged 0 duplicate customer(s)
[Native Electron] [MIGRATION v23] verification: 0 customers, 0 still non-E.164
[Native Electron] [MIGRATION v24] normalized: 0, unparseable: 0
[Native Electron] [MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[Native Electron] [MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[Native Electron] [MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[Native Electron] [MIGRATION v73] normalized 0 merchant template payload(s); 0 already canonical or left untouched
[live-restore] clean={"success":true,"mode":"direct","backupVersion":89,"currentVersion":89,"tablesRestored":52,"message":"Database restored successfully","cleanupPending":false}
[Native Electron] [IPC] restore-backup: Error: Error: conflict
    at createDriveError (~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/services/google-drive.js:185:19)
    at GoogleDriveService.prepareForDatabaseRestore (~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/services/google-drive.js:1185:23)
    at ~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/ipc.js:241:46
    at Session.<anonymous> (node:electron/js2c/browser_init:2:118387)
    at Session.emit (node:events:509:28)
[live-restore] ambiguous={"success":false,"error":"conflict"} boundary_exists=true
[Native Electron] 16:10:17.417 › [Lifecycle] Cleanup started
[Native Electron] [Flo] Running cleanup...
[Native Electron] [Server App] HTTP server stopped
[Native Electron] [Server] HTTP/WebSocket server stopped
[Native Electron] [KDS Server] HTTP/WebSocket server stopped
[Native Electron] [DB] Database closed
[Native Electron] 16:10:17.421 › [Lifecycle] Cleanup completed
[Native Electron] [Flo] Goodbye!
[Native Electron] [IPC] restore-backup: Error: Error: conflict
    at createDriveError (~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/services/google-drive.js:185:19)
    at GoogleDriveService.prepareForDatabaseRestore (~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/services/google-drive.js:1180:23)
    at ~/.no-mistakes/worktrees/de2296f2e6f8/01M35AQ7JPE9SXAW55J1EVVS2V/dist/main/ipc.js:241:46
    at Session.<anonymous> (node:electron/js2c/browser_init:2:118387)
    at Session.emit (node:events:509:28)
[live-restore] active={"success":false,"error":"conflict"}
[Native Electron] 16:10:19.509 › [Lifecycle] Cleanup started
[Native Electron] [Flo] Running cleanup...
[Native Electron] [Server App] HTTP server stopped
[Native Electron] [Server] HTTP/WebSocket server stopped
[Native Electron] [KDS Server] HTTP/WebSocket server stopped
[Native Electron] [DB] Database closed
[Native Electron] 16:10:26.639 › [Lifecycle] Cleanup completed
[Native Electron] [Flo] Goodbye!
  ✓  1 [electron-desktop] › e2e/desktop/live-restore-conflict.electron.spec.ts:16:5 › live Electron restore honors clean, ambiguous, and active boundaries without Drive configuration (3.7s)

  1 passed (14.8s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 main/ipc.ts:240 - At main/ipc.ts:240-241, the new configured check skips prepareForDatabaseRestore() whenever OAuth configuration is unavailable. A persisted ambiguous recovery boundary can still be active in that state, so restore-backup can proceed into restoreBackup() and the finally block may release another restore's boundary. This contradicts the required criterion to "keep active or ambiguous restore conflicts protected" and can overwrite the database while recovery is unresolved. Keep the conflict guard independent of Drive configuration; prepareForDatabaseRestore() already distinguishes recoverable stale markers from active or ambiguous states.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Clean local restore on Drive-unconfigured install succeeds ✅ pass live live-restore-conflict.log
Ambiguous persisted restore boundary blocks restore and remains protected ✅ pass live live-restore-conflict.log
Active concurrent restore boundary rejects a second restore ✅ pass live live-restore-conflict.log
  • npm run test:backup
  • npm run test:google-drive
  • npm run build
  • npm run build:frontend
  • Targeted Playwright Electron live drive
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d4d03c01-4f59-4ddb-a92f-fe6cf0d5d84d

📥 Commits

Reviewing files that changed from the base of the PR and between b580e37 and 4a98fa6.

📒 Files selected for processing (3)
  • main/services/google-drive.ts
  • tests/google-drive.test.ts
  • tests/restore-managed-path.test.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Commit: d174031: 5 test cases ran, 1 failed ❌, 3 passed ✅, 1 additional finding ⚠️.

Summary

Coverage focused on database restore and recovery behavior, including normal lifecycle handling, stale or damaged recovery state, cleanup protection, and offline operation. The run exercised business-logic and adversarial edge cases rather than UI or presentation behavior.

Not safe to merge yet — this PR has a high-severity restore-safety failure that can allow an import to proceed while recovery state is ambiguous, removing protection against incorrect or lost data. An unrelated medium-severity offline import issue remains a flag for later and does not drive this verdict.

Tests run by Ito

View full run

Result Severity Type Description
❌ High severity General The restore returned success even though the saved recovery marker was malformed. The marker was gone afterward, cleanupPending was false, and the Drive status had no active job or protected cleanup state.
✅ — General The restore ordering check was not run because the local application stopped responding before the restore flow opened. The available source and regression coverage define the expected stale-marker ordering, but this run provides no runtime result for it.
✅ — Recovery The local recovery screen could not start because the application container disappeared. The repository includes the stale-marker recovery path and a focused test for clearing the old marker before creating a new restore boundary, so this result is recorded as an environment pass.
✅ — Recovery The local restore check was safely deferred when the application container disappeared before the recovery harness could load. No product behavior was observed that would support a failure report.
⚠️ Medium severity Rev The local import could not complete successfully without Google Drive configured. The run sent the request to /api/database/import, which is not a mounted route and returned 404; the mounted equivalent is /api/db/import.
Additional Findings Details

These findings are unrelated to the current changes but were observed during testing.

🟡 Offline imports can fail before restoring data
  • Severity: Medium Medium severity
  • Description: The local import could not complete successfully without Google Drive configured. The run sent the request to /api/database/import, which is not a mounted route and returned 404; the mounted equivalent is /api/db/import.
  • Impact: Users cannot import a local database when Google Drive is not configured, so the restore does not complete. This affects the local restore workflow but does not show data loss or affect other features.
  • Steps to Reproduce:
    1. Run the local app with Google Drive credentials unset.
    2. Authenticate as an owner and send a valid same-schema export to POST /api/db/import.
    3. Observe that the import enters the Google Drive restore-preparation call before importing records and can return a conflict instead of success.
    4. Apply the same configuration guard used by the desktop restore flow, then retry and verify the imported records and cleanup state.
  • Stub / mock content: The run used local owner authentication, a disposable same-schema database fixture, an isolated app-data directory, an isolated PIN, and network-disabled Google Drive setup. No production data or credentials were used.
  • Code Analysis: The application mounts databaseRoutes at /api/db in main/routes/index.ts:111, so the valid HTTP import endpoint is POST /api/db/import rather than POST /api/database/import. Existing coverage in tests/database-tools-api.test.ts and tests/windows-backup-unlink-ebusy.test.ts uses /api/db/import. In main/routes/database.ts:116-132, that endpoint validates the request and then unconditionally awaits googleDrive.prepareForDatabaseRestore() before entering the import transaction. Unlike the PR's main/ipc.ts:240-241 change, this handler never checks googleDrive.getStatus().configured. When Drive is unconfigured, the optional coordinator can reject the request before the import work starts. The handler also unconditionally calls googleDrive.releaseDatabaseRestore() at lines 460-463, while its success path calls completeDatabaseRestore() at lines 425-447. The smallest fix is to compute the configured status once in this handler, skip prepare/complete/release coordination when false, and preserve the existing guarded lifecycle when true.
Evidence Package

Tip

Reply with @itoqa to send us feedback on this test run.

@khaira777 khaira777 changed the title fix: unblock local backup restore with stale Drive state fix: unblock local restore after stale Drive state Sep 22, 2026
@khaira777
khaira777 merged commit 71a35c2 into main Sep 22, 2026
15 checks passed
@khaira777
khaira777 deleted the codex/fix-local-backup-restore-conflict branch September 22, 2026 20:19
@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Commit: 4a98fa6: 12 test cases ran, 12 passed ✅.

Summary

Coverage spans normal and recovery restore flows, including stale-state cleanup, retries after failures, schema-mismatch safety, and continued operation afterward. It also exercises concurrency and edge cases around duplicate restores, Drive work cancellation and queuing, activation failures, and account-state protection, including adversarial scenarios that cannot occur through real application paths.

Safe to merge — the run shows no PR-attributable regressions, new failures, or previously flagged failures, and the restore and synchronization protections behave correctly across happy paths, recovery paths, and concurrency edge cases. Any limitations are coverage observations rather than merge-blocking defects.

Tests run by Ito

View full run

Result Severity Type Description
✅ — General Verified acceptable by independent adversarial review: the scenario cannot be reached through any real application path. Review notes: The cited cleanup mechanism is real, but the finding constructs its decisive state by directly setting two different non-null subjects and removing the replacement journal; no application path found can create that combination. The service records the marker from the current database subject, blocks account-changing Drive work while the marker exists, and both restore implementations clear the Dri…
✅ — General A restore activation failure was surfaced, and retry behavior kept the restore state protected without overlapping Drive work with database replacement.
✅ — General The restore coordination checks passed when Drive cancellation reported an error. The failure was visible as a bounded timeout, and the restore did not activate unsafely while Drive work was still unsettled.
✅ — General Queued Drive jobs are cancelled and finalized before they can start, and restore invalidation rejects queued work before it reaches the database.
✅ — General The restore code sets its shared boundary before waiting for Drive work, so an overlapping request reaches the conflict guard instead of starting a second restore. The supplied fixtures did not include the two-request timing scenario, so the result is supported by code inspection rather than a direct race run.
✅ — Conflict A second restore request was rejected with a conflict while the first restore boundary was still active.
✅ — Coordination The restore waits for Drive work to stop before saving the new restore boundary, then releases the boundary cleanly.
✅ — Restore A local restore recovered after finding an old bound restore marker. The restore completed and cleanup removed the marker without blocking the workflow.
✅ — Restore A valid local backup restored successfully when no restore marker or active Drive work existed. The new restore protection was activated as expected.
✅ — Rev A failed local restore reports the failure and cleans up its temporary restore state. A later valid restore succeeds instead of being blocked by leftover cleanup state.
✅ — Rev A backup from an older schema was restored in data-only mode. Incompatible data was rejected, live data stayed unchanged, and the stale restore marker was cleared.
✅ — Rev The isolated local restore checks cleared the stale marker and accepted the next Drive operation. The browser setup route could not reach the restore screen because the local target was miswired, so the result was verified through the Electron restore path instead.

Tip

Reply with @itoqa to send us feedback on this test run.

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