[GH-ISSUE #1549] [Issue]: search_lorebook tool returns disabled and out-of-scope lorebook entries #794

Closed
opened 2026-10-20 17:33:27 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

The built-in search_lorebook tool still searches every stored lorebook entry, so disabled or out-of-scope lorebooks can be returned to tool-using agents.

Expected behavior

search_lorebook should only return entries that are allowed for the active chat/generation context, or its contract should clearly distinguish a global library search from active lorebook retrieval. Disabled lorebooks, disabled folders, and unrelated chat/character/persona scopes should not leak into agent tool results by default.

Actual behavior

Native Tauri QA on origin/refactor showed search_lorebook returning an entry from a disabled lorebook when activatedLorebookEntries was empty. Source inspection matches the behavior: src/engine/generation/tools-runtime.ts loads all lorebook-entries, merges them with activated entries, and scores them without checking the parent lorebook enabled/scope/folder state.

Steps to reproduce

  1. Create or seed a disabled lorebook with an enabled entry whose content contains a unique marker.
  2. In a persisted chat, call the built-in search_lorebook tool with a query matching that marker and an empty activatedLorebookEntries input.
  3. Observe that the disabled lorebook entry is returned with source: "stored".
  4. Compare against the dedicated Knowledge Retrieval/Router source path in src/engine/generation/agent-runner.ts, which now scopes source lorebooks before loading 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: origin/refactor at f120eb33
  • Run mode: Tauri desktop
  • OS + version: Windows desktop, exact version not captured
  • Node + pnpm versions: Node v24.16.0, pnpm 10.33.2
  • Rust version, if relevant: rustc 1.95.0
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant; reproduced through native app storage/tool runtime path

Logs, screenshots, or video

No public screenshot needed. Native QA proof returned the disabled-book entry from search_lorebook with source: "stored". The relevant code path is src/engine/generation/tools-runtime.ts, where searchLorebookTool(...) calls storage.list("lorebook-entries") and scores all rows.

Regression notes

Related to #1505, which was closed after the dedicated Knowledge Retrieval/Router executors were scoped. This appears to be a remaining built-in tool path rather than the exact executor path fixed for that issue.

Additional context

Acceptance criteria could be either:

  • Filter stored fallback entries through the same active lorebook scope rules used by the agent knowledge source path, including disabled lorebooks/folders and chat/character/persona scope; or
  • Change the tool contract/UI copy so search_lorebook is explicitly a global library search, then make that behavior visible and opt-in enough that disabled/out-of-scope entries are not surprising.

Add regression coverage for disabled and unrelated lorebooks once the intended contract is chosen.

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 @Xelvanis on GitHub (May 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1549 Originally assigned to: @Promansis on GitHub. ## Summary The built-in `search_lorebook` tool still searches every stored lorebook entry, so disabled or out-of-scope lorebooks can be returned to tool-using agents. ## Expected behavior `search_lorebook` should only return entries that are allowed for the active chat/generation context, or its contract should clearly distinguish a global library search from active lorebook retrieval. Disabled lorebooks, disabled folders, and unrelated chat/character/persona scopes should not leak into agent tool results by default. ## Actual behavior Native Tauri QA on `origin/refactor` showed `search_lorebook` returning an entry from a disabled lorebook when `activatedLorebookEntries` was empty. Source inspection matches the behavior: `src/engine/generation/tools-runtime.ts` loads all `lorebook-entries`, merges them with activated entries, and scores them without checking the parent lorebook enabled/scope/folder state. ## Steps to reproduce 1. Create or seed a disabled lorebook with an enabled entry whose content contains a unique marker. 2. In a persisted chat, call the built-in `search_lorebook` tool with a query matching that marker and an empty `activatedLorebookEntries` input. 3. Observe that the disabled lorebook entry is returned with `source: "stored"`. 4. Compare against the dedicated Knowledge Retrieval/Router source path in `src/engine/generation/agent-runner.ts`, which now scopes source lorebooks before loading 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 - [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: `origin/refactor` at `f120eb33` - Run mode: Tauri desktop - OS + version: Windows desktop, exact version not captured - Node + pnpm versions: Node `v24.16.0`, pnpm `10.33.2` - Rust version, if relevant: `rustc 1.95.0` - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant; reproduced through native app storage/tool runtime path ## Logs, screenshots, or video No public screenshot needed. Native QA proof returned the disabled-book entry from `search_lorebook` with `source: "stored"`. The relevant code path is `src/engine/generation/tools-runtime.ts`, where `searchLorebookTool(...)` calls `storage.list("lorebook-entries")` and scores all rows. ## Regression notes Related to #1505, which was closed after the dedicated Knowledge Retrieval/Router executors were scoped. This appears to be a remaining built-in tool path rather than the exact executor path fixed for that issue. ## Additional context Acceptance criteria could be either: - Filter stored fallback entries through the same active lorebook scope rules used by the agent knowledge source path, including disabled lorebooks/folders and chat/character/persona scope; or - Change the tool contract/UI copy so `search_lorebook` is explicitly a global library search, then make that behavior visible and opt-in enough that disabled/out-of-scope entries are not surprising. Add regression coverage for disabled and unrelated lorebooks once the intended contract is chosen. ## 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-20 17:33:27 +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#794
No description provided.