Skip to content

fix(document): clone parser_config to break dataset aliasing; drop dead parser-config helpers - #20381

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
jay77721:refactor/pr1-cleanup
Sep 29, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
jay77721:refactor/pr1-cleanup

Conversation

@jay77721

@jay77721 jay77721 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR fixes document/dataset parser_config aliasing in the Go document creation path and removes unused parser-config code.

  1. Isolate document configuration. cloneParserConfigForDocument uses common.DeepMergeMaps to copy nested JSON maps and slices. newDatasetDocument clones the resolved config for local, web, empty, and synced documents; file2document, which constructs its own Document, clones directly. A document can then change its component settings without changing the dataset or sibling documents.
  2. Keep synced documents valid when the dataset config is null. A nullable dataset parser_config becomes an independent empty object before writing the non-null document.parser_config column. The sync path relies on the clone in newDatasetDocument, avoiding a second copy. The previous sync helper also produced an empty object for a null input.
  3. Remove unused code and stale references. Delete the uncalled KnowledgebaseDAO UpdateParserConfig, DeleteFieldMap, and mergeConfig helpers, and remove rag/app/table.py path and line references from table chunker comments.

Related Issue

Split from #19347, which bundles the table column-mode feature together with the independent fixes above. This PR carries only those fixes so they can land without the feature; the column-mode work will be resubmitted separately, re-anchored on main's current parser/chunking contract (67d68725f made parser_config component-scoped with no flat-key compatibility, which superseded part of that branch's premise).

Changes

  • internal/service/document: deep-copy document configs, normalize null dataset configs to empty document configs, remove copyJSONMap, and cover nested isolation and the full synced-document insert path with unit tests.
  • internal/dao/kb.go: remove unused parser-config helpers.
  • internal/ingestion/component/chunker/table.go and its test: remove stale Python file references from comments.

Test Plan

  • bash build.sh --test ./internal/service/document/... ./internal/dao/... ./internal/ingestion/component/chunker/... — all three packages pass on the updated branch; the script's native unit tests pass too.
  • TestSyncDocumentUpsertWithNilDatasetParserConfig reproduces the previous NOT NULL constraint failed: document.parser_config error before the fix and verifies that a synced document now persists an empty JSON object.
  • A fresh worktree needs bash build.sh --cpp before the Go tests if librag_tokenizer_c_api.a has not been built.

Document upload (both file2document and sync_document) previously
passed kb.ParserConfig directly, or copyJSONMap()'d it shallowly, to
resolveDocumentParser. resolveDocumentParser keeps the base map on the
no-parser-switch path, so the resulting document.ParserConfig nested
maps were the same maps the dataset row hands out. Writing a component
entry into one document would leak into the dataset and every sibling
document created from it.

cloneParserConfigForDocument does a real deep copy via DeepMergeMaps.
newDatasetDocument now calls it unconditionally as the safety net.
copyJSONMap becomes dead and is removed.

The snapshot branch also touched this file for table column mode; that
logic (tableDocumentConfigForFile, table_column_names_by_file) is left
in the feature branch, not here.
UpdateParserConfig, DeleteFieldMap and their deep-merge helper
mergeConfig had no callers anywhere in internal/. The live dataset
update path writes parser_config through the dataset/document services,
so these DAO methods were leftover dead code.
The Python table chunker (rag/app/table.py) is gone, but the Go port's
comments still cited it by path — and cited a line number (:656) that no
longer maps to anything. Keep the provenance ("the Python table
chunker") without the dead path or line number.
@jay77721 jay77721 added go Pull requests that update go code ☯️ refactor Pull request that refactor/refine code 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Sep 29, 2026
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

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: dbcaba8a-2164-4ce8-8790-56184b921903

📥 Commits

Reviewing files that changed from the base of the PR and between d153fd4 and ed4ab8b.

📒 Files selected for processing (4)
  • internal/service/document/document_test.go
  • internal/service/document/document_upload.go
  • internal/service/document/document_upload_test.go
  • internal/service/document/sync_document.go
💤 Files with no reviewable changes (1)
  • internal/service/document/document_upload.go

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


📝 Walkthrough

Walkthrough

The changes remove two knowledge-base parser configuration methods and their merge helper. Document creation and file conversion now pass cloned parser configuration maps. Sync passes the knowledge base configuration directly. Tests cover clone isolation and sync with nil configuration. Table chunker comments no longer cite repository paths.

Changes

Parser Configuration Handling

Layer / File(s) Summary
Remove parser configuration DAO methods
internal/dao/kb.go
Removes UpdateParserConfig, DeleteFieldMap, and the private mergeConfig helper.
Pass parser configuration to document operations
internal/service/document/document_upload.go, internal/service/document/document_upload_test.go, internal/service/document/file2document.go, internal/service/document/sync_document.go, internal/service/document/document_test.go
Document creation and file conversion pass cloned parser configuration maps. Sync passes kb.ParserConfig directly to parser resolution. Tests cover clone isolation and sync when the persisted configuration is nil.

Table Chunker Comments

Layer / File(s) Summary
Update table chunker comments
internal/ingestion/component/chunker/table.go, internal/ingestion/component/chunker/table_test.go
Revises comments about the Python table chunker contract without repository path references.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: haruko386, xugangqiang

Merge Risk: ⚪ Minimal · up to ed4ab

The removed methods have no repository callers, and sync does not change the dataset’s parser configuration. No actionable issue remains before normal merge checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ed4ab

Document configuration is better isolated from its dataset, and no new authorization path was identified. An unusual parser-template failure could still alter the dataset configuration held in memory during sync; its production reachability is unconfirmed.

Retained concerns

  • Low · architecture · inferred: On a loaded-but-invalid built-in DSL, sync parser resolution can mutate the dataset-owned in-memory configuration before making the document copy. Whether that exceptional path occurs in production is unresolved.
Security review details

Security Blast Radius

  • inferred — The identified exceptional mutation concerns the task knowledgebase map in memory and potentially later processing that reuses it. The inspected path does not show a database write of the mutated dataset map or a change to tenant identity.

Trust Boundaries and Controls

  • observed — A filename can select a different parser, but that branch loads a registered built-in DSL rather than a DSL supplied by the synced document. No new authorization decision uses parser configuration.

Hardening Proposals

  • proposed — Preserve an independent input map at the sync resolver boundary, or make schema-extraction failure return an error rather than passing its input to mutating configuration helpers.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 7 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.
Title check ✅ Passed The title clearly identifies the two main changes: cloning parser configuration to prevent aliasing and removing unused parser-configuration helpers.
Description check ✅ Passed The description includes a complete Summary section and provides clear background, implementation details, related issue context, affected files, and test coverage.
  • 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 map,
Then keeps its nested leaves intact.
A table row hops chunk by chunk,
While old path notes are gone.
The tests watch nil configs pass,
And springtime files stay neatly apart.

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

@yuzhichang
yuzhichang merged commit 83b8e2c into infiniflow:main Sep 29, 2026
6 checks passed
@jay77721
jay77721 deleted the refactor/pr1-cleanup branch October 16, 2026 03:20
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 go Pull requests that update go code ☯️ refactor Pull request that refactor/refine code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants