[PR #2047] [MERGED] Fix batched lorebook activation entry reads #5409

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-2035-lorebook-entry-batch


📝 Commits (1)

  • db1d97d Fix batched lorebook activation entry reads

📊 Changes

9 files changed (+305 additions, -11 deletions)

View changed files

📝 src-tauri/src/commands/storage/commands/entities.rs (+71 -0)
📝 src-tauri/src/http_dispatch.rs (+50 -1)
📝 src-tauri/src/lib.rs (+1 -0)
📝 src/engine/capabilities/storage.ts (+1 -0)
➕ src/engine/generation/active-lorebook-scanner.test.ts (+94 -0)
📝 src/engine/generation/active-lorebook-scanner.ts (+74 -6)
📝 src/engine/generation/tools-runtime.ts (+3 -3)
📝 src/shared/api/remote-runtime.ts (+1 -0)
📝 src/shared/api/storage-api.ts (+10 -1)

📄 Description

Linked issue

Closes #2035

Why this change

  • Active lorebook activation was reading entries once per active lorebook, which multiplies the collection scan cost on large profiles.

What changed

  • Added a focused batched lorebook-entry read command backed by the existing Rust list_where_in storage primitive.
  • Added a shared API wrapper and optional StorageGateway method for batched lorebook-entry reads.
  • Updated active lorebook scanning and stored lorebook tool search to group batched entries by lorebook in memory while preserving disabled-folder filtering and the single-book fallback for lightweight gateways.
  • Added focused TypeScript and Rust coverage for the batched scanner path plus desktop/remote command dispatch.

Refactor impact

Primary owner:

  • Engine generation, shared API, Rust storage/remote runtime.

Impact areas reviewed:

  • Active lorebook prompt assembly.
  • Active lorebook info scans through scanActiveLorebooks.
  • Stored lorebook search used by generation tool runtime.
  • Embedded Tauri command registration and remote runtime command dispatch.

Boundary notes:

  • Engine code still depends only on the StorageGateway capability.
  • Feature/runtime code continues through shared API wrappers, not raw Tauri.
  • The new Rust command is focused on lorebook entries and is also exposed through the remote runtime allowlist/dispatch path.

Pressure points touched:

  • src-tauri/src/lib.rs command registration.
  • src-tauri/src/http_dispatch.rs remote command dispatch.
  • src/engine/generation/active-lorebook-scanner.ts prompt assembly scanner.
  • src/engine/generation/tools-runtime.ts stored lorebook search.

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 ran pnpm exec vitest run src/engine/generation/active-lorebook-scanner.test.ts: passed. The scanner read three active lorebooks with one batched entry read and zero single-book entry reads, while excluding an entry in a disabled folder.
  • Codex ran cargo test --manifest-path src-tauri/Cargo.toml lorebook_entries_list_by_lorebook_ids -- --nocapture: passed. Covers the native command helper and remote dispatch path with should-not-match lorebook rows.
  • Codex ran node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json: passed.
  • Codex ran pnpm check: passed after the final staged diff, including the new test file.
  • Bunny review: pass before PR open. Boundary and proof were reviewed against the core claim.

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 is an internal read-path performance regression fix and does not add user-discoverable behavior.

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. This is a backend/prompt-assembly read-path fix with no visible UI state. Verification is command-based and recorded above.

Summary by CodeRabbit

  • New Features

    • Added batch retrieval capability for lorebook entries from multiple lorebooks in a single operation, improving performance during lore activation and search operations.
  • Tests

    • Added tests verifying correct batch loading of lorebook entries with proper filtering of active entries across multiple lorebooks and fallback behavior.

🔄 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/2047 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-2035-lorebook-entry-batch` --- ### 📝 Commits (1) - [`db1d97d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db1d97dae413b672d6961531ce5a9bd593a9e696) Fix batched lorebook activation entry reads ### 📊 Changes **9 files changed** (+305 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/commands/entities.rs` (+71 -0) 📝 `src-tauri/src/http_dispatch.rs` (+50 -1) 📝 `src-tauri/src/lib.rs` (+1 -0) 📝 `src/engine/capabilities/storage.ts` (+1 -0) ➕ `src/engine/generation/active-lorebook-scanner.test.ts` (+94 -0) 📝 `src/engine/generation/active-lorebook-scanner.ts` (+74 -6) 📝 `src/engine/generation/tools-runtime.ts` (+3 -3) 📝 `src/shared/api/remote-runtime.ts` (+1 -0) 📝 `src/shared/api/storage-api.ts` (+10 -1) </details> ### 📄 Description ## Linked issue Closes #2035 ## Why this change - Active lorebook activation was reading entries once per active lorebook, which multiplies the collection scan cost on large profiles. ## What changed - Added a focused batched lorebook-entry read command backed by the existing Rust `list_where_in` storage primitive. - Added a shared API wrapper and optional `StorageGateway` method for batched lorebook-entry reads. - Updated active lorebook scanning and stored lorebook tool search to group batched entries by lorebook in memory while preserving disabled-folder filtering and the single-book fallback for lightweight gateways. - Added focused TypeScript and Rust coverage for the batched scanner path plus desktop/remote command dispatch. ## Refactor impact Primary owner: - Engine generation, shared API, Rust storage/remote runtime. Impact areas reviewed: - Active lorebook prompt assembly. - Active lorebook info scans through `scanActiveLorebooks`. - Stored lorebook search used by generation tool runtime. - Embedded Tauri command registration and remote runtime command dispatch. Boundary notes: - Engine code still depends only on the `StorageGateway` capability. - Feature/runtime code continues through shared API wrappers, not raw Tauri. - The new Rust command is focused on lorebook entries and is also exposed through the remote runtime allowlist/dispatch path. Pressure points touched: - `src-tauri/src/lib.rs` command registration. - `src-tauri/src/http_dispatch.rs` remote command dispatch. - `src/engine/generation/active-lorebook-scanner.ts` prompt assembly scanner. - `src/engine/generation/tools-runtime.ts` stored lorebook search. ## 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 ran `pnpm exec vitest run src/engine/generation/active-lorebook-scanner.test.ts`: passed. The scanner read three active lorebooks with one batched entry read and zero single-book entry reads, while excluding an entry in a disabled folder. - Codex ran `cargo test --manifest-path src-tauri/Cargo.toml lorebook_entries_list_by_lorebook_ids -- --nocapture`: passed. Covers the native command helper and remote dispatch path with should-not-match lorebook rows. - Codex ran `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json`: passed. - Codex ran `pnpm check`: passed after the final staged diff, including the new test file. - Bunny review: pass before PR open. Boundary and proof were reviewed against the core claim. ## 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 is an internal read-path performance regression fix and does not add user-discoverable behavior. ## 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. This is a backend/prompt-assembly read-path fix with no visible UI state. Verification is command-based and recorded above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added batch retrieval capability for lorebook entries from multiple lorebooks in a single operation, improving performance during lore activation and search operations. * **Tests** * Added tests verifying correct batch loading of lorebook entries with proper filtering of active entries across multiple lorebooks and fallback behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:03 +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#5409
No description provided.