Repository navigation
fix(scan): cut summary comments on a rune boundary - #1852
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
3a04f15 to
a7b1f72
Compare
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed both changed files and the existing discussion. The function-name search also found closed, unmerged #916. I checked its scan formatter patch: it addressed the same UTF-8 symptom by changing the budget to 280 runes as part of a broader summary feature. This PR is a useful standalone fix that preserves the existing 280-byte prefix budget. #1854 modifies a different viewer helper. No coordination with a later or inactive implementation is needed for this fix.
The len(oneLine) > maxLine guard makes oneLine[cut] in bounds. Backing up over continuation bytes preserves a whole-rune prefix for valid UTF-8 input, leaves ASCII cuts unchanged, and adds the existing three-byte ellipsis only afterward. The original one-line flattening and surrounding list formatting are untouched. I found no blocking defect.
I independently exercised the exact cut algorithm in an isolated Go harness over ASCII, two-, three-, four-byte and mixed strings of varying lengths. All 2,000 summary cases stayed valid UTF-8 and within 283 bytes; the 200-CJK-rune case produced exactly 93 runes plus '...' (282 bytes), while the old slice was invalid. These are isolated algorithm checks, not an execution of the repository's full scan tests.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
Description
buildSummaryCommentsList(internal/scan/agent.go) flattens each comment to one line and cuts it at 280 bytes withoneLine[:maxLine]. That is a byte slice, so when the comment is in Chinese, Japanese or Korean (common for this tool), the cut usually lands inside a multi-byte character and the summary list sent to the model ends with a broken byte such as\xe7....The fix backs the cut up to the nearest rune start with
utf8.RuneStartbefore appending..., so the list stays valid UTF-8 and never goes over 280 bytes plus the ellipsis. ASCII comments are cut at exactly the same place as before.Type of Change
How Has This Been Tested?
TestBuildSummaryCommentsList_TruncatesOnRuneBoundarybuilds a comment of 200 x U+7A7A (\u7a7a, 3 bytes each in UTF-8, so byte 280 is one byte into the 94th rune). Onmainit fails withsummary list is not valid UTF-8: "...空\xe7...\n"; with the fix it gets exactly 93 runes plus....go run scripts/verify-english-only.go,go test ./internal/scan/,go vet ./internal/scan/andgofmt -lare clean.go test ./internal/scan/passes locallyChecklist
go fmt,go vet)AI-assistance note: I prepared this change with help from Grok Bot, an AI coding assistant, then reviewed the code and ran the tests myself.
Related Issues
None found; no open PR touches
buildSummaryCommentsList's truncation.