[GH-ISSUE #2326] [Issue]: Knowledge-retrieval multi-chunk consolidation can silently drop earlier chunks' facts when the model under-merges #1154

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — Data-loss (transient context). Knowledge-retrieval multi-chunk consolidation returns only the last chunk's extraction when every chunk produced text, trusting the model to have merged the prior chunks via a soft prompt instruction. If the model under-merges (common with small/instruction-weak models), all facts from earlier chunks are silently dropped from the injected knowledge context. The partial-failure branch is actually safer than the full-success branch.

Expected behavior

Consolidation should not silently lose earlier chunks' facts. When all chunks produced extractions, either verify the final pass is a superset or fall back to joining/deduping all extractions (as the partial branch already does).

Actual behavior

src/engine/agents-runtime/knowledge/knowledge-retrieval.ts:135-162:

// The last extraction is the consolidated result
const consolidated = extractions[extractions.length - 1]!;
return { ...data: { text: consolidated } ... };

When chunks.length > 1 AND extractions.length === chunks.length, only the last extraction is returned, discarding extractions[0..n-2]. The prior extractions are fed to the model purely as a soft instruction via _previousExtractions (line 100, rendered in agent-executor.ts:1697-1708: "Consolidate them into a single, coherent summary..."); the system prompt never reinforces consolidation. The extractions.length < chunks.length branch (136-148) safely concatenates all partials "so we don't drop earlier results" — so a partial failure is strictly safer than full success.

Steps to reproduce

  1. Knowledge Retrieval agent with source material exceeding sourceContextBudget (default 6000 tokens) so it splits into 2+ chunks.
  2. Every chunk returns a non-empty extraction.
  3. The final consolidation pass under-merges → facts from chunks 1..n-1 are dropped from the injected context.

Impact area

  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • React-free engine behavior, contracts, agents, or capability ports

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (shared engine; also server mode)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: worst with small/local models

Logs, screenshots, or video

Static source audit; cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main. Depends on model misbehavior (not deterministic), only triggers for chunked sources, and the lost data is transient injected context regenerated next turn (no persisted corruption), hence low.

Additional context

Suggested fix: in the === branch, don't blindly trust the model merged — guard with a superset/length heuristic and fall back to joining all extractions, or simplest, always join+dedupe all extractions like the < branch already does.

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2326 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — Data-loss (transient context).** Knowledge-retrieval multi-chunk consolidation returns only the last chunk's extraction when every chunk produced text, trusting the model to have merged the prior chunks via a soft prompt instruction. If the model under-merges (common with small/instruction-weak models), all facts from earlier chunks are silently dropped from the injected knowledge context. The partial-failure branch is actually safer than the full-success branch. ## Expected behavior Consolidation should not silently lose earlier chunks' facts. When all chunks produced extractions, either verify the final pass is a superset or fall back to joining/deduping all extractions (as the partial branch already does). ## Actual behavior `src/engine/agents-runtime/knowledge/knowledge-retrieval.ts:135-162`: ```ts // The last extraction is the consolidated result const consolidated = extractions[extractions.length - 1]!; return { ...data: { text: consolidated } ... }; ``` When `chunks.length > 1` AND `extractions.length === chunks.length`, only the last extraction is returned, discarding `extractions[0..n-2]`. The prior extractions are fed to the model purely as a soft instruction via `_previousExtractions` (line 100, rendered in `agent-executor.ts:1697-1708`: "Consolidate them into a single, coherent summary..."); the system prompt never reinforces consolidation. The `extractions.length < chunks.length` branch (136-148) safely concatenates all partials "so we don't drop earlier results" — so a partial failure is strictly safer than full success. ## Steps to reproduce 1. Knowledge Retrieval agent with source material exceeding `sourceContextBudget` (default 6000 tokens) so it splits into 2+ chunks. 2. Every chunk returns a non-empty extraction. 3. The final consolidation pass under-merges → facts from chunks 1..n-1 are dropped from the injected context. ## Impact area - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [x] React-free engine behavior, contracts, agents, or capability ports ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (shared engine; also server mode) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: worst with small/local models ## Logs, screenshots, or video Static source audit; cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. Depends on model misbehavior (not deterministic), only triggers for chunked sources, and the lost data is transient injected context regenerated next turn (no persisted corruption), hence low. ## Additional context Suggested fix: in the `===` branch, don't blindly trust the model merged — guard with a superset/length heuristic and fall back to joining all extractions, or simplest, always join+dedupe all extractions like the `<` branch already does. ## Template check Please uncheck 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.
bsakaguchi 2026-10-21 05:28:01 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2396, merged into refactor.

<!-- gh-comment-id:4637945239 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2396, merged into `refactor`.
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#1154
No description provided.