Repository navigation
fix(parser): propagate cancellation while waiting for vision figure futures - #17014
yuzhichang merged 1 commit into
Conversation
vision_figure_parser_docx_wrapper_naive and VisionFigureParser.__call__ submitted every figure's vision-LLM call to a ThreadPoolExecutor and then blocked on as_completed() until all of them finished, without ever invoking callback() in between. Cancellation is only observed where callback() is called (it checks a Redis flag and raises TaskCanceledException), so pressing "Cancel" on a running dataflow test had no effect until every submitted vision call finished or timed out - several minutes on a busy/slow vision backend. Three sibling wrappers (vision_figure_parser_docx_wrapper, vision_figure_parser_pdf_wrapper, vision_figure_parser_figure_xlsx_wrapper) also swallowed TaskCanceledException into their generic "except Exception as e" handler that logs a visual-model error and continues, which would have silently turned a user cancellation into a logged error and let the pipeline continue. Fix: - Replace the unbounded as_completed() wait with wait() using a 1.0s timeout and return_when=FIRST_COMPLETED, polling once a second so a cancellation is observed promptly instead of only after the whole batch drains. - On TaskCanceledException (or any other exception), cancel every future that hasn't started yet and unwind the local ThreadPoolExecutor without waiting for stragglers; on normal completion, shut it down normally. - Re-raise TaskCanceledException explicitly in the three wrapper functions instead of letting the broad except clause absorb it. - Guard against an explicit callback=None (kwargs.get with a default only substitutes the default when the key is absent, not when its value is None). Note: futures that already started (their HTTP call to the vision backend is in flight) cannot be forcibly aborted - concurrent.futures has no API for that. This change stops new work from starting once a cancellation is observed; already-in-flight requests still run to completion or their own timeout. Verified against a live RAGFlow + Ollama deployment: before this change, cancelling a dataflow test run with several pending figures left the backend logging vision requests for 3+ minutes with no visible effect from the Cancel button. After this change, the same scenario surfaced "Task ... has been canceled" and TaskCanceledException in the task log and transitioned the task to canceled within about a minute, bounded by the already-in-flight requests' own timeout.
📝 WalkthroughWalkthroughFigure parser wrappers now re-raise task cancellations distinctly. DOCX and vision parsing use incremental completion handling, progress callbacks, and explicit cancellation of pending futures during errors. ChangesFigure parser concurrency
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deepdoc/parser/figure_parser.py`:
- Around line 306-307: Update the description assignment in the figure parsing
flow to keep self.descriptions[figure_num] as a list. When txt is present,
prepend it as a separate list element before the existing descriptions rather
than joining them into a string, preserving the schema and ensuring a delimiter
between the vision text and caption.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1196ca62-10c4-4ff5-a8c8-4cdda807fbd9
📒 Files selected for processing (1)
deepdoc/parser/figure_parser.py
| if txt: | ||
| self.descriptions[figure_num] = txt + "\n".join(self.descriptions[figure_num]) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
Preserve list type for figure descriptions to maintain schema contract.
Assigning a concatenated string to self.descriptions[figure_num] breaks the expected data schema where descriptions must be a list (enforced by assertions earlier in the file and strictly relied upon by filters like is_figure_item on line 123). If the description is transformed into a string, downstream consumers will fail to recognize or process the boosted figures correctly.
Additionally, the current string concatenation txt + "\n".join(...) lacks a delimiter, merging the vision output directly into the existing caption without spaces. Prepending the new text as an element to the list solves both issues.
🐛 Proposed fix to maintain the list structure
- if txt:
- self.descriptions[figure_num] = txt + "\n".join(self.descriptions[figure_num])
+ if txt:
+ self.descriptions[figure_num] = [txt] + self.descriptions[figure_num]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if txt: | |
| self.descriptions[figure_num] = txt + "\n".join(self.descriptions[figure_num]) | |
| if txt: | |
| self.descriptions[figure_num] = [txt] + self.descriptions[figure_num] |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@deepdoc/parser/figure_parser.py` around lines 306 - 307, Update the
description assignment in the figure parsing flow to keep
self.descriptions[figure_num] as a list. When txt is present, prepend it as a
separate list element before the existing descriptions rather than joining them
into a string, preserving the schema and ensuring a delimiter between the vision
text and caption.
|
LGTM. @yuzhichang pls have a second eye check. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17014 +/- ##
===========================================
- Coverage 93.16% 39.04% -54.13%
===========================================
Files 10 54 +44
Lines 717 14947 +14230
Branches 118 118
===========================================
+ Hits 668 5836 +5168
- Misses 29 9085 +9056
- Partials 20 26 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What
vision_figure_parser_docx_wrapper_naiveandVisionFigureParser.__call__submit every figure's vision-LLM call to aThreadPoolExecutorand then block onas_completed()until all of them finish, without ever callingcallback()in between. Task cancellation is only observed atcallback()call sites — it checks a Redis flag and raisesTaskCanceledException— so cancelling a dataflow run while it's inside one of these loops has no visible effect until every submitted vision call finishes or hits its own timeout (minutes, on a slow/busy vision backend).The three call sites that wrap
VisionFigureParser(vision_figure_parser_docx_wrapper,vision_figure_parser_pdf_wrapper,vision_figure_parser_figure_xlsx_wrapper) also catchTaskCanceledExceptioninside their genericexcept Exception as e:handler, which logs a "visual model error" and continues — i.e. a cancellation would be silently turned into a logged error instead of stopping the pipeline.Fix
as_completed()wait withwait(..., timeout=1.0, return_when=FIRST_COMPLETED), polling once a second so a cancellation is observed while other figures are still in flight, rather than only after the whole batch drains.TaskCanceledException(or any other exception), cancel every future that hasn't started running yet, and unwind the executor without waiting for stragglers; on normal completion, shut it down normally.TaskCanceledExceptionexplicitly in the three wrapper functions instead of letting the broadexcept Exceptionabsorb it.callback=None(kwargs.get("callback", default)only substitutes the default when the key is absent, not when its value isNone).What this does not fix
concurrent.futureshas no API to forcibly abort a future that's already running — a vision call whose HTTP request is in flight will run to completion (or its own@timeout(30, 3)) regardless of this change. This fix stops new vision calls from starting once a cancellation is observed; it does not abort ones already sent to the backend.Testing
Verified against a live RAGFlow + Ollama deployment, cancelling a dataflow test run on a PDF with several figures still pending:
Task ... has been canceled(checked roughly once a second, matching the new poll interval) andTaskCanceledException/handle_task canceledwithin about a minute of pressing Cancel — bounded by the already-in-flight requests' own timeout, not by this change.No automated test is included; this is concurrency/cancellation behavior that's awkward to assert deterministically without a real (or heavily mocked) backend and a real ThreadPoolExecutor. Open to suggestions on how the maintainers would want this covered.