[GH-ISSUE #2694] [Issue]: Knowledge-router never excludes constant lorebook entries, double-injecting always-on lore #1340

Closed
opened 2026-10-21 05:31:48 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2694

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The knowledge-router is passed the full set of context-eligible lorebook entries including constant: true (always-on) entries, even though the router's own contract says the route layer must drop constant entries (they are already injected unconditionally elsewhere). The result is that constant lorebook entries can be injected twice into the prompt.

Expected behavior

Constant (always-on) lorebook entries are injected unconditionally by the normal lorebook pipeline; they should be excluded from the knowledge-router candidate set so they aren't injected a second time.

Actual behavior

The route builds knowledgeRouterEntries by filtering for enabled / non-exhausted-ephemeral / context-filter-passing entries, then passes that set verbatim into executeKnowledgeRouter. It never drops entries with constant: true. The knowledge-router docstring explicitly states the route layer is responsible for dropping constant: true entries because they're already injected unconditionally — but that filtering step is missing, so a constant entry that also matches the router can be injected both by the constant path and by the router.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • packages/server/src/routes/generate.routes.ts:4465-4488 — builds knowledgeRouterEntries (enabled / ephemeral / context-filter checks; no constant filter); passed to executeKnowledgeRouter at :4921.
  • packages/server/src/services/agents/knowledge-router.ts:255-257 — docstring stating the route layer must drop constant: true entries.
  • Constant entries are unconditionally activated in keyword-scanner.ts:445-454.

Steps to reproduce

  1. Create a lorebook entry with constant: true and content that the knowledge-router would also select as relevant.
  2. Generate. Inspect the assembled prompt: the entry's content appears twice — once from the constant injection path and once from the knowledge-router's selection.

Suggested fix

Filter out constant: true entries when building knowledgeRouterEntries (generate.routes.ts:4465-4488), honoring the router's documented contract, so constant entries are injected only by the unconditional path.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of conditional prompt insertion. Wastes context budget and double-weights always-on lore. Part of a set of conditional-injection issues filed together.

Template check

Please uncheck (untick) 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 @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2694 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The knowledge-router is passed the full set of context-eligible lorebook entries **including `constant: true` (always-on) entries**, even though the router's own contract says the route layer must drop constant entries (they are already injected unconditionally elsewhere). The result is that constant lorebook entries can be injected **twice** into the prompt. ## Expected behavior Constant (always-on) lorebook entries are injected unconditionally by the normal lorebook pipeline; they should be excluded from the knowledge-router candidate set so they aren't injected a second time. ## Actual behavior The route builds `knowledgeRouterEntries` by filtering for `enabled` / non-exhausted-ephemeral / context-filter-passing entries, then passes that set verbatim into `executeKnowledgeRouter`. It never drops entries with `constant: true`. The knowledge-router docstring explicitly states the route layer is responsible for dropping `constant: true` entries because they're already injected unconditionally — but that filtering step is missing, so a constant entry that also matches the router can be injected both by the constant path and by the router. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - `packages/server/src/routes/generate.routes.ts:4465-4488` — builds `knowledgeRouterEntries` (enabled / ephemeral / context-filter checks; **no `constant` filter**); passed to `executeKnowledgeRouter` at `:4921`. - `packages/server/src/services/agents/knowledge-router.ts:255-257` — docstring stating the route layer must drop `constant: true` entries. - Constant entries are unconditionally activated in `keyword-scanner.ts:445-454`. ## Steps to reproduce 1. Create a lorebook entry with `constant: true` and content that the knowledge-router would also select as relevant. 2. Generate. Inspect the assembled prompt: the entry's content appears twice — once from the constant injection path and once from the knowledge-router's selection. ## Suggested fix Filter out `constant: true` entries when building `knowledgeRouterEntries` (`generate.routes.ts:4465-4488`), honoring the router's documented contract, so constant entries are injected only by the unconditional path. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of conditional prompt insertion. Wastes context budget and double-weights always-on lore. Part of a set of conditional-injection issues filed together. ## Template check Please **uncheck (untick)** 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.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Fixed in branch codex/spicy-issue-sweep-2026-06-21.

What changed:

  • Knowledge-router candidate loading now filters out constant: true lorebook entries.
  • Constant entries remain handled by the standard lorebook activation path, avoiding duplicate prompt injection.

Final repo checks will run after the full issue sweep.

<!-- gh-comment-id:4761537466 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in branch `codex/spicy-issue-sweep-2026-06-21`. What changed: - Knowledge-router candidate loading now filters out `constant: true` lorebook entries. - Constant entries remain handled by the standard lorebook activation path, avoiding duplicate prompt injection. Final repo checks will run after the full issue sweep.
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#1340
No description provided.