feat(plan): fix invalid tool calls in plan mode#18352
Conversation
Summary of ChangesHello @Adib234, 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 enhances the robustness of the system by addressing instances where the Gemini model would incorrectly attempt to call mode-switching tools ('enter_plan_mode' or 'exit_plan_mode') in inappropriate contexts. By integrating explicit warnings directly into the system prompts and refining the dynamic tool exclusion logic, the changes proactively guide the model's behavior, preventing 'hallucinated' tool calls and ensuring smoother state transitions within the application. Highlights
Changelog
Activity
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
|
|
Size Change: +1.18 kB (0%) Total Size: 23.7 MB
ℹ️ View Unchanged
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust mechanism to prevent invalid tool calls by dynamically synchronizing the available tools (enter_plan_mode and exit_plan_mode) with the current approval mode. This is a good improvement over relying solely on prompt instructions. The changes in packages/core/src/config/config.ts correctly handle this synchronization during initialization and mode transitions. New tests have also been added to verify this behavior.
I've identified a potential race condition in how the tool synchronization and system instruction updates are handled during mode transitions. My review comment provides a suggestion to resolve this to ensure the application state remains consistent.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request aims to prevent invalid tool calls for enter_plan_mode and exit_plan_mode by synchronizing their availability based on the current approval mode. However, a critical security vulnerability exists: the current implementation fails to restrict other dangerous, write-capable tools during the read-only Plan Mode, creating an incomplete security boundary. This could allow unauthorized file modifications or command executions if the LLM is manipulated. Additionally, plan-related tools could be registered even if the planning feature is disabled.
…ntal.plan The enter_plan_mode tool was being registered unconditionally when not in plan mode. This change updates syncPlanModeTools to only register the tool if experimental.plan is enabled. Added regression tests to verify that the tool is correctly registered or unregistered based on the experimental.plan setting. Follow up to #18352 Related to #18334
Summary
The changes prevent the Gemini model from attempting to use
enter_plan_modewhile already in Plan Mode andexit_plan_modewhile in Default Mode. This is achieved syncing plan mode tools correctly when we change approval modes.Details
We now register and unregister tools so that the model cannot have access to running that tool and then we refresh the chat so the model doesn't think it can call the tool
Related Issues
Closes #18334
How to Validate
If you are in plan mode, try to trigger the enter plan mode tool by creating another plan. It should not trigger enter plan mode tool call.
If you are not in plan mode, try triggering the exit plan mode tool but telling it to exit the plan or "I've finished creating a plan now exit". It should not call exit plan mode tool.
Pre-Merge Checklist