diff --git a/bugbug/tools/code_review/agent.py b/bugbug/tools/code_review/agent.py index f04de3d860..ecda769f59 100644 --- a/bugbug/tools/code_review/agent.py +++ b/bugbug/tools/code_review/agent.py @@ -49,7 +49,10 @@ convert_generated_comments_to_inline, format_patch_set, ) -from bugbug.tools.core.exceptions import LargeDiffError, ModelResultError +from bugbug.tools.core.exceptions import ( + LargeDiffError, + RecursionLimitError, +) from bugbug.tools.core.llms import DEFAULT_ANTHROPIC_MODEL, get_tokenizer from bugbug.tools.core.platforms.base import Patch @@ -235,11 +238,11 @@ async def generate_review_comments( }, context=CodeReviewContext(patch=patch), stream_mode="values", - config={"recursion_limit": 50}, + config={"recursion_limit": 100}, ): result = chunk except GraphRecursionError as e: - raise ModelResultError("The model could not complete the review") from e + raise RecursionLimitError("The model could not complete the review") from e return result["structured_response"].comments, manifest diff --git a/bugbug/tools/core/exceptions.py b/bugbug/tools/core/exceptions.py index 78d1e92fa9..e2dd3133f0 100644 --- a/bugbug/tools/core/exceptions.py +++ b/bugbug/tools/core/exceptions.py @@ -27,5 +27,9 @@ class RunawayGenerationError(ModelResultError): """ +class RecursionLimitError(ModelResultError): + """Occurs when the agent exceeds the maximum number of recursive steps.""" + + class LargeDiffError(Exception): """Occurs when the diff is too large to be processed.""" diff --git a/services/reviewhelper-api/app/review_processor.py b/services/reviewhelper-api/app/review_processor.py index 198eeb4dcb..84cffce308 100644 --- a/services/reviewhelper-api/app/review_processor.py +++ b/services/reviewhelper-api/app/review_processor.py @@ -7,7 +7,7 @@ from app.config import settings from app.database.models import GeneratedComment, ReviewRequest from app.enums import Platform -from bugbug.tools.core.exceptions import LargeDiffError +from bugbug.tools.core.exceptions import LargeDiffError, RecursionLimitError from bugbug.tools.core.platforms.phabricator import ( PhabricatorPatch, get_phabricator_client, @@ -81,6 +81,10 @@ async def process_review( raise ReviewProcessingError( "The diff size exceeds the current processing limits." ) from e + except RecursionLimitError as e: + raise ReviewProcessingError( + "Review Helper could not complete the review within the configured agent step limit." + ) from e generated_comments = [ GeneratedComment(