Conversation
WalkthroughThe changes introduce improved error handling and validation in the AI-based pull request title generation process and OpenAI chat completion client. Retry logic is added for empty AI-generated titles, and the OpenAI client now checks for empty or unsupported responses, returning errors accordingly. Changes
Assessment against linked issues
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the robustness and validation around OpenAI-based title generation by adding retry and trimming logic, explicit error handling, and disabling reasoning.
- Add retry logic (up to 3 attempts) with a brief pause when the generated title is empty
- Trim whitespace from the AI-generated title and normalize casing
- Handle cases where the API returns no choices or unwanted reasoning content, and disable the thinking flag in chat templates
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| provider/openai/openai.go | Validate that r.Choices is non-empty, reject reasoning outputs, and set enable_thinking |
| cmd/commit.go | Implement retry loop for empty titles, trim and normalize the title, and surface errors |
Comments suppressed due to low confidence (3)
cmd/commit.go:190
- Indexing a UTF-8 string by byte can break on multibyte characters; use rune slicing or the
unicodepackage to lowercase the first character safely.
summarizeTitle = strings.TrimRight(strings.ToLower(string(summarizeTitle[0]))+summarizeTitle[1:], ".")
provider/openai/openai.go:186
- New logic that handles zero-choice responses should be covered by unit tests to verify correct error handling when the API returns no choices.
if len(r.Choices) == 0 {
provider/openai/openai.go:187
- [nitpick] This error could include more context (e.g., model name, request ID) to aid in debugging when no choices are returned.
return nil, fmt.Errorf("no choices returned from API")
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
cmd/commit.go(2 hunks)provider/openai/openai.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: windows-latest @ Go stable
- GitHub Check: Analyze (go)
- GitHub Check: windows-latest @ Go stable
🔇 Additional comments (3)
cmd/commit.go (1)
4-4: LGTM - Import addition is appropriate.The
fmtimport is correctly added to support the new error formatting in the retry logic.provider/openai/openai.go (2)
162-164: LGTM - Correct implementation of thinking mode disable.The
ChatTemplateKwargsconfiguration properly disables thinking mode as required by the PR objectives, ensuring the OpenAI API doesn't return reasoning content.
186-192: Excellent defensive programming - proper API response validation.The validation improvements are well-implemented:
- Empty choices check: Prevents potential index out of bounds errors
- Reasoning content rejection: Aligns with PR objectives to disallow reasoning models
- Clear error messages: Help with debugging and user understanding
This validation complements the retry logic in
cmd/commit.goby ensuring that invalid responses are caught early and handled appropriately.
- Add retry logic for generating the pull request title, retrying up to 3 times if the response is empty - Return an explicit error if the OpenAI API returns no choices, or if reasoning content is present (unsupported) - Improve error reporting for failed title generation attempts fix #242 Signed-off-by: appleboy <[email protected]>
fix #242
Summary by CodeRabbit