mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2617] [Issue]: Knowledge-retrieval source files (incl. PDFs) re-read and re-parsed from disk every generation turn (no cache) #1290
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1290
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2617
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — performance. When a knowledge-retrieval agent is configured with
sourceFileIds, the generate pipeline re-reads and re-parses every source file from disk on every generation turn with no cache — a fullreadFilefor text formats and a fullPDFParse().getText()re-parse for PDFs. Uploads are bounded only by the global 256MB cap, so a large PDF means a multi-MB read plus a CPU-heavy parse on the request path every message, scaling linearly with file size/count and blocking the event loop on PDF parse.Expected behavior
Extracted source text should be cached and reused across turns (extract once per file version, or at least once per chat session), not recomputed per message.
Actual behavior
extractFileText(knowledge-sources.routes.ts:78-107) doesreadFile()of the whole file for text formats andPDFParse().getText()for PDFs. There is no memoization:agentContextis built per-request (~3524) and_knowledgeRetrievalMaterialis assigned only at~3923, consumed byshouldRunKR(~4217-4221, gated only by!input.regenerateMessageId, so normal turns re-extract every message). Upload size is bounded only byMAX_UPLOAD_BYTES = 256MB(app.ts:44/68) with no per-source extraction cap.Steps to reproduce
Environment
staging @ 56f700cd(v2.0.0)Logs, screenshots, or video
Static source audit, cited to file:line above.
Additional context
Fix sketch. Cache extracted text per file id keyed on
(id, size, uploadedAt/mtime)and reuse across turns; invalidate on re-upload/delete. The upload route already storessizein meta. Optionally cap per-source extraction size and/or move PDF parsing off the request path. At minimum, extract once per chat session rather than per turn.Regression notes. Not a regression — the identical logic exists on
main(generate.routes.ts~5554-5575) andextractFileTextis byte-identical on both branches. Gated behind opt-in knowledge-retrieval config, hence medium not high.Template check
@Romuromylus commented on GitHub (Jun 18, 2026):
Related to #2621 — same knowledge-sources subsystem (per-turn extraction perf here, meta.json TOCTOU there).
@Romuromylus commented on GitHub (Jun 18, 2026):
Fixed in #2623, merged to
staging(e1132e5b). Closing manually since the PR targetedstagingrather than the default branch.