[GH-ISSUE #1301] [Issue]: Lorebook entry keyword logic broken — AND triggers on the first keyword alone; OR and NOT don't work #644

Closed
opened 2026-10-20 17:31:11 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Lorebook entry keyword logic is not working. Using the in-editor keyword test, an
entry that should require all keywords (AND) is activated by the first keyword
alone, and OR and NOT logic do not work either. The keywords in the entries are
lowercase, so case sensitivity is not the variable.

Expected behavior

AND should require all configured keywords to match; OR should require any to
match; NOT should exclude the entry when matched. The in-editor keyword test
should reflect the real activation rules.

Actual behavior

AND activates the entry with just the first keyword present; OR and NOT have no
effect.

Steps to reproduce

  1. Create a lorebook entry with multiple keywords and set the selective logic to
    AND.
  2. Use the in-editor keyword test with text containing only the first keyword.
  3. Observe the entry activates (AND should require all keywords).
  4. Repeat with OR and with NOT — neither behaves as expected.

(Keywords are lowercase in the 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: not provided
  • Run mode: not specified
  • OS + version: not specified
  • Node + pnpm versions: not provided
  • Rust version, if relevant: not provided
  • Remote Runtime URL configured? not specified
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

The reporter attached images of the in-editor keyword test results (one for the
AND case, two more for OR/NOT). They were not provided here as files or URLs, so
they are not attached. The screenshots would clarify whether the keywords were
entered as primary or secondary keys (see triage pointer).

Regression notes

Not provided.

Additional context

Source: forum post by Era [GS] (2-Star), 5/23/26 10:21 PM, with an addendum at
10:25 PM ("OR and NOT are not working either"). The original post referenced a
title that was not included here; the subject is inferred from the content and
addendum to be lorebook keyword / selective logic (AND/OR/NOT).

Triage pointer (from a scan, not from the reporter): the pure selective-logic
helper is correct — testSecondaryKeys in
src/engine/shared/regex/lorebook-keyword-matching.ts implements and = every,
or = some, not = !some. However, the scanner applies selective logic ONLY to
secondary keys, gated by entry.selective:
src/engine/generation-core/lorebooks/keyword-scanner.ts (~L459-464) calls
testPrimaryKeys(entry.keys, ...) (any primary key match activates) and only
applies testSecondaryKeys(entry.secondaryKeys, ..., entry.selectiveLogic, ...)
when entry.selective && entry.secondaryKeys.length > 0. Consequences:

  • Primary keys always use any-match (OR semantics). If the user expects AND/OR/NOT
    to apply across the primary keyword set, AND will appear to trigger on the first
    keyword and OR/NOT will have no effect.
  • The selective logic only takes effect for SECONDARY keys, and only when the
    entry's selective flag is enabled.

This points at either (a) the entry editor / in-editor test not routing the user's
keywords and selective configuration to the fields the scanner actually uses
(primary vs secondary keys, the selective flag), or (b) a semantics mismatch
between what the test UI implies and the real activation rule. The maintainer
should verify the editor and the in-editor test against the scanner wiring
(L459-464) and confirm the intended semantics of selectiveLogic for primary vs
secondary keys. The reporter's screenshots would show whether the keywords were
entered as primary or secondary keys.

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 @GetBeholder on GitHub (May 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1301 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Lorebook entry keyword logic is not working. Using the in-editor keyword test, an entry that should require all keywords (AND) is activated by the first keyword alone, and OR and NOT logic do not work either. The keywords in the entries are lowercase, so case sensitivity is not the variable. ## Expected behavior AND should require all configured keywords to match; OR should require any to match; NOT should exclude the entry when matched. The in-editor keyword test should reflect the real activation rules. ## Actual behavior AND activates the entry with just the first keyword present; OR and NOT have no effect. ## Steps to reproduce 1. Create a lorebook entry with multiple keywords and set the selective logic to AND. 2. Use the in-editor keyword test with text containing only the first keyword. 3. Observe the entry activates (AND should require all keywords). 4. Repeat with OR and with NOT — neither behaves as expected. (Keywords are lowercase in the entries.) ## Impact area - [ ] App shell, navigation, startup, or providers - [x] 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: not provided - Run mode: not specified - OS + version: not specified - Node + pnpm versions: not provided - Rust version, if relevant: not provided - Remote Runtime URL configured? not specified - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video The reporter attached images of the in-editor keyword test results (one for the AND case, two more for OR/NOT). They were not provided here as files or URLs, so they are not attached. The screenshots would clarify whether the keywords were entered as primary or secondary keys (see triage pointer). ## Regression notes Not provided. ## Additional context Source: forum post by Era [GS] (2-Star), 5/23/26 10:21 PM, with an addendum at 10:25 PM ("OR and NOT are not working either"). The original post referenced a title that was not included here; the subject is inferred from the content and addendum to be lorebook keyword / selective logic (AND/OR/NOT). Triage pointer (from a scan, not from the reporter): the pure selective-logic helper is correct — `testSecondaryKeys` in `src/engine/shared/regex/lorebook-keyword-matching.ts` implements `and` = every, `or` = some, `not` = !some. However, the scanner applies selective logic ONLY to secondary keys, gated by `entry.selective`: `src/engine/generation-core/lorebooks/keyword-scanner.ts` (~L459-464) calls `testPrimaryKeys(entry.keys, ...)` (any primary key match activates) and only applies `testSecondaryKeys(entry.secondaryKeys, ..., entry.selectiveLogic, ...)` when `entry.selective && entry.secondaryKeys.length > 0`. Consequences: - Primary keys always use any-match (OR semantics). If the user expects AND/OR/NOT to apply across the primary keyword set, AND will appear to trigger on the first keyword and OR/NOT will have no effect. - The selective logic only takes effect for SECONDARY keys, and only when the entry's `selective` flag is enabled. This points at either (a) the entry editor / in-editor test not routing the user's keywords and selective configuration to the fields the scanner actually uses (primary vs secondary keys, the `selective` flag), or (b) a semantics mismatch between what the test UI implies and the real activation rule. The maintainer should verify the editor and the in-editor test against the scanner wiring (L459-464) and confirm the intended semantics of selectiveLogic for primary vs secondary keys. The reporter's screenshots would show whether the keywords were entered as primary or secondary keys. ## 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:31:11 +07:00
Author
Owner

@franko-c commented on GitHub (May 27, 2026):

seems like the AND/OR/NOT logic at LorebookEditor.tsx:636 only applies to secondary keys — primary keys always match with OR (any single one triggers). if entry.secondaryKeys.length === 0 the selective check is skipped entirely regardless of the logic setting.

are your keywords in the Secondary Keys field or the Primary Keys field? the UI shows the logic buttons either way but they only gate the secondary set.

<!-- gh-comment-id:4551957744 --> @franko-c commented on GitHub (May 27, 2026): seems like the AND/OR/NOT logic at `LorebookEditor.tsx:636` only applies to secondary keys — primary keys always match with OR (any single one triggers). if `entry.secondaryKeys.length === 0` the selective check is skipped entirely regardless of the logic setting. are your keywords in the Secondary Keys field or the Primary Keys field? the UI shows the logic buttons either way but they only gate the secondary set.
Author
Owner

@SpicyMarinara commented on GitHub (May 27, 2026):

Fixed on refactor in 8058f66dd4: lorebook secondary keyword logic now honors AND/OR/NOT whenever secondary keys exist, including older imports without the selective flag; editor preview was aligned too. Added focused Vitest coverage and ran pnpm check.

<!-- gh-comment-id:4555716535 --> @SpicyMarinara commented on GitHub (May 27, 2026): Fixed on refactor in 8058f66dd4affb1e74e4bdbce3b7d4580554fb9b: lorebook secondary keyword logic now honors AND/OR/NOT whenever secondary keys exist, including older imports without the selective flag; editor preview was aligned too. Added focused Vitest coverage and ran pnpm check.
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#644
No description provided.