Skip to content

fix: route TokenChunker delimiter_mode "one" to OneChunker in Go ingestion - #18121

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/token-chunker-one-delimiter-mode
Aug 14, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/token-chunker-one-delimiter-mode

Conversation

@euvre

@euvre euvre commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

The DSL contract shared by the web UI and the Python runtime expresses single-chunk mode as a TokenChunker node with delimiter_mode: "one". In Go that behaviour lives in the separate OneChunker component, and TokenChunkerParam.Validate only accepts token_size / delimiter. As a result, a knowledge base configured with the One method failed at canvas compile time:

factory: TokenChunker: schema: field "delimiter_mode" has invalid value "one"

and the ingestor kept retrying the failed task indefinitely (the file appeared to be "parsing forever").

Fix: translate the contract at the single chunker factory entry point (newChunkerByName in internal/ingestion/component/chunker/common.go) — a TokenChunker component whose delimiter_mode is "one" now builds a OneChunker. This keeps one implementation path (no duplicated chunking logic), preserves the DSL node id (progress/log counting unaffected), and fixes both the ingestion pipeline and the agent canvas paths since they share the same registry factory. The strict constructor-level validation on TokenChunker is unchanged.

Adds a regression test (TestNewChunkerByName_TokenChunkerOneMode) pinning the translation. bash build.sh --test ./internal/ingestion/component/chunker/... passes.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 11, 2026
@euvre euvre added the ci Continue Integration label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 668ca36c-850d-40ff-8eef-ebe96febd7a6

📥 Commits

Reviewing files that changed from the base of the PR and between 423c848 and c154974.

📒 Files selected for processing (2)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/one_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/one_test.go

📝 Walkthrough

Walkthrough

The chunker factory now routes TokenChunker requests with delimiter_mode: "one" to NewOneChunker. A regression test verifies successful construction and the resulting component type.

Changes

Token chunker routing

Layer / File(s) Summary
One-mode chunker dispatch
internal/ingestion/component/chunker/common.go, internal/ingestion/component/chunker/one_test.go
The factory selects NewOneChunker for token chunkers with "one" delimiter mode. The test verifies successful construction of *OneChunkerComponent.

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

Mergeability Score: ⚪ Minimal · up to c1549

This localized change routes the single-chunk configuration to the intended implementation and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the chunker’s route,
One-mode pieces hop out.
The factory points them to the right place,
A test confirms the type and trace.
“All sorted!” says the rabbit with grace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, fix, scope, and regression test.
Title check ✅ Passed The title clearly and concisely identifies the main routing fix for TokenChunker delimiter_mode "one".
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@euvre
euvre requested a review from wangq8 August 11, 2026 11:18

@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

🤖 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 `@internal/service/tenant.go`:
- Around line 529-533: Update the model lookup in the tenant model validation
flow around GetModelByProviderIDAndInstanceIDAndModelName to use the existing
model-type mapping and the type-aware tenant-model DAO query, passing the
requested model type alongside provider, instance, and name. Add a regression
test covering an active same-name tenant_model row with a different model_type
and verify it is not returned for the requested type.
🪄 Autofix

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: f6e118d4-11e4-4b9f-b580-1f5535e29720

📥 Commits

Reviewing files that changed from the base of the PR and between 8bd5768 and 8c9192e.

📒 Files selected for processing (3)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/one_test.go
  • internal/service/tenant.go

Comment thread internal/service/tenant.go Outdated
Comment on lines 529 to 533
// Check if the model exists and is active. The tenant_model row is the
// source of truth here — providers with an empty factory catalog (e.g.
// OpenAI-API-Compatible, whose models are user-defined) cannot be
// validated against the catalog. Mirrors Python's _get_model_info.
modelEntity, err := s.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(ctx, dao.DB, modelProvider.ID, modelInstance.ID, modelName)

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve model-type validation when using tenant_model as the source of truth.

This lookup filters by provider, instance, and model name only. An active row for a different model_type can therefore satisfy a chat, embedding, or rerank lookup. The result can be returned under the wrong ModelType and passed to incompatible downstream code.

Use the existing model-type mapping and type-aware tenant-model query. Add a regression test for an active same-name row with the wrong type. (raw.githubusercontent.com)

Proposed fix
-	modelEntity, err := s.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(ctx, dao.DB, modelProvider.ID, modelInstance.ID, modelName)
+	_, _, expectedModelType, err := tenantDefaultModelFields(modelType)
+	if err != nil {
+		return nil, nil, nil, false, err
+	}
+	modelEntity, err := s.modelDAO.GetByProviderIDAndInstanceIDAndModelTypeAndModelName(
+		ctx, dao.DB, modelProvider.ID, modelInstance.ID, int(expectedModelType), modelName,
+	)
📝 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.

Suggested change
// Check if the model exists and is active. The tenant_model row is the
// source of truth here — providers with an empty factory catalog (e.g.
// OpenAI-API-Compatible, whose models are user-defined) cannot be
// validated against the catalog. Mirrors Python's _get_model_info.
modelEntity, err := s.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(ctx, dao.DB, modelProvider.ID, modelInstance.ID, modelName)
// Check if the model exists and is active. The tenant_model row is the
// source of truth here — providers with an empty factory catalog (e.g.
// OpenAI-API-Compatible, whose models are user-defined) cannot be
// validated against the catalog. Mirrors Python's _get_model_info.
_, _, expectedModelType, err := tenantDefaultModelFields(modelType)
if err != nil {
return nil, nil, nil, false, err
}
modelEntity, err := s.modelDAO.GetByProviderIDAndInstanceIDAndModelTypeAndModelName(
ctx, dao.DB, modelProvider.ID, modelInstance.ID, int(expectedModelType), modelName,
)
🤖 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 `@internal/service/tenant.go` around lines 529 - 533, Update the model lookup
in the tenant model validation flow around
GetModelByProviderIDAndInstanceIDAndModelName to use the existing model-type
mapping and the type-aware tenant-model DAO query, passing the requested model
type alongside provider, instance, and name. Add a regression test covering an
active same-name tenant_model row with a different model_type and verify it is
not returned for the requested type.

Source: MCP tools

@euvre euvre closed this Aug 11, 2026
@euvre euvre reopened this Aug 12, 2026

@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 root cause is well-identified and the fix at the newChunkerByName dispatch layer is clean — translating the DSL contract rather than relaxing schema validation is the right approach.

A few things to address:

1. Unrelated tenant.go changes
The internal/service/tenant.go changes (removing factoryModelTypeName and the factory model-type validation in GetModelInfo) are unrelated to the TokenChunker → OneChunker routing. These should be split into a separate PR with their own justification. Mixing fixes makes bisecting and reverting harder. If the factory catalog validation was blocking OpenAI-API-Compatible providers (as the comment suggests), that deserves its own change with appropriate context.

2. delimiter_mode value casing
The check mode == "one" is exact and case-sensitive. Is the web UI guaranteed to always emit lowercase "one"? If the DSL contract allows "One" or "ONE", this would miss it. Consider strings.EqualFold.

Otherwise LGTM — the test pins the translation well, and the fix is minimal and focused.

@wangq8

wangq8 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

@euvre resolve conflict.

…ntract shared by the web UI and the Python runtime expresses single-chunk mode as TokenChunker with delimiter_mode "one". In Go that behaviour lives in the OneChunker component, and TokenChunker's schema validation only accepts token_size/delimiter — so a knowledge base configured with the "One" method failed at canvas compile time (schema: field "delimiter_mode" has invalid value "one") and the ingestor kept retrying the task forever. Translate the contract at the chunker factory entry point: a TokenChunker component whose delimiter_mode is "one" now builds a OneChunker, keeping a single implementation path while preserving the DSL node id for progress tracking. Adds a regression test pinning the translation.
@euvre
euvre force-pushed the fix/token-chunker-one-delimiter-mode branch from 8c9192e to c154974 Compare August 13, 2026 15:33
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@wangq8 wangq8 added ci Continue Integration and removed ci Continue Integration labels Aug 14, 2026
@wangq8
wangq8 merged commit fe963e6 into infiniflow:main Aug 14, 2026
10 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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants