[PR #2355] [MERGED] Fix lorebook macro rollback on budget skips #5558

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-2278-lorebook-var-rollback


📝 Commits (4)

  • 03103a6 Fix lorebook macro rollback on budget skips
  • bdd5126 Port lorebook macro budget convergence
  • 4995235 Preserve lorebook budget skip state
  • 3c08a4c Cover lorebook budget replay regressions

📊 Changes

4 files changed (+460 additions, -44 deletions)

View changed files

📝 src/engine/generation-core/lorebooks/prompt-injector.ts (+4 -2)
📝 src/engine/generation/active-lorebook-scanner.test.ts (+265 -0)
📝 src/engine/generation/active-lorebook-scanner.ts (+180 -42)
📝 src/engine/generation/prompt-assembly.ts (+11 -0)

📄 Description

Linked issue

Closes #2278

Why this change

  • Budget-dropped lorebook entries resolved macros before their budget check, so {{setvar}}/{{addvar}} mutations from entries that were never injected could leak into later kept entries and prompt sections.

What changed

  • Added an optional variable snapshot hook to lorebook content resolution.
  • Restored the macro-variable snapshot only when an activated lorebook entry is skipped by lorebook/chat budget.
  • Wired prompt assembly's macro resolver to provide that snapshot.
  • Added regression coverage proving skipped setvar rolls back while selected setvar still commits for later kept entries.

Refactor impact

Primary owner:

  • engine generation

Impact areas reviewed:

  • Active lorebook budget selection
  • Prompt assembly macro resolution
  • Lorebook content resolver contract

Boundary notes:

  • The fix stays in React-free engine code and prompt assembly wiring.
  • No shared API, feature UI, Rust, remote runtime, schema, storage, dependency, or release metadata changes.

Pressure points touched:

  • scanActiveLorebooks budget selection
  • assembleGenerationPrompt lorebook content resolver

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 reproduced the regression with pnpm test src\engine\generation\active-lorebook-scanner.test.ts: before the fix, the kept entry resolved to flag=leaked instead of the prior value.
  • Codex verified the fix with pnpm test src\engine\generation\active-lorebook-scanner.test.ts: 9 tests passed, including the rollback regression and the selected-entry commit edge case.
  • Codex ran pnpm typecheck: passed.
  • Codex ran pnpm check: passed.
  • Codex ran the Marinara proof gate against scratch/bugfix-verification.json: passed.
  • Bunny review pass: passed before opening this draft.
  • Manual UI verification: N/A, this is a React-free engine logic regression with no visible UI state.

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:

  • N/A; this fixes internal lorebook macro behavior and does not add a user-discoverable feature.

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

No docs or release-note changes needed for this narrow engine regression fix.

UI evidence

N/A. This is a React-free engine logic fix; command proof is listed above.


🔄 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/2355 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/issue-2278-lorebook-var-rollback` --- ### 📝 Commits (4) - [`03103a6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/03103a6dbbcdf13fe0b31af8fdfb3f457bfb9948) Fix lorebook macro rollback on budget skips - [`bdd5126`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdd5126ad5decbe1021269d707c26bb58f2a5ac4) Port lorebook macro budget convergence - [`4995235`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4995235c5969570478873079e74735a53bb1b97b) Preserve lorebook budget skip state - [`3c08a4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3c08a4c7ce6843d59c04b0f9165835720ed5602c) Cover lorebook budget replay regressions ### 📊 Changes **4 files changed** (+460 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation-core/lorebooks/prompt-injector.ts` (+4 -2) 📝 `src/engine/generation/active-lorebook-scanner.test.ts` (+265 -0) 📝 `src/engine/generation/active-lorebook-scanner.ts` (+180 -42) 📝 `src/engine/generation/prompt-assembly.ts` (+11 -0) </details> ### 📄 Description ## Linked issue Closes #2278 ## Why this change - Budget-dropped lorebook entries resolved macros before their budget check, so `{{setvar}}`/`{{addvar}}` mutations from entries that were never injected could leak into later kept entries and prompt sections. ## What changed - Added an optional variable snapshot hook to lorebook content resolution. - Restored the macro-variable snapshot only when an activated lorebook entry is skipped by lorebook/chat budget. - Wired prompt assembly's macro resolver to provide that snapshot. - Added regression coverage proving skipped `setvar` rolls back while selected `setvar` still commits for later kept entries. ## Refactor impact Primary owner: - engine generation Impact areas reviewed: - Active lorebook budget selection - Prompt assembly macro resolution - Lorebook content resolver contract Boundary notes: - The fix stays in React-free engine code and prompt assembly wiring. - No shared API, feature UI, Rust, remote runtime, schema, storage, dependency, or release metadata changes. Pressure points touched: - `scanActiveLorebooks` budget selection - `assembleGenerationPrompt` lorebook content resolver ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Codex reproduced the regression with `pnpm test src\engine\generation\active-lorebook-scanner.test.ts`: before the fix, the kept entry resolved to `flag=leaked` instead of the prior value. - Codex verified the fix with `pnpm test src\engine\generation\active-lorebook-scanner.test.ts`: 9 tests passed, including the rollback regression and the selected-entry commit edge case. - Codex ran `pnpm typecheck`: passed. - Codex ran `pnpm check`: passed. - Codex ran the Marinara proof gate against `scratch/bugfix-verification.json`: passed. - Bunny review pass: passed before opening this draft. - Manual UI verification: N/A, this is a React-free engine logic regression with no visible UI state. ## 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. - [x] 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: - N/A; this fixes internal lorebook macro behavior and does not add a user-discoverable feature. ## Docs and release impact - [x] 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 No docs or release-note changes needed for this narrow engine regression fix. ## UI evidence N/A. This is a React-free engine logic fix; command proof is listed above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:22 +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#5558
No description provided.