Skip to content

MnemoSync Phase 0: verified project backups and safe restore - #3

Merged
ehitimum merged 11 commits into
mainfrom
codex/mnemosync-backup
Nov 24, 2026
Merged

ehitimum merged 11 commits into
mainfrom
codex/mnemosync-backup

Conversation

@ehitimum

@ehitimum ehitimum commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Add the first MnemoSync Phase 0 implementation: native local project recovery archives, before any transport or merge can mutate existing projects. Depends on #2 and targets its strategy branch; retarget after #2 merges.

Writers can create a backup in Settings, save a separate ZIP copy, and restore a selected backup. Desktop cards and phone rows use the existing visual conventions. The browser explains native-only availability. Progress, cancellation, errors, retry, duplicate requests and early file-size checks are covered by mounted tests. The App persists the latest dirty chapter first and aborts backup when that save fails.

Native ZIPs contain a versioned SHA-256/length manifest and allowlisted chapters, hierarchy, maps, assets, AI conversations and exports. Credentials, registry and pairing grants are excluded. Extraction rejects corruption, unsafe paths, case collisions, links, unsupported versions and oversized data. Restore verifies in private staging, activates a fresh UUID and visible (restored) name, disconnects the AI configuration, then registers the copy. Originals stay intact. Image attributes and known map asset fields relocate structurally, including Windows paths and HTML entities; prose and graph IDs remain unchanged.

Validation:

  • npm run check: lint, types, all 130 tests and production build pass.
  • npm run test:regression: 41 regressions pass (10 new backup UI/App tests, plus shared runtime and fixed-clock AI history regressions).
  • cargo check passes.
  • cargo test: 56 pass, including 11 new archive tests; 3 existing live-AI tests intentionally ignored. Loopback pairing passes with network permission.
  • cargo clippy -- -D warnings and git diff --check pass.

Draft acceptance gates: saved browser policy blocked visual preview, and installed Windows/real Android picker, off-device copy and rendering still need device verification. Large-project memory/crash testing remains pending. ZIPs are unencrypted, include private AI conversations, and checksums detect corruption rather than authenticate an author; settings explains this. Rust minimum rises to 1.88 for ZIP 9.5. Local E: build-cache hard-link warnings and existing Vite large-chunk warnings are environmental/pre-existing.

No LAN/Drive sync, Smart Merge, SQLite/IndexedDB migration or new device permissions are enabled. Updated architecture, DEVLOG, roadmap, test matrix and handoff memory with the implementation and remaining gates. Integrated #2's Node 24.15 runtime correction and explicit AI undo boundaries after CI exposed inherited startup/timing bugs; the full local frontend suite was rerun afterward.

ehitimum and others added 10 commits November 15, 2026 16:37
Each with a regression (cargo test backup::, backup*.regression.test.tsx):
1. A damaged chapter, a missing image or one outside the project no longer
   blocks the backup: damaged files are archived as-is (listed in the
   manifest) and reported as warnings. Restore stays strict about integrity
   and every chapter that was valid, and restores listed ones byte for byte.
2. Schema 2 archives store images as mnemo-asset:<file> and no sourceRoot
   (no source path or OS user name). Schema 1 archives still restore.
3. Backups are named <project>-<yyyy-mm-dd-hhmm>.zip, listed in the card
   with date, size, Save a copy and a confirmed delete; newest 5 kept.
4. Restore and Save a copy pass file locations; Rust opens the picked file
   (desktop path in the fs scope, Android content URI). No whole archive in
   the web view or memory, and it works with 2.1.1's narrowed fs scope.
5. The backup saves through flushIfDirty (the guarded persistCurrent).
Also: the card explains that restored copies keep AI chats but not the AI
connection. Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the local sync core used by every transport: per-entity immutable
revisions (project, folder, chapter metadata, chapter text, assets) with
content-derived ids, SQLite WAL state outside project folders, disk scan
change capture, causal fast-forward, deterministic field merges, preserved
text conflicts, edit-beats-delete, staged updates for the open chapter,
frozen batches for crash-safe publishing, and portable asset references.

Fix backup restore leaving fantasy-map "My Imports" paths pointing at the
original project (regression tests in backup/tests.rs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Desktop sign-in uses the loopback redirect with PKCE (S256) in the writer's
browser and only the drive.appdata scope; the refresh token lives in the OS
secret store, access tokens in memory. The OAuth client comes from the
environment or a git-ignored .env.local at build time.

The Drive transport publishes gzip blobs before immutable batch files in
appDataFolder, finds new batches through the changes feed with a listing
fallback, ignores duplicate uploads and malformed files, and classifies
401/403/429/5xx/quota errors without discarding queued work.

A background worker syncs enabled projects after saves (debounced) and on a
poll with backoff, refuses silent Google account switches, and exposes
status, download, conflict and staged-update commands.

Also write imported images atomically so a crash or a sync scan never sees
a half-written asset, and stop syncing a project that leaves the library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lict review

Settings gains a Google Drive card (desktop and phone variants) with
sign-in, per-project sync toggles, downloads from other devices and sync
notes; a quiet status pill appears only for synced projects. The open
chapter is reported to the backend so its text is never replaced under the
editor: a banner offers to load the newer version (after saving), and
parallel edits open a side-by-side review that keeps the other version as
its own chapter by default. Remote renames and moves merge into the open
chapter without dropping unsaved typing.

Regression suites cover the settings flows, banner, review (inert previews)
and the App save boundary. Widen the AI suite's streamed-response waits and
cap Vitest at half the cores: App-mounting suites timed out on busy desktops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the inline google-auth Android plugin (Google Play services
AuthorizationClient for drive.appdata, no refresh token stored) with its
ACL permission, and silent re-authorization when the short-lived token
lapses.

Fix two sync bugs found in review: turning a project's sync off and on
reset its batch counter so new batches reused published numbers, and
re-enabling under another Google account published nothing (both covered
by engine regressions). Report needs-auth after signing out while projects
stay bound to the account. Mark desktop-only pairing helpers so Android
builds are warning-free.

Document the design as built, Google Cloud setup and open items in
MNEMOSYNC_DRIVE.md and update architecture, devlog, roadmap, testing,
threat model, test matrix and the MnemoSync handoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Drive test

The first live setup showed a raw "403: accessNotConfigured" when the
Cloud project lacked the Drive API; it now says what to enable. A retry
after such a failure reuses the stored grant instead of repeating the
browser consent.

Add an ignored live test (cargo test live_drive -- --ignored) that runs two
engines against the real appDataFolder under a throwaway project and
cleans up. Passed against the writer's own Cloud project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Data loss (each with an engine regression):
- An unreadable chapter or a missing documents folder no longer becomes a
  delete on every device; the last good state is kept with one note.
- Engine writes re-check the file under project::files_lock (shared with the
  save commands) and capture a newer save first, so it merges or conflicts.
- Conflict review and resolve scan first, so the latest typing is a version.
- Delete + two different edits keeps both edits as a conflict.
- Remote deletes and replaced damaged copies go to <project>/sync-trash/.

Sign-in and Drive client:
- A stray loopback request no longer ends the sign-in.
- Retrying Connect keeps a valid grant unless Google rejects it.
- Drive sync is off on Linux (no keyring backend) and says why.
- Read the newer error shape (SERVICE_DISABLED); shorter text in release.
- Expired change cursor detected by status; catalogue date kept current.

Smaller: id validation in sync commands, Android device model name, Drive
space used in settings, "Back up, then sync", Beta label, stricter live-test
cleanup. Docs and test matrix updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ehitimum
ehitimum force-pushed the codex/mnemosync-foundation branch from 8b4977b to 88a04de Compare November 15, 2026 10:48
@ehitimum
ehitimum force-pushed the codex/mnemosync-backup branch from 5096ebb to 3b0c25c Compare November 15, 2026 10:48
@ehitimum

Copy link
Copy Markdown
Owner Author

Changes for the review

This branch was rebased onto the updated PR #2 (which sits on 2.1.1), so the duplicate history and the merge commits are gone. The review fixes are in one commit on top. Each has a regression test (cargo test backup::, regression/backup*.regression.test.tsx).

# Finding Change
1 One bad reference or damaged chapter blocks every backup The export backs up everything valid and returns warnings. A damaged chapter file is archived as-is and listed under damaged in the manifest; images outside the project or missing are counted. Restore stays strict about integrity (sizes, checksums, paths, folder tree, every chapter that was valid) and restores the files the backup itself marked as damaged byte for byte, so the backup still restores. Folder cycles and a damaged project.json still refuse.
2 Absolute source path in the archive Schema 2 stores images as mnemo-asset:<file> (the same form as MnemoSync) and drops sourceRoot. A test asserts the archive contains no source folder. Schema 1 archives still restore (test).
3 Backups accumulate unseen Files are named <project>-<yyyy-mm-dd-hhmm>.zip. The card lists this project's backups (date, size) with "Save a copy…" and a confirmed delete, and says how many belong to other projects. The newest 5 per project are kept. New commands: list_backups, delete_backup. Both name only files directly in the backups folder.
4 Whole archive in memory restore_project_backup({path}) opens the dialog-picked file in Rust (desktop path checked against the fs scope, or an Android content URI) and reads it with bounded per-entry reads. save_backup_copy({source, destination}) copies file to file. This also keeps "Save a copy" working with 2.1.1's narrowed webview file access.
5 Duplicate save path onBackup now uses flushIfDirty (the 2.1.1 persistCurrent, with its guard and error result).

Small points:

  • The card says a restored copy brings AI conversations back but not the AI connection.
  • rust-version 1.88 (ZIP 9.5) is noted here, as asked, for contributors.

Checks

On the rebased stack top (this PR plus #4): npm run check (155 tests, lint, types, build) · cargo test 106 passed · clippy clean.

Not verified: restore and "Save a copy" with Android's document picker on a real phone.

🤖 Generated with Claude Code

MnemoSync: Google Drive sync on a shared sync engine
@ehitimum
ehitimum marked this pull request as ready for review November 24, 2026 04:19
@ehitimum
ehitimum changed the base branch from codex/mnemosync-foundation to main November 24, 2026 04:19
@ehitimum
ehitimum merged commit a6f5873 into main Nov 24, 2026
3 checks passed
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