[GH-ISSUE #7980] [Issue]: Lorebook transfer failures can cause data loss, and embedded sync errors may go unnoticed #4380

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

Originally created by @minikkeuen on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7980

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Moving entries between lorebooks can cause data loss if an error occurs after some source entries have already been deleted.

Additionally, failures when synchronizing a linked lorebook back to a character's embedded character_book may be silently ignored, allowing an operation to appear successful despite incomplete synchronization.

Expected behavior

  • Failed lorebook transfers should restore all affected entries and references to their original state.
  • Source entries should never be lost because of a partially completed transfer.
  • Embedded character-book synchronization failures should be propagated to callers rather than silently ignored.
  • Operations should not report success when required synchronization has failed.

Actual behavior

Lorebook transfer rollback

  • Destination entries are created before source entries are deleted.
  • If an error occurs after some source entries have been deleted, the rollback removes the newly created destination entries without restoring the deleted source entries.
  • This can result in entries being lost from both lorebooks.

Embedded character-book synchronization

  • syncCharacterBookFromLorebook can return a failed status instead of throwing an exception.
  • Some callers do not check this status.
  • As a result, synchronization failures may go unnoticed, leaving the embedded character book out of sync with the linked lorebook.

Steps to reproduce

These issues were identified through source-code inspection and reproduced using automated regression tests with injected failures.

Scenario A: Lorebook transfer failure

  1. Create two lorebooks and add multiple entries to the source lorebook.
  2. Start transferring multiple entries from the source to the destination.
  3. Inject a storage failure after at least one source entry has been deleted.
  4. Observe that the operation attempts to roll back the destination entries.
  5. Verify that previously deleted source entries are not restored, resulting in data loss.

Scenario B: Embedded character-book synchronization failure

  1. Create a character with an embedded lorebook and a linked standalone lorebook.
  2. Modify the linked lorebook through an operation that triggers embedded character-book synchronization.
  3. Inject a failure into the synchronization operation.
  4. Observe that the synchronization function returns a failed status.
  5. Verify that the calling operation may still report success without propagating the failure.

Environment

  • Marinara Engine version: v2.5.1
  • Install type: source
  • OS + version: macOS 26.6.2 (Apple Silicon)
  • Browser or app shell: Local web interface

Logs, screenshots, or video

No browser screenshots or runtime error logs are available.

Both issues were identified through source-code inspection and reproduced using automated regression tests with injected storage and synchronization failures.

Additional context

Affected implementation areas:

  • packages/server/src/routes/lorebooks.routes.ts
  • packages/server/src/services/lorebook/character-book-sync.ts
  • Related lorebook mutation routes and character import handling

The proposed fixes:

  • Restore source entries, destination entries, and affected references when a lorebook transfer fails.
  • Propagate embedded character-book synchronization failures to callers.
  • Add regression tests for both failure scenarios.

The synchronization fix does not introduce full transactional rollback for every operation that modifies a lorebook before synchronization.

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 @minikkeuen on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7980 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Moving entries between lorebooks can cause data loss if an error occurs after some source entries have already been deleted. Additionally, failures when synchronizing a linked lorebook back to a character's embedded `character_book` may be silently ignored, allowing an operation to appear successful despite incomplete synchronization. ## Expected behavior - Failed lorebook transfers should restore all affected entries and references to their original state. - Source entries should never be lost because of a partially completed transfer. - Embedded character-book synchronization failures should be propagated to callers rather than silently ignored. - Operations should not report success when required synchronization has failed. ## Actual behavior **Lorebook transfer rollback** - Destination entries are created before source entries are deleted. - If an error occurs after some source entries have been deleted, the rollback removes the newly created destination entries without restoring the deleted source entries. - This can result in entries being lost from both lorebooks. **Embedded character-book synchronization** - `syncCharacterBookFromLorebook` can return a failed status instead of throwing an exception. - Some callers do not check this status. - As a result, synchronization failures may go unnoticed, leaving the embedded character book out of sync with the linked lorebook. ## Steps to reproduce These issues were identified through source-code inspection and reproduced using automated regression tests with injected failures. **Scenario A: Lorebook transfer failure** 1. Create two lorebooks and add multiple entries to the source lorebook. 2. Start transferring multiple entries from the source to the destination. 3. Inject a storage failure after at least one source entry has been deleted. 4. Observe that the operation attempts to roll back the destination entries. 5. Verify that previously deleted source entries are not restored, resulting in data loss. **Scenario B: Embedded character-book synchronization failure** 1. Create a character with an embedded lorebook and a linked standalone lorebook. 2. Modify the linked lorebook through an operation that triggers embedded character-book synchronization. 3. Inject a failure into the synchronization operation. 4. Observe that the synchronization function returns a failed status. 5. Verify that the calling operation may still report success without propagating the failure. ## Environment - Marinara Engine version: v2.5.1 - Install type: source - OS + version: macOS 26.6.2 (Apple Silicon) - Browser or app shell: Local web interface ## Logs, screenshots, or video No browser screenshots or runtime error logs are available. Both issues were identified through source-code inspection and reproduced using automated regression tests with injected storage and synchronization failures. ## Additional context Affected implementation areas: - `packages/server/src/routes/lorebooks.routes.ts` - `packages/server/src/services/lorebook/character-book-sync.ts` - Related lorebook mutation routes and character import handling The proposed fixes: - Restore source entries, destination entries, and affected references when a lorebook transfer fails. - Propagate embedded character-book synchronization failures to callers. - Add regression tests for both failure scenarios. The synchronization fix does not introduce full transactional rollback for every operation that modifies a lorebook before synchronization. ## 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.
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#4380
No description provided.