Skip to content

fix(api): don't split a character when truncating git event text - #851

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
dhananjay6561:fix/git-truncate-utf8
Dec 2, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
dhananjay6561:fix/git-truncate-utf8

Conversation

@dhananjay6561

Copy link
Copy Markdown
Contributor

Summary

truncate in the git service cut by bytes, so a comment or review longer than its cap (500 / 2000 / 4000 bytes for automation payloads, 400 for the inbox reason) could end in half a multi-byte character, which shows up as a � in the automation event. It now drops the partial rune with strings.ToValidUTF8, the same way automation_consumer.go already caps event vars.

Added a small table test with accented, CJK and emoji text.

Fixes #850

Type of Change

  • Other (bug fix)

Checklist

  • The change is focused and scoped.
  • Related documentation is updated (no docs affected).
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 05:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@dhananjay6561

Copy link
Copy Markdown
Contributor Author

@pikann small one: git event text cut at a byte limit could end in half a character, this keeps it on a whole rune. Happy to adjust if you'd prefer it elsewhere

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

ℹ️ No blocking issues — one non-blocking follow-up below.

Approach: sound — keep the existing byte caps and drop the partial rune after slicing, reusing the exact idiom already used in automation_consumer.go, so every automation payload site gets the fix without changing cap semantics.

Reviewed changes — reviewed both commits of the truncation fix, plus the call sites the helper feeds:

  • Byte-safe truncation — truncate now pipes the capped prefix through strings.ToValidUTF8(..., ""), so the 500/2000/4000-byte automation caps and the 400-byte inbox reason end on a rune boundary.
  • Table test — covers the no-truncation path plus splits inside accented, CJK and emoji text; go test ./internal/service/git/ -run TestTruncate passes.

Non-blocking

  • buildPrompt still cuts the same event text mid-rune. prompt.go:157 does text[:maxEventText] (6000 bytes) directly on ev.Text, so the broken-character symptom this PR fixes for automation payloads can still appear in the agent prompt; swapping it for the now-safe truncate(text, maxEventText) would close it.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann 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! Thank you for the contribution! 🚀

@pikann
pikann merged commit 1c05582 into Paca-AI:master Dec 2, 2026
6 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.

[Bug] Truncated Git event text can end in half a character

3 participants