[GH-ISSUE #1979] Anchor lorebook depth injection to chat history bounds #971

Closed
opened 2026-10-21 05:24:15 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @cha1latte on GitHub.

Problem

Target 7 lorebooks parityscan found a likely depth-injection parity gap.

Legacy anchored at depth lorebook entries to the chat history window. Refactor anchors depth entries against the full assembled prompt length, after other prompt and injected blocks may already be present.

Refactor evidence

  • src/engine/generation-core/lorebooks/prompt-injector.ts:73-82 accepts only messages and depth entries, then computes insertion with messages.length - entry.depth.
  • src/engine/generation/prompt-assembly.ts:2551-2564 inserts conversation/context blocks, then calls injectAtDepth without history bounds.
  • src/engine/generation/prompt-assembly.ts:1925-1928 inserts some context blocks before the last user message, which can change the full-message anchor used by depth injection.

Legacy behavior

  • packages/server/src/services/lorebook/prompt-injector.ts:19-24 supported minIndex and anchorIndex options.
  • packages/server/src/services/lorebook/prompt-injector.ts:95-104 inserted depth entries relative to the bounded anchor.
  • packages/server/src/services/prompt/assembler.ts:458-463 passed findHistoryBounds(finalMessages) into injectAtDepth.

Impact

Lorebook entries configured for at depth can land at a different prompt position when non-history prompt blocks sit after or inside the chat history area. That changes the relative placement expected by legacy/ST-style lorebooks.

Expected behavior

Depth injection should be anchored to the chat history bounds when history is present, matching legacy behavior. Fallback to full prompt length only when no history bounds exist.

Suggested fix

Restore bounded depth-injection options, compute history bounds in refactor prompt assembly before injecting lorebook/character/author-note depth entries, and add focused local proof with prompt blocks around history plus an at depth lorebook entry.

Parent: #1904 target 7 lorebooks parityscan.

Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1979 Originally assigned to: @cha1latte on GitHub. ## Problem Target 7 lorebooks parityscan found a likely depth-injection parity gap. Legacy anchored `at depth` lorebook entries to the chat history window. Refactor anchors depth entries against the full assembled prompt length, after other prompt and injected blocks may already be present. ## Refactor evidence - `src/engine/generation-core/lorebooks/prompt-injector.ts:73-82` accepts only messages and depth entries, then computes insertion with `messages.length - entry.depth`. - `src/engine/generation/prompt-assembly.ts:2551-2564` inserts conversation/context blocks, then calls `injectAtDepth` without history bounds. - `src/engine/generation/prompt-assembly.ts:1925-1928` inserts some context blocks before the last user message, which can change the full-message anchor used by depth injection. ## Legacy behavior - `packages/server/src/services/lorebook/prompt-injector.ts:19-24` supported `minIndex` and `anchorIndex` options. - `packages/server/src/services/lorebook/prompt-injector.ts:95-104` inserted depth entries relative to the bounded anchor. - `packages/server/src/services/prompt/assembler.ts:458-463` passed `findHistoryBounds(finalMessages)` into `injectAtDepth`. ## Impact Lorebook entries configured for `at depth` can land at a different prompt position when non-history prompt blocks sit after or inside the chat history area. That changes the relative placement expected by legacy/ST-style lorebooks. ## Expected behavior Depth injection should be anchored to the chat history bounds when history is present, matching legacy behavior. Fallback to full prompt length only when no history bounds exist. ## Suggested fix Restore bounded depth-injection options, compute history bounds in refactor prompt assembly before injecting lorebook/character/author-note depth entries, and add focused local proof with prompt blocks around history plus an `at depth` lorebook entry. Parent: #1904 target 7 lorebooks parityscan.
bsakaguchi 2026-10-21 05:24:15 +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#971
No description provided.