[PR #7435] [MERGED] fix(lorebooks): clean up library folder references on deletion #7732

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

📋 Pull Request Information

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

Base: staging ← Head: fix/lorebook-folder-references


📝 Commits (3)

  • 588aa0f fix(lorebooks): clean up library folder references on deletion
  • a6990a8 Merge remote-tracking branch 'origin/staging' into fix/lorebook-folder-references
  • 614c88e fix(lorebooks): keep delete-hook order and make folder cleanup non-fatal

📊 Changes

6 files changed (+170 additions, -5 deletions)

View changed files

📝 packages/client/src/components/panels/LorebooksPanel.tsx (+7 -4)
📝 packages/client/src/hooks/use-lorebooks.ts (+3 -0)
📝 packages/server/src/app.ts (+9 -0)
📝 packages/server/src/services/storage/library-folders.storage.ts (+51 -1)
📝 packages/server/src/services/storage/lorebooks.storage.ts (+2 -0)
➕ scripts/regressions/lorebook-library-folder-references.regression.ts (+98 -0)

📄 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 #7431

Why this change

  • Deleting a lorebook could leave its ID in library-folder references, causing folder counts to include lorebooks that no longer exist.
  • These stale references persisted across page refreshes and server restarts, leaving existing folders with incorrect counts.

What changed

  • Remove library-folder references when a lorebook is deleted.
  • Prune existing orphaned lorebook references during server startup.
  • Update client-side folder counts and invalidate the relevant cache after deletion.
  • Preserve unrelated library-folder data.
  • Add a regression test covering deletion and stale-reference cleanup.
  • Update the changelog. The changelog entry was dropped when staging was merged in: PRs no longer add CHANGELOG.md entries.
  • Maintainer follow-up: the folder-list cache refresh now runs after the chats refresh in useDeleteLorebook (the open-issues regression checks that block's order), and the startup cleanup logs a warning instead of stopping the server if it fails.

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

  • Confirmed that restarting the server corrects existing stale folder counts.
  • Confirmed that deleting a lorebook immediately updates its folder count.
  • node scripts/run-regressions.mjs --filter lorebook-library-folder-references — passed (1/1).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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 attached.

Summary by CodeRabbit

  • Bug Fixes
    • Lorebook folder counts now reflect the items currently shown when filtering or when all pages are loaded. When more pages remain and no filter is active, counts continue to represent the folder’s full contents.
    • Deleting a lorebook now removes its references from lorebook folders, and stale references to missing lorebooks are cleaned up. Preset folder contents remain unaffected by lorebook deletions.
    • Folder counts are consistent across desktop and touch actions.

🔄 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/7435 **Author:** [@minikkeuen](https://github.com/minikkeuen) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/lorebook-folder-references` --- ### 📝 Commits (3) - [`588aa0f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/588aa0f0cecf495a143406fc3f75a71dfe0426db) fix(lorebooks): clean up library folder references on deletion - [`a6990a8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a6990a830a1ef08cf804d8b5da1595044f38b79d) Merge remote-tracking branch 'origin/staging' into fix/lorebook-folder-references - [`614c88e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/614c88ecaa3519ad21030922879947f588ff3baa) fix(lorebooks): keep delete-hook order and make folder cleanup non-fatal ### 📊 Changes **6 files changed** (+170 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/panels/LorebooksPanel.tsx` (+7 -4) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+3 -0) 📝 `packages/server/src/app.ts` (+9 -0) 📝 `packages/server/src/services/storage/library-folders.storage.ts` (+51 -1) 📝 `packages/server/src/services/storage/lorebooks.storage.ts` (+2 -0) ➕ `scripts/regressions/lorebook-library-folder-references.regression.ts` (+98 -0) </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`. ## Linked issue Closes #7431 ## Why this change - Deleting a lorebook could leave its ID in library-folder references, causing folder counts to include lorebooks that no longer exist. - These stale references persisted across page refreshes and server restarts, leaving existing folders with incorrect counts. ## What changed - Remove library-folder references when a lorebook is deleted. - Prune existing orphaned lorebook references during server startup. - Update client-side folder counts and invalidate the relevant cache after deletion. - Preserve unrelated library-folder data. - Add a regression test covering deletion and stale-reference cleanup. - ~~Update the changelog.~~ The changelog entry was dropped when `staging` was merged in: PRs no longer add `CHANGELOG.md` entries. - Maintainer follow-up: the folder-list cache refresh now runs after the chats refresh in `useDeleteLorebook` (the `open-issues` regression checks that block's order), and the startup cleanup logs a warning instead of stopping the server if it fails. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] 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 - Confirmed that restarting the server corrects existing stale folder counts. - Confirmed that deleting a lorebook immediately updates its folder count. - `node scripts/run-regressions.mjs --filter lorebook-library-folder-references` — passed (1/1). ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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 attached. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Lorebook folder counts now reflect the items currently shown when filtering or when all pages are loaded. When more pages remain and no filter is active, counts continue to represent the folder’s full contents. * Deleting a lorebook now removes its references from lorebook folders, and stale references to missing lorebooks are cleaned up. Preset folder contents remain unaffected by lorebook deletions. * Folder counts are consistent across desktop and touch actions. <!-- 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-24 04:06:57 +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#7732
No description provided.