Skip to content

Conversation

@sergeibbb
Copy link
Member

@sergeibbb sergeibbb commented Jun 26, 2025

Implement robust AI-assisted rebase generation with validation and retry logic

This solves #4395.

This piece of work introduces a new, robust workflow for generating AI-assisted rebases that organize code changes into logical commits. The changes add the generateRebase method, which now includes automatic retry logic: if the AI's response is missing hunks, includes extra hunks, or uses duplicates, the system will provide feedback and retry up to three times. The main workflow is broken into helper methods:

  • sendRebaseRequestWithRetry orchestrates the retry loop and validation for AI responses.
  • sendRebaseFirstAttempt handles the initial AI request and stores the conversation prompt for use in retries.
  • validateRebaseResponse checks the AI's JSON output for correctness, ensuring all required hunks are present exactly once and no extras or duplicates exist. It also generates specific retry prompts to feed back to the AI if issues are found, using the dedent utility for clear formatting.

Detailed logging and error messages are added to make debugging easier. These changes ensure that AI-generated commit suggestions are always structurally correct, improving both reliability and reviewability of the tool's output.

Checklist

  • I have followed the guidelines in the Contributing document
  • My changes follow the coding style of this project
  • My changes build without any errors or warnings
  • My changes have been formatted and linted
  • My changes include any required corresponding changes to the documentation (including CHANGELOG.md and README.md)
  • My changes have been rebased and squashed to the minimal number (typically 1) of relevant commits
  • My changes have a descriptive commit message with a short title, including a Fixes $XXX - or Closes #XXX - prefix to auto-close the issue that your PR addresses

@sergeibbb sergeibbb linked an issue Jun 26, 2025 that may be closed by this pull request
1 task
@sergeibbb sergeibbb force-pushed the feature/4395-retry-on-invalid-hunks branch from 826cb3e to e9ee84c Compare June 26, 2025 14:37
@sergeibbb sergeibbb force-pushed the feature/4395-retry-on-invalid-hunks branch from e9ee84c to 473a77d Compare June 26, 2025 17:39
sergeibbb added a commit that referenced this pull request Jun 26, 2025
@sergeibbb sergeibbb force-pushed the feature/4395-retry-on-invalid-hunks branch from 473a77d to e9ee3fc Compare June 26, 2025 17:48
sergeibbb added a commit that referenced this pull request Jun 26, 2025
@sergeibbb sergeibbb requested a review from d13 June 26, 2025 17:54
sergeibbb added a commit that referenced this pull request Jun 26, 2025
@sergeibbb sergeibbb force-pushed the feature/4395-retry-on-invalid-hunks branch from 713d1b4 to 161a5be Compare June 26, 2025 17:55
Copy link
Member

@d13 d13 left a comment

Choose a reason for hiding this comment

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

LGTM, branch just needs updating

@sergeibbb sergeibbb force-pushed the feature/4395-retry-on-invalid-hunks branch from 161a5be to 0aeac8d Compare July 7, 2025 17:24
@sergeibbb sergeibbb merged commit 2c98179 into main Jul 7, 2025
3 checks passed
sergeibbb added a commit that referenced this pull request Jul 7, 2025
@sergeibbb sergeibbb deleted the feature/4395-retry-on-invalid-hunks branch July 7, 2025 17:28
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.

Improve experience for invalid generateRebase responses

2 participants