[GH-ISSUE #1793] Restore lorebook parity for delete cleanup, prompt injection, ephemeral entries, and imports #874

Closed
opened 2026-10-21 05:22:43 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Xelvanis on GitHub (Jun 1, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1793

Originally assigned to: @cha1latte on GitHub.

Summary

Legacy lorebook behavior has several parity gaps in the refactor path. These affect deletion cleanup, prompt assembly correctness, ephemeral entry state, macro/budget handling, and SillyTavern import normalization.

Refactor commit audited: 84f40efd

Findings

1. Deleting a lorebook does not clear linked references

Refactor generic deletion removes the lorebook plus child entries/folders, but does not clear chat metadata or linked character embedded-lorebook metadata.

Refactor paths:

  • src/features/catalog/lorebooks/hooks/use-lorebooks.ts
  • src-tauri/src/commands/storage/commands/entities.rs

Legacy paths:

  • packages/server/src/routes/lorebooks.routes.ts
  • packages/server/src/services/lorebook/character-book-sync.ts

Expected behavior:

  • Remove deleted lorebook IDs from chat activeLorebookIds
  • Clear linked character character_book
  • Clear extensions.importMetadata.embeddedLorebook

2. Depth injection can shift prompt positions

Refactor depth injection computes insertion indexes against a mutating message array. Legacy anchors insertion against original history bounds before splicing.

Refactor paths:

  • src/engine/generation-core/lorebooks/prompt-injector.ts
  • src/engine/generation/prompt-assembly.ts

Legacy paths:

  • packages/server/src/services/lorebook/prompt-injector.ts
  • packages/server/src/services/prompt/assembler.ts

Impact:
Mixed-depth lorebook entries, character depth prompts, and author note insertion can land at different positions than legacy.

3. Ephemeral lore entries do not decrement per chat

Refactor has entryStateOverrides in the chat contract, but active lorebook scanning does not apply or persist ephemeral countdown state.

Refactor paths:

  • src/engine/contracts/types/chat.ts
  • src/engine/generation/active-lorebook-scanner.ts
  • src/engine/generation/start-generation.ts

Legacy path:

  • packages/server/src/services/lorebook/index.ts

Impact:
Finite-use lore entries can continue activating after their intended use count reaches zero.

4. Lore macro and budget handling is weaker than legacy

Refactor budgets raw lore content and injects some lore without macro resolution. Legacy resolves lore content with variable snapshot commit/rollback before final budget selection.

Refactor paths:

  • src/engine/generation/active-lorebook-scanner.ts
  • src/engine/generation-core/lorebooks/prompt-injector.ts
  • src/engine/generation/prompt-assembly.ts

Legacy paths:

  • packages/server/src/services/prompt/macro-context.ts
  • packages/server/src/services/lorebook/index.ts
  • packages/server/src/services/prompt/marker-expander.ts

Impact:
Lore entries can be selected based on pre-expansion size, dropped macro side effects are not handled like legacy, and some injected lore can keep unresolved macros.

5. SillyTavern import normalization misses selective/probability cases

Refactor import normalization can preserve raw numeric selectiveLogic and does not handle useProbability: false.

Refactor path:

  • src-tauri/src/commands/storage/imports/normalization.rs

Legacy path:

  • packages/server/src/services/import/st-lorebook.importer.ts

Expected behavior:

  • Map SillyTavern selectiveLogic values: 0 -> and, 1 -> or, 2 -> not
  • Treat useProbability: false / use_probability: false as disabled probability

Non-gaps / intentional differences

  • Refactor lorebook schema is mostly aligned with legacy.
  • Refactor UI is mostly parity or better after the latest editor split.
  • Local sidecar embeddings appear intentionally retired in refactor, not a parity bug.

Suggested fix order

  1. Add lorebook delete cleanup for chat metadata and linked character embedded refs.
  2. Port anchor-aware depth injection.
  3. Apply and persist per-chat ephemeral entry overrides.
  4. Port macro-aware lore budget selection with commit/rollback behavior.
  5. Normalize SillyTavern selective logic and probability flags during import.

Verification

Static parity audit only. No app run or automated test pass was performed for this report.

Originally created by @Xelvanis on GitHub (Jun 1, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1793 Originally assigned to: @cha1latte on GitHub. ## Summary Legacy lorebook behavior has several parity gaps in the refactor path. These affect deletion cleanup, prompt assembly correctness, ephemeral entry state, macro/budget handling, and SillyTavern import normalization. Refactor commit audited: `84f40efd` ## Findings ### 1. Deleting a lorebook does not clear linked references Refactor generic deletion removes the lorebook plus child entries/folders, but does not clear chat metadata or linked character embedded-lorebook metadata. Refactor paths: - `src/features/catalog/lorebooks/hooks/use-lorebooks.ts` - `src-tauri/src/commands/storage/commands/entities.rs` Legacy paths: - `packages/server/src/routes/lorebooks.routes.ts` - `packages/server/src/services/lorebook/character-book-sync.ts` Expected behavior: - Remove deleted lorebook IDs from chat `activeLorebookIds` - Clear linked character `character_book` - Clear `extensions.importMetadata.embeddedLorebook` ### 2. Depth injection can shift prompt positions Refactor depth injection computes insertion indexes against a mutating message array. Legacy anchors insertion against original history bounds before splicing. Refactor paths: - `src/engine/generation-core/lorebooks/prompt-injector.ts` - `src/engine/generation/prompt-assembly.ts` Legacy paths: - `packages/server/src/services/lorebook/prompt-injector.ts` - `packages/server/src/services/prompt/assembler.ts` Impact: Mixed-depth lorebook entries, character depth prompts, and author note insertion can land at different positions than legacy. ### 3. Ephemeral lore entries do not decrement per chat Refactor has `entryStateOverrides` in the chat contract, but active lorebook scanning does not apply or persist ephemeral countdown state. Refactor paths: - `src/engine/contracts/types/chat.ts` - `src/engine/generation/active-lorebook-scanner.ts` - `src/engine/generation/start-generation.ts` Legacy path: - `packages/server/src/services/lorebook/index.ts` Impact: Finite-use lore entries can continue activating after their intended use count reaches zero. ### 4. Lore macro and budget handling is weaker than legacy Refactor budgets raw lore content and injects some lore without macro resolution. Legacy resolves lore content with variable snapshot commit/rollback before final budget selection. Refactor paths: - `src/engine/generation/active-lorebook-scanner.ts` - `src/engine/generation-core/lorebooks/prompt-injector.ts` - `src/engine/generation/prompt-assembly.ts` Legacy paths: - `packages/server/src/services/prompt/macro-context.ts` - `packages/server/src/services/lorebook/index.ts` - `packages/server/src/services/prompt/marker-expander.ts` Impact: Lore entries can be selected based on pre-expansion size, dropped macro side effects are not handled like legacy, and some injected lore can keep unresolved macros. ### 5. SillyTavern import normalization misses selective/probability cases Refactor import normalization can preserve raw numeric `selectiveLogic` and does not handle `useProbability: false`. Refactor path: - `src-tauri/src/commands/storage/imports/normalization.rs` Legacy path: - `packages/server/src/services/import/st-lorebook.importer.ts` Expected behavior: - Map SillyTavern `selectiveLogic` values: `0 -> and`, `1 -> or`, `2 -> not` - Treat `useProbability: false` / `use_probability: false` as disabled probability ## Non-gaps / intentional differences - Refactor lorebook schema is mostly aligned with legacy. - Refactor UI is mostly parity or better after the latest editor split. - Local sidecar embeddings appear intentionally retired in refactor, not a parity bug. ## Suggested fix order 1. Add lorebook delete cleanup for chat metadata and linked character embedded refs. 2. Port anchor-aware depth injection. 3. Apply and persist per-chat ephemeral entry overrides. 4. Port macro-aware lore budget selection with commit/rollback behavior. 5. Normalize SillyTavern selective logic and probability flags during import. ## Verification Static parity audit only. No app run or automated test pass was performed for this report.
Author
Owner

@cha1latte commented on GitHub (Jun 1, 2026):

Fixed in #1834

<!-- gh-comment-id:4595177598 --> @cha1latte commented on GitHub (Jun 1, 2026): Fixed in #1834
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#874
No description provided.