From ab808fd1146f88204d2b099a52c835fb271dcb29 Mon Sep 17 00:00:00 2001 From: diana-jung <104146180+diana-jung@users.noreply.github.com> Date: Wed, 26 Nov 2025 14:38:29 +0900 Subject: [PATCH 1/4] fix: Apply suggestions_score_threshold filter to inline code suggestions in dual publishing mode - Added score filtering to push_inline_code_suggestions - Ensured inline suggestions are properly filtered when dual publishing is enabled - High-importance suggestions appear in both table and inline; others only inline --- pr_agent/tools/pr_code_suggestions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 30292074..fcb1d0c5 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -539,7 +539,10 @@ class PRCodeSuggestions: async def push_inline_code_suggestions(self, data): code_suggestions = [] - if not data['code_suggestions']: + score_threshold = max(1, int(get_settings().pr_code_suggestions.suggestions_score_threshold)) + filtered_suggestions = [d for d in data['code_suggestions'] if int(d.get('score', 0)) >= score_threshold] + + if not filtered_suggestions: get_logger().info('No suggestions found to improve this PR.') if self.progress_response: return self.git_provider.edit_comment(self.progress_response, @@ -547,7 +550,7 @@ class PRCodeSuggestions: else: return self.git_provider.publish_comment('No suggestions found to improve this PR.') - for d in data['code_suggestions']: + for d in filtered_suggestions: try: if get_settings().config.verbosity_level >= 2: get_logger().info(f"suggestion: {d}") @@ -941,4 +944,4 @@ class PRCodeSuggestions: except Exception as e: get_logger().info(f"Could not reflect on suggestions, error: {e}") return "" - return response_reflect \ No newline at end of file + return response_reflect From 1315fa651ba7c013bb699dd4fada2c1cd4a0a3f7 Mon Sep 17 00:00:00 2001 From: diana-jung <104146180+diana-jung@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:56:32 +0900 Subject: [PATCH 2/4] Fix: decouple inline and table suggestion filtering logic - **Refactor `run` method in `PRCodeSuggestions`**: - Pre-filter suggestions based on `suggestions_score_threshold` early in the process to prevent publishing low-score suggestions in any mode. - Separate inline and table publishing logic for better clarity and control. - Ensure dual publishing mode correctly displays all valid suggestions inline while filtering the summary table based on `dual_publishing_score_threshold`. - Fix potential issue where the progress bar or "no suggestions" message could be mishandled when no high-score suggestions exist for the table. - **Update `push_inline_code_suggestions`**: - Re-verify score threshold within the function to ensure robust filtering (though pre-filtering in `run` handles this primarily now). --- pr_agent/tools/pr_code_suggestions.py | 103 ++++++++++++++++---------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index fcb1d0c5..17c7cc12 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -123,59 +123,82 @@ class PRCodeSuggestions: await self.publish_no_suggestions() return + # Filter data by suggestions_score_threshold + score_threshold = max(1, int(get_settings().pr_code_suggestions.suggestions_score_threshold)) + data['code_suggestions'] = [ + d for d in data['code_suggestions'] + if int(d.get('score', 0)) >= score_threshold + ] + + if not data['code_suggestions']: + await self.publish_no_suggestions() + return + # publish the suggestions if get_settings().config.publish_output: # If a temporary comment was published, remove it self.git_provider.remove_initial_comment() - # Publish table summarized suggestions - if ((not get_settings().pr_code_suggestions.commitable_code_suggestions) and - self.git_provider.is_supported("gfm_markdown")): + # Logic for Inline Suggestions + dual_threshold = int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) + if get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0: + await self.push_inline_code_suggestions(data) - # generate summarized suggestions - pr_body = self.generate_summarized_suggestions(data) - get_logger().debug(f"PR output", artifact=pr_body) + # Logic for Table Suggestions + if self.git_provider.is_supported("gfm_markdown") and \ + (not get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0): - # require self-review - if get_settings().pr_code_suggestions.demand_code_suggestions_self_review: - pr_body = await self.add_self_review_text(pr_body) + data_for_table = data + # dual publishing mode + if dual_threshold > 0: + data_for_table = {'code_suggestions': []} + for suggestion in data['code_suggestions']: + if int(suggestion.get('score', 0)) >= dual_threshold: + data_for_table['code_suggestions'].append(suggestion) - # add usage guide - if (get_settings().pr_code_suggestions.enable_chat_text and get_settings().config.is_auto_command - and isinstance(self.git_provider, GithubProvider)): - pr_body += "\n\n>💡 Need additional feedback ? start a [PR chat](https://chromewebstore.google.com/detail/ephlnjeghhogofkifjloamocljapahnl) \n\n" - if get_settings().pr_code_suggestions.enable_help_text: - pr_body += "
\n\n
💡 Tool usage guide:
\n\n" - pr_body += HelpMessage.get_improve_usage_guide() - pr_body += "\n
\n" + if data_for_table['code_suggestions']: + # generate summarized suggestions + pr_body = self.generate_summarized_suggestions(data_for_table) + get_logger().debug(f"PR output", artifact=pr_body) - # Output the relevant configurations if enabled - if get_settings().get('config', {}).get('output_relevant_configurations', False): - pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions') + # require self-review + if get_settings().pr_code_suggestions.demand_code_suggestions_self_review: + pr_body = await self.add_self_review_text(pr_body) - # publish the PR comment - if get_settings().pr_code_suggestions.persistent_comment: # true by default - self.publish_persistent_comment_with_history(self.git_provider, - pr_body, - initial_header="## PR Code Suggestions ✨", - update_header=True, - name="suggestions", - final_update_message=False, - max_previous_comments=get_settings().pr_code_suggestions.max_history_len, - progress_response=self.progress_response) + # add usage guide + if (get_settings().pr_code_suggestions.enable_chat_text and get_settings().config.is_auto_command + and isinstance(self.git_provider, GithubProvider)): + pr_body += "\n\n>💡 Need additional feedback ? start a [PR chat](https://chromewebstore.google.com/detail/ephlnjeghhogofkifjloamocljapahnl) \n\n" + if get_settings().pr_code_suggestions.enable_help_text: + pr_body += "
\n\n
💡 Tool usage guide:
\n\n" + pr_body += HelpMessage.get_improve_usage_guide() + pr_body += "\n
\n" + + # Output the relevant configurations if enabled + if get_settings().get('config', {}).get('output_relevant_configurations', False): + pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions') + + # publish the PR comment + if get_settings().pr_code_suggestions.persistent_comment: # true by default + self.publish_persistent_comment_with_history(self.git_provider, + pr_body, + initial_header="## PR Code Suggestions ✨", + update_header=True, + name="suggestions", + final_update_message=False, + max_previous_comments=get_settings().pr_code_suggestions.max_history_len, + progress_response=self.progress_response) + else: + if self.progress_response: + self.git_provider.edit_comment(self.progress_response, body=pr_body) + else: + self.git_provider.publish_comment(pr_body) else: if self.progress_response: - self.git_provider.edit_comment(self.progress_response, body=pr_body) - else: - self.git_provider.publish_comment(pr_body) - - # dual publishing mode - if int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) > 0: - await self.dual_publishing(data) + self.git_provider.remove_comment(self.progress_response) else: - await self.push_inline_code_suggestions(data) - if self.progress_response: - self.git_provider.remove_comment(self.progress_response) + if self.progress_response and not (get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0): + self.git_provider.remove_comment(self.progress_response) else: get_logger().info('Code suggestions generated for PR, but not published since publish_output is False.') pr_body = self.generate_summarized_suggestions(data) From d80e229bdf91dfc66801d1feaa19bcb57dc78c38 Mon Sep 17 00:00:00 2001 From: diana-jung <104146180+diana-jung@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:04:09 +0900 Subject: [PATCH 3/4] implementation: Remove the duplicate filtering logic Co-authored-by: qodo-merge-for-open-source[bot] <189517486+qodo-merge-for-open-source[bot]@users.noreply.github.com> --- pr_agent/tools/pr_code_suggestions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 17c7cc12..cf6c18c9 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -562,8 +562,7 @@ class PRCodeSuggestions: async def push_inline_code_suggestions(self, data): code_suggestions = [] - score_threshold = max(1, int(get_settings().pr_code_suggestions.suggestions_score_threshold)) - filtered_suggestions = [d for d in data['code_suggestions'] if int(d.get('score', 0)) >= score_threshold] + if not data['code_suggestions']: if not filtered_suggestions: get_logger().info('No suggestions found to improve this PR.') From 7b9e8bff3b0825c4f893cfc0d671b2a045f73c69 Mon Sep 17 00:00:00 2001 From: diana-jung <104146180+diana-jung@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:07:25 +0900 Subject: [PATCH 4/4] chore: Recover the original inline code logic --- pr_agent/tools/pr_code_suggestions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index cf6c18c9..e0ccc033 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -563,8 +563,6 @@ class PRCodeSuggestions: code_suggestions = [] if not data['code_suggestions']: - - if not filtered_suggestions: get_logger().info('No suggestions found to improve this PR.') if self.progress_response: return self.git_provider.edit_comment(self.progress_response, @@ -572,7 +570,7 @@ class PRCodeSuggestions: else: return self.git_provider.publish_comment('No suggestions found to improve this PR.') - for d in filtered_suggestions: + for d in data['code_suggestions']: try: if get_settings().config.verbosity_level >= 2: get_logger().info(f"suggestion: {d}")