[PR #2379] [MERGED] Flush pending storage writes on app quit #5568

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2379
Author: @Romuromylus
Created: 6/5/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/storage-flush-on-quit


📝 Commits (2)

  • 9a7e73c Flush pending storage writes on app quit
  • 76051ac Log quit-time storage flush failures instead of swallowing them

📊 Changes

2 files changed (+44 additions, -2 deletions)

View changed files

📝 src-tauri/crates/storage/src/lib.rs (+26 -0)
📝 src-tauri/src/lib.rs (+18 -2)

📄 Description

Linked issue

Closes #2319

Why this change

Storage writes are debounced ~750ms before hitting disk. The Tauri app exited via .run(generate_context!()) with no exit handler, so any write still inside the debounce window when the user closed the app was lost. The Drop backstop on FileStorage is gated on being the sole cache owner, which the in-flight debounce thread defeats during exactly that window.

What changed

  • Build the app and drive it with .build(ctx).expect(...).run(|handle, event| ...), flushing storage on RunEvent::ExitRequested / RunEvent::Exit so pending writes are persisted before the process exits.
  • The FileStorage Drop guard is intentionally left unchanged: dropping a still-shared, dirty storage (e.g. during a read-only health probe) must not eagerly persist seeded defaults; the explicit on-quit flush is the correct, scoped fix.

Refactor impact

Primary owner: app shell + Rust storage (src-tauri/src/lib.rs, src-tauri/crates/storage/src/lib.rs)

Impact areas reviewed:

  • run() keeps its () signature, so main.rs is untouched. flush() drains the dirty cache synchronously and is already used on other paths.

Boundary notes:

  • The exit handler (app layer) calls storage.flush() (public storage-crate API). No new cross-layer coupling.

Pressure points touched:

  • src-tauri/src/lib.rs (run loop only — command registration unchanged)

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace — green, including new flush_persists_pending_debounced_writes_to_disk (a dirty, not-yet-written collection lands on disk after flush() and the dirty flag clears). Existing health_liveness_skips_writable_probe_by_default still passes (Drop semantics unchanged).

Feature Discoverability

  • N/A because this PR is a durability bugfix and does not add a new thing users need to find.

Reason:

  • Persists existing writes on quit.

Docs and release impact

  • No docs changes needed

🔄 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/2379 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/storage-flush-on-quit` --- ### 📝 Commits (2) - [`9a7e73c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9a7e73ce0d24db1b772bea42d4eb36031f347669) Flush pending storage writes on app quit - [`76051ac`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76051ac6371747daaa665b4ea4af7c0a604b9727) Log quit-time storage flush failures instead of swallowing them ### 📊 Changes **2 files changed** (+44 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/storage/src/lib.rs` (+26 -0) 📝 `src-tauri/src/lib.rs` (+18 -2) </details> ### 📄 Description ## Linked issue Closes #2319 ## Why this change Storage writes are debounced ~750ms before hitting disk. The Tauri app exited via `.run(generate_context!())` with no exit handler, so any write still inside the debounce window when the user closed the app was lost. The `Drop` backstop on `FileStorage` is gated on being the sole cache owner, which the in-flight debounce thread defeats during exactly that window. ## What changed - Build the app and drive it with `.build(ctx).expect(...).run(|handle, event| ...)`, flushing storage on `RunEvent::ExitRequested` / `RunEvent::Exit` so pending writes are persisted before the process exits. - The `FileStorage` `Drop` guard is intentionally left **unchanged**: dropping a still-shared, dirty storage (e.g. during a read-only health probe) must not eagerly persist seeded defaults; the explicit on-quit flush is the correct, scoped fix. ## Refactor impact Primary owner: app shell + Rust storage (`src-tauri/src/lib.rs`, `src-tauri/crates/storage/src/lib.rs`) Impact areas reviewed: - `run()` keeps its `()` signature, so `main.rs` is untouched. `flush()` drains the dirty cache synchronously and is already used on other paths. Boundary notes: - The exit handler (app layer) calls `storage.flush()` (public storage-crate API). No new cross-layer coupling. Pressure points touched: - `src-tauri/src/lib.rs` (run loop only — command registration unchanged) ## Validation - [ ] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `cargo clippy --workspace --all-targets -- -D warnings` — clean - `cargo test --workspace` — green, including new `flush_persists_pending_debounced_writes_to_disk` (a dirty, not-yet-written collection lands on disk after `flush()` and the dirty flag clears). Existing `health_liveness_skips_writable_probe_by_default` still passes (Drop semantics unchanged). ## Feature Discoverability - [x] N/A because this PR is a durability bugfix and does not add a new thing users need to find. Reason: - Persists existing writes on quit. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:26 +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#5568
No description provided.