Skip to content

Fix: parse by somark in parser - #17355

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:fix/resolve-model-id-in-parser
Jul 24, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:fix/resolve-model-id-in-parser

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

Summary

As title, recognize parse_method provider.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 24, 2026
@Lynn-Inf
Lynn-Inf requested a review from wangq8 July 24, 2026 09:27
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Jul 24, 2026
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PDF parser now recognizes tenant model IDs, resolves their provider and instance through tenant services, and normalizes them into the provider-qualified format used by downstream parsing logic.

Changes

Tenant-aware PDF parser configuration

Layer / File(s) Summary
Resolve tenant parser models
rag/flow/parser/parser.py
Imports tenant model services and converts tenant model IDs into model_name@instance_name@provider_name before provider-specific parsing.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: jinhai-cn

Poem

A bunny hops through parser schemes,
Unpacking tenants’ model dreams.
Provider, instance, name align,
Then parsing follows the proper line.
Squeak—configuration now is fine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: parser support for tenant/provider-based parse_method handling.
Description check ✅ Passed The description includes the required Summary section and states the parser now recognizes the parse_method provider.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
rag/flow/parser/parser.py (3)

343-353: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add focused regression coverage for tenant parser selection.

Cover successful normalization into @mineru, @paddleocr, and @somark, plus missing-provider/instance and cross-tenant rejection cases so the new branch cannot silently regress into Vision parsing.

As per coding guidelines, “Preserve valid behavior with focused tests.”

🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Add focused regression
tests for the tenant-model resolution branch in the parser, covering successful
normalization to `@mineru`, `@paddleocr`, and `@somark`. Also cover missing provider
or instance records and cross-tenant model references, asserting these cases do
not fall through into Vision parsing and preserve the expected rejection
behavior.

Source: Coding guidelines


343-353: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add observability for the new resolution flow.

Successful normalization and invalid/missing tenant model configuration currently produce no log entry, making parser-selection failures difficult to diagnose. Add structured debug/info logging for resolution and warning/error logging before rejecting invalid configuration; do not log credentials.

As per coding guidelines, **/*.py: Add logging for new flows.

🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Add logging around the
tenant-model resolution block in the parser flow: record successful
normalization with non-sensitive identifiers, and emit warning or error logs
when the tenant model, provider, or instance lookup/configuration is invalid
before the parser selection rejects it. Use the module’s existing logger and
ensure credentials or other sensitive configuration values are never logged.

Source: Coding guidelines


346-350: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid a database lookup for every parser name.

This condition queries TenantModelService for every non-empty value, including built-in methods such as deepdoc, mineru, paddleocr, and somark. Short-circuit known parser literals or provide a single optimized tenant-model resolver to avoid an unnecessary database round trip for every PDF.

🤖 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 `@rag/flow/parser/parser.py` around lines 346 - 350, Update the
raw_parse_method handling in the parser flow to recognize built-in parser
literals such as deepdoc, mineru, paddleocr, and somark before calling
TenantModelService.get_by_id. Short-circuit those known values so they do not
trigger tenant-model, provider, or instance database lookups, while preserving
the existing resolver behavior for non-built-in names.
🤖 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 `@rag/flow/parser/parser.py`:
- Around line 343-353: Update the tenant-model normalization block around
TenantModelService.get_by_id to use tenant-scoped lookups for the model and
provider, and validate that the resolved instance belongs to the model’s
provider and self._canvas._tenant_id. If model, provider, or instance resolution
is partial or invalid, raise the established configuration error instead of
leaving raw_parse_method unchanged; only normalize to the provider-qualified
name after all validations pass.

---

Nitpick comments:
In `@rag/flow/parser/parser.py`:
- Around line 343-353: Add focused regression tests for the tenant-model
resolution branch in the parser, covering successful normalization to `@mineru`,
`@paddleocr`, and `@somark`. Also cover missing provider or instance records and
cross-tenant model references, asserting these cases do not fall through into
Vision parsing and preserve the expected rejection behavior.
- Around line 343-353: Add logging around the tenant-model resolution block in
the parser flow: record successful normalization with non-sensitive identifiers,
and emit warning or error logs when the tenant model, provider, or instance
lookup/configuration is invalid before the parser selection rejects it. Use the
module’s existing logger and ensure credentials or other sensitive configuration
values are never logged.
- Around line 346-350: Update the raw_parse_method handling in the parser flow
to recognize built-in parser literals such as deepdoc, mineru, paddleocr, and
somark before calling TenantModelService.get_by_id. Short-circuit those known
values so they do not trigger tenant-model, provider, or instance database
lookups, while preserving the existing resolver behavior for non-built-in names.
🪄 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 Plus

Run ID: 312a0cd5-c741-498a-9baa-a49e03090191

📥 Commits

Reviewing files that changed from the base of the PR and between bdfc3ad and 3f4656c.

📒 Files selected for processing (1)
  • rag/flow/parser/parser.py

Comment thread rag/flow/parser/parser.py
Comment on lines +343 to +353
# If raw_parse_method is a tenant_model ID, resolve it to
# model_name@instance_name@provider_name so the provider-specific
# branches below can match the per-provider suffix.
if isinstance(raw_parse_method, str) and raw_parse_method:
exist, model_obj = TenantModelService.get_by_id(raw_parse_method)
if exist:
provider_ok, provider_obj = TenantModelProviderService.get_by_id(model_obj.provider_id)
instance_ok, instance_obj = TenantModelInstanceService.get_by_id(model_obj.instance_id)
if provider_ok and instance_ok:
raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Scope and validate tenant parser models before normalization.

These lookups use global get_by_id, so they do not verify that the model/provider/instance belongs to self._canvas._tenant_id or that the instance belongs to the model’s provider. If provider or instance resolution fails, the ID remains unchanged and later falls through to the Vision parser instead of failing clearly.

Use the tenant-scoped provider lookup, validate the instance relationship, and raise a configuration error on partial resolution.

Proposed validation
+        tenant_id = self._canvas._tenant_id
         if isinstance(raw_parse_method, str) and raw_parse_method:
             exist, model_obj = TenantModelService.get_by_id(raw_parse_method)
             if exist:
-                provider_ok, provider_obj = TenantModelProviderService.get_by_id(model_obj.provider_id)
+                provider_ok, provider_obj = TenantModelProviderService.get_by_tenant_id_and_provider_id(
+                    tenant_id, model_obj.provider_id
+                )
                 instance_ok, instance_obj = TenantModelInstanceService.get_by_id(model_obj.instance_id)
-                if provider_ok and instance_ok:
-                    raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}"
+                if not provider_ok or not instance_ok or instance_obj.provider_id != model_obj.provider_id:
+                    raise RuntimeError("Invalid tenant PDF parser model configuration")
+                raw_parse_method = f"{model_obj.model_name}@{instance_obj.instance_name}@{provider_obj.provider_name}"
🤖 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 `@rag/flow/parser/parser.py` around lines 343 - 353, Update the tenant-model
normalization block around TenantModelService.get_by_id to use tenant-scoped
lookups for the model and provider, and validate that the resolved instance
belongs to the model’s provider and self._canvas._tenant_id. If model, provider,
or instance resolution is partial or invalid, raise the established
configuration error instead of leaving raw_parse_method unchanged; only
normalize to the provider-qualified name after all validations pass.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (cd9db94) to head (3f4656c).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17355   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix! The change looks clean and addresses a real gap — when parse_method is passed as a tenant_model ID (UUID) from the new Tenant LLM Provider UI, it was silently falling through all parser branches without matching.

What this does well:

  • Minimal, focused change (14 lines, single file)
  • Properly resolves tenant_model ID → model_name@instance_name@provider_name format that the existing @somark/@mineru/@paddleocr suffix checks expect
  • Guards each lookup result (exist, provider_ok, instance_ok) before constructing the resolved string
  • No change to existing behavior when raw_parse_method is already a proper parser name

One small suggestion (non-blocking):
If the provider or instance lookup fails (e.g. data inconsistency), it currently fails silently — raw_parse_method stays as the raw UUID and falls through all parser branches. Consider adding a logging.warning(...) in the fall-through case to help with debugging.

Verified:

  • All three service classes (TenantModelService, TenantModelProviderService, TenantModelInstanceService) exist and inherit get_by_id from CommonService
  • Model fields (model_name, instance_name, provider_name) match the constructed format
  • No circular import risk — these are leaf DB service imports, consistent with existing patterns in this file

LGTM 👍

@wangq8
wangq8 merged commit a154d75 into infiniflow:main Jul 24, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants