Skip to content

fix(core): handle policy ALLOW for exit_plan_mode#21802

Merged
ruomengz merged 2 commits intogoogle-gemini:mainfrom
backnotprop:fix/exit-plan-mode-policy-allow
Mar 12, 2026
Merged

fix(core): handle policy ALLOW for exit_plan_mode#21802
ruomengz merged 2 commits intogoogle-gemini:mainfrom
backnotprop:fix/exit-plan-mode-policy-allow

Conversation

@backnotprop
Copy link
Contributor

@backnotprop backnotprop commented Mar 10, 2026

Fixes #21806

Problem

When a user policy grants decision = "allow" for exit_plan_mode, the scheduler correctly skips the confirmation phase. However, this means shouldConfirmExecute() is never called, so approvalPayload remains null. The tool then falls through to the rejection branch and returns "Rejected (no feedback)" — even though the policy explicitly allowed execution.

Solution

Default approvalPayload to { approved: true, approvalMode: DEFAULT } when null. This matches the existing behavior of the ALLOW branch inside shouldConfirmExecute() (line 149-157), which sets the same values when the message bus returns ALLOW.

Test

Added a test that calls execute() directly without calling shouldConfirmExecute() first, simulating the scheduler's policy ALLOW path. Verifies the tool approves with DEFAULT mode and sets the approved plan path.

Use case

User policies that auto-allow exit_plan_mode enable hook-driven plan approval workflows — e.g. routing plan review to a web UI via BeforeTool hooks (see plannotator). Without this fix, the policy allow decision has no effect on this tool.

When a user policy grants `decision = "allow"` for exit_plan_mode, the
scheduler skips the confirmation phase entirely. This means
shouldConfirmExecute is never called and approvalPayload remains null.

The tool then falls through to the rejection branch and returns
"Rejected (no feedback)" — even though the policy explicitly allowed it.

Default approvalPayload to approved with DEFAULT mode when null,
matching the behavior of the ALLOW branch in shouldConfirmExecute.
@google-cla
Copy link

google-cla bot commented Mar 10, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 bug where explicit policy allowances for exit_plan_mode were being incorrectly interpreted as rejections. By ensuring that the approvalPayload is correctly initialized to an approved state when the confirmation step is bypassed due to policy, the system now accurately honors user policies, enabling seamless hook-driven plan approval workflows.

Highlights

  • Policy ALLOW for exit_plan_mode: Previously, when a user policy explicitly allowed exit_plan_mode, the approvalPayload remained null because the confirmation phase was skipped, causing the system to incorrectly reject the execution.
  • approvalPayload handling: The approvalPayload is now defaulted to an approved state ({ approved: true, approvalMode: DEFAULT }) if it is null, ensuring that policy-allowed executions proceed as intended.
Changelog
  • packages/core/src/tools/exit-plan-mode.ts
    • Corrected the handling of approvalPayload when exit_plan_mode is allowed by policy.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 exit_plan_mode would incorrectly reject execution when an ALLOW policy was in place, due to approvalPayload being null. The fix introduces a nullish coalescing operator to provide a default approval payload, ensuring the tool call proceeds as expected. The change is clear, well-commented, and effectively resolves the issue described. The implementation looks solid.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 10, 2026
@backnotprop
Copy link
Contributor Author

I've signed the CLA now

@jerop
Copy link
Contributor

jerop commented Mar 10, 2026

@backnotprop please file an issue for this and add tests for this change, thank you for the contribution!

@jerop jerop self-requested a review March 10, 2026 01:20
@jerop jerop self-assigned this Mar 10, 2026
Covers the case where the scheduler skips confirmation due to a policy
ALLOW decision, calling execute() without shouldConfirmExecute().

Verifies the tool defaults to approved with DEFAULT mode.

Fixes google-gemini#21806
@backnotprop
Copy link
Contributor Author

backnotprop commented Mar 10, 2026

done @jerop , ty.

#21806

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! and removed status/need-issue Pull requests that need to have an associated issue. labels Mar 10, 2026
@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Mar 11, 2026
Copy link
Contributor

@ruomengz ruomengz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! LGTM

@backnotprop
Copy link
Contributor Author

Awesome, you can probably announce a cool antigravity integration - giving cli users a better surface to review plans and automate the feedback loop to cli from that surface.

@ruomengz ruomengz added this pull request to the merge queue Mar 12, 2026
Merged via the queue into google-gemini:main with commit 7506b00 Mar 12, 2026
28 checks passed
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix exit_plan_mode ignoring policy allow decision when scheduler skips confirmation

3 participants