-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(planners): allow BuiltInPlanner subclasses to override process_planning_response #4141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(planners): allow BuiltInPlanner subclasses to override process_planning_response #4141
Conversation
…anning_response Previously, isinstance(planner, BuiltInPlanner) caused all subclasses to be skipped in the response processor, preventing custom process_planning_response implementations from being called. This change uses method override detection instead of type checking, ensuring: - BuiltInPlanner itself is skipped (returns None) - Subclasses without override are skipped (no side effects) - Subclasses with override have their method called Fixes google#4133
Summary of ChangesHello @maru0804, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug that prevented Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses a bug where overridden process_planning_response methods in BuiltInPlanner subclasses were not being called. The fix, which involves checking the method identity directly instead of using isinstance, is clever and correct. The accompanying tests are thorough, covering the overridden subclass, the base class, and a non-overridden subclass to ensure the new logic works as expected. I've suggested a minor refactoring in the tests to reduce code duplication by parameterizing two similar test cases, which will improve maintainability. Overall, this is a high-quality contribution that effectively resolves the issue.
Address review feedback by combining test_base_builtin_planner_process_planning_response_not_called and test_non_overridden_subclass_process_planning_response_not_called into a single parameterized test to reduce code duplication.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes an issue where process_planning_response was not called for subclasses of BuiltInPlanner. The change from isinstance to a method identity check is a clever and effective solution. The accompanying tests are thorough, covering the regression case for overridden methods, as well as verifying that the base class and non-overriding subclasses are correctly skipped. I have one suggestion to simplify the test code slightly. Overall, this is a great contribution.
Address review feedback: wraps is not needed since BuiltInPlanner.process_planning_response simply returns None. A standard MagicMock is sufficient for assert_not_called().
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively resolves an issue where overridden methods in BuiltInPlanner subclasses were not being called. The solution, which checks for method identity rather than using isinstance, is clever and correct. The accompanying tests are thorough, covering the fixed case, the base class case, and the non-overridden subclass case. I've made one suggestion to improve the robustness of one of the new tests by narrowing the scope of a patch, but overall this is a solid contribution.
| with patch.object( | ||
| BuiltInPlanner, | ||
| 'process_planning_response', | ||
| ) as mock_method: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current test patches BuiltInPlanner at the class level. While this works, it's a bit subtle as it relies on the patch interacting with the is check in the implementation. A clearer and more robust approach is to patch the method on the planner instance. This better isolates the test's scope and verifies the behavior without being tightly coupled to the implementation of the conditional check.
with patch.object(planner, 'process_planning_response') as mock_method:
Summary
Fixes #4133
Problem
When users create a subclass of
BuiltInPlannerand overrideprocess_planning_response(), the method was never called because the response processor usedisinstance(planner, BuiltInPlanner)which returnsTruefor all subclasses.Solution
Changed the check to detect whether
process_planning_responsehas been overridden:This ensures:
BuiltInPlanneritself is skipped (returnsNone)Testing
Added 3 new tests:
test_overridden_subclass_process_planning_response_called- Regression test for Bug:AutomaticFunctionCallingConfig(disable=True)is ignored - Planner hook bypassed #4133test_base_builtin_planner_process_planning_response_not_called- Verifies base class is skippedtest_non_overridden_subclass_process_planning_response_not_called- Verifies non-overriding subclasses are also skipped