[GH-ISSUE #1264] [Issue]: Make the backups actually work please for us to not lose progress #616

Closed
opened 2026-10-20 17:30:47 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Navgner on GitHub (May 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1264

Originally assigned to: @cha1latte on GitHub.

Summary

My computer crashed, causing both messages.json and its backup messages.json.bak to become corrupted (either filled with null bytes \u0000 or truncated). When this happens, Marinara Engine completely refuses to start due to unhandled JSON parsing errors during bootstrap. The only way to make the engine launch again is to manually delete or edit these files, which results in losing all conversation history and progression. This critical corruption issue has happened to me twice so far.

List of corrupted files (all became unparseable or filled with \u0000 simultaneously):

The crash corrupted not only the active database files but also their corresponding backups, indicating they might have been kept open or written to at the same time:

  • packages/server/data/storage/manifest.json & manifest.json.bak
  • packages/server/data/storage/tables/messages.json & messages.json.bak
  • packages/server/data/storage/tables/message_swipes.json & message_swipes.json.bak
  • packages/server/data/storage/tables/memory_chunks.json & memory_chunks.json.bak

Expected behavior

The server should handle JSON parsing errors gracefully during the startup/bootstrap phase.
If both the primary database file and its backup are unparseable or corrupted:

  1. The server should not crash or exit abruptly.
  2. It should automatically rename the corrupted files (e.g., to messages.json.corrupted) to preserve them for manual recovery.
  3. It should start with a fresh/empty database state and display a warning in the UI/console, rather than refusing to boot.
  4. Ideally, file writes should be atomic (writing to a temporary file first, then renaming) to prevent both the main file and the .bak file from being corrupted simultaneously during a system crash.

Actual behavior

The server crashes immediately during bootstrap with a SyntaxError (e.g., Unexpected token '\u0000' or Unterminated string in JSON) and exits. The application cannot be used at all until the user manually intervenes in the file system.

Steps to reproduce

  1. Start Marinara Engine and generate some chat history.
  2. Simulate a sudden crash/power loss during a write operation
  3. Try to start Marinara Engine.
  4. Observe the unhandled bootstrap error and the unexpected server exit.

Environment

  • Marinara Engine version: Release: v1.6.1Build: 77a30fa
  • Install type: Source (running via pnpm/Node)
  • OS + version: Windows 11
  • Browser or app shell: Firefox
  • Node.js version: v24.14.1
  • Package manager: pnpm 10.33.2

Error Log 1: Corruption with Null Bytes (\u0000)

{"level":50,"time":1779812749373,"pid":2020,"hostname":"SIAM","err":{"type":"SyntaxError","message":"Unexpected token '\u0000', "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"... is not valid JSON","stack":"SyntaxError: Unexpected token '\u0000', "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"... is not valid JSON\n at JSON.parse ()\n at parseJsonFile (file:///C:/Games/3Marinara/packages/server/dist/db/file-backed-store.js:265:30)..."},"msg":"[file-storage] C:\Games\3Marinara\packages\server\data\storage\tables\messages.json is corrupt; recovering from C:\Games\3Marinara\packages\server\data\storage\tables\messages.json.bak"}

Error Log 2: Corruption with Bad Control Character / Truncated JSON

{"level":50,"time":1779812749500,"pid":2020,"hostname":"SIAM","err":{"type":"SyntaxError","message":"Bad control character in string literal in JSON at position 33471828 (line 1 column 33471829)","stack":"SyntaxError: Bad control character in string literal in JSON at position 33471828 (line 1 column 33471829)\n at JSON.parse ()\n at parseJsonFile (file:///C:/Games/3Marinara/packages/server/dist/db/file-backed-store.js:273:29)..."},"msg":"[startup] Unhandled error during server bootstrap"}

Additional context

The backup mechanism (.bak) currently fails to protect against data loss in the event of a system-wide crash, likely because both files are being modified or kept open around the same time, or because the writing process is not atomic. Implementing safe/atomic file writing (such as using a temporary file write followed by an atomic replace) would prevent database corruption on unexpected shutdowns.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Navgner on GitHub (May 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1264 Originally assigned to: @cha1latte on GitHub. ## Summary My computer crashed, causing both `messages.json` and its backup `messages.json.bak` to become corrupted (either filled with null bytes `\u0000` or truncated). When this happens, Marinara Engine completely refuses to start due to unhandled JSON parsing errors during bootstrap. The only way to make the engine launch again is to manually delete or edit these files, which results in losing all conversation history and progression. This critical corruption issue has happened to me twice so far. ### List of corrupted files (all became unparseable or filled with `\u0000` simultaneously): The crash corrupted not only the active database files but also their corresponding backups, indicating they might have been kept open or written to at the same time: - `packages/server/data/storage/manifest.json` & `manifest.json.bak` - `packages/server/data/storage/tables/messages.json` & `messages.json.bak` - `packages/server/data/storage/tables/message_swipes.json` & `message_swipes.json.bak` - `packages/server/data/storage/tables/memory_chunks.json` & `memory_chunks.json.bak` ## Expected behavior The server should handle JSON parsing errors gracefully during the startup/bootstrap phase. If both the primary database file and its backup are unparseable or corrupted: 1. The server should not crash or exit abruptly. 2. It should automatically rename the corrupted files (e.g., to `messages.json.corrupted`) to preserve them for manual recovery. 3. It should start with a fresh/empty database state and display a warning in the UI/console, rather than refusing to boot. 4. Ideally, file writes should be atomic (writing to a temporary file first, then renaming) to prevent both the main file and the `.bak` file from being corrupted simultaneously during a system crash. ## Actual behavior The server crashes immediately during bootstrap with a `SyntaxError` (e.g., `Unexpected token '\u0000'` or `Unterminated string in JSON`) and exits. The application cannot be used at all until the user manually intervenes in the file system. ## Steps to reproduce 1. Start Marinara Engine and generate some chat history. 2. Simulate a sudden crash/power loss during a write operation 3. Try to start Marinara Engine. 4. Observe the unhandled bootstrap error and the unexpected server exit. ## Environment - Marinara Engine version: Release: v1.6.1Build: 77a30fa - Install type: Source (running via pnpm/Node) - OS + version: Windows 11 - Browser or app shell: Firefox - Node.js version: v24.14.1 - Package manager: pnpm 10.33.2 ### Error Log 1: Corruption with Null Bytes (`\u0000`) {"level":50,"time":1779812749373,"pid":2020,"hostname":"SIAM","err":{"type":"SyntaxError","message":"Unexpected token '\u0000', "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"... is not valid JSON","stack":"SyntaxError: Unexpected token '\u0000', "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"... is not valid JSON\n at JSON.parse (<anonymous>)\n at parseJsonFile (file:///C:/Games/3Marinara/packages/server/dist/db/file-backed-store.js:265:30)..."},"msg":"[file-storage] C:\Games\3Marinara\packages\server\data\storage\tables\messages.json is corrupt; recovering from C:\Games\3Marinara\packages\server\data\storage\tables\messages.json.bak"} ### Error Log 2: Corruption with Bad Control Character / Truncated JSON {"level":50,"time":1779812749500,"pid":2020,"hostname":"SIAM","err":{"type":"SyntaxError","message":"Bad control character in string literal in JSON at position 33471828 (line 1 column 33471829)","stack":"SyntaxError: Bad control character in string literal in JSON at position 33471828 (line 1 column 33471829)\n at JSON.parse (<anonymous>)\n at parseJsonFile (file:///C:/Games/3Marinara/packages/server/dist/db/file-backed-store.js:273:29)..."},"msg":"[startup] Unhandled error during server bootstrap"} ## Additional context The backup mechanism (`.bak`) currently fails to protect against data loss in the event of a system-wide crash, likely because both files are being modified or kept open around the same time, or because the writing process is not atomic. Implementing safe/atomic file writing (such as using a temporary file write followed by an atomic replace) would prevent database corruption on unexpected shutdowns. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:30:47 +07:00
  • closed this issue
  • added the
    server
    bug
    labels
Author
Owner

@cha1latte commented on GitHub (May 26, 2026):

fixed in refactor #1312

<!-- gh-comment-id:4548783459 --> @cha1latte commented on GitHub (May 26, 2026): fixed in refactor #1312
Author
Owner

@dougvan1701 commented on GitHub (May 29, 2026):

But how can we recover from this? My messages.json.bak is 20mg larger than the messages.json that the server creates after recovery. I am missing a TON of chats.

<!-- gh-comment-id:4575212570 --> @dougvan1701 commented on GitHub (May 29, 2026): But how can we recover from this? My messages.json.bak is 20mg larger than the messages.json that the server creates after recovery. I am missing a TON of chats.
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#616
No description provided.