[GH-ISSUE #2642] [Issue]: PDF extraction-failure sentinel is cached permanently, poisoning the knowledge source for the process lifetime #1302

Closed
opened 2026-10-21 05:31:11 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — correctness (regression). extractFileText caches its result keyed on (size, uploadedAt) unconditionally, including the failure sentinel string "[PDF text extraction failed]" written in the PDF catch block. A transient pdf-parse failure is therefore cached for the rest of the process lifetime and injected as knowledge material on every subsequent turn, with no retry short of delete-and-reupload.

Expected behavior

A transient PDF extraction failure (worker spawn failure under memory pressure, a momentary file lock, an OOM in pdf-parse during a busy turn) should be retried on the next turn — only successful extractions should be cached.

Actual behavior

packages/server/src/routes/knowledge-sources.routes.ts:159–187:

} catch {
  text = "[PDF text extraction failed]";
} finally { ... }
// ...
if (fileId && metadata) {
  setCachedText(fileId, { size: metadata.size, uploadedAt: metadata.uploadedAt, text });
}

The setCachedText call runs unconditionally, so the failure sentinel is cached. The cache invalidates only on delete (line 255) or re-upload (which mints a new nanoid). generate.routes.ts:4412 calls extractFileText every knowledge-retrieval turn, and the only downstream gate is text.trim() (4413) — the non-empty sentinel passes — so ## File: <name>\n[PDF text extraction failed] is injected as knowledge material on every later turn until the process restarts or the file is re-uploaded.

Steps to reproduce

  1. Add a PDF knowledge source and enable knowledge retrieval for an agent.
  2. Cause a transient pdf-parse failure on the first turn that reads it (e.g. resource pressure / momentary lock).
  3. Observe [PDF text extraction failed] is cached and re-injected on every subsequent turn, even after the transient condition clears.

Environment

  • Marinara Engine version: staging @ 3dc062e2
  • Install type: source
  • OS + version: n/a (static source audit)
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

Fix sketch: do not cache the failure sentinel — skip setCachedText when PDF extraction throws (cache only on success), or store a short-lived negative entry so the next turn re-attempts the parse.

Regression notes: Regression vs main — worked on the release build, broken/missing on staging. On main, extractFileText(filePath) has no cache and re-parses every call (packages/server/src/routes/knowledge-sources.routes.ts:78–106), so a transient failure self-heals on the next turn. The cache was added on staging (the per-turn re-parse fix for #2617) and introduced this poisoning. Last-known-good: main knowledge-sources.routes.ts:78–106.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2642 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — correctness (regression).** `extractFileText` caches its result keyed on `(size, uploadedAt)` unconditionally, including the failure sentinel string `"[PDF text extraction failed]"` written in the PDF catch block. A *transient* pdf-parse failure is therefore cached for the rest of the process lifetime and injected as knowledge material on every subsequent turn, with no retry short of delete-and-reupload. ## Expected behavior A transient PDF extraction failure (worker spawn failure under memory pressure, a momentary file lock, an OOM in `pdf-parse` during a busy turn) should be retried on the next turn — only successful extractions should be cached. ## Actual behavior `packages/server/src/routes/knowledge-sources.routes.ts:159–187`: ```ts } catch { text = "[PDF text extraction failed]"; } finally { ... } // ... if (fileId && metadata) { setCachedText(fileId, { size: metadata.size, uploadedAt: metadata.uploadedAt, text }); } ``` The `setCachedText` call runs unconditionally, so the failure sentinel is cached. The cache invalidates only on delete (line 255) or re-upload (which mints a new nanoid). `generate.routes.ts:4412` calls `extractFileText` every knowledge-retrieval turn, and the only downstream gate is `text.trim()` (4413) — the non-empty sentinel passes — so `## File: <name>\n[PDF text extraction failed]` is injected as knowledge material on every later turn until the process restarts or the file is re-uploaded. ## Steps to reproduce 1. Add a PDF knowledge source and enable knowledge retrieval for an agent. 2. Cause a transient `pdf-parse` failure on the first turn that reads it (e.g. resource pressure / momentary lock). 3. Observe `[PDF text extraction failed]` is cached and re-injected on every subsequent turn, even after the transient condition clears. ## Environment - Marinara Engine version: `staging @ 3dc062e2` - Install type: source - OS + version: n/a (static source audit) - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context Fix sketch: do not cache the failure sentinel — skip `setCachedText` when PDF extraction throws (cache only on success), or store a short-lived negative entry so the next turn re-attempts the parse. Regression notes: **Regression vs `main`** — worked on the release build, broken/missing on `staging`. On `main`, `extractFileText(filePath)` has no cache and re-parses every call (`packages/server/src/routes/knowledge-sources.routes.ts:78–106`), so a transient failure self-heals on the next turn. The cache was added on `staging` (the per-turn re-parse fix for #2617) and introduced this poisoning. Last-known-good: `main` `knowledge-sources.routes.ts:78–106`. ## Template check - [ ] I DID NOT read this template and provide the requested details.
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#1302
No description provided.