From ad659d14cdb6a0a16a5098c904fe98fb23959e0a Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 29 Jul 2026 15:17:57 +0200 Subject: [PATCH 1/2] Make 'Hackbot Launchpad' header text point to the Hackbot Launchpad homepage (#6420) --- bugbug/tools/code_review/agent.py | 8 ++++++- bugbug/tools/code_review/prompts.py | 6 ++++- tests/test_code_review.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/bugbug/tools/code_review/agent.py b/bugbug/tools/code_review/agent.py index 01c448ee29..7efbf45aa5 100644 --- a/bugbug/tools/code_review/agent.py +++ b/bugbug/tools/code_review/agent.py @@ -7,7 +7,7 @@ import json import os -from datetime import datetime +from datetime import UTC, datetime from logging import getLogger from typing import Optional @@ -61,6 +61,10 @@ logger = getLogger(__name__) +def current_date_for_prompt() -> str: + return datetime.now(UTC).date().isoformat() + + class CodeReviewTool(GenerativeModelTool): version = 2 @@ -209,6 +213,7 @@ def generate_initial_prompt( created_before = patch.date_created if self.is_experiment_env else None return FIRST_MESSAGE_TEMPLATE.format( + current_date=current_date_for_prompt(), patch=format_patch_set(patch.patch_set), patch_summarization=patch_summary, external_context=external_context, @@ -263,6 +268,7 @@ async def assess_patch_scope( Returns at most one comment. Empty when no split is warranted. """ prompt = PATCH_SCOPE_PROMPT.format( + current_date=current_date_for_prompt(), target_software=self.target_software, patch=format_patch_set(patch.patch_set), patch_summary=patch_summary, diff --git a/bugbug/tools/code_review/prompts.py b/bugbug/tools/code_review/prompts.py index 3b91556f7e..72b39fe194 100644 --- a/bugbug/tools/code_review/prompts.py +++ b/bugbug/tools/code_review/prompts.py @@ -60,6 +60,8 @@ PATCH_SCOPE_PROMPT = """You are an expert {target_software} engineer assessing whether a pull request is too large or unfocused to be reviewed well. +Current date: {current_date} + Large changes are harder to review and empirically carry higher defect and regression risk: reviewer defect-detection drops sharply once a change grows past a few hundred changed lines, and at Mozilla the patches that introduce regressions tend to be the larger ones. Decide whether to suggest the author split this patch into smaller, independently reviewable pieces. Either of these is a reason to suggest a split: @@ -89,7 +91,9 @@ """ -FIRST_MESSAGE_TEMPLATE = """Here is a summary of the patch: +FIRST_MESSAGE_TEMPLATE = """Current date: {current_date} + +Here is a summary of the patch: {patch_summarization} diff --git a/tests/test_code_review.py b/tests/test_code_review.py index 8a533766da..0de3b10947 100644 --- a/tests/test_code_review.py +++ b/tests/test_code_review.py @@ -1284,6 +1284,26 @@ def _make_scope_tool(scope_response): return tool +def test_generate_initial_prompt_includes_current_date(): + pytest.importorskip("langchain") + from bugbug.tools.code_review.agent import CodeReviewTool + + tool = CodeReviewTool.__new__(CodeReviewTool) + tool.is_experiment_env = False + tool._get_comment_examples = MagicMock(return_value="") + tool._get_generated_examples = MagicMock(return_value="") + + review_patch = make_patch("--- a/f.txt\n+++ b/f.txt\n@@ -0,0 +1 @@\n+a\n") + + with patch( + "bugbug.tools.code_review.agent.current_date_for_prompt", + return_value="2026-07-30", + ): + prompt = tool.generate_initial_prompt(review_patch, "summary") + + assert "Current date: 2026-07-30" in prompt + + def test_assess_patch_scope_returns_at_most_one_comment(): # The model returns two comments; the pass must keep only the first. comments = [ @@ -1305,6 +1325,20 @@ def test_assess_patch_scope_returns_at_most_one_comment(): assert result[0].comment == "Split this patch 0" +def test_assess_patch_scope_prompt_includes_current_date(): + tool = _make_scope_tool(PatchScopeResponse(comments=[])) + + review_patch = make_patch("--- a/f.txt\n+++ b/f.txt\n@@ -0,0 +1,2 @@\n+a\n+b\n") + with patch( + "bugbug.tools.code_review.agent.current_date_for_prompt", + return_value="2026-07-30", + ): + asyncio.run(tool.assess_patch_scope(review_patch, "summary")) + + prompt = tool.scope_agent.ainvoke.call_args.args[0]["messages"][0].content + assert "Current date: 2026-07-30" in prompt + + def test_assess_patch_scope_returns_empty_when_no_split_warranted(): tool = _make_scope_tool(PatchScopeResponse(comments=[])) From d7dfed789cfc57d3a726a64c74c2c5ee21bcad5d Mon Sep 17 00:00:00 2001 From: ayoubdiourin7 Date: Fri, 31 Jul 2026 11:23:21 +0200 Subject: [PATCH 2/2] Address code review prompt feedback --- bugbug/tools/code_review/agent.py | 1 - bugbug/tools/code_review/prompts.py | 2 -- tests/test_code_review.py | 34 ----------------------------- 3 files changed, 37 deletions(-) diff --git a/bugbug/tools/code_review/agent.py b/bugbug/tools/code_review/agent.py index 7efbf45aa5..0520f6b1a8 100644 --- a/bugbug/tools/code_review/agent.py +++ b/bugbug/tools/code_review/agent.py @@ -268,7 +268,6 @@ async def assess_patch_scope( Returns at most one comment. Empty when no split is warranted. """ prompt = PATCH_SCOPE_PROMPT.format( - current_date=current_date_for_prompt(), target_software=self.target_software, patch=format_patch_set(patch.patch_set), patch_summary=patch_summary, diff --git a/bugbug/tools/code_review/prompts.py b/bugbug/tools/code_review/prompts.py index 72b39fe194..59adc4bdf2 100644 --- a/bugbug/tools/code_review/prompts.py +++ b/bugbug/tools/code_review/prompts.py @@ -60,8 +60,6 @@ PATCH_SCOPE_PROMPT = """You are an expert {target_software} engineer assessing whether a pull request is too large or unfocused to be reviewed well. -Current date: {current_date} - Large changes are harder to review and empirically carry higher defect and regression risk: reviewer defect-detection drops sharply once a change grows past a few hundred changed lines, and at Mozilla the patches that introduce regressions tend to be the larger ones. Decide whether to suggest the author split this patch into smaller, independently reviewable pieces. Either of these is a reason to suggest a split: diff --git a/tests/test_code_review.py b/tests/test_code_review.py index 0de3b10947..8a533766da 100644 --- a/tests/test_code_review.py +++ b/tests/test_code_review.py @@ -1284,26 +1284,6 @@ def _make_scope_tool(scope_response): return tool -def test_generate_initial_prompt_includes_current_date(): - pytest.importorskip("langchain") - from bugbug.tools.code_review.agent import CodeReviewTool - - tool = CodeReviewTool.__new__(CodeReviewTool) - tool.is_experiment_env = False - tool._get_comment_examples = MagicMock(return_value="") - tool._get_generated_examples = MagicMock(return_value="") - - review_patch = make_patch("--- a/f.txt\n+++ b/f.txt\n@@ -0,0 +1 @@\n+a\n") - - with patch( - "bugbug.tools.code_review.agent.current_date_for_prompt", - return_value="2026-07-30", - ): - prompt = tool.generate_initial_prompt(review_patch, "summary") - - assert "Current date: 2026-07-30" in prompt - - def test_assess_patch_scope_returns_at_most_one_comment(): # The model returns two comments; the pass must keep only the first. comments = [ @@ -1325,20 +1305,6 @@ def test_assess_patch_scope_returns_at_most_one_comment(): assert result[0].comment == "Split this patch 0" -def test_assess_patch_scope_prompt_includes_current_date(): - tool = _make_scope_tool(PatchScopeResponse(comments=[])) - - review_patch = make_patch("--- a/f.txt\n+++ b/f.txt\n@@ -0,0 +1,2 @@\n+a\n+b\n") - with patch( - "bugbug.tools.code_review.agent.current_date_for_prompt", - return_value="2026-07-30", - ): - asyncio.run(tool.assess_patch_scope(review_patch, "summary")) - - prompt = tool.scope_agent.ainvoke.call_args.args[0]["messages"][0].content - assert "Current date: 2026-07-30" in prompt - - def test_assess_patch_scope_returns_empty_when_no_split_warranted(): tool = _make_scope_tool(PatchScopeResponse(comments=[]))