[PR #2875] [MERGED] fix: preserve knowledge router prompt injections #5775

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2875
Author: @TheLonelyDevil9
Created: 6/25/2026
Status: ✅ Merged
Merged: 6/27/2026
Merged by: @SpicyMarinara

Base: staging ← Head: tld/fix-2874-knowledge-router-output


📝 Commits (3)

  • 993259e fix: preserve knowledge router prompt injections
  • 247f769 test: cover assistant-tail agent injections
  • c5e9054 Merge branch 'staging' into tld/fix-2874-knowledge-router-output

📊 Changes

3 files changed (+93 additions, -29 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+5 -29)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+28 -0)
📝 scripts/regressions/prompt.regression.ts (+60 -0)

📄 Description

What?

Fix Knowledge Router output being omitted from assembled prompts in established chats.

Why?

Router requests can complete and return lorebook selections, but established chats can lose that output before final prompt assembly, so the main model cannot use it.

How?

  • Store separate Knowledge Router and Knowledge Retrieval prompt injections as protected prompt injection messages instead of appending them to chat history.
  • Keep the runtime-section replacement path intact when a preset section handles the agent output.
  • Add a prompt regression that forces long-history context fitting and verifies the router injection survives while old history is trimmed.

Testing?

  • pnpm regression:prompt
  • pnpm check

Anything Else?

Closes #2874.

Summary by CodeRabbit

  • New Features
    • Improved how injected agent instructions are added to prompts, with cleaner formatting for different agent types and wrapping styles.
  • Bug Fixes
    • Prompts now preserve injected instructions more reliably when long conversation history is trimmed for model limits.
  • Tests
    • Added regression coverage for prompt fitting to ensure older context is removed while injected routing instructions remain included.

🔄 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/2875 **Author:** [@TheLonelyDevil9](https://github.com/TheLonelyDevil9) **Created:** 6/25/2026 **Status:** ✅ Merged **Merged:** 6/27/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `tld/fix-2874-knowledge-router-output` --- ### 📝 Commits (3) - [`993259e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/993259e5bfadea531ff77449a91a74471a15019e) fix: preserve knowledge router prompt injections - [`247f769`](https://github.com/Pasta-Devs/Marinara-Engine/commit/247f769a9d69ae601a24f49f4f09e7041cb146c6) test: cover assistant-tail agent injections - [`c5e9054`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c5e905446e0db32e4f1901ab8be2254ad65e0b1a) Merge branch 'staging' into tld/fix-2874-knowledge-router-output ### 📊 Changes **3 files changed** (+93 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+5 -29) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+28 -0) 📝 `scripts/regressions/prompt.regression.ts` (+60 -0) </details> ### 📄 Description ## What? Fix Knowledge Router output being omitted from assembled prompts in established chats. ## Why? Router requests can complete and return lorebook selections, but established chats can lose that output before final prompt assembly, so the main model cannot use it. ## How? - Store separate Knowledge Router and Knowledge Retrieval prompt injections as protected prompt injection messages instead of appending them to chat history. - Keep the runtime-section replacement path intact when a preset section handles the agent output. - Add a prompt regression that forces long-history context fitting and verifies the router injection survives while old history is trimmed. ## Testing? - pnpm regression:prompt - pnpm check ## Anything Else? Closes #2874. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved how injected agent instructions are added to prompts, with cleaner formatting for different agent types and wrapping styles. * **Bug Fixes** * Prompts now preserve injected instructions more reliably when long conversation history is trimmed for model limits. * **Tests** * Added regression coverage for prompt fitting to ensure older context is removed while injected routing instructions remain included. <!-- 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:19:23 +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#5775
No description provided.