[PR #1312] [MERGED] Fix refactor storage corruption recovery #5030

Closed
opened 2026-10-22 04:12:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1312
Author: @cha1latte
Created: 5/26/2026
Status: ✅ Merged
Merged: 5/26/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/refactor-issue-1264-storage-recovery


📝 Commits (1)

  • 956a9c7 Fix refactor storage corruption recovery

📊 Changes

2 files changed (+371 additions, -79 deletions)

View changed files

📝 src-tauri/crates/storage/src/lib.rs (+344 -79)
📝 src-tauri/src/state.rs (+27 -0)

📄 Description

Linked issue

Closes #1264

Why this change

  • Refactor-branch storage could still fail hard when a collection JSON file was corrupt during startup or a read path.
  • Users need corrupted files preserved for manual recovery while the app recreates a safe empty collection instead of refusing to launch.

What changed

  • Added collection read recovery in marinara-storage: corrupt primary files are renamed with .corrupted-*, valid .bak files are used when available, and both corrupt primary/backup files are preserved before recreating an empty collection.
  • Added durable .bak refresh before collection writes, while avoiding copying NUL-filled primary files over a valid backup.
  • Added Rust regression coverage for valid-backup recovery, both-files-corrupt recovery, should-not-match valid files, repeated backup refresh, NUL-primary backup protection, and the AppState::from_data_dir startup path.

Refactor impact

Primary owner:

Rust storage

Impact areas reviewed:

  • src-tauri/crates/storage/src/lib.rs
  • src-tauri/src/state.rs
  • Storage API entrypoints that read collections, chat messages, and startup migration state

Boundary notes:

  • Kept the behavior inside the Rust storage crate and startup test coverage; no React, shared API, Tauri command registration, dependency, schema, or release metadata changes.
  • This targets the refactor storage layout under <data_dir>/data/collections/*.json; the old packages/server/data/storage layout from the issue text is outside this refactor-branch PR.

Pressure points touched:

  • File-backed Rust storage read/write paths.

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

  • Codex machine verification:
    • Before fix: cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage corrupt_collection -- --nocapture reproduced the failure with AppError { code: "json_error", message: "expected value at line 1 column 1" }.
    • After fix: cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage -- --nocapture passed with 15 tests.
    • After fix: cargo test --manifest-path src-tauri/Cargo.toml app_state_startup_recovers_when_collection_and_backup_are_corrupt -- --nocapture passed.
    • After fix: pnpm check passed architecture, frontend typecheck, Rust workspace check, and docs check.
    • Proof gate: node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json passed locally.
  • Manual user-data note: if recovery triggers, corrupt files are preserved beside the original under <data_dir>/data/collections/ as <collection>.json.corrupted-<pid>-<nonce> and, when present, <collection>.json.bak.corrupted-<pid>-<nonce>. Back those files up to a separate folder outside the Marinara data directory before attempting manual recovery.
  • No browser/Tauri manual verification was needed for this non-UI storage fix.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

N/A - non-UI storage recovery fix. Console warning proof is covered by the Rust test output.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1312 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/26/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/refactor-issue-1264-storage-recovery` --- ### 📝 Commits (1) - [`956a9c7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/956a9c7d11e2158b970fc6931a1089513defe1b3) Fix refactor storage corruption recovery ### 📊 Changes **2 files changed** (+371 additions, -79 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/storage/src/lib.rs` (+344 -79) 📝 `src-tauri/src/state.rs` (+27 -0) </details> ### 📄 Description ## Linked issue Closes #1264 ## Why this change - Refactor-branch storage could still fail hard when a collection JSON file was corrupt during startup or a read path. - Users need corrupted files preserved for manual recovery while the app recreates a safe empty collection instead of refusing to launch. ## What changed - Added collection read recovery in `marinara-storage`: corrupt primary files are renamed with `.corrupted-*`, valid `.bak` files are used when available, and both corrupt primary/backup files are preserved before recreating an empty collection. - Added durable `.bak` refresh before collection writes, while avoiding copying NUL-filled primary files over a valid backup. - Added Rust regression coverage for valid-backup recovery, both-files-corrupt recovery, should-not-match valid files, repeated backup refresh, NUL-primary backup protection, and the `AppState::from_data_dir` startup path. ## Refactor impact Primary owner: Rust storage Impact areas reviewed: - `src-tauri/crates/storage/src/lib.rs` - `src-tauri/src/state.rs` - Storage API entrypoints that read collections, chat messages, and startup migration state Boundary notes: - Kept the behavior inside the Rust storage crate and startup test coverage; no React, shared API, Tauri command registration, dependency, schema, or release metadata changes. - This targets the refactor storage layout under `<data_dir>/data/collections/*.json`; the old `packages/server/data/storage` layout from the issue text is outside this refactor-branch PR. Pressure points touched: - File-backed Rust storage read/write paths. ## Validation - [ ] `pnpm check` passes locally - [ ] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [ ] `pnpm check:architecture` passes locally - [ ] `pnpm check:docs` passes locally - [ ] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes - Codex machine verification: - Before fix: `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage corrupt_collection -- --nocapture` reproduced the failure with `AppError { code: "json_error", message: "expected value at line 1 column 1" }`. - After fix: `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage -- --nocapture` passed with 15 tests. - After fix: `cargo test --manifest-path src-tauri/Cargo.toml app_state_startup_recovers_when_collection_and_backup_are_corrupt -- --nocapture` passed. - After fix: `pnpm check` passed architecture, frontend typecheck, Rust workspace check, and docs check. - Proof gate: `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` passed locally. - Manual user-data note: if recovery triggers, corrupt files are preserved beside the original under `<data_dir>/data/collections/` as `<collection>.json.corrupted-<pid>-<nonce>` and, when present, `<collection>.json.bak.corrupted-<pid>-<nonce>`. Back those files up to a separate folder outside the Marinara data directory before attempting manual recovery. - No browser/Tauri manual verification was needed for this non-UI storage fix. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence N/A - non-UI storage recovery fix. Console warning proof is covered by the Rust test output. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:37 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5030
No description provided.