[GH-ISSUE #2448] [Issue]: 12-PROMPT-RUNTIME-lorebook-injection-budget-depth drops later smaller entries after budget skip #1202

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

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

Originally assigned to: @Promansis on GitHub.

Summary

12-PROMPT-RUNTIME-lorebook-injection-budget-depth parity gap from #2442 Batch 5: refactor treats the first over-budget lorebook entry as exhausting that lorebook/chat budget, so later smaller entries can be dropped. Legacy skips the over-budget entry but continues evaluating later candidates.

Expected behavior

Legacy behavior: lorebook budget selection skips an entry that exceeds the per-lorebook or chat token budget, records diagnostics, and continues checking later candidates that may still fit.

Acceptance criteria:

  • Over-budget lorebook entries do not permanently exhaust the lorebook/chat budget for later candidates in the same selection pass.
  • Later smaller entries that fit remaining budget are still selected.
  • Skipped-entry diagnostics are preserved.
  • World info before/after and depth injection order remain unchanged.

Actual behavior

Refactor sets exhaustedLorebookIds or chatBudgetExhausted when an entry is skipped, and subsequent candidates are treated as over budget even if they would fit remaining budget.

Steps to reproduce

  1. Create active lorebook entries where an earlier candidate exceeds the remaining lorebook or chat budget.
  2. Add a later candidate from the same active scope that is small enough to fit the remaining budget.
  3. Generate a prompt and inspect activated/skipped lorebook entries.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: refactor, static trace during #2442 Batch 5
  • Run mode: not run; static parityscan
  • OS + version: not relevant
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

Proof:

  • Legacy budget selection only checks lorebookBudget > 0 && lorebookTokens + entryTokens > lorebookBudget and tokenBudget > 0 && state.totalTokens + entryTokens > tokenBudget, then returns a skipped diagnostic without marking the entire budget exhausted: main:packages/server/src/services/lorebook/index.ts:428-456.
  • Refactor adds state.exhaustedLorebookIds.has(...) and state.chatBudgetExhausted to the over-budget checks, and sets those flags on a skip: src/engine/generation/active-lorebook-scanner.ts:653-664, src/engine/generation/active-lorebook-scanner.ts:679-717.
  • Refactor still returns budget skipped diagnostics through prompt assembly: src/engine/generation/prompt-assembly.ts:3485-3488.

Files inspected:

  • main:packages/server/src/services/lorebook/index.ts
  • main:packages/server/src/services/lorebook/prompt-injector.ts
  • main:packages/server/src/routes/generate.routes.ts
  • main:packages/server/src/services/prompt/assembler.ts
  • src/engine/generation/active-lorebook-scanner.ts
  • src/engine/generation-core/lorebooks/prompt-injector.ts
  • src/engine/generation/prompt-assembly.ts
  • src/engine/generation-core/lorebooks/active-lorebook-scope.ts

Regression notes

Legacy main behavior was traced as source of truth for #2442. This is a refactor parity gap in prompt assembly lorebook injection budgeting.

Additional context

Linked tracker: #2442
Surface: 12-PROMPT-RUNTIME-lorebook-injection-budget-depth

Batch 5 also scanned 12-PROMPT-RUNTIME-lorebook-scan-activation and found no gap; no issue filed for that surface.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2448 Originally assigned to: @Promansis on GitHub. ## Summary `12-PROMPT-RUNTIME-lorebook-injection-budget-depth` parity gap from #2442 Batch 5: refactor treats the first over-budget lorebook entry as exhausting that lorebook/chat budget, so later smaller entries can be dropped. Legacy skips the over-budget entry but continues evaluating later candidates. ## Expected behavior Legacy behavior: lorebook budget selection skips an entry that exceeds the per-lorebook or chat token budget, records diagnostics, and continues checking later candidates that may still fit. Acceptance criteria: - Over-budget lorebook entries do not permanently exhaust the lorebook/chat budget for later candidates in the same selection pass. - Later smaller entries that fit remaining budget are still selected. - Skipped-entry diagnostics are preserved. - World info before/after and depth injection order remain unchanged. ## Actual behavior Refactor sets `exhaustedLorebookIds` or `chatBudgetExhausted` when an entry is skipped, and subsequent candidates are treated as over budget even if they would fit remaining budget. ## Steps to reproduce 1. Create active lorebook entries where an earlier candidate exceeds the remaining lorebook or chat budget. 2. Add a later candidate from the same active scope that is small enough to fit the remaining budget. 3. Generate a prompt and inspect activated/skipped lorebook entries. ## Impact area - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] React-free engine behavior, contracts, agents, or capability ports - [ ] Shared API wrapper or remote runtime routing - [ ] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: refactor, static trace during #2442 Batch 5 - Run mode: not run; static parityscan - OS + version: not relevant - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video Proof: - Legacy budget selection only checks `lorebookBudget > 0 && lorebookTokens + entryTokens > lorebookBudget` and `tokenBudget > 0 && state.totalTokens + entryTokens > tokenBudget`, then returns a skipped diagnostic without marking the entire budget exhausted: `main:packages/server/src/services/lorebook/index.ts:428-456`. - Refactor adds `state.exhaustedLorebookIds.has(...)` and `state.chatBudgetExhausted` to the over-budget checks, and sets those flags on a skip: `src/engine/generation/active-lorebook-scanner.ts:653-664`, `src/engine/generation/active-lorebook-scanner.ts:679-717`. - Refactor still returns budget skipped diagnostics through prompt assembly: `src/engine/generation/prompt-assembly.ts:3485-3488`. Files inspected: - `main:packages/server/src/services/lorebook/index.ts` - `main:packages/server/src/services/lorebook/prompt-injector.ts` - `main:packages/server/src/routes/generate.routes.ts` - `main:packages/server/src/services/prompt/assembler.ts` - `src/engine/generation/active-lorebook-scanner.ts` - `src/engine/generation-core/lorebooks/prompt-injector.ts` - `src/engine/generation/prompt-assembly.ts` - `src/engine/generation-core/lorebooks/active-lorebook-scope.ts` ## Regression notes Legacy `main` behavior was traced as source of truth for #2442. This is a refactor parity gap in prompt assembly lorebook injection budgeting. ## Additional context Linked tracker: #2442 Surface: `12-PROMPT-RUNTIME-lorebook-injection-budget-depth` Batch 5 also scanned `12-PROMPT-RUNTIME-lorebook-scan-activation` and found no gap; no issue filed for that surface. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:56 +07:00
  • closed this issue
  • added the
    bug
    label
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#1202
No description provided.