49 Commits

Author SHA1 Message Date
Leveling
9bed004617 test(parsing): stop racing interpreter startup in the MinerU lifecycle checks (#3089)
* test(parsing): stop racing interpreter startup in the MinerU lifecycle checks

The Windows `import-check` job flakes on `dev`. It failed at 2026-11-30 03:12
and 03:32 on `79a66cb3` and `6b00f010`, passed on the same step 90 minutes
later in another run, and passed on `218dbe31` the evening before. Nothing
between those runs touched `.github/`, `tests/services/parsing/`,
`tests/runtime/` or the MinerU engine, so the workflow and the code under test
were identical in the green and red runs.

Reproduced, and the cause is a timing premise in the tests, not the runner.

The race
--------

`test_deadline_and_cancellation_settle_the_owned_tree[True]` sets
`timeout=0.8` and only cancels once the fixture child has spawned a grandchild
and written `child.pid`:

    def check():
        if cancelled and list(...glob(".../child.pid")):
            raise IndexingCancelled(...)

`local.py` starts its clock before `cli_process()`, which on Windows creates a
Job Object, spawns a suspended interpreter, resumes it and queries its threads.
That work plus two more interpreter startups has to fit inside the same 0.8s.
When it does not, the deadline wins before the marker exists and the assertion
reports `TIMEOUT is not CANCELLED`.

Measured on an idle machine the marker lands in 0.067-0.085s, so the margin
looked comfortable. Delaying only the child's first write, with no CPU
contention at all:

    startup delay | result    | expected  | verdict
         0.0s     | cancelled | cancelled | pass
         0.5s     | cancelled | cancelled | pass
         0.7s     | timeout   | cancelled | FAIL
         0.9s     | timeout   | cancelled | FAIL
         1.2s     | timeout   | cancelled | FAIL

CPU contention alone reproduced the same signature
`assert <LocalParseReason.TIMEOUT> is <LocalParseReason.CANCELLED>` at line 138,
plus `assert 2.087 < 2` and `assert 3.757 < 1.5` on neighbouring cases.

The production ordering is correct and is left alone: `run.check()` is
evaluated before the deadline comparison, so an available cancellation always
wins. What the tests must not do is depend on how fast the runner started a
Python interpreter.

What changed
------------

- `_await_marker()` waits for a fixture marker with a real timeout and a
  message that distinguishes "the CLI never started" from "the runner was
  slow". Bare `(path,) = glob(...)` unpacking turned both into
  `ValueError: not enough values to unpack (expected 1, got 0)`, which is what
  made these CI failures unreadable.
- The cancellation case waits for the recorded child before raising, so the
  interruption is decided by policy rather than by interpreter startup. A 3s
  startup delay now passes where 0.7s used to fail.
- Wall-clock bounds that were only guarding "did not wait for the descendant"
  were widened off the interpreter-startup budget (`elapsed < 2` -> `< 15`,
  `elapsed < 1.5` -> `< 10`, `elapsed < 2.5` -> `< 15`). The idle-threshold and
  deadline assertions that carry the actual meaning are unchanged.
- `_await_settled()` treats `psutil.AccessDenied` as "not settled yet" instead
  of raising mid-test.
- The decoy process in `test_parent_exit_does_not_wait_for_descendant_stdout`
  lives 120s instead of 10s, so a slow run cannot make it die of old age and be
  reported as "cleanup touched an unrelated process".
- `test_detached_venv_launcher_has_no_console` asserts the marker exists before
  reading it, instead of raising `FileNotFoundError` after its 15s wait.

Observability
-------------

The Windows step now runs with `-rA --durations=15`. Without them the job
reported only "Process completed with exit code 1" with no test name, which is
why these failures needed a local reproduction to attribute.

Verification
------------

- `pytest -q -rA --durations=15 tests/services/parsing/test_mineru_process_lifecycle.py tests/runtime/test_launcher.py::test_detached_venv_launcher_has_no_console`
  -> 7 passed, 10 skipped (the skips are POSIX/Darwin-only cases).
- Deliberate-startup-delay harness: 0.0/0.5/0.9/1.5/3.0s all report
  `cancelled` after the change; 0.7s+ reported `timeout` before it.
- `ruff check` and `ruff format --check` clean on both files; workflow YAML
  parses.

No production code is changed.

* test(parsing): synchronise the deadline fixtures with grandchild startup

Addresses review on #3089. Two real defects:

1. The deadline case of test_deadline_and_cancellation_settle_the_owned_tree
   still raced. Only the cancellation branch waited for `child.pid`; the
   deadline branch killed the fixture at 0.8s and then read a marker that was
   never written, so a 1.3s startup delay produced `TIMEOUT` and then a failed
   marker read. Both branches now synchronise through `check()`: it waits for
   the recorded grandchild and only then either raises (cancellation) or returns
   and lets the deadline comparison run. The timeout assertion is preserved.

   test_explicit_client_timeout_also_bounds_parent_runtime had the same shape —
   it read `deadline.txt` after a 1.2s kill. The record is written before the
   child parks, so it exists whenever the child started at all, and the read now
   reports "CLI did not start" instead of an unpacking error.

2. test_parent_exit_does_not_wait_for_descendant_stdout had lost its teeth: the
   new 10s bound exceeded the grandchild's 2s sleep, so an implementation that
   waited for inherited stdout could finish inside the bound and pass. The
   grandchild now lives 60s and the bound is 20s, derived from the fixture, so
   waiting for it fails the test again.

Verified with a 1.3s pre-startup delay (the reviewer's repro): both lifecycle
cases report the expected reason and the tree is settled. 0.0/1.3/2.0/3.0s all
pass. `7 passed, 10 skipped`; ruff clean.

* test: wait for the MinerU deadline record before enforcing the timeout

---------

Co-authored-by: Qiuner <wdst3635@163.com>
2026-11-30 05:55:09 -03:00
Bingxi Zhao (Frank)
e96cba219c feat(docling): expose optional enrichments and version remote cache
Fixes #2518
2026-11-15 01:20:52 +08:00
Bingxi Zhao (Frank)
8ecf2da95f fix(parsing): validate uploads against available parser formats
Fixes #2338
2026-11-15 01:20:52 +08:00
Bingxi Zhao (Frank)
92a26ae3cc fix(storage): isolate attachment writes and settle document parsing
Local dev repairs for #2244, #2245, #2255, #2426, #2453. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Bingxi Zhao (Frank)
6fcdec2ec8 Merge PR #2550: feat(parsing): emit content_list blocks from the Docling adapter
Normalize Docling coordinates to top-left 0..1000 before unions, omit unverifiable geometry, and bump the cache schema. Tests cover both origins, non-square pages, mixed records, and invalid sizes (36 passed; optional docling-core test skipped).
2026-11-14 23:14:04 +08:00
Bingxi Zhao (Frank)
4889243501 Merge PR #2553: fix(parsing): preserve LiteParse page metadata
Format the parser regression tests; combined adapter suite passed.
2026-11-14 23:04:56 +08:00
Bingxi Zhao (Frank)
2b2e7bb335 Merge PR #2519: fix(parsing): report a Docling option-setup fallback instead of swallowing it 2026-11-14 22:58:51 +08:00
lazytalk
406bcbf680 fix(parsing): preserve LiteParse page metadata 2026-11-09 21:49:28 +08:00
evan188199-tech
bce9252c43 fix(parsing): pass doc to Docling table HTML export and flush list groups on page transitions (#2518) 2026-11-09 20:42:59 +08:00
evan188199-tech
43fb66686d fix(parsing): read Docling list provenance and split list groups per page (#2518) 2026-11-09 19:55:47 +08:00
evan188199-tech
34c08e4c6a feat(parsing): emit content_list blocks from the Docling adapter (#2518)
Map the Docling document body into MinerU-shaped content_list blocks so
LightRAG/LlamaIndex indexes built with the Docling engine get equation,
table, and image structure with picture crops instead of a markdown-only
index.

- new engines/docling/content_list.py: duck-typed mapper (no Docling
  import) emitting text/heading, equation, table (HTML body, merged cells
  preserved), image (crop saved under images/), list, and code blocks;
  furniture/page chrome skipped; empty formulas and crop-less pictures
  dropped rather than emitted unresolvable; markdown fallback kept when
  the document yields no structure
- local_worker: request generate_picture_images crops; write
  <stem>_content_list.json + images/ beside the markdown export
- engine: local parser signature folds in the content_list schema
  version so pre-block markdown-only caches are re-parsed; remote mode
  unchanged (markdown only)
2026-11-09 19:04:47 +08:00
panghufattiger996-maker
23fa8ca6f6 fix(parsing): report a Docling option-setup fallback instead of swallowing it
_build_converter falls back to a bare DocumentConverter() when Docling's
option API moves, which is the right behaviour for a compatible release.
It did so under a bare 'except Exception' with no output, and Docling
defaults do_ocr to True while DeepTutor defaults it to False: a failed
option setup therefore turned OCR on, changed the parse output and made
the run slower with nothing in the log to explain it (#2518).

Emit one stderr line naming the exception, the message and both dropped
options. The worker runs under 'python -m' and the parent relays stderr
through on_output, so that line reaches the parse log. The option imports
stay inside the try, so an older Docling without them still degrades
exactly as before -- only the silence is gone.
2026-11-08 15:14:30 +08:00
Tazeem Mahashin
e372aacc90 fix(parsing): recheck groups that disappear during cleanup inspection 2026-11-06 12:37:11 -05:00
Bingxi Zhao (Frank)
39f744114f Confirm process group settlement and load the mastery transcript on demand 2026-11-06 02:16:17 +08:00
Bingxi Zhao (Frank)
11bc2c794f Merge #2328 from Antonio-Faure 2026-11-06 01:56:23 +08:00
Bingxi Zhao (Frank)
b819aa7b1b Merge #2269 from Plastic-time 2026-11-06 01:56:20 +08:00
Antonio-Faure
e3380f3756 fix(deps): make the Docling parser installable in the official image 2026-11-01 21:36:04 +01:00
RRFZ
1b41175cad fix(parsing): keep model-download jobs readable on non-UTF-8 Windows
The Docling and MinerU model downloads read their child's output with
text=True and no encoding, so the backend decoded it with the ANSI code
page. Under `deeptutor start` the backend gets PYTHONIOENCODING=utf-8
but not UTF-8 mode, so on a cp936/cp932 server the downloader writes
UTF-8 tqdm bars that the pump cannot decode. The first bar raised
UnicodeDecodeError, the pump stopped reading, the child blocked on the
full pipe and the job stayed "running" with an empty log.

Follow the MinerU parse subprocess: run the downloader with
PYTHONUTF8=1 and decode its output as UTF-8 with errors="replace".
2026-10-31 21:01:18 -04:00
cgycorey
3845c9f231 test(parsing): stop racing init's reaping of a killed MinerU child
test_parent_exit_does_not_wait_for_descendant_stdout asserted
`not psutil.pid_exists(child)` immediately after the CLI exited, but
cli_process only SIGKILLs the group and waits for the direct child: an
orphaned grandchild is reaped by init, so there is a real window where the
pid still exists as a zombie.

Running the whole file in a loop fails 2 of 8 runs on 40c051b7 and 5 of 8 on
f7aed0744 (v1.7.1), and every failure is `status=zombie` -- the kill landed
and only the reaping was late. The test alone passes 12 of 12 in isolation,
which is why it reads as a CI-only flake.

Wait up to 0.25s for the pid to disappear, accepting a zombie or dead state
but still failing a running process. The window stays under the child's 2s
lifetime, so a kill that never landed still fails instead of dying of old
age. After the change the same loop passes 15 of 15, and with os.killpg
disabled the test still fails, so the relaxed check kept its teeth.

The deadline/cancel test carried the same immediate check against the same
reaping window, so it uses the helper too.

Those cleanup assertions only ever see the settled answer, so a separate test
pins both answers with real processes: a live pid is not settled, and an
unreaped kill is. Swapping the helper for the old `not pid_exists` check
makes that test fail.
2026-10-31 20:50:58 +00:00
Bingxi Zhao (Frank)
64ad8598de Merge commit 'cc9a60237bcc7e4213f574081824c49c92569ed8' into codex/validate-reviewed-integration 2026-10-31 18:53:15 +08:00
Bingxi Zhao (Frank)
def8bdc8c6 Merge commit '1876207b5c248eb4ee4375e34779ed332a11d284' into codex/validate-reviewed-integration 2026-10-31 18:52:30 +08:00
hongthana
cb9984d15c fix(settings): clarify offline parser installation guidance 2026-10-30 10:35:22 +07:00
朱鸿儒
e51c25f726 fix(docx): preserve native OMML equation structure 2026-10-30 10:41:28 +08:00
alphaliujin
0512aed5a1 fix(readiness): fail closed when MinerU model cache root is unreadable
The container backend runs as the unprivileged deeptutor user while
supervisor leaves HOME pointing at root's home. mineru_models_ready()
probed <HOME>/.cache/modelscope/hub/models outside its try/except, so
the PermissionError propagated into build_settings_readiness(), which
maps any exception to parser_probe_failed and shows no cause in the UI.

- mineru_models_ready(): treat an unreadable/absent cache root as
  "cannot confirm" and return False (models_missing) instead of raising.
- build_settings_readiness(): log the parser probe exception with a
  traceback before recording parser_probe_failed.
- Dockerfile: create /home/deeptutor and set HOME for the backend and
  frontend supervisor programs, so profile data resolves under the
  service user.
- Add a regression test for the unreadable-cache-root case.
2026-10-29 18:09:31 +08:00
Bingxi Zhao (Frank)
fbab59acbf feat: modularize installation and enforce feature dependency boundaries 2026-10-28 01:02:29 +08:00
Bingxi Zhao (Frank)
c3b98baf34 fix(parsing): align MinerU deadlines and retain terminal errors (#1982) 2026-10-19 01:52:28 +08:00
yepyhun
d48b6278d3 fix(mineru): own CLI workers and avoid log-silence termination 2026-10-12 13:12:57 +02:00
Bingxi Zhao (Frank)
428287fb16 fix(parsing): preserve failed MinerU attempts and usable outputs (#1612) 2026-10-04 18:38:56 +08:00
Bingxi Zhao (Frank)
eba05bc067 test(mineru): preserve normalization and slicing settings together 2026-10-04 15:01:27 +08:00
Bingxi Zhao (Frank)
bb70aa2253 Merge dev into PR #1672 and preserve integrated behavior 2026-10-04 15:00:37 +08:00
Bingxi Zhao (Frank)
335301bff3 Merge dev into PR #1669 and preserve integrated behavior 2026-10-04 14:59:02 +08:00
ZyPulse
056e6a8172 fix(parsing): restore source pages and resume completed MinerU slices 2026-09-30 10:07:37 +08:00
ZyPulse
1220a8e552 fix(parsing): add opt-in normalization for tiny scanned PDF pages 2026-09-30 09:40:43 +08:00
cxzyy
666fa17c1c test(parsing): cover local MinerU failure classification
13 tests: every LocalParseReason, backend mapping (distinct messages; install hint only for cli_missing), legacy bool contracts, bounded detail, and the backward-compatible MinerUError shape.
2026-09-29 23:55:56 +08:00
polaris-smart
4fe036231b feat(parsing): auto-slice oversized PDFs for MinerU cloud parsing
Co-authored-by: polaris-smart <286855282+polaris-smart@users.noreply.github.com>
2026-09-27 11:59:14 +08:00
Bingxi Zhao (Frank)
c129e9a0c5 fix: verify MinerU repository names in ModelScope cache 2026-09-27 02:23:10 +08:00
FriedorixNietzsche
fff69b43be fix: detect MinerU models in ModelScope cache layout 2026-09-25 13:41:59 +08:00
Bingxi Zhao (Frank)
4defba8b99 Merge commit 'refs/pr/1371' into codex/evan-backend-prs-20260923 2026-09-23 10:27:59 +08:00
ZQR1101
182acb8ad7 fix(parsing): fall back to a text-capable engine when the global default can't take a file (#1502) 2026-09-21 10:25:07 +08:00
XZH
785f13cca7 feat(knowledge): add Zotero BibTeX search
Refs #1303.
2026-09-10 09:49:20 -07:00
Bingxi Zhao (Frank)
02ba56793e chore: checkpoint backend stabilization workspace 2026-09-01 21:28:15 +08:00
Bingxi Zhao (Frank)
da9492fbaf feat(parsing): integrate MinerU multi-format inputs (#1087) 2026-08-30 16:36:43 +08:00
Alok Saboo
6cb65a2a79 feat(parsing): add remote Apache Tika parsing engine (#875)
Follow-up to #845. Tika is remote-only: files are sent to a configured tika-server via PUT /tika and the extracted text is written as Markdown, so no local install or model download is needed.
2026-08-19 23:38:04 +08:00
Alok Saboo
5062924279 feat: Add remote Docling Serve parsing support (#845)
* feat: Add remote Docling Serve parsing support

* fix: close remote uploads and await settings saves

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-08-16 19:25:53 +08:00
绝世这天下
9228d10abc feat(parsing): add LiteParse as a document parsing engine (#771)
* feat: integrate liteparse as a document parsing engine

* feat: implement background task dispatching for knowledge base processing

- Added `_dispatch_background_task` to run long-running tasks on a separate daemon thread, preventing blocking of the main event loop during knowledge base ingestion.
- Updated `upload_files` and `create_knowledge_base` functions to utilize the new background task dispatching method.
- Implemented rollback functionality for partially created knowledge bases in case of failures during file saving.
- Enhanced tests to verify the correct offloading of file saving and background task execution.

* update

* docs: add Open Source Partners section with PageIndex

* docs: replace partner blurb with PageIndex promo code

* docs: link PageIndex subscription to developer portal

* docs: point PageIndex logo at its GitHub repo

* fix: harden Responses stream parsing (#825)

* fix: remove obsolete Typer extra (#817)

* fix: normalize RAG citation payloads (#808)

* fix: decouple mastery paths from chat sessions (#810)

* fix(parsing): hold LiteParse to the workdir contract

The engine landed with three knobs that could not work as written:

- ``extract_images`` was gated on a user-supplied ``image_output_dir``
  that defaulted to empty, so image extraction never ran. Even when set,
  images landed outside ``images/`` and the Markdown kept LiteParse's
  bare ``![](img_p1_1.png)`` names, so the cache loader saw neither.
  Images now go to the workdir's ``images/`` like the PyMuPDF4LLM engine,
  links are rewritten to ``images/<name>``, and an empty dir is removed.
- ``output_format`` was selectable, but the parse always writes ``.md``;
  picking JSON or text produced a mislabelled document. Pinned to
  Markdown and dropped from the settings slice.
- ``image_output_dir`` was a free-text path joined onto the workdir.
  Removed with the rest.

Also: normalize the slice with the shared coercers (a bare ``bool()``
reads the string ``"false"`` as True), allow-list ``image_mode``, pass
``quiet`` and ``ocr_failure_fatal=False`` so a systemic OCR failure
degrades to recovered text instead of losing the document, pin the
extra to ``<3.0``, and keep the engine lists in the three tests that
assert them exactly.

Excludes the unrelated background-task/rollback/off-loop changes this
branch carried in ``api/routers/knowledge.py``: dev already routes
uploads through ``_save_uploaded_files_off_loop``, and the rest is a
separate change that deserves its own review.

---------

Co-authored-by: chenhj <hanjiang.chen@1stcs.cn>
Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-08-12 17:06:52 +08:00
Bingxi Zhao (Frank)
9d285f1078 fix(wecom,parsing): bound the reply-frame cache; harden img_path anchoring
Follow-up to #631/#628: wecom's _chat_frames now uses the same
LRU-bounded OrderedDict idiom as the dedup cache (cap 1000) so
long-running bots can't grow it unboundedly, frame-body extraction is
deduped into one helper, and the dead _loop attribute is gone.
_absolutize_img_paths now skips non-string entries and refuses to
anchor traversal paths ('..' components) with a warning, so a crafted
content_list cannot point the vision stage outside the cache dir.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 01:38:06 +08:00
xor_xe
68613a6418 fix: resolve relative img_path in parsed content lists to absolute paths
MinerU emits img_path entries like images/x.png relative to the
content-list file inside the parse cache. RAG-Anything resolves them
against its own working directory, so the vision stage cannot open the
images when indexing with LightRAG. Anchor relative img_path values at
the content dir when loading the cached IR; the cached JSON itself stays
relative so cache dirs remain relocatable.

Fixes #624
2026-07-15 13:53:50 +04:00
Bingxi Zhao (Frank)
eef785ae1e integrate lightrag-server & other fixes. 2026-06-24 15:54:12 +08:00
Bingxi Zhao (Frank)
c9d387e2b6 super super great great update 2026-06-17 00:56:27 +08:00