[PR #7981] [MERGED] fix(lorebooks): restore failed transfers and propagate embedded sync errors #8038

Closed
opened 2026-10-24 04:09:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7981
Author: @minikkeuen
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: pr/lorebook-integrity-staging


📝 Commits (4)

  • 55c3ad0 fix: roll back failed lorebook entry transfers atomically
  • 9db3adf fix: propagate embedded lorebook synchronization failures to mutations
  • e1d1223 fix: roll back lorebook mutations when embedded sync fails
  • 4eda0a2 fix: reject embedded imports when their character is missing

📊 Changes

12 files changed (+946 additions, -256 deletions)

View changed files

📝 packages/server/src/routes/characters.routes.ts (+16 -17)
📝 packages/server/src/routes/lorebook-text.routes.ts (+1 -1)
📝 packages/server/src/routes/lorebooks.routes.ts (+93 -55)
📝 packages/server/src/services/import/st-character.importer.ts (+27 -28)
📝 packages/server/src/services/import/st-lorebook.importer.ts (+157 -143)
📝 packages/server/src/services/lorebook/character-book-sync.ts (+16 -6)
📝 packages/server/src/services/storage/lorebooks.storage.ts (+7 -5)
➕ scripts/regressions/data-integrity-character-pointer.regression.ts (+94 -0)
➕ scripts/regressions/data-integrity-embedded-sync.regression.ts (+147 -0)
➕ scripts/regressions/data-integrity-lorebook-transfer.regression.ts (+80 -0)
➕ scripts/regressions/data-integrity-sync-atomic.regression.ts (+304 -0)
📝 scripts/regressions/lorebook-images.regression.ts (+4 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7980

Why this change

  • A failed lorebook entry transfer can cause data loss if some source entries have already been deleted before the failure occurs.
  • The existing rollback removes newly created destination entries without restoring source entries deleted earlier in the operation.
  • Embedded character-book synchronization can return a failed status that some callers ignore, allowing operations to appear successful despite incomplete synchronization.

What changed

  • Restore source entries, destination entries, and affected references when a lorebook transfer fails.
  • Ensure partially completed transfers are rolled back consistently instead of leaving entries missing from both lorebooks.
  • Propagate embedded character-book synchronization failures to callers rather than silently ignoring failed statuses.
  • Update affected lorebook mutation routes and character import handling to report synchronization errors.
  • Add regression tests covering partial transfer failures and embedded synchronization failures.
  • Preserve existing behavior for successful transfers and synchronization operations.

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

Additional automated validation:

  • Lorebook transfer rollback regression test passed.
  • Embedded character-book synchronization regression test passed.
  • Related prompt regression tests (3 groups) passed.
  • Additional TypeScript checks passed.
  • Both fixes were applied to the latest upstream/staging without merge conflicts.

Manual verification notes

  • Browser-based manual verification has not been performed.
  • Automated regression tests cover injected storage failures during lorebook transfers and failures during embedded character-book synchronization.
  • The synchronization fix propagates errors but does not provide full transactional rollback for every mutation performed before synchronization.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No screenshots or recordings are available. These changes address server-side data integrity and error handling without introducing UI changes.


🔄 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/7981 **Author:** [@minikkeuen](https://github.com/minikkeuen) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `pr/lorebook-integrity-staging` --- ### 📝 Commits (4) - [`55c3ad0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/55c3ad0c8386bbf9843077aadcc5e9ca30b233ae) fix: roll back failed lorebook entry transfers atomically - [`9db3adf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9db3adf83de5ad14ed28a2d92a09689cfd29e2e3) fix: propagate embedded lorebook synchronization failures to mutations - [`e1d1223`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e1d1223a773a4603c6c112d73e9ba296840e983d) fix: roll back lorebook mutations when embedded sync fails - [`4eda0a2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4eda0a2caa38e28805957fbe37d5c47d6c5f8750) fix: reject embedded imports when their character is missing ### 📊 Changes **12 files changed** (+946 additions, -256 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/characters.routes.ts` (+16 -17) 📝 `packages/server/src/routes/lorebook-text.routes.ts` (+1 -1) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+93 -55) 📝 `packages/server/src/services/import/st-character.importer.ts` (+27 -28) 📝 `packages/server/src/services/import/st-lorebook.importer.ts` (+157 -143) 📝 `packages/server/src/services/lorebook/character-book-sync.ts` (+16 -6) 📝 `packages/server/src/services/storage/lorebooks.storage.ts` (+7 -5) ➕ `scripts/regressions/data-integrity-character-pointer.regression.ts` (+94 -0) ➕ `scripts/regressions/data-integrity-embedded-sync.regression.ts` (+147 -0) ➕ `scripts/regressions/data-integrity-lorebook-transfer.regression.ts` (+80 -0) ➕ `scripts/regressions/data-integrity-sync-atomic.regression.ts` (+304 -0) 📝 `scripts/regressions/lorebook-images.regression.ts` (+4 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #7980 ## Why this change - A failed lorebook entry transfer can cause data loss if some source entries have already been deleted before the failure occurs. - The existing rollback removes newly created destination entries without restoring source entries deleted earlier in the operation. - Embedded character-book synchronization can return a failed status that some callers ignore, allowing operations to appear successful despite incomplete synchronization. ## What changed - Restore source entries, destination entries, and affected references when a lorebook transfer fails. - Ensure partially completed transfers are rolled back consistently instead of leaving entries missing from both lorebooks. - Propagate embedded character-book synchronization failures to callers rather than silently ignoring failed statuses. - Update affected lorebook mutation routes and character import handling to report synchronization errors. - Add regression tests covering partial transfer failures and embedded synchronization failures. - Preserve existing behavior for successful transfers and synchronization operations. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `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) - [x] Read and followed `CONTRIBUTING.md` Additional automated validation: - Lorebook transfer rollback regression test passed. - Embedded character-book synchronization regression test passed. - Related prompt regression tests (3 groups) passed. - Additional TypeScript checks passed. - Both fixes were applied to the latest `upstream/staging` without merge conflicts. ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - Browser-based manual verification has not been performed. - Automated regression tests cover injected storage failures during lorebook transfers and failures during embedded character-book synchronization. - The synchronization fix propagates errors but does not provide full transactional rollback for every mutation performed before synchronization. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No screenshots or recordings are available. These changes address server-side data integrity and error handling without introducing UI changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:51 +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#8038
No description provided.