Skip to content

Comments

fix(core): prevent duplicate tool approval entries in auto-saved.toml#19487

Merged
Abhijit-2592 merged 3 commits intomainfrom
abhijit-2592/fix-duplicate-in-auto-saved-toml
Feb 19, 2026
Merged

fix(core): prevent duplicate tool approval entries in auto-saved.toml#19487
Abhijit-2592 merged 3 commits intomainfrom
abhijit-2592/fix-duplicate-in-auto-saved-toml

Conversation

@Abhijit-2592
Copy link
Contributor

Summary

This PR fixes an issue where selecting "Allow for all future sessions" in a tool confirmation dialog caused the corresponding policy entry to be added twice to the auto-saved.toml file.

Details

The root cause was redundant UPDATE_POLICY message triggers:

  1. Individual Tools: BaseToolInvocation and several specific tools (shell, edit, write-file, etc.) published a policy update within their onConfirm callback.
  2. Schedulers: Both Scheduler and CoreToolScheduler independently called updatePolicy() after a confirmation was resolved.

This PR centralizes the responsibility for publishing policy updates in the schedulers and removes the redundant triggers from individual tool implementations. This ensures that exactly one write to disk occurs per user confirmation.

Key changes:

  • Centralized policy update logic in Scheduler (already present) and CoreToolScheduler (newly added).
  • Removed manual publishPolicyUpdate and setApprovalMode calls from all tool invocations.
  • Updated confirmation-policy.test.ts and web-fetch.test.ts to reflect the centralized architecture.

Related Issues

Closes #19485

How to Validate

  1. Start Gemini CLI: npm run start
  2. Trigger a tool confirmation (e.g., run ls with shell confirmation enabled).
  3. Select "Allow for all future sessions".
  4. Open ~/.gemini/policies/auto-saved.toml and verify only one entry was added for that tool.
  5. Run unit tests: npx vitest run packages/core/src/tools/confirmation-policy.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

@Abhijit-2592 Abhijit-2592 requested a review from a team as a code owner February 18, 2026 23:24
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Abhijit-2592, 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 addresses a bug that caused duplicate entries in the auto-saved.toml file when a user selected to always allow a tool for future sessions. The fix centralizes the responsibility for updating tool approval policies within the core scheduling components, eliminating redundant calls from individual tool implementations. This ensures that policy changes are applied consistently and only once per user confirmation, improving the reliability of tool configuration persistence.

Highlights

  • Centralized Policy Updates: Policy update logic has been centralized in Scheduler and CoreToolScheduler, ensuring a single point of control for saving tool approval decisions.
  • Removed Redundant Triggers: Manual publishPolicyUpdate and setApprovalMode calls have been removed from individual tool invocations (e.g., BaseToolInvocation, shell, edit, write-file, web-fetch, remote-invocation, enter-plan-mode, mcp-tool, memoryTool).
  • Updated Test Suites: Existing test files (confirmation-policy.test.ts and web-fetch.test.ts) were updated to reflect the new centralized architecture, asserting that individual tools no longer directly publish policy updates or set approval modes.
Changelog
  • packages/core/src/agents/remote-invocation.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback, as policy updates are now handled centrally by the scheduler.
  • packages/core/src/core/coreToolScheduler.ts
    • Imported the updatePolicy function to enable centralized policy management.
    • Added a messageBus property to the CoreToolScheduler class to facilitate policy updates.
    • Initialized the messageBus property in the constructor.
    • Implemented a centralized updatePolicy call within the handleConfirmation method, ensuring policy updates occur at the scheduler level.
  • packages/core/src/tools/confirmation-policy.test.ts
    • Modified test cases to reflect that onConfirm callbacks no longer directly publish UPDATE_POLICY messages or call setApprovalMode.
    • Updated variable names (shouldPublish to _shouldPublish, persist to _persist) to indicate they are no longer directly used in the test logic.
  • packages/core/src/tools/edit.ts
    • Changed ToolConfirmationOutcome import to a type-only import.
    • Removed the publishPolicyUpdate and setApprovalMode calls from the onConfirm callback, delegating policy and mode transitions to the scheduler.
  • packages/core/src/tools/enter-plan-mode.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback, centralizing policy updates.
  • packages/core/src/tools/mcp-tool.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback for persistent policy updates, as this is now handled by the scheduler.
  • packages/core/src/tools/memoryTool.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback, centralizing policy updates.
  • packages/core/src/tools/shell.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback, centralizing policy updates.
  • packages/core/src/tools/tools.ts
    • Removed the publishPolicyUpdate call from the onConfirm callback in BaseToolInvocation, ensuring all policy updates are handled centrally.
  • packages/core/src/tools/web-fetch.test.ts
    • Updated the test description to clarify that setApprovalMode should no longer be called by onConfirm.
    • Modified assertions to confirm that mockConfig.setApprovalMode is not called, aligning with the centralized policy update logic.
  • packages/core/src/tools/web-fetch.ts
    • Changed ToolConfirmationOutcome import to a type-only import.
    • Removed the publishPolicyUpdate and setApprovalMode calls from the onConfirm callback, delegating policy and mode transitions to the scheduler.
  • packages/core/src/tools/write-file.ts
    • Changed ToolConfirmationOutcome import to a type-only import.
    • Removed the publishPolicyUpdate and setApprovalMode calls from the onConfirm callback, delegating policy and mode transitions to the scheduler.
Activity
  • The pull request was created by Abhijit-2592 to fix an issue with duplicate tool approval entries.
  • The author provided a detailed summary, explanation of the root cause, key changes, related issues, and validation steps.
  • The author included a pre-merge checklist, indicating that tests were added/updated and validation was performed on MacOS using npm run and npx.
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 causing duplicate tool approval entries in auto-saved.toml. The root cause was redundant policy update triggers in both individual tool onConfirm callbacks and the schedulers. The fix correctly centralizes this logic within the CoreToolScheduler, removing the duplicated calls from all tool implementations. This is a solid refactoring that not only fixes the bug but also improves the overall architecture by centralizing responsibility and reducing code duplication. The changes have been applied consistently across all relevant tools and their tests have been updated accordingly.

@github-actions
Copy link

github-actions bot commented Feb 18, 2026

Size Change: -1 kB (0%)

Total Size: 24.5 MB

Filename Size Change
./bundle/gemini.js 24.5 MB -1 kB (0%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/fix-duplicate-in-auto-saved-toml branch 2 times, most recently from e909f5a to fc6985a Compare February 19, 2026 04:09
Copy link
Collaborator

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

LGTM, let's just remove the coreToolScheduler changes

Abhijit-2592 and others added 3 commits February 19, 2026 11:16
Centralized the responsibility for publishing policy updates in the tool schedulers (Scheduler and CoreToolScheduler). Removed redundant publishPolicyUpdate and manual setApprovalMode calls from individual tool implementations. Updated associated tests to reflect the new centralized architecture.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/fix-duplicate-in-auto-saved-toml branch from fb62d93 to be636bc Compare February 19, 2026 19:17
@Abhijit-2592 Abhijit-2592 added this pull request to the merge queue Feb 19, 2026
Merged via the queue into main with commit 3408542 Feb 19, 2026
27 checks passed
@Abhijit-2592 Abhijit-2592 deleted the abhijit-2592/fix-duplicate-in-auto-saved-toml branch February 19, 2026 20:14
spencer426 pushed a commit that referenced this pull request Feb 20, 2026
…#19487)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate tool approval entries in auto-saved.toml

2 participants