[PR #3205] [MERGED] [codex] Fix Knowledge Router prompt injection #5842

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3205
Author: @SpicyMarinara
Created: 7/4/2026
Status: ✅ Merged
Merged: 7/4/2026
Merged by: @SpicyMarinara

Base: staging ← Head: codex/fix-knowledge-router-injection


📝 Commits (1)

  • a2441c6 Fix Knowledge Router prompt injection

📊 Changes

3 files changed (+119 additions, -19 deletions)

View changed files

📝 packages/server/src/services/agents/knowledge-router.ts (+52 -14)
📝 packages/server/src/services/generation/runtime-agent-sections.ts (+11 -3)
📝 scripts/regressions/prompt.regression.ts (+56 -2)

📄 Description

Why

Knowledge Router could run successfully from the provider perspective while its prompt section disappeared from the main generation. Issue #3190 reports that a preset section like This is where additional lore will be... {{agent::knowledge-router}} vanished when the agent was enabled, and selected lore was not visible in the assembled writing prompt.

Closes #3190

Root Cause

Runtime agent cleanup treated an unresolved Knowledge Router placeholder as a reason to remove the entire wrapped prompt section. If the router returned an empty parsed result, or returned selected IDs under a common alias the parser did not recognize, the cleanup removed both the macro and the user's surrounding static prompt text.

What Changed

  • Preserves user-authored text around unused runtime agent placeholders while still pruning macro-only empty sections.
  • Makes Knowledge Router response parsing accept common selected-ID shapes such as selectedEntryIds, selectedEntries, entries, entry_id, and array responses.
  • Adds prompt regressions covering surrounding text preservation, empty macro pruning, and router parser aliases.

Validation

  • Manually verify Knowledge Router selected lore appears in Peek Prompt / prompt inspector for a Roleplay chat with a Knowledge Router preset section.
  • Manually verify a macro-only Knowledge Router section disappears cleanly when no entries are selected.
  • Manually verify surrounding static text remains visible when {{agent::knowledge-router}} resolves empty.

Local proof runs:

  • pnpm regression:prompt
  • pnpm --filter @marinara-engine/server lint

🔄 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/3205 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 7/4/2026 **Status:** ✅ Merged **Merged:** 7/4/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/fix-knowledge-router-injection` --- ### 📝 Commits (1) - [`a2441c6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a2441c6f3a8bbbb48a4d8161771977c5d4222c29) Fix Knowledge Router prompt injection ### 📊 Changes **3 files changed** (+119 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/knowledge-router.ts` (+52 -14) 📝 `packages/server/src/services/generation/runtime-agent-sections.ts` (+11 -3) 📝 `scripts/regressions/prompt.regression.ts` (+56 -2) </details> ### 📄 Description ## Why Knowledge Router could run successfully from the provider perspective while its prompt section disappeared from the main generation. Issue #3190 reports that a preset section like `This is where additional lore will be... {{agent::knowledge-router}}` vanished when the agent was enabled, and selected lore was not visible in the assembled writing prompt. Closes #3190 ## Root Cause Runtime agent cleanup treated an unresolved Knowledge Router placeholder as a reason to remove the entire wrapped prompt section. If the router returned an empty parsed result, or returned selected IDs under a common alias the parser did not recognize, the cleanup removed both the macro and the user's surrounding static prompt text. ## What Changed - Preserves user-authored text around unused runtime agent placeholders while still pruning macro-only empty sections. - Makes Knowledge Router response parsing accept common selected-ID shapes such as `selectedEntryIds`, `selectedEntries`, `entries`, `entry_id`, and array responses. - Adds prompt regressions covering surrounding text preservation, empty macro pruning, and router parser aliases. ## Validation - [ ] Manually verify Knowledge Router selected lore appears in Peek Prompt / prompt inspector for a Roleplay chat with a Knowledge Router preset section. - [ ] Manually verify a macro-only Knowledge Router section disappears cleanly when no entries are selected. - [ ] Manually verify surrounding static text remains visible when `{{agent::knowledge-router}}` resolves empty. Local proof runs: - `pnpm regression:prompt` - `pnpm --filter @marinara-engine/server lint` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:20:05 +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#5842
No description provided.