Skip to content

fix(scan): cut summary comments on a rune boundary - #1852

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
kevin9327:fix/summary-list-rune-boundary
Nov 16, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
kevin9327:fix/summary-list-rune-boundary

Conversation

@kevin9327

@kevin9327 kevin9327 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

buildSummaryCommentsList (internal/scan/agent.go) flattens each comment to one line and cuts it at 280 bytes with oneLine[: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.RuneStart before 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

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

TestBuildSummaryCommentsList_TruncatesOnRuneBoundary builds a comment of 200 x U+7A7A (\u7a7a, 3 bytes each in UTF-8, so byte 280 is one byte into the 94th rune). On main it fails with summary 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/ and gofmt -l are clean.

  • go test ./internal/scan/ passes locally

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have signed the CLA
  • I disclosed the AI tool below and reviewed its output; commits are not attributed to AI.

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@kevin9327
kevin9327 force-pushed the fix/summary-list-rune-boundary branch from 3a04f15 to a7b1f72 Compare October 31, 2026 15:07

@chaojixinren chaojixinren 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.

LGTM

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lizhengfeng101 lizhengfeng101 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.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 13e5e95 into alibaba:main Nov 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants