[PR #528] [MERGED] Fix stale linked lorebook count after deletion #4655

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/528
Author: @cha1latte
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @cha1latte

Base: main ← Head: fix/issue-494-linked-lorebook-count


📝 Commits (2)

  • 7ca641c Fix stale linked lorebook count after deletion
  • 4da2af0 Add real UI evidence for issue 494

📊 Changes

6 files changed (+35 additions, -8 deletions)

View changed files

➕ docs/pr-evidence/494/issue-494-proof.png (+0 -0)
➕ docs/pr-evidence/494/issue-494-real-ui-after.png (+0 -0)
➕ docs/pr-evidence/494/issue-494-real-ui-before.png (+0 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+15 -8)
📝 packages/server/src/routes/lorebooks.routes.ts (+2 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+18 -0)

📄 Description

Linked issue

Closes #494

Why this change

  • Deleting a lorebook that was linked to a chat left its ID in activeLorebookIds, so the chat settings drawer could show two visible lorebooks while the Lorebooks section count still reported three, even after restart.

What changed

  • Removed deleted lorebook IDs from chat metadata when a whole lorebook is deleted.
  • Kept the chat metadata cleanup on the queued metadata patch path so unrelated metadata edits are preserved.
  • Count and render only linked lorebooks that still exist in the chat settings drawer.
  • Added real before/after app screenshots for the chat settings Lorebooks section.

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

  • Codex verification:
    • pnpm --dir packages/server exec tsx ../../scratch/issue-494-linked-lorebook-count-repro.ts
      • Before fix: reproduced the stale raw count case where metadata still had 3 linked lorebook IDs while only 2 lorebooks still existed.
      • After fix: passed; deleting the stale lorebook ID removes it from chat metadata while preserving unrelated metadata and unaffected chats.
    • pnpm check passed locally.
    • GitHub container-build-test passed on PR #528.
    • GitHub pnpm-validate passed on PR #528.
    • CodeRabbit review completed with no inline comments or unresolved review threads on the previous head; re-run requested after the evidence-only push.
    • CONTRIBUTING.md and AGENTS.md were read for PR/validation rules.
    • pnpm db:push was attempted, but this checkout has no db:push script; no schema files changed.
  • Real app UI verification:
    • Started the fixed branch locally with pnpm dev.
    • Seeded a roleplay chat with three linked lorebooks through the app API.
    • Opened the real Chat Settings drawer in Playwright and captured the Lorebooks section showing count 3 and three linked lorebooks.
    • Deleted one linked lorebook through the app API.
    • Reopened the same real Chat Settings drawer in Playwright and captured the Lorebooks section showing count 2 with only the two remaining lorebooks.
  • Checked edge cases:
    • Removed lorebook disappears from the expanded list.
    • Remaining linked lorebooks stay visible.
    • Empty/unrelated metadata is preserved by the focused storage repro.
    • No schema files changed; pnpm db:push is not available in this checkout.

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)

No user-facing docs or version files changed.

UI evidence (if applicable)

Before deleting one of three linked lorebooks, the real Chat Settings drawer shows count 3 and all three linked lorebooks:

Before deleting linked lorebook

After deleting the middle linked lorebook, the real Chat Settings drawer shows count 2 and only the two remaining linked lorebooks:

After deleting linked lorebook

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where deleted lorebooks could remain active in chats. Lorebook references are now properly cleaned up when a lorebook is deleted, and the chat interface displays only valid active lorebooks.

🔄 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/528 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/7/2026 **Status:** ✅ Merged **Merged:** 5/7/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `main` ← **Head:** `fix/issue-494-linked-lorebook-count` --- ### 📝 Commits (2) - [`7ca641c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7ca641cf893db67a68dcfba253420e52521ae29c) Fix stale linked lorebook count after deletion - [`4da2af0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4da2af0438dddeb02a403e7f7a597e93846c40c0) Add real UI evidence for issue 494 ### 📊 Changes **6 files changed** (+35 additions, -8 deletions) <details> <summary>View changed files</summary> ➕ `docs/pr-evidence/494/issue-494-proof.png` (+0 -0) ➕ `docs/pr-evidence/494/issue-494-real-ui-after.png` (+0 -0) ➕ `docs/pr-evidence/494/issue-494-real-ui-before.png` (+0 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+15 -8) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+2 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+18 -0) </details> ### 📄 Description ## 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 #494 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - Deleting a lorebook that was linked to a chat left its ID in `activeLorebookIds`, so the chat settings drawer could show two visible lorebooks while the Lorebooks section count still reported three, even after restart. ## What changed <!-- List the key changes in this PR --> - Removed deleted lorebook IDs from chat metadata when a whole lorebook is deleted. - Kept the chat metadata cleanup on the queued metadata patch path so unrelated metadata edits are preserved. - Count and render only linked lorebooks that still exist in the chat settings drawer. - Added real before/after app screenshots for the chat settings Lorebooks section. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [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 <!-- Describe exactly what was tested, including commands, browser flows, evidence artifacts, and remaining blockers. --> <!-- If Codex ticked a box, it must also describe the exact proof for that item. Untick anything not backed by concrete evidence in this PR body. --> - Codex verification: - `pnpm --dir packages/server exec tsx ../../scratch/issue-494-linked-lorebook-count-repro.ts` - Before fix: reproduced the stale raw count case where metadata still had 3 linked lorebook IDs while only 2 lorebooks still existed. - After fix: passed; deleting the stale lorebook ID removes it from chat metadata while preserving unrelated metadata and unaffected chats. - `pnpm check` passed locally. - GitHub `container-build-test` passed on PR #528. - GitHub `pnpm-validate` passed on PR #528. - CodeRabbit review completed with no inline comments or unresolved review threads on the previous head; re-run requested after the evidence-only push. - `CONTRIBUTING.md` and `AGENTS.md` were read for PR/validation rules. - `pnpm db:push` was attempted, but this checkout has no `db:push` script; no schema files changed. - Real app UI verification: - Started the fixed branch locally with `pnpm dev`. - Seeded a roleplay chat with three linked lorebooks through the app API. - Opened the real Chat Settings drawer in Playwright and captured the Lorebooks section showing count `3` and three linked lorebooks. - Deleted one linked lorebook through the app API. - Reopened the same real Chat Settings drawer in Playwright and captured the Lorebooks section showing count `2` with only the two remaining lorebooks. - Checked edge cases: - Removed lorebook disappears from the expanded list. - Remaining linked lorebooks stay visible. - Empty/unrelated metadata is preserved by the focused storage repro. - No schema files changed; `pnpm db:push` is not available in this checkout. ## 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) No user-facing docs or version files changed. ## UI evidence (if applicable) Before deleting one of three linked lorebooks, the real Chat Settings drawer shows count `3` and all three linked lorebooks: ![Before deleting linked lorebook](https://raw.githubusercontent.com/cha1latte/Marinara-Engine/fix/issue-494-linked-lorebook-count/docs/pr-evidence/494/issue-494-real-ui-before.png) After deleting the middle linked lorebook, the real Chat Settings drawer shows count `2` and only the two remaining linked lorebooks: ![After deleting linked lorebook](https://raw.githubusercontent.com/cha1latte/Marinara-Engine/fix/issue-494-linked-lorebook-count/docs/pr-evidence/494/issue-494-real-ui-after.png) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue where deleted lorebooks could remain active in chats. Lorebook references are now properly cleaned up when a lorebook is deleted, and the chat interface displays only valid active lorebooks. <!-- 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:09:31 +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#4655
No description provided.