[PR #2396] [MERGED] Merge all chunk extractions when knowledge consolidation under-merges #5580

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2396
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/knowledge-merge-all-chunks


📝 Commits (2)

  • def5f28 Merge all chunk extractions when knowledge consolidation under-merges
  • beb1421 Require all prior-extraction lines to survive before trusting consolidation

📊 Changes

1 file changed (+46 additions, -2 deletions)

View changed files

📝 src/engine/agents-runtime/knowledge/knowledge-retrieval.ts (+46 -2)

📄 Description

Linked issue

Closes #2326

Why this change

  • In multi-chunk knowledge retrieval, when every chunk extracts successfully the code returned ONLY the final LLM-consolidated extraction and discarded all earlier chunks' extractions. That is correct only if the consolidation pass is a true superset of every prior excerpt. A weak model (or many chunks) can under-merge and silently drop earlier chunks' facts, losing retrieved knowledge from the injected context.

What changed

  • In executeKnowledgeRetrieval (src/engine/agents-runtime/knowledge/knowledge-retrieval.ts), the all-chunks-succeeded branch now checks whether the consolidation actually preserved each prior extraction (first content-bearing line survives, case-insensitive). If it did, the consolidated text is returned verbatim (happy path unchanged). If it under-merged, it falls back to joining the consolidated pass plus every dropped prior extraction, de-duplicated — mirroring the existing partial-failure branch's "never drop" behavior.

Refactor impact

Primary owner: engine generation (agents-runtime)

Impact areas reviewed:

  • src/engine/agents-runtime/knowledge/knowledge-retrieval.ts (multi-pass consolidation branch only)

Boundary notes:

  • None. Engine-only, no new imports; single-pass / zero-extraction / single-extraction / partial-failure branches untouched.

Pressure points touched:

  • None.

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm vitest run src/engine/agents-runtime/knowledge/knowledge-retrieval.test.ts — 2 passed (new file): under-merged consolidation now preserves FACT_1/FACT_2/FACT_3; a true-superset consolidation returns verbatim with no duplicated blocks.
  • pnpm exec tsc -b — clean. ESLint — clean.

Feature Discoverability

  • Updated src/features/shell/discovery/
  • N/A because this PR is a data-loss bugfix in existing plumbing.

Reason:

  • No new discoverable surface.

Docs and release impact

  • No docs changes needed

🔄 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/2396 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/knowledge-merge-all-chunks` --- ### 📝 Commits (2) - [`def5f28`](https://github.com/Pasta-Devs/Marinara-Engine/commit/def5f287e2ea1dc9b1c9bac81781204e038b8410) Merge all chunk extractions when knowledge consolidation under-merges - [`beb1421`](https://github.com/Pasta-Devs/Marinara-Engine/commit/beb14218b7a6a4841e347a9c971cc654b8208df2) Require all prior-extraction lines to survive before trusting consolidation ### 📊 Changes **1 file changed** (+46 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/agents-runtime/knowledge/knowledge-retrieval.ts` (+46 -2) </details> ### 📄 Description ## Linked issue Closes #2326 ## Why this change - In multi-chunk knowledge retrieval, when every chunk extracts successfully the code returned ONLY the final LLM-consolidated extraction and discarded all earlier chunks' extractions. That is correct only if the consolidation pass is a true superset of every prior excerpt. A weak model (or many chunks) can under-merge and silently drop earlier chunks' facts, losing retrieved knowledge from the injected context. ## What changed - In `executeKnowledgeRetrieval` (`src/engine/agents-runtime/knowledge/knowledge-retrieval.ts`), the all-chunks-succeeded branch now checks whether the consolidation actually preserved each prior extraction (first content-bearing line survives, case-insensitive). If it did, the consolidated text is returned verbatim (happy path unchanged). If it under-merged, it falls back to joining the consolidated pass plus every dropped prior extraction, de-duplicated — mirroring the existing partial-failure branch's "never drop" behavior. ## Refactor impact Primary owner: engine generation (agents-runtime) Impact areas reviewed: - `src/engine/agents-runtime/knowledge/knowledge-retrieval.ts` (multi-pass consolidation branch only) Boundary notes: - None. Engine-only, no new imports; single-pass / zero-extraction / single-extraction / partial-failure branches untouched. Pressure points touched: - None. ## Validation - [x] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm vitest run src/engine/agents-runtime/knowledge/knowledge-retrieval.test.ts` — 2 passed (new file): under-merged consolidation now preserves FACT_1/FACT_2/FACT_3; a true-superset consolidation returns verbatim with no duplicated blocks. - `pnpm exec tsc -b` — clean. ESLint — clean. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` - [x] N/A because this PR is a data-loss bugfix in existing plumbing. Reason: - No new discoverable surface. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:32 +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#5580
No description provided.