Skip to content

fix(agent): prevent silent scope expansion when initial approach fails#28171

Open
Suryap-hub wants to merge 1 commit into
google-gemini:mainfrom
Suryap-hub:fix/agent-scope-creep-28155
Open

fix(agent): prevent silent scope expansion when initial approach fails#28171
Suryap-hub wants to merge 1 commit into
google-gemini:mainfrom
Suryap-hub:fix/agent-scope-creep-28155

Conversation

@Suryap-hub

Copy link
Copy Markdown

Fixes #28155

Problem

When asked to review a specific set of lines, the agent silently
expanded its scope — running scripts and reading the full file
without user approval. Instead of staying within the requested
boundaries, it switched strategies without informing the user.

Root Cause

The mandateConfirm function in snippets.ts lacked explicit
instructions to prevent the agent from silently escalating its
approach when it couldn't find an answer quickly.

Fix

Added 3 guardrails to the mandateConfirm function in
packages/core/src/prompts/snippets.ts:

  • Do not change approach silently: If initial approach fails,
    tell the user and ask before switching to a broader strategy.
  • Stay within stated boundaries: If asked to review N lines,
    only read those N lines — do not read the full file or run
    scripts unless explicitly asked.
  • Escalation requires confirmation: Before running any shell
    command to investigate further, ask the user first.

Testing

  • npm run build -w packages/core
  • npm test -w packages/core

@Suryap-hub Suryap-hub requested review from a team as code owners June 27, 2026 08:38
@google-cla

google-cla Bot commented Jun 27, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the size/xl An extra large PR label Jun 27, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/XL

  • Lines changed: 1586102
  • Additions: +2
  • Deletions: -1586100
  • Files changed: 2877

@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 addresses issue #28155 by implementing strict guardrails in the agent's decision-making process. The changes ensure that the agent respects user-defined boundaries and prevents silent escalation, requiring explicit user approval before switching strategies or executing sensitive commands.

Highlights

  • Prevent Silent Scope Expansion: Added guardrails to the mandateConfirm function to ensure the agent explicitly notifies the user before switching to a broader strategy when an initial approach fails.
  • Boundary Enforcement: Implemented logic to restrict the agent to the requested line range, preventing unauthorized reading of full files or execution of scripts.
  • Escalation Confirmation: Introduced a mandatory confirmation step before the agent executes any shell commands to investigate further.
Ignored Files
  • Ignored by pattern: .gemini/** (46)
    • .gemini/commands/code-guide.toml
    • .gemini/commands/core.toml
    • .gemini/commands/find-docs.toml
    • .gemini/commands/frontend.toml
    • .gemini/commands/full-context.toml
    • .gemini/commands/github/cleanup-back-to-main.toml
    • .gemini/commands/introspect.toml
    • .gemini/commands/oncall/pr-review.toml
    • .gemini/commands/prompt-suggest.toml
    • .gemini/commands/review-and-fix.toml
    • .gemini/commands/review-frontend.toml
    • .gemini/commands/strict-development-rules.md
    • .gemini/config.yaml
    • .gemini/settings.json
    • .gemini/skills/agent-tui/SKILL.md
    • .gemini/skills/async-pr-review/SKILL.md
    • .gemini/skills/async-pr-review/policy.toml
    • .gemini/skills/async-pr-review/scripts/async-review.sh
    • .gemini/skills/async-pr-review/scripts/check-async-review.sh
    • .gemini/skills/behavioral-evals/SKILL.md
    • .gemini/skills/behavioral-evals/assets/interactive_eval.ts.txt
    • .gemini/skills/behavioral-evals/assets/standard_eval.ts.txt
    • .gemini/skills/behavioral-evals/references/creating.md
    • .gemini/skills/behavioral-evals/references/fixing.md
    • .gemini/skills/behavioral-evals/references/promoting.md
    • .gemini/skills/behavioral-evals/references/running.md
    • .gemini/skills/ci/SKILL.md
    • .gemini/skills/ci/scripts/ci.mjs
    • .gemini/skills/code-reviewer/SKILL.md
    • .gemini/skills/docs-changelog/SKILL.md
    • .gemini/skills/docs-changelog/references/highlights_examples.md
    • .gemini/skills/docs-changelog/references/index_template.md
    • .gemini/skills/docs-changelog/references/latest_template.md
    • .gemini/skills/docs-changelog/references/preview_template.md
    • .gemini/skills/docs-writer/SKILL.md
    • .gemini/skills/docs-writer/quota-limit-style-guide.md
    • .gemini/skills/docs-writer/references/docs-auditing.md
    • .gemini/skills/github-issue-creator/SKILL.md
    • .gemini/skills/pr-address-comments/SKILL.md
    • .gemini/skills/pr-address-comments/scripts/fetch-pr-info.js
    • .gemini/skills/pr-creator/SKILL.md
    • .gemini/skills/review-duplication/SKILL.md
    • .gemini/skills/string-reviewer/SKILL.md
    • .gemini/skills/string-reviewer/references/settings.md
    • .gemini/skills/string-reviewer/references/word-list.md
    • .gemini/skills/tui-tester/SKILL.md
  • Ignored by pattern: .github/workflows/** (46)
    • .github/workflows/agent-session-drift-check.yml
    • .github/workflows/build-unsigned-mac-binaries.yml
    • .github/workflows/chained_e2e.yml
    • .github/workflows/ci.yml
    • .github/workflows/community-report.yml
    • .github/workflows/deflake.yml
    • .github/workflows/docs-audit.yml
    • .github/workflows/docs-page-action.yml
    • .github/workflows/docs-rebuild.yml
    • .github/workflows/eval-pr.yml
    • .github/workflows/eval.yml
    • .github/workflows/evals-nightly.yml
    • .github/workflows/gemini-automated-issue-dedup.yml
    • .github/workflows/gemini-automated-issue-triage.yml
    • .github/workflows/gemini-cli-bot-brain.yml
    • .github/workflows/gemini-cli-bot-pulse.yml
    • .github/workflows/gemini-lifecycle-manager.yml
    • .github/workflows/gemini-scheduled-issue-dedup.yml
    • .github/workflows/gemini-scheduled-issue-triage.yml
    • .github/workflows/gemini-scheduled-pr-triage.yml
    • .github/workflows/gemini-self-assign-issue.yml
    • .github/workflows/issue-opened-labeler.yml
    • .github/workflows/label-backlog-child-issues.yml
    • .github/workflows/label-workstream-rollup.yml
    • .github/workflows/links.yml
    • .github/workflows/memory-nightly.yml
    • .github/workflows/perf-nightly.yml
    • .github/workflows/pr-rate-limiter.yaml
    • .github/workflows/pr-size-labeler-batch-run.yml
    • .github/workflows/pr-size-labeler.yml
    • .github/workflows/release-change-tags.yml
    • .github/workflows/release-manual.yml
    • .github/workflows/release-nightly.yml
    • .github/workflows/release-notes.yml
    • .github/workflows/release-patch-0-from-comment.yml
    • .github/workflows/release-patch-1-create-pr.yml
    • .github/workflows/release-patch-2-trigger.yml
    • .github/workflows/release-patch-3-release.yml
    • .github/workflows/release-promote.yml
    • .github/workflows/release-rollback.yml
    • .github/workflows/release-sandbox.yml
    • .github/workflows/smoke-test.yml
    • .github/workflows/test-build-binary.yml
    • .github/workflows/trigger_e2e.yml
    • .github/workflows/unassign-inactive-assignees.yml
    • .github/workflows/verify-release.yml
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 the 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 counterproductive. 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.

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.

@github-actions

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@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 unexpectedly deletes a vast number of critical configuration, workflow, and documentation files—including .gitignore, CODEOWNERS, Dockerfile, and README.md—while completely omitting the intended code changes. The reviewer correctly flagged these deletions as critical issues that break repository governance, security, and deployment capabilities. Please verify your branch to ensure you did not accidentally delete these core files.

Comment thread README.md
@@ -1,412 +0,0 @@
# Gemini CLI

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.

critical

This pull request deletes the README.md file along with numerous other critical configuration, workflow, and documentation files, while completely omitting the changes to packages/core/src/prompts/snippets.ts described in the PR title and description. Please verify your branch and ensure you are not accidentally deleting the repository's core files.

Comment thread .gitignore
@@ -1,70 +0,0 @@
# API keys and secrets

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.

critical

Deleting the .gitignore file is highly critical as it can lead to sensitive files, API keys, or build artifacts being accidentally committed to the repository.

Comment thread .github/CODEOWNERS
@@ -1,22 +0,0 @@
# By default, require reviews from the maintainers for all files.

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.

critical

Deleting the CODEOWNERS file removes the repository's branch protection and review routing rules, which is a critical security and governance risk.

Comment thread Dockerfile
@@ -1,94 +0,0 @@
# ---- Stage 1: Builder ----

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.

critical

Deleting the main Dockerfile prevents the creation of the application's container images, which breaks the deployment and sandboxing capabilities of the CLI.

@Suryap-hub

Copy link
Copy Markdown
Author

The size/XL label is incorrect — this PR only modifies 1 line in
snippets.ts. The large diff is due to untracked files being
included in the commit. I will fix this in a follow-up push.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. size/xl An extra large PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gemini-3.1-pro-preview continues to have similar bug

1 participant