Skip to content

Drop unscoped (flat) parser_config keys instead of rejecting them - #20445

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/drop-flat-parser-config-keys
Sep 30, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/drop-flat-parser-config-keys

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

The Go backend enforces a component-scoped-only contract for parser_config: every top-level key must be keyed by a component id (contain ":"), e.g. "Parser:abc123". Previously any flat (non-component-scoped) key was rejected with an error. This breaks requests that still carry legacy or single-instance flat keys — most notably the File input node, whose id is the bare name "File" (a DSL has exactly one File instance, so it is never scoped as File:<id>).

Flat keys are legacy transport artifacts that downstream consumers (CleanComponentParams) never read, so rejecting them was stricter than the actual processing. This change drops such keys and logs a warning instead of failing the request.

What changed

  • Added DropUnscopedParserConfigKeys (internal/service/dataset/helpers.go): removes top-level keys that do not contain ":" and returns the dropped key names. Only top-level keys are affected; keys nested inside a component node (e.g. "Extractor:AutoExtractDefault.metadata") are preserved.
  • ValidateParserConfig / ValidateDocumentParserConfig now drop flat keys and still enforce the size limit (they no longer return an error for flat keys).
  • The three entry points now drop + warn:
    • dataset create (crud.go) — warns with tenant_id
    • dataset update (update.go) — warns with dataset_id, tenant_id
    • document change_parser (handler/document.go) — warns with user_id, dataset_id, document_id

Why a warning, not silent

The dropped key names and request context are logged so misbehaving clients (or stale saved configs) are traceable via the warning rather than silently changing behavior without a signal.

Test plan

  • Rewrote the previous "flat key rejected" tests into "flat key dropped" tests in helpers_test.go.
  • Added TestDropUnscopedParserConfigKeys covering: nil/empty maps, top-level flat-key removal, preservation of component-scoped keys, and preservation of nested flat-looking keys inside a component node.
  • bash build.sh --test ./internal/service/dataset/... ./internal/handler/... passes.

Note for reviewers

This is a deliberate relaxation of the strict validation contract (previously fail-fast on flat keys) into lenient drop + warn. It is intended as a stopgap for existing/legacy flat keys (e.g. the File node); the long-term direction remains component-scoped config. The size limit on parser_config is unchanged.

The Go backend enforces a component-scoped-only contract for
parser_config: every top-level key must be keyed by a component id
(contain ":"), e.g. "Parser:abc123". Previously a flat key such as the
single File input node (id "File") was rejected with an error, which
breaks requests that still carry legacy or single-instance flat keys.

Flat keys are legacy transport artifacts that downstream consumers
(CleanComponentParams) never read, so they are now silently dropped
rather than rejected. All three entry points (dataset create, dataset
update, document change_parser) drop such keys and log a warning that
includes the dropped key names and request context (tenant/dataset/user
id) for traceability. The size limit is still enforced.
@xugangqiang xugangqiang added the ci Continue Integration label Sep 30, 2026
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 22e8d053-42b0-470c-bd55-afb6d0036a2d

📥 Commits

Reviewing files that changed from the base of the PR and between 36420e0 and 7c39a38.

📒 Files selected for processing (1)
  • test/testcases/restful_api/test_datasets.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Parser configuration validation removes top-level keys without : and reports their names. Dataset creation, dataset updates, and document updates log removed keys. The existing 65,535-byte size limit remains.

Changes

Parser Configuration Filtering

Layer / File(s) Summary
Filter and validate parser configuration keys
internal/service/dataset/helpers.go, internal/service/dataset/helpers_test.go
A helper removes top-level keys without : and returns their names. Dataset and document validators filter those keys before applying the existing size limit. Tests cover removal, reporting, and preservation of component-scoped keys and nested values.
Apply filtering to dataset operations
internal/service/dataset/crud.go, internal/service/dataset/update.go, test/testcases/restful_api/test_datasets.py
Dataset creation and updates use the shared validator and log removed keys with tenant and dataset identifiers. Validation errors continue to return CodeArgumentError. REST API tests skip legacy flat-key cases for Go proxy runs and cover component-scoped update settings.
Apply filtering to document updates
internal/handler/document.go
Document updates log removed keys with user, dataset, and document identifiers. Validation errors continue to be handled after logging.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: 6ba3i

Merge Risk: ⚪ Minimal · up to 7c39a

The reviewed test changes look safe to merge. The parser-config filtering itself is covered only by the author-reported test run.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 7c39a

Component-scoped processing and ownership checks remain intact. The main risk is that discarded input is excluded from configuration-size validation while its complete key names are logged, potentially increasing shared logging costs. The effective exposure depends on request and logging limits that were not established.

Retained concerns

  • Low · security · inferred: The new warning path logs every discarded key name even though those names have already been removed from configuration-size accounting. Authenticated callers can therefore increase warning payload size independently of retained configuration size. This creates a potential shared-logging resource-exhaustion path; practical impact depends on unverified ingress limits and logging quotas.
Security review details

Security Blast Radius

  • inferred — The identified new exposure is to shared warning infrastructure from authenticated API callers, rather than demonstrated cross-tenant configuration access. Dataset-update warnings occur before the transactional ownership check, and document warnings occur before service-level dataset/document ownership checks.

Security Findings and Attack Paths

  • inferred — A caller can supply many or long top-level names without a colon. Filtering removes them before size validation, but the returned list is emitted in a warning. Repetition could consume logging resources. Structured encoding limits syntax injection; actual exhaustion and its maximum environment-wide impact are not established.

Trust Boundaries and Controls

  • observed — The routes remain behind authentication. Dataset persistence requires locked ownership/team authorization; document updates require dataset ownership and document membership. Acceptance of flat keys does not replace these service controls.

Resilience and Maintainability Implications

  • observed — Document updates check active ingestion state before configuration mutation. Configuration persistence, parser-reset operations, and response readback remain separate steps; the inspected source does not establish atomic rollback across the complete document operation.

Hardening Proposals

  • proposed — Bound warning output by total bytes and key count, reporting truncation and dropped-key totals. Establish an ingress request budget independently of the retained-configuration size limit.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, implementation, affected entry points, rationale, tests, and intended scope.
Title check ✅ Passed The title clearly and concisely describes the main change: dropping unscoped parser_config keys instead of rejecting them.
  • Fix all pre-merge checks with AI

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

A rabbit checks each parser key,
Flat keys hop out, scoped keys stay.
Dataset logs record the names,
Document logs do so the same.
The size limit still holds its place,
Then clover celebrates the case.

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

Previously the three entry points dropped unscoped (flat) parser_config
keys via DropUnscopedParserConfigKeys and then validated the size limit
in two different ways: crud/update called validateDatasetParserConfigSize
directly, while document called ValidateDocumentParserConfig, which
dropped the keys again — a redundant double drop.

Make ValidateParserConfig and ValidateDocumentParserConfig return the
names of the dropped keys ([]string, error) so every entry path shares a
single drop call and a single logging site. This removes the redundant
drop in the document path and gives ValidateParserConfig a production
caller (it was only referenced by tests before).

Tests updated to the new signature; two new tests assert the returned
dropped-key list.
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 30, 2026
…act tests

PR infiniflow#20445 changed the Go backend to silently drop (rather than reject)
component-unscoped flat parser_config keys with code 0. Update the two
contract tests that still asserted the old code-101 rejection:

- test_dataset_update_parser_config_valid_matrix_contract: all cases are
  flat keys, so assert code 0 and that the dropped keys do not survive in
  the stored config.
- test_dataset_update_parser_config_invalid_values_contract: flat keys are
  dropped before field validation, so assert code 0 instead of the
  field-level error message.

The Python (non-Go) branches are dead code: CI always runs with
API_PROXY_SCHEME="go" (sep-tests.yml api_proxy_schemes=["go"]) and the
Python backend has been removed from main, so they are removed entirely.

Co-authored-by: xugangqiang <[email protected]>
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 30, 2026
… ones

Go no longer accepts legacy flat parser_config (the create-path tests
already skip it for Go), so the two update-path contract tests that
asserted the old code-101 rejection are rewritten to match:

- test_dataset_update_parser_config_valid_matrix_contract and
  test_dataset_update_parser_config_invalid_contract now pytest.skip for
  Go (consistent with the create-path convention). They keep their
  Python round-trip/validation assertions as documentation but never run
  under CI, which is always API_PROXY_SCHEME="go" since the Python
  backend was removed from main.

The intended component-scoped contract is covered by two new tests:

- test_dataset_update_parser_config_component_scoped_roundtrip: discovers
  the real chunker component id from a created dataset and verifies a
  dataset-level parent_child setting reaches the runtime chunker node and
  round-trips (children_delimiters list).
- test_dataset_update_parser_config_accepts_bare_file_node: the DSL emits a
  single input node keyed by the bare id "File" (no colon); the Go backend
  tolerates it (dropped server-side) instead of rejecting with 101, which
  is the back-compat fix from PR infiniflow#20445.

Co-authored-by: xugangqiang <[email protected]>
@xugangqiang
xugangqiang force-pushed the fix/drop-flat-parser-config-keys branch from 9d017d2 to 36420e0 Compare September 30, 2026 08:26
… ones

Go no longer accepts legacy flat parser_config (the create-path tests
already skip it for Go), so the two update-path contract tests that
asserted the old code-101 rejection are rewritten to match:

- test_dataset_update_parser_config_valid_matrix_contract and
  test_dataset_update_parser_config_invalid_contract now pytest.skip for
  Go (consistent with the create-path convention). They keep their
  Python round-trip/validation assertions as documentation but never run
  under CI, which is always API_PROXY_SCHEME="go" since the Python
  backend was removed from main.

The intended component-scoped contract is covered by two new tests:

- test_dataset_update_parser_config_component_scoped_roundtrip: discovers
  the real chunker component id from a created dataset and verifies a
  dataset-level parent_child setting reaches the runtime chunker node and
  round-trips (children_delimiters list).
- test_dataset_update_parser_config_accepts_bare_file_node: the DSL emits a
  single input node keyed by the bare id "File" (no colon); the Go backend
  tolerates it (dropped server-side) instead of rejecting with 101, which
  is the back-compat fix from PR infiniflow#20445.

Co-authored-by: xugangqiang <[email protected]>
@xugangqiang
xugangqiang force-pushed the fix/drop-flat-parser-config-keys branch from 36420e0 to 7c39a38 Compare September 30, 2026 08:35
@xugangqiang xugangqiang added ci Continue Integration and removed ci Continue Integration labels Sep 30, 2026
@yuzhichang
yuzhichang merged commit 4ef147e into infiniflow:main Sep 30, 2026
10 of 11 checks passed
@xugangqiang
xugangqiang deleted the fix/drop-flat-parser-config-keys branch October 28, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants