[PR #730] [MERGED] Preserve file-native backups during self-heal #4752

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

📋 Pull Request Information

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

Base: main ← Head: fix/file-native-self-heal-backup


📝 Commits (2)

  • afc887d Preserve file-native backups during self-heal
  • 0ad07fd Merge branch 'main' into fix/file-native-self-heal-backup

📊 Changes

2 files changed (+167 additions, -7 deletions)

View changed files

📝 packages/server/src/db/file-backed-store.ts (+20 -7)
📝 packages/server/test/file-backed-store.test.ts (+147 -0)

📄 Description

Linked issue

Closes #728

Why this change

  • File-native startup can recover a table or manifest from .bak, then the self-heal save copies the still-corrupt non-NUL primary over that valid .bak before rewriting the primary.
  • If the repair write is interrupted, or another failure lands before .bak is refreshed from a valid primary, the recovery source is gone.

What changed

  • Track file paths that were recovered from .bak during startup.
  • Skip .bak refresh for the self-heal write of those recovered files, so the valid backup remains available while the primary is repaired.
  • Clear recovery markers after the flush succeeds, allowing later normal saves to refresh .bak from repaired primaries.
  • Added regression tests for malformed non-NUL chats.json and manifest.json with valid .bak files.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Verified malformed non-NUL tables/chats.json recovers from a valid .bak, repairs the primary file, and leaves .bak parseable.
  • Verified malformed non-NUL manifest.json recovers from a valid .bak, repairs the primary file, and leaves .bak parseable.
  • Verified the existing NUL-filled primary recovery path still keeps .bak parseable.
  • Ran pnpm --dir packages/server exec tsx --import ./test/setup-env.ts --test test/file-backed-store.test.ts.
  • Ran pnpm check, pnpm version:check, and pnpm guard:installer-artifacts.
  • Built and ran the Docker image, then checked / and /api/health.
  • Launched the built app locally with a clean temp data dir and checked basic app navigation in Chrome at desktop and mobile viewports, including light/dark theme behavior.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A - backend file-storage recovery behavior only.

Summary by CodeRabbit

Release Notes

  • New Features

    • Automatic backup recovery and self-healing: The system now detects corrupted data and manifest files, automatically recovering from backups without requiring manual intervention.
  • Bug Fixes

    • Enhanced data resilience against file corruption, ensuring critical information is preserved and accessible.

Review Change Stack


🔄 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/730 **Author:** [@NeoKazuya](https://github.com/NeoKazuya) **Created:** 5/12/2026 **Status:** ✅ Merged **Merged:** 5/12/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/file-native-self-heal-backup` --- ### 📝 Commits (2) - [`afc887d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/afc887d777fa3fb43e79e2dce64f46f950234d53) Preserve file-native backups during self-heal - [`0ad07fd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ad07fd794737410e1a9dd390771264281126cfe) Merge branch 'main' into fix/file-native-self-heal-backup ### 📊 Changes **2 files changed** (+167 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/db/file-backed-store.ts` (+20 -7) 📝 `packages/server/test/file-backed-store.test.ts` (+147 -0) </details> ### 📄 Description ## Linked issue Closes #728 ## Why this change - File-native startup can recover a table or manifest from `.bak`, then the self-heal save copies the still-corrupt non-NUL primary over that valid `.bak` before rewriting the primary. - If the repair write is interrupted, or another failure lands before `.bak` is refreshed from a valid primary, the recovery source is gone. ## What changed - Track file paths that were recovered from `.bak` during startup. - Skip `.bak` refresh for the self-heal write of those recovered files, so the valid backup remains available while the primary is repaired. - Clear recovery markers after the flush succeeds, allowing later normal saves to refresh `.bak` from repaired primaries. - Added regression tests for malformed non-NUL `chats.json` and `manifest.json` with valid `.bak` files. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Verified malformed non-NUL `tables/chats.json` recovers from a valid `.bak`, repairs the primary file, and leaves `.bak` parseable. - Verified malformed non-NUL `manifest.json` recovers from a valid `.bak`, repairs the primary file, and leaves `.bak` parseable. - Verified the existing NUL-filled primary recovery path still keeps `.bak` parseable. - Ran `pnpm --dir packages/server exec tsx --import ./test/setup-env.ts --test test/file-backed-store.test.ts`. - Ran `pnpm check`, `pnpm version:check`, and `pnpm guard:installer-artifacts`. - Built and ran the Docker image, then checked `/` and `/api/health`. - Launched the built app locally with a clean temp data dir and checked basic app navigation in Chrome at desktop and mobile viewports, including light/dark theme behavior. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A - backend file-storage recovery behavior only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Automatic backup recovery and self-healing: The system now detects corrupted data and manifest files, automatically recovering from backups without requiring manual intervention. * **Bug Fixes** * Enhanced data resilience against file corruption, ensuring critical information is preserved and accessible. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/730) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:21 +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#4752
No description provided.