Add more tools (based on searchfox-py) to the LLM review agent, and make it patch stack aware to a certain extent#6051
Merged
Conversation
33dbdae to
798947f
Compare
Collaborator
Author
|
padenot/searchfox-cli@v0.10.12...v0.13.0 are the changes in |
44f260f to
3917e53
Compare
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
marco-c
reviewed
May 27, 2026
3917e53 to
a5eccfc
Compare
marco-c
reviewed
May 28, 2026
marco-c
reviewed
May 28, 2026
d72e7e9 to
6eda3aa
Compare
Collaborator
Author
|
@marco-c last one is a fix for a new failure on main, ptal |
marco-c
previously approved these changes
May 28, 2026
6eda3aa to
0c07eb3
Compare
suhaibmujahid
previously approved these changes
May 28, 2026
expand_context now shows the file as it appears after the full patch stack is applied. A new patch_apply module provides reusable primitives: - strip_diff_prefix, find_patched_file, apply_patched_file: diff utilities with tenacity retries on both fetches for transient failures - get_file_after_stack(patch, path, fetch): applies patch.patch_stack in order on top of whatever base the caller provides via fetch() expand_context calls get_file_after_stack with patch.get_old_file as the fetch function. The Patch base class gains patch_stack (default: [patch_set]), get_base_revision(), and patch_stack_warning(); phabricator.py overrides all three. Non-linear stacks fall back to the current patch only and set a warning that expand_context surfaces prominently so the agent can flag it in the review. expand_context also gains optional start_line / end_line — omitting either returns from the beginning or to the end of the file.
Expose the searchfox Python API (searchfox-cli) as LangChain tools wired into the code review agent. expand_context switches its fetch function from patch.get_old_file to searchfox at the patch's base revision, using get_file_after_stack from patch_apply. - expand_context: searchfox at base revision + full patch stack applied - search_text: free-text / regex search with file-type and path filters - get_blame: per-line commit history - get_field_layout: C++ class/struct memory layout - find_definition: look up a function, method, class, or struct - search_identifier: exact identifier search with file-type filters - calls_from / calls_to / calls_between: call graph traversal with depth - check_can_gc: SpiderMonkey GC hazard analysis for C++ functions All tools support langs (list) and tests filters where applicable. No additional tests for the tool wrappers: the tools are thin call-and-format wrappers over searchfox-py, which is tested independently in its own repo. Closes mozilla#5284 diff --git a/bugbug/tools/code_review/agent.py b/bugbug/tools/code_review/agent.py
- Define SEARCHFOX_TOOLS list in langchain_tools.py; import and use it in agent.py instead of listing tools inline - Remove create_find_function_definition_tool and function_search parameter; the new find_definition tool is a cleaner replacement - Move logger above _retry; use functools.cache for _get_client - Add patch.get_old_file fallback in expand_context before falling back to searchfox tip - Add get_function_at_line tool (searchfox-py 0.14.0); bump requirement and lockfile accordingly - Rename langchain_tools.py to searchfox_tools.py
- Rename searchfox_tools.py back to langchain_tools.py - Extract fetch closure to module-level _fetch_file to reduce nesting - Use specific exception types instead of bare Exception where possible
0c07eb3 to
1c115b7
Compare
marco-c
pushed a commit
that referenced
this pull request
May 28, 2026
…ake it patch stack aware to a certain extent (#6051) * Make expand_context patch-stack aware expand_context now shows the file as it appears after the full patch stack is applied. A new patch_apply module provides reusable primitives: - strip_diff_prefix, find_patched_file, apply_patched_file: diff utilities with tenacity retries on both fetches for transient failures - get_file_after_stack(patch, path, fetch): applies patch.patch_stack in order on top of whatever base the caller provides via fetch() expand_context calls get_file_after_stack with patch.get_old_file as the fetch function. The Patch base class gains patch_stack (default: [patch_set]), get_base_revision(), and patch_stack_warning(); phabricator.py overrides all three. Non-linear stacks fall back to the current patch only and set a warning that expand_context surfaces prominently so the agent can flag it in the review. expand_context also gains optional start_line / end_line — omitting either returns from the beginning or to the end of the file. * Add searchfox-based tools to the code review agent Expose the searchfox Python API (searchfox-cli) as LangChain tools wired into the code review agent. expand_context switches its fetch function from patch.get_old_file to searchfox at the patch's base revision, using get_file_after_stack from patch_apply. - expand_context: searchfox at base revision + full patch stack applied - search_text: free-text / regex search with file-type and path filters - get_blame: per-line commit history - get_field_layout: C++ class/struct memory layout - find_definition: look up a function, method, class, or struct - search_identifier: exact identifier search with file-type filters - calls_from / calls_to / calls_between: call graph traversal with depth - check_can_gc: SpiderMonkey GC hazard analysis for C++ functions All tools support langs (list) and tests filters where applicable. No additional tests for the tool wrappers: the tools are thin call-and-format wrappers over searchfox-py, which is tested independently in its own repo. Closes #5284 diff --git a/bugbug/tools/code_review/agent.py b/bugbug/tools/code_review/agent.py * Address review comments, add get_function_at_line tool - Define SEARCHFOX_TOOLS list in langchain_tools.py; import and use it in agent.py instead of listing tools inline - Remove create_find_function_definition_tool and function_search parameter; the new find_definition tool is a cleaner replacement - Move logger above _retry; use functools.cache for _get_client - Add patch.get_old_file fallback in expand_context before falling back to searchfox tip - Add get_function_at_line tool (searchfox-py 0.14.0); bump requirement and lockfile accordingly - Rename langchain_tools.py to searchfox_tools.py * Address review comments from suhaib - Rename searchfox_tools.py back to langchain_tools.py - Extract fetch closure to module-level _fetch_file to reduce nesting - Use specific exception types instead of bare Exception where possible * Try phabricator before searchfox when fetching base file content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The two patches can be reviewed independently but are close in location so I'm putting one branch for both.