[Bug]: PDF parsing kills the whole server process (pdfium.dll BEX64 0xc0000409) and the interrupted add_resource task is replayed on every restart, causing a crash loop
Issue Origin
Observed or reproduced in a real environment
Bug Description
Importing three text-layer Chinese thesis PDFs (99 / 207 / 101 pages) with ov add-resource terminated the OpenViking server process twice. The process dies inside pdfium.dll with Windows exception 0xc0000409 (BEX64) and no Python traceback — openviking-server.log simply stops in the middle of PDF parsing. Because the interrupted tasks stay in status=running, every restart re-delivers the same three add_resource messages (identical message_id) and the server crashes again a few seconds later, so the service cannot be kept up while those messages exist.
The failure is not a parsing rejection: it is a process-level native crash, which makes the whole server (HTTP API, MCP endpoint, bot gateway) unavailable.
Steps to Reproduce
- Start
openviking-server0.5.0 (local dev auth,with_bot=true, default parser config). - Submit three large text-layer PDFs within a few seconds, e.g.
ov add-resource <thesis-a.pdf> --parent-auto-create viking://resources/<dir>for a 99-page thesis, then the same for a 207-page and a 101-page thesis. - All three tasks enter
stage=parsing([AddResourceStarted]in the log). - ~12–18 s later the
python.exehosting the server is terminated by Windows (Application Error 1000 / WER BEX64). - Restart the server: the same three messages are re-delivered and it crashes again a few seconds later.
Expected Behavior
-
A single problematic PDF that makes a native parser library crash must fail that resource only — the server should stay alive (worker isolation, e.g. parsing PDFs in a subprocess with a timeout), and the failure should surface as a task error.
-
A crash must not leave a task in
runningthat is automatically replayed on every startup with no retry bound; recovery should either mark such tasksfailedor cap the replay attempts, otherwise the server cannot be started successfully while the poison message exists.
Actual Behavior
Windows reports a process-level crash with no Python-side error. Details:
python.exe(server process) dies; Windows Application Error 1000:Faulting application name: python.exe,Faulting module name: pdfium.dll, version: 156.0.8076.0,Exception code: 0xc0000409,Fault offset: 0x0000000000490ea9(WER event:BEX64).- Occurred twice: 19:03:29 and 19:10:31 (local, +08:00), both times while the three PDFs were being parsed concurrently.
openviking-server.loghas no exception or traceback; the last lines are normalopenviking.parse.parsers.pdfheading-detection INFO lines, then the log stops.- Task records are left non-terminal:
{"status": "running", "stage": "parsing", "error": null}. - On restart the durable queue re-delivers the same messages:
[AddResourceStarted] task_id=<same-task-id> ... message_id=a483bd5a-... / ace55a2a-... / 52a8576d-...(identical ids to the original submission), i.e. the work is replayed rather than skipped. - Deleting the three persisted task JSON files did not stop the replay — the messages are re-delivered from the durable queue, so the crash loop cannot be cleared from the task store alone.
Minimal Reproducible Example
Not minimized to a single page yet. Suspected call path in `openviking/parse/parsers/pdf.py` (0.5.0):
async def _convert_local(self, pdf_path, storage=None, resource_name=None):
# pdfplumber / pdfminer work is synchronous and heavy -> thread pool
return await asyncio.to_thread(self._convert_local_sync, pdf_path, storage, resource_name)
def _extract_image_from_page(self, page, img_info):
try:
cropped = page.crop(bbox)
page_image = cropped.to_image(resolution=self.config.image_resolution) # pdfplumber -> pypdfium2 -> pdfium.dll
buffer = io.BytesIO()
page_image.save(buffer, format="PNG")
return buffer.getvalue()
except Exception as e:
logger.debug(f"Image extraction error: {e}")
return None
`asyncio.to_thread` means several documents can be rendering through pypdfium2 concurrently, and a native fault is not catchable by the surrounding `except Exception`.
Error Logs
Windows Application log (paths redacted):
Application Error (ID 1000)
Faulting application name: python.exe, version: 0.0.0.0
Faulting module name: pdfium.dll, version: 156.0.8076.0
Exception code: 0xc0000409
Fault offset: 0x0000000000490ea9
Windows Error Reporting (ID 1001)
Event name: BEX64
P4: pdfium.dll P5: 156.0.8076.0 P8: c0000409
Server log tail immediately before the process dies:
19:03:17,018 - openviking.parse.parsers.pdf - INFO - Heading detection: source=bookmarks, headings=105, bookmarks=105, resolved=105, unresolved=0
19:03:17,166 - openviking.parse.parsers.pdf - WARNING - Failed to extract bookmarks:
19:03:26,670 - openviking.parse.parsers.pdf - INFO - Heading detection: source=font_analysis, headings=6, bookmarks=0, resolved=0, unresolved=0
<process terminated, no traceback>
Recovery/replay evidence after restart:
19:14:53,182 - openviking.service.task_tracker - INFO - [TaskTracker] Initialized (store=PersistentTaskStore, max_tasks=10000)
19:14:53,722 - openviking.storage.queuefs.add_resource_processor - INFO - [AddResourceStarted] task_id=e2ce2183-... message_id=a483bd5a-...
19:14:53,724 - openviking.storage.queuefs.add_resource_processor - INFO - [AddResourceStarted] task_id=6a69f5de-... message_id=ace55a2a-...
19:14:53,724 - openviking.storage.queuefs.add_resource_processor - INFO - [AddResourceStarted] task_id=e9163a96-... message_id=52a8576d-...
OpenViking Version
0.5.0
Python Version
3.12.14
Operating System
Windows
Model Backend
None
Additional Context
Environment: Windows 11 (Build 22631), OpenViking 0.5.0 (CLI + server), Python 3.12.14, pypdfium2 5.14.0 (pdfium 156.0.8076.0), pdfplumber 0.11.10, pdfminer.six 20260107; default parser config (strategy=local, no parsers.* overrides), embedding.max_concurrent=4, vlm.max_concurrent=8, server.auth_mode=dev, with_bot=true.
All three PDFs are text-based (PyMuPDF extracts ~50k / ~107k / ~50k CJK characters per document), so this is not a scanned-PDF/OCR issue.
Non-determinism: the crash happened on the first two runs (both times while the three documents were parsed concurrently) and did not happen on a later run of the very same three files, which completed successfully. A single-document import was not tested in isolation.
Figure extraction is separately unreliable, and its failure is silent:
- first import of the three files:
Local conversion: ... 17 images,9 images,11 images(PNG files on disk, image links in the Markdown); - later imports of the same files:
0 images,0 images,0 images— no PNG files and no image references at all in the Markdown, while the text still cites 115 / 94 figure captions ("图X.Y"); - the log contains no
Failed to extract image ...warning in either case, so the per-page loop overpage.imagesapparently saw nothing to extract, and the task still reportsstatus: "success". - Control check on the same machine with the identical stack (
pdfplumber 0.11.10+pypdfium2 5.14.0, same venv) rendered the first images of all three PDFs fine (8/8 renders, no exception), so this is not a deterministic property of these files or of this pdfium build.
Suggested directions:
- Isolate parsing in a child process (crash containment + timeout) so a native fault cannot take down the HTTP/MCP server.
- Guard the pdfium render path (serialize
to_image()calls, or use a single dedicated worker). - On startup, do not replay
runningadd_resourcemessages unconditionally — bound the attempts and mark the taskfailedafter repeated crashes, so a poison message cannot block service startup. - Surface the parser library and failure stage in
ov task status, and log image-extraction loss at warning level instead of silently finishing with 0 images.
Confirming the queue-side root cause on current main and taking this on (fix scope = Expected #2).
Root cause (read at main):
openviking/storage/queuefs/named_queue.py:224-248— dequeue→process→ack is at-least-once; on a process crash,RecoverStaleunconditionally resetsprocessingback topending(comment at :232-233) with no delivery-attempt counter anywhere on the path, so a poison message is re-delivered forever.openviking/storage/queuefs/add_resource_processor.py:150-178—tracker.create(task_id)passes through for tasks already inrunning(the terminal guard doesn't cover RUNNING), andreplay_result is None(:181-183) triggers a full re-parse — so every restart re-runs the crashing parse. The only bounded requeue today is the lock-handoff path (:124-131,lock_handoff_retrycapped).- The native crash itself (
openviking/parse/parsers/pdf.py:220-225→to_image()→ pdfium.dll) is not catchable byexcept Exception; worker-process isolation for parsing (Expected #1) is a separate, larger follow-up — not part of this fix.
Plan: add a persisted delivery_attempt counter to the message payload (same pattern as lock_handoff_retry); on exceeding the cap, mark the task failed via tracker.fail and ack/dead-letter the message instead of re-delivering, so a poison message can no longer block startup. I'll include an offline repro that simulates an uncatchable crash via a subprocess os._exit(1).
This investigation and the fix are prepared with AI assistance (Claude); I'm the author and will review/test everything before submitting.
PR: #5919 — caps persisted delivery_attempt at 3 (incremented in task meta before any crash-prone work), then dead-letters the message (acked for good), marks the task failed via tracker.fail with an actionable error, and logs [AddResourceDeadLetter]. Scope: Expected #2 only; worker-process isolation for parsing (Expected #1) stays a follow-up.
Verification: new tests/storage/test_add_resource_poison_message.py is red on main (2 failed — the 4th delivery re-runs the crashing parse, no ack, task stuck running) and green after the fix (2 passed); tests/storage and tests/storage tests/service FAILED+ERROR lists are byte-identical to the main baseline (pre-existing ragfs_python ImportError environment failures only).