Repository navigation
fix(chunk): keep postprocessed sizes in runes - #20747
kassdinzheng123 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is identified for this change. Pre-merge checks |
|
kokhlo
left a comment
There was a problem hiding this comment.
Verified locally on b3e0e5c4 vs pristine main 5ccba271 (A/B with the same probe on both heads).
A/B probe (go test ./internal/parser/chunk/ -run TestProbeSizeAB -v, scenario → size on main → size on this PR):
| scenario | content | main | PR |
|---|---|---|---|
merge CJK (MergeTargetSize: 8) |
甲乙 丙丁 |
13 | 5 |
| filter-only CJK | 中文 |
6 | 2 |
| astral-plane (CJK ext B) | 𠈌𠈌𠈌 |
12 | 3 |
| length split (window=2) | 甲乙/丙丁/戊己 |
2/2/2 | 2/2/2 (unchanged, splitByLength already counts runes) |
So the mismatch is exactly the one described in the body: merge/filter paths rewrote rune-based sizes into byte counts, 3x for CJK.
Mutation check: reverting just the RuneCountInString line (back to len(GetContent())) fails precisely the three new tests — TestPostprocessSizeCountsRunes, TestPostprocessPreservesLengthSplitRuneSizes, TestRunSizeCountsRunes — and nothing else in the package (go test ./internal/parser/chunk/ -count=1: ok before/after).
Consistency check: I grepped for other Size = len(...) writes near chunk paths — mergeChunks/filterChunks already count runes (len([]rune(...)) / bufRunes), splitByLength writes end-start over a rune slice, so this line was the only byte-based Size write left in the package. Downstream consumers of ChunkData.Size are the CLI chunk explain path (internal/cli/user_command.go:3258) and JSON serialization — both treat it as a display/metadata number, no byte-arithmetic on it anywhere, so the switch cannot break a consumer.
One non-blocking note: the JSON field is documented nowhere as bytes or runes; if some external consumer (API response for chunk listings?) assumed bytes, this is a behavior change — but I found no such consumer in-tree, and the length splitter (the only other Size producer) has always been rune-based, so runes is the consistent contract.
|
LGTM |
|
Hold on. Lets unify the size of bytes/runes/tokens later. |
yuzhichang
left a comment
There was a problem hiding this comment.
No blocking findings in the rune-count change itself; the size is now consistent with the splitter and merge/filter limits. Keeping this as a comment because the PR is still a draft and the earlier direction on unifying byte/rune/token sizing is still open.
|
Closing this draft PR since chunk-size unit unification is still on hold and #22317 already tracks the same rune-count fix as a non-draft PR. |
Summary
Follow-up to #20690, addressing zpf121's separate follow-up about
ChunkData.Size.Count final chunk sizes in Unicode code points (runes), rather than bytes, when
PostprocessOperator.ExecuteassignsChunkData.Size. This keeps the reported size aligned with the length splitter and the rune-based merge/filter limits. ASCII sizes are unchanged.Root cause
splitByLengthsetsSizeto the number of runes in each window. Postprocessing subsequently overwrites it withlen(GetContent()), a byte count, even when a filter leaves the content untouched. A CJK length split with sizes2/2/1therefore becomes6/6/3after postprocessing.The same mismatch is visible through the typed
chunk.Runentry point used by the CLI: merging甲乙and丙丁produces甲乙 丙丁, which is 5 runes but was reported as size 13.The fix uses
utf8.RuneCountInStringat the existing assignment, without changing how chunks are split, merged, or filtered.Preserved behavior and scope
Tests
Three new top-level regressions fail on the unmodified target main; the existing 32 top-level tests pass there:
Runentry point: CJK merge, filtering, oversized standalone chunks, and an ASCII control.With the fix, on ZGC using Go 1.27.0:
CGO_ENABLED=0 go test ./internal/parser/chunk/ -count=1: all 35 top-level tests pass.CGO_ENABLED=1 go test ./internal/parser/chunk/ -race -count=20: passes.CGO_ENABLED=0 go vet ./internal/parser/chunk/: passes.gofmtandgit diff --check: pass.The official
bash build.sh --test ./internal/parser/chunk/entry point remains blocked in the isolated test environment by the missingoffice_oxidenative library. The touched package imports only the standard library and has no CGO source files, so the package-scoped checks above were run directly. Full-repository/native integration tests were not run.Risk
Low and limited to the reported size of postprocessed non-ASCII chunks. The serialized field name and all chunking decisions remain unchanged.