Skip to content

fix commit message invalid utf8#4009

Open
hungz wants to merge 3 commits into
semaphoreui:developfrom
hungz:fix/commit-message-invalid-utf8
Open

fix commit message invalid utf8#4009
hungz wants to merge 3 commits into
semaphoreui:developfrom
hungz:fix/commit-message-invalid-utf8

Conversation

@hungz

@hungz hungz commented Jul 6, 2026

Copy link
Copy Markdown

fix issue #3993

Summary by CodeRabbit

  • New Features

    • Commit messages are now processed into a UTF-8-safe form for storage and display, preserving readable text with unusual characters.
  • Bug Fixes

    • Truncation is now Unicode/rune-aware (max 100 runes), avoiding cuts in the middle of multi-byte characters.
    • Invalid UTF-8 byte sequences are sanitized into valid UTF-8 for reliable display/storage.
    • Embedded NUL characters are removed from stored commit messages.

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.

Pull request overview

This PR addresses #3993 by centralizing commit message sanitization at the point where the message is persisted, preventing PostgreSQL UTF-8 transaction failures caused by invalid byte sequences and ensuring the stored commit message stays within the DB column limit.

Changes:

  • Sanitize persisted commit messages by stripping NUL bytes, replacing invalid UTF-8 sequences, and capping length by runes.
  • Remove Git-client-side truncation logic and its tests, shifting responsibility to the persistence layer.
  • Add targeted unit tests for UTF-8 sanitization and rune-based capping.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
services/tasks/TaskRunner_logging.go Sanitizes commit messages before persisting task updates.
pkg/conv/conv.go Introduces UTF-8 sanitization + rune-capping helper for commit messages.
pkg/conv/conv_test.go Adds tests covering valid input, rune caps, invalid bytes, and NUL stripping.
db_lib/GoGitClient.go Stops truncating commit messages at fetch time (now returns full message).
db_lib/CmdGitClient.go Removes commit message truncation at fetch time.
db_lib/commit_message.go Deletes legacy rune-truncation helper (superseded by conv sanitization).
db_lib/commit_message_test.go Removes tests for deleted legacy truncation helper.

Comment thread pkg/conv/conv.go Outdated
Comment thread pkg/conv/conv.go Outdated
Comment thread db_lib/GoGitClient.go
Comment thread pkg/conv/conv.go Outdated
@hungz
hungz force-pushed the fix/commit-message-invalid-utf8 branch 2 times, most recently from 3b0a367 to 0b52f11 Compare July 7, 2026 09:58
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bc09781e-760a-497c-911a-6a8e4bc30a19

📥 Commits

Reviewing files that changed from the base of the PR and between 6e96ad3 and 0b00923.

📒 Files selected for processing (8)
  • db_lib/CmdGitClient.go
  • db_lib/GoGitClient.go
  • db_lib/commit_message.go
  • db_lib/commit_message_test.go
  • pkg/conv/conv.go
  • pkg/conv/conv_test.go
  • services/tasks/TaskRunner_logging.go
  • services/tasks/local_executor.go
💤 Files with no reviewable changes (3)
  • db_lib/commit_message.go
  • db_lib/CmdGitClient.go
  • db_lib/commit_message_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkg/conv/conv_test.go
  • pkg/conv/conv.go
  • services/tasks/TaskRunner_logging.go
  • services/tasks/local_executor.go
  • db_lib/GoGitClient.go

📝 Walkthrough

Walkthrough

This PR adds UTF-8-safe commit message truncation, uses it for task commit-message storage and logging, and returns the raw git commit message in one retrieval path.

Changes

Commit message sanitization

Layer / File(s) Summary
New TruncateValidUTF8 helper and tests
pkg/conv/conv.go, pkg/conv/conv_test.go
Adds TruncateValidUTF8 that caps strings to 100 runes, strips NUL bytes, and replaces invalid UTF-8 sequences, with tests covering valid, over-limit, invalid-byte, and NUL-containing inputs.
Wiring into GoGitClient and TaskRunner
db_lib/GoGitClient.go, services/tasks/TaskRunner_logging.go, services/tasks/local_executor.go
GetLastCommitMessage logs a sanitized version while keeping the raw message, and both commit-message persistence paths now store conv.TruncateValidUTF8(message).
CmdGitClient returns raw message
db_lib/CmdGitClient.go
GetLastCommitMessage no longer truncates the git output before returning it.

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

Sequence Diagram(s)

sequenceDiagram
  participant GoGitClient
  participant conv
  participant TaskRunner
  participant LocalExecutor
  participant Task

  GoGitClient->>conv: TruncateValidUTF8(msg)
  conv-->>GoGitClient: sanitized log message
  TaskRunner->>conv: TruncateValidUTF8(message)
  conv-->>TaskRunner: sanitized message
  TaskRunner->>Task: store CommitMessage
  LocalExecutor->>conv: TruncateValidUTF8(message)
  conv-->>LocalExecutor: sanitized message
  LocalExecutor->>Task: store CommitMessage
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing invalid UTF-8 handling in commit messages.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Comment @coderabbitai help to get the list of available commands.

@hungz
hungz force-pushed the fix/commit-message-invalid-utf8 branch from 0b52f11 to 7e8537f Compare July 8, 2026 02:31

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/conv/conv.go (1)

10-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider parameterizing the rune limit.

commitMessageMaxRunes and the doc comment tie this general-purpose pkg/conv utility to the commit-message domain specifically. If other callers ever need a different length cap, this hardcoded 100 will need to be duplicated or the function forked. Consider exposing the limit as a parameter (e.g., TruncateValidUTF8(s string, maxRunes int)) with a commit-message-specific wrapper/constant kept in the calling package.

🤖 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 `@pkg/conv/conv.go` around lines 10 - 23, The UTF-8 truncation helper is
hardcoded to the commit-message rune limit, which makes the generic utility
inflexible. Update TruncateValidUTF8 to accept a max-rune parameter and use that
throughout the truncation logic, then move the commit-message-specific constant
and any wrapper into the calling package so pkg/conv remains reusable. Keep the
existing behavior for sanitizing invalid UTF-8 and NUL bytes, but remove the
commit-message-specific coupling from the function name/comment and internal
limit.
🤖 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.

Inline comments:
In `@db_lib/GoGitClient.go`:
- Around line 234-239: The commit message returned by GetLastCommitMessage is
being passed through unsanitized into the local executor flow, so update
GoGitClient.GetLastCommitMessage to sanitize the message before returning it,
using the same truncation/UTF-8-safe handling as TaskRunner.SetCommit or a
shared helper. Ensure the value that reaches local_executor.go and then
Task.CommitMessage/taskDetails is already valid UTF-8, and keep the logging
consistent with the sanitized message.

---

Nitpick comments:
In `@pkg/conv/conv.go`:
- Around line 10-23: The UTF-8 truncation helper is hardcoded to the
commit-message rune limit, which makes the generic utility inflexible. Update
TruncateValidUTF8 to accept a max-rune parameter and use that throughout the
truncation logic, then move the commit-message-specific constant and any wrapper
into the calling package so pkg/conv remains reusable. Keep the existing
behavior for sanitizing invalid UTF-8 and NUL bytes, but remove the
commit-message-specific coupling from the function name/comment and internal
limit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f9352231-a5b1-46b7-8ecf-f76a320fad6e

📥 Commits

Reviewing files that changed from the base of the PR and between 5902d9c and 7e8537f.

📒 Files selected for processing (7)
  • db_lib/CmdGitClient.go
  • db_lib/GoGitClient.go
  • db_lib/commit_message.go
  • db_lib/commit_message_test.go
  • pkg/conv/conv.go
  • pkg/conv/conv_test.go
  • services/tasks/TaskRunner_logging.go
💤 Files with no reviewable changes (3)
  • db_lib/CmdGitClient.go
  • db_lib/commit_message_test.go
  • db_lib/commit_message.go

Comment thread db_lib/GoGitClient.go
@hungz
hungz force-pushed the fix/commit-message-invalid-utf8 branch from 7e8537f to 98ece29 Compare July 8, 2026 02:36
@fiftin
fiftin requested a review from Copilot July 9, 2026 09:43
@fiftin

fiftin commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@fiftin

fiftin commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

@cursoragent review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Note

Unit test generation is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 2f9e17ece2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread services/tasks/TaskRunner_logging.go Outdated
Comment thread pkg/conv/conv.go Outdated
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request

@hungz
hungz force-pushed the fix/commit-message-invalid-utf8 branch from 6e96ad3 to 0b00923 Compare July 13, 2026 09:12
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.

3 participants