From b12c1baac3d439618aaecd45aa8f770d55220595 Mon Sep 17 00:00:00 2001 From: Meni Yakove Date: Thu, 30 Apr 2026 07:57:17 +0000 Subject: [PATCH] fix: include base branch in AI title suggestion prompt The AI prompt for conventional title suggestions told the AI to "look at the recent commits and changes" without specifying the base branch. When the worktree state didn't clearly show PR changes, the AI had no context and returned invalid suggestions. Now the prompt includes explicit git commands with the base branch: - `git diff origin/{base_ref}` - `git log origin/{base_ref}..HEAD --oneline` This ensures the AI always knows how to find the diff, regardless of the worktree checkout state. Closes #1019 --- .../libs/handlers/runner_handler.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/webhook_server/libs/handlers/runner_handler.py b/webhook_server/libs/handlers/runner_handler.py index 4eda7def8..5370b04db 100644 --- a/webhook_server/libs/handlers/runner_handler.py +++ b/webhook_server/libs/handlers/runner_handler.py @@ -690,17 +690,6 @@ async def _get_ai_title_suggestion( else: types_info = f"Allowed types: {', '.join(allowed_names)}" - prompt = ( - "You are in a git repository checked out to a PR branch.\n" - "Look at the recent commits and changes to understand what this PR does.\n" - f"Current PR title: {title}\n" - f"{types_info}\n" - f"Required format: [optional scope]: \n" - f"Output ONLY the corrected title on a single line.\n" - f"Do NOT include any explanation, reasoning, markdown, or quotes.\n" - f"Example output: feat: add user authentication" - ) - cli_flags: list[str] = [] if ai_provider == "claude": cli_flags = ["--dangerously-skip-permissions"] @@ -710,11 +699,28 @@ async def _get_ai_title_suggestion( cli_flags = ["--force"] try: + base_ref = await github_api_call( + lambda: pull_request.base.ref, logger=self.logger, log_prefix=self.log_prefix + ) + async with self._checkout_worktree(pull_request=pull_request) as (wt_success, worktree_path, _, _): if not wt_success: self.logger.warning(f"{self.log_prefix} Failed to create worktree for AI title suggestion") return None + prompt = ( + "You are in a git repository checked out to a PR branch.\n" + f"Run `git diff origin/{base_ref}` to see the changes in this PR.\n" + f"Run `git log origin/{base_ref}..HEAD --oneline` to see the commit messages.\n" + f"Based on the diff and commit messages, suggest a conventional commit title.\n\n" + f"Current PR title: {title}\n" + f"{types_info}\n" + f"Required format: [optional scope]: \n" + f"Output ONLY the corrected title on a single line.\n" + f"Do NOT include any explanation, reasoning, markdown, or quotes.\n" + f"Example output: feat: add user authentication" + ) + success, result = await call_ai_cli( prompt=prompt, ai_provider=ai_provider,