Skip to content

Comments

feat(core): exempt high-signal tools from output masking#18545

Merged
abhipatel12 merged 2 commits intomainfrom
abhi/skip-skills-for-masking
Feb 8, 2026
Merged

feat(core): exempt high-signal tools from output masking#18545
abhipatel12 merged 2 commits intomainfrom
abhi/skip-skills-for-masking

Conversation

@abhipatel12
Copy link
Collaborator

Summary

This PR ensures that high-signal tools (skills, memory, user input, and state transitions) are exempt from context window masking.

Previously, the ToolOutputMaskingService would mask any tool output older than the protection window once prunable tokens exceeded the threshold. This was problematic for tools like activate_skill, where the model needs the instruction set and resource mappings to function correctly across long-running sessions.

Details

  • Added an EXEMPT_TOOLS set containing activate_skill, save_memory, ask_user, enter_plan_mode, and exit_plan_mode.
  • Updated the backward scan in ToolOutputMaskingService to skip masking for any functionResponse from these tools.
  • Exempt tools no longer contribute to the prunable token count, ensuring they are preserved indefinitely.
  • Verified that existing shell tool masking and protection window logic remains unaffected.

Related Issues

N/A

How to Validate

  1. Run the targeted unit tests:
    npm test -w @google/gemini-cli-core -- src/services/toolOutputMaskingService.test.ts
  2. Verify the new test case "should never mask exempt tools (like activate_skill) even if they are deep in history" passes.
  3. (Optional) Run npm run preflight to verify the entire monorepo.

Pre-Merge Checklist

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

Ensures that tools providing essential instructions or state transitions
(activate_skill, save_memory, ask_user, plan_mode) are never masked,
preserving critical context for the model.

- Added EXEMPT_TOOLS set to ToolOutputMaskingService
- Updated backward scan to skip exempt tool outputs
- Added comprehensive unit tests for exemption logic
@abhipatel12 abhipatel12 requested a review from a team as a code owner February 7, 2026 21:56
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, 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 ToolOutputMaskingService by introducing an exemption mechanism for high-signal tool outputs. Previously, important tool responses could be masked to manage context window size, leading to potential loss of critical information for the model. The changes ensure that outputs from essential tools, like those related to skill activation, memory, and user interaction, are always preserved, thereby improving the model's ability to maintain context and execute complex, long-running tasks effectively.

Highlights

  • Exemption of High-Signal Tools: Outputs from critical tools such as activate_skill, save_memory, ask_user, enter_plan_mode, and exit_plan_mode are now exempt from context window masking.
  • New EXEMPT_TOOLS Set: A new EXEMPT_TOOLS set has been introduced to explicitly list tools whose outputs should never be masked, ensuring their persistence in the conversation history.
  • Updated Masking Logic: The ToolOutputMaskingService has been modified to skip masking for any functionResponse originating from tools within the EXEMPT_TOOLS set during its backward scan.
  • Token Count Exclusion: Exempt tools no longer contribute to the prunable token count, guaranteeing that their outputs are preserved indefinitely, regardless of context window pressure.
  • New Test Case: A new unit test has been added to toolOutputMaskingService.test.ts to specifically verify that exempt tools are never masked, even when they are deep in the conversation history.
Changelog
  • packages/core/src/services/toolOutputMaskingService.test.ts
    • Imported ACTIVATE_SKILL_TOOL_NAME and MEMORY_TOOL_NAME for testing purposes.
    • Added a new test case 'should never mask exempt tools (like activate_skill) even if they are deep in history' to validate the new masking exemption logic.
  • packages/core/src/services/toolOutputMaskingService.ts
    • Imported additional tool names: ACTIVATE_SKILL_TOOL_NAME, MEMORY_TOOL_NAME, ASK_USER_TOOL_NAME, ENTER_PLAN_MODE_TOOL_NAME, and EXIT_PLAN_MODE_TOOL_NAME.
    • Defined a new constant EXEMPT_TOOLS as a Set containing the names of tools whose outputs should always be preserved.
    • Modified the mask method within ToolOutputMaskingService to check if a functionResponse belongs to an exempt tool and, if so, to skip masking that output.
Activity
  • The pull request was created by abhipatel12.
  • The author provided a detailed summary, specific implementation details, and validation steps.
  • The pre-merge checklist indicates that relevant documentation updates were handled via code comments.
  • Tests have been added/updated to cover the new functionality.
  • Validation was performed on MacOS.
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 introduces an exemption list for high-signal tools to prevent their output from being masked by the ToolOutputMaskingService. The change is well-implemented by creating a Set of exempt tool names and skipping them during the masking process, which correctly ensures that critical context from tools like activate_skill and save_memory is preserved across long sessions. The accompanying test case is thorough and correctly validates that exempt tools are never masked, while other bulky tool outputs are handled as before. The implementation is clean, efficient, and correct.

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Size Change: +364 B (0%)

Total Size: 23.9 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 23.8 MB +364 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@abhipatel12 abhipatel12 enabled auto-merge February 7, 2026 22:03
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 7, 2026
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 7, 2026
@smoldersguy170-lab
Copy link

Merged via the queue into main with commit a1f2aac Feb 8, 2026
26 checks passed
@abhipatel12 abhipatel12 deleted the abhi/skip-skills-for-masking branch February 8, 2026 00:10
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants