[PR #838] [MERGED] Fix Knowledge Retrieval prompt preset sections #4800

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/838
Author: @Promansis
Created: 5/14/2026
Status: ✅ Merged
Merged: 5/15/2026
Merged by: @Promansis

Base: staging ← Head: fix/828-knowledge-retrieval-preset-section


📝 Commits (3)

  • e67b9b2 fix #828 knowledge retrieval preset sections
  • 2b07b29 fix: guard empty runtime agent wrapping
  • 76e7e54 fix: cover runtime agent cleanup edge cases

📊 Changes

4 files changed (+399 additions, -6 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+155 -3)
📝 packages/server/src/services/prompt/assembler.ts (+55 -3)
📝 packages/server/test/lorebook-processing.test.ts (+128 -0)
➕ packages/server/test/runtime-agent-section-cleanup.test.ts (+61 -0)

📄 Description

Linked issue

Closes #828

Why this change

  • Knowledge Retrieval output could be generated when enabled through chat settings, but the same agent's "Add as Prompt Section" marker in an RP prompt preset resolved before the agent had fresh output, so the section was omitted from the prompt sent to the model.
  • If Knowledge Retrieval or Knowledge Router is enabled through both chat settings and a prompt preset section, the output should be inserted once at the configured preset location.

What changed

  • Added runtime agent data support to prompt assembly so KR/Router agent marker sections can receive fresh per-generation output instead of stale saved runs.
  • Updated generation routing to replace only nonce-scoped runtime marker placeholders and avoid duplicate append-at-end injection when a preset section handled the output.
  • Removed unused runtime marker sections and empty group wrappers when KR/Router produce no output.
  • Added focused server coverage for runtime agent marker insertion, macro-absent marker preservation, and cleanup of empty XML/Markdown grouped runtime sections.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Automated validation run by Codex: pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/lorebook-processing.test.ts test/runtime-agent-section-cleanup.test.ts; passed.
  • Automated validation run by Codex: pnpm check; passed.
  • Not run: desktop app RP prompt preset manual verification with a live Knowledge Retrieval source.
  • Not run: Docker/Podman container verification.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No docs or release metadata changes expected; this is a narrow server prompt assembly and generation routing fix.

UI evidence (if applicable)

N/A. Server prompt assembly behavior only; no UI surface changed.

Summary by CodeRabbit

  • New Features

    • Added runtime agent section support for knowledge-retrieval and knowledge-router preset outputs with token placeholders
    • Enhanced prompt assembly to better integrate agent-generated content with automatic cleanup of unused sections
  • Tests

    • Added comprehensive tests for runtime agent section handling and prompt assembly with agent data

Review Change Stack


🔄 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/838 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 5/14/2026 **Status:** ✅ Merged **Merged:** 5/15/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix/828-knowledge-retrieval-preset-section` --- ### 📝 Commits (3) - [`e67b9b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e67b9b2edfdaa05c1d83dc1c39806ca0c821d385) fix #828 knowledge retrieval preset sections - [`2b07b29`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2b07b29660566872713c4b1f4f59ffb13c89cb7e) fix: guard empty runtime agent wrapping - [`76e7e54`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76e7e54b34833af028b19abd096efd932ecb691f) fix: cover runtime agent cleanup edge cases ### 📊 Changes **4 files changed** (+399 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+155 -3) 📝 `packages/server/src/services/prompt/assembler.ts` (+55 -3) 📝 `packages/server/test/lorebook-processing.test.ts` (+128 -0) ➕ `packages/server/test/runtime-agent-section-cleanup.test.ts` (+61 -0) </details> ### 📄 Description ## Linked issue Closes #828 ## Why this change - Knowledge Retrieval output could be generated when enabled through chat settings, but the same agent's "Add as Prompt Section" marker in an RP prompt preset resolved before the agent had fresh output, so the section was omitted from the prompt sent to the model. - If Knowledge Retrieval or Knowledge Router is enabled through both chat settings and a prompt preset section, the output should be inserted once at the configured preset location. ## What changed - Added runtime agent data support to prompt assembly so KR/Router agent marker sections can receive fresh per-generation output instead of stale saved runs. - Updated generation routing to replace only nonce-scoped runtime marker placeholders and avoid duplicate append-at-end injection when a preset section handled the output. - Removed unused runtime marker sections and empty group wrappers when KR/Router produce no output. - Added focused server coverage for runtime agent marker insertion, macro-absent marker preservation, and cleanup of empty XML/Markdown grouped runtime sections. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Automated validation run by Codex: `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/lorebook-processing.test.ts test/runtime-agent-section-cleanup.test.ts`; passed. - Automated validation run by Codex: `pnpm check`; passed. - Not run: desktop app RP prompt preset manual verification with a live Knowledge Retrieval source. - Not run: Docker/Podman container verification. ## Docs and release impact - [x] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Version/release files updated (only if this PR includes a version bump) No docs or release metadata changes expected; this is a narrow server prompt assembly and generation routing fix. ## UI evidence (if applicable) N/A. Server prompt assembly behavior only; no UI surface changed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added runtime agent section support for knowledge-retrieval and knowledge-router preset outputs with token placeholders * Enhanced prompt assembly to better integrate agent-generated content with automatic cleanup of unused sections * **Tests** * Added comprehensive tests for runtime agent section handling and prompt assembly with agent data <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/838) <!-- review_stack_entry_end --> <!-- 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:10:45 +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#4800
No description provided.