[PR #1984] [MERGED] Fix latest user lorebook budget priority #5375

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1984
Author: @cha1latte
Created: 6/2/2026
Status: ✅ Merged
Merged: 6/2/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/issue-1978-latest-lorebook-budget


📝 Commits (1)

  • ae73f0b Fix latest user lorebook budget priority

📊 Changes

3 files changed (+107 additions, -1 deletions)

View changed files

📝 src/engine/generation-core/lorebooks/keyword-scanner.ts (+14 -0)
➕ src/engine/generation-core/lorebooks/prompt-injector.test.ts (+90 -0)
📝 src/engine/generation-core/lorebooks/prompt-injector.ts (+3 -1)

📄 Description

Linked issue

Closes #1978

Why this change

  • Target 7 lorebooks parityscan found that the refactor dropped legacy latest-user-message match metadata during lorebook activation. Under a tight lorebook token budget, an older-context match could consume budget before an entry that matched the newest user turn.

What changed

  • Added matchedLatestUserMessage metadata to activated lorebook entries when a primary key matches the latest user message.
  • Updated lorebook token-budget ordering to keep constants first, then latest-user-message primary-key matches, then existing entry order.
  • Added a focused regression test for two activated non-constant entries where budget only fits the latest-user match.

Refactor impact

Primary owner:

  • engine generation

Impact areas reviewed:

  • Lorebook keyword scanner metadata.
  • Lorebook token-budget ordering and skipped-entry diagnostics.
  • Prompt assembly callers that consume ActivatedEntry metadata.

Boundary notes:

  • Change stays in src/engine; no React, shared API, Tauri, storage, import/export, provider, or UI boundaries changed.

Pressure points touched:

  • Lorebook prompt injection budget ordering only.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Codex scratch repro before fix: pnpm exec vitest run --config scratch\vitest.issue-1978.config.mts failed because budget selection included older-context instead of latest-user.
  • Codex scratch repro after fix: pnpm exec vitest run --config scratch\vitest.issue-1978.config.mts passed.
  • Codex committed regression: pnpm exec vitest run src\engine\generation-core\lorebooks\prompt-injector.test.ts passed.
  • Codex lane check: pnpm typecheck passed.
  • Codex pre-PR baseline after rebase: pnpm check passed.
  • Codex proof gate: node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json passed.
  • Bunny review: passed before draft prep; branch is one focused commit ahead of upstream/refactor, diff scope is three lorebook engine files, and git diff --check upstream/refactor...HEAD is clean.
  • Manual live generation UI smoke not run; the core claim is covered by lorebook scanner/budgeter tests and this PR does not change visible UI.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Bugfix only; no new discoverable feature or workflow.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

N/A; no visible UI change.


🔄 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/1984 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/2/2026 **Status:** ✅ Merged **Merged:** 6/2/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-1978-latest-lorebook-budget` --- ### 📝 Commits (1) - [`ae73f0b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ae73f0b4a84d73c839db77533dafe7a5f97597d0) Fix latest user lorebook budget priority ### 📊 Changes **3 files changed** (+107 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation-core/lorebooks/keyword-scanner.ts` (+14 -0) ➕ `src/engine/generation-core/lorebooks/prompt-injector.test.ts` (+90 -0) 📝 `src/engine/generation-core/lorebooks/prompt-injector.ts` (+3 -1) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #1978 ## Why this change - Target 7 lorebooks parityscan found that the refactor dropped legacy latest-user-message match metadata during lorebook activation. Under a tight lorebook token budget, an older-context match could consume budget before an entry that matched the newest user turn. ## What changed - Added `matchedLatestUserMessage` metadata to activated lorebook entries when a primary key matches the latest user message. - Updated lorebook token-budget ordering to keep constants first, then latest-user-message primary-key matches, then existing entry order. - Added a focused regression test for two activated non-constant entries where budget only fits the latest-user match. ## Refactor impact Primary owner: - engine generation Impact areas reviewed: - Lorebook keyword scanner metadata. - Lorebook token-budget ordering and skipped-entry diagnostics. - Prompt assembly callers that consume `ActivatedEntry` metadata. Boundary notes: - Change stays in `src/engine`; no React, shared API, Tauri, storage, import/export, provider, or UI boundaries changed. Pressure points touched: - Lorebook prompt injection budget ordering only. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Codex scratch repro before fix: `pnpm exec vitest run --config scratch\vitest.issue-1978.config.mts` failed because budget selection included `older-context` instead of `latest-user`. - Codex scratch repro after fix: `pnpm exec vitest run --config scratch\vitest.issue-1978.config.mts` passed. - Codex committed regression: `pnpm exec vitest run src\engine\generation-core\lorebooks\prompt-injector.test.ts` passed. - Codex lane check: `pnpm typecheck` passed. - Codex pre-PR baseline after rebase: `pnpm check` passed. - Codex proof gate: `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` passed. - Bunny review: passed before draft prep; branch is one focused commit ahead of `upstream/refactor`, diff scope is three lorebook engine files, and `git diff --check upstream/refactor...HEAD` is clean. - Manual live generation UI smoke not run; the core claim is covered by lorebook scanner/budgeter tests and this PR does not change visible UI. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Bugfix only; no new discoverable feature or workflow. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence N/A; no visible UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:15:43 +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#5375
No description provided.