Skip to content

fix(cli): defer tool exclusions to policy engine in non-interactive mode - #20639

Merged
kschaab merged 3 commits into
google-gemini:mainfrom
EricRahm:fix-policy-engine-non-interactive
Mar 5, 2026
Merged

kschaab merged 3 commits into
google-gemini:mainfrom
EricRahm:fix-policy-engine-non-interactive

Conversation

@EricRahm

Copy link
Copy Markdown
Contributor

Summary

Removes the hardcoded extraExcludes logic from the CLI configuration layer that was incorrectly overriding high-priority Policy Engine 'allow' rules in non-interactive mode.

Details

The Policy Engine now serves as the single source of truth for tool availability, relying on its native ASK_USER to DENY translation to ensure headless safety.

Verifies that the Policy Engine correctly downgrades ASK_USER tools to DENY in headless (non-interactive) mode when no custom policy is present. Also ensures that explicit ALLOW policies defined in .toml files can override this behavior.

Related Issues

Fixes #20469

How to Validate

npm run test -- packages/cli/src/config/config.test.ts
npm run test:e2e -- integration-tests/policy-headless.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@EricRahm
EricRahm requested a review from a team as a code owner February 28, 2026 00:07
@gemini-code-assist

Copy link
Copy Markdown
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 refactors the CLI's tool exclusion mechanism in non-interactive (headless) mode. Previously, certain tools were hardcoded for exclusion, which could incorrectly override explicit 'allow' rules defined by the Policy Engine. The changes centralize tool availability decisions within the Policy Engine, making it the definitive source of truth. This ensures that the CLI behaves predictably in headless environments, automatically denying tools requiring user interaction unless explicitly permitted by a policy, thereby preventing hangs and improving security.

Highlights

  • Policy Engine Centralization: Removed hardcoded extraExcludes logic from the CLI configuration layer, making the Policy Engine the single source of truth for tool availability in non-interactive mode.
  • Headless Mode Safety: Ensured the Policy Engine correctly translates ASK_USER decisions to DENY in headless (non-interactive) mode by default, preventing the CLI from hanging due to tools requiring user interaction.
  • Policy Overrides: Verified that explicit ALLOW policies defined in .toml files can successfully override the default headless denial behavior for tools.
  • New Integration Tests: Added comprehensive integration tests to validate the Policy Engine's behavior in headless mode, covering default denials, explicit allowances for shell commands, and read-only tools.
Changelog
  • integration-tests/policy-headless-readonly.responses
    • Added model responses for testing read-only tool behavior in headless mode.
  • integration-tests/policy-headless-shell-allowed.responses
    • Added model responses for testing allowed shell commands in headless mode.
  • integration-tests/policy-headless-shell-denied.responses
    • Added model responses for testing denied shell commands in headless mode.
  • integration-tests/policy-headless.test.ts
    • Added comprehensive integration tests to verify the Policy Engine's tool exclusion logic in non-interactive mode, covering default denials and explicit allowances.
  • packages/cli/src/config/config.test.ts
    • Updated existing tests to remove assertions related to the old hardcoded tool exclusion logic.
    • Added new expectations aligned with Policy Engine control over tool exclusions.
  • packages/cli/src/config/config.ts
    • Removed the createToolExclusionFilter function and associated hardcoded defaultExcludes logic.
    • Streamlined tool exclusion to rely solely on the Policy Engine's decisions.
    • Explicitly blocked ASK_USER_TOOL_NAME in non-interactive mode to guarantee it can never be allowed when no human is present.
Activity
  • EricRahm created the pull request to address an issue where hardcoded tool exclusions in the CLI were overriding Policy Engine rules in non-interactive mode.
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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 refactors the tool exclusion logic for non-interactive mode. It removes the hardcoded extraExcludes from the CLI configuration and delegates the responsibility of handling tool availability to the Policy Engine. This allows high-priority allow rules in the Policy Engine to correctly override default behaviors in headless mode. The change is supported by updates to unit tests and the addition of a new integration test suite that validates the new policy-driven behavior in various headless scenarios.

@gemini-cli gemini-cli Bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 28, 2026
Removes the hardcoded `extraExcludes` logic from the CLI configuration
layer that was incorrectly overriding high-priority Policy Engine 'allow'
rules in non-interactive mode. The Policy Engine now serves as the single
source of truth for tool availability, relying on its native `ASK_USER`
to `DENY` translation to ensure headless safety.

Verifies that the Policy Engine correctly downgrades ASK_USER tools to
DENY in headless (non-interactive) mode when no custom policy is present.
Also ensures that explicit ALLOW policies defined in .toml files can
override this behavior.

Fixes google-gemini#20469
@gemini-cli gemini-cli Bot added the help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! label Mar 2, 2026
Removes leftover generateContent mock responses that caused 'Unexpected response type' crashes when executed from npm script environments where the Agent Router is correctly bypassed (e.g. CI).

Also replaces hardcoded absolute paths in read_file test mocks with relative paths to prevent file-not-found errors in dynamic test directories.
@EricRahm
EricRahm force-pushed the fix-policy-engine-non-interactive branch from df4cd47 to fafd16a Compare March 2, 2026 23:27
@kschaab
kschaab added this pull request to the merge queue Mar 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@kschaab
kschaab added this pull request to the merge queue Mar 5, 2026
Merged via the queue into google-gemini:main with commit c72cfad Mar 5, 2026
26 of 27 checks passed
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
cocosheng-g pushed a commit that referenced this pull request May 6, 2026
…ode (#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
…ode (google-gemini#20639)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Policy Engine rules ignored in non-interactive mode with --approval-mode auto_edit

4 participants