Skip to content

refactor(go): remove dead atom-split helpers from TokenChunker - #17920

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
xugangqiang:fix/go-chunker-remove-dead-atom-split
Aug 6, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
xugangqiang:fix/go-chunker-remove-dead-atom-split

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Why

The production merge path (mergeByTokenSize / mergeByTokenSizeFromJSON) keeps over-budget units whole and relies on the embedding/rerank layer to truncate them, per the TokenChunker contract (#17799: remove atom-split, no hard_cap). The deleted helpers implemented the opposite behaviour and had no production caller, so they contradicted the contract and misled readers into thinking atom-split was active.

Parser vs chunker layering

Python's _split_oversized_unit lives at the parser layer (pre-split before naive_merge), not in the chunker. Go's parser backends are currently skeletons, so there is no parser-side equivalent yet; if added later it belongs in internal/parser/parser/*, not the chunker.

Test plan

bash build.sh --test ./internal/ingestion/component/chunker/... passes; the new text-path test passes and the orphaned atom-split tests are gone.

Changes

  • 3 files changed, 32 insertions(+), 250 deletions(-)

Remove splitOversizedUnit, splitAtomByTokenBudget and atomRE from
internal/ingestion/component/chunker/token.go, and delete
split_oversized_guard_test.go (added by infiniflow#17740).

These implemented an atom-split that is never wired into the production
merge path (mergeByTokenSize / mergeByTokenSizeFromJSON keep over-budget
units whole). They contradict the TokenChunker contract (infiniflow#17799: remove
atom-split; over-budget units are kept whole and truncated later by the
embedding/rerank layer).

Also drop the now-unused wordCount/charCount helpers from
token_strict_cap_test.go, and add TestMergeByTokenSize_OversizedUnitStaysWhole
to pin the contract invariant on the text path (the JSON path is already
covered by TestMergeByTokenSizeFromJSON_OversizedUnitStaysWhole).
@xugangqiang xugangqiang added the ci Continue Integration label Aug 6, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 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: cc4e2758-3c86-4c9d-9459-ad7a234bded1

📥 Commits

Reviewing files that changed from the base of the PR and between 5475db3 and 071418c.

📒 Files selected for processing (2)
  • internal/ingestion/component/chunker/token.go
  • internal/ingestion/component/chunker/token_strict_cap_test.go
💤 Files with no reviewable changes (1)
  • internal/ingestion/component/chunker/token_strict_cap_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/ingestion/component/chunker/token.go

📝 Walkthrough

Walkthrough

The chunker removes oversized-unit atom splitting and related helper tests. A regression test confirms that an oversized delimiter-free unit remains one unchanged chunk.

Changes

Oversized unit handling

Layer / File(s) Summary
Preserve oversized units as whole chunks
internal/ingestion/component/chunker/token.go, internal/ingestion/component/chunker/token_strict_cap_test.go
The atom-splitting implementation and helper-based tests are removed. Text-path coverage confirms that an oversized delimiter-free unit remains one unchanged chunk.

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

Possibly related issues

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: jinhai-cn, yingfeng, yuzhichang

Poem

A rabbit keeps one chunk intact,

No atom splits from the contract.
Long text stays in its original place,
Tests confirm the unchanged trace.
Hop, hop—the whole unit holds!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the removal of unused atom-splitting helpers from TokenChunker.
Description check ✅ Passed The description includes the required Summary section and explains the changes, rationale, layering, and test plan.
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.

🧹 Nitpick comments (1)
internal/ingestion/component/chunker/token_strict_cap_test.go (1)

142-149: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove migration history from the test comment.

The comment includes #17799, split_oversized_guard_test.go, and the reason for deleting the old test. Keep it focused on the current invariant: an oversized delimiter-free text unit remains one unchanged chunk.

Proposed comment
-// TestMergeByTokenSize_OversizedUnitStaysWhole mirrors
-// TestMergeByTokenSizeFromJSON_OversizedUnitStaysWhole on the text path: a
-// single block of text that exceeds chunk_token_size and contains no
-// sentence delimiter must be emitted as ONE whole chunk — never atom-split.
-// This pins the `#17799` contract invariant on the text path (the JSON path
-// is already covered by TestMergeByTokenSizeFromJSON_OversizedUnitStaysWhole).
-// It replaces the orphaned split_oversized_guard_test.go, which guarded the
-// now-removed atom-split instead of the contract behaviour.
+// TestMergeByTokenSize_OversizedUnitStaysWhole verifies that an oversized
+// delimiter-free text unit remains one unchanged chunk.

As per coding guidelines, keep package comments and doc comments aligned with the current runtime path rather than migration history.

🤖 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/ingestion/component/chunker/token_strict_cap_test.go` around lines
142 - 149, Update the comment above TestMergeByTokenSize_OversizedUnitStaysWhole
to remove issue numbers, references to split_oversized_guard_test.go, JSON-path
comparison, and migration rationale. Keep only the current invariant that an
oversized delimiter-free text unit is emitted as one unchanged chunk without
atom-splitting.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@internal/ingestion/component/chunker/token_strict_cap_test.go`:
- Around line 142-149: Update the comment above
TestMergeByTokenSize_OversizedUnitStaysWhole to remove issue numbers, references
to split_oversized_guard_test.go, JSON-path comparison, and migration rationale.
Keep only the current invariant that an oversized delimiter-free text unit is
emitted as one unchanged chunk without atom-splitting.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 97c1f601-6c4a-4504-9329-8a7a88f10677

📥 Commits

Reviewing files that changed from the base of the PR and between 8bc3421 and 5475db3.

📒 Files selected for processing (3)
  • internal/ingestion/component/chunker/split_oversized_guard_test.go
  • internal/ingestion/component/chunker/token.go
  • internal/ingestion/component/chunker/token_strict_cap_test.go
💤 Files with no reviewable changes (2)
  • internal/ingestion/component/chunker/split_oversized_guard_test.go
  • internal/ingestion/component/chunker/token.go

Add a SCOPE bullet to token.go pinning the infiniflow#17799 over-budget-unit
contract: keep whole, no atom-split; if oversized-unit handling is ever
needed it belongs at the chunker side (or a dedicated PreSplitter stage)
with an explicit token budget + tokenizer, NOT in the parser and NOT as a
char-window atom-split. This guards against reintroducing the misplaced
splitOversizedUnit helpers that were just removed.

Trim the migration narrative from TestMergeByTokenSize_OversizedUnitStaysWhole
that pointed at the now-removed split_oversized_guard_test.go (per AGENTS.md:
drop stale comments describing a superseded design).
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 109b74e into infiniflow:main Aug 6, 2026
3 checks passed
@xugangqiang
xugangqiang deleted the fix/go-chunker-remove-dead-atom-split branch August 12, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants