Skip to content

fix(plan): keep approved plan during chat compression#21284

Merged
abhipatel12 merged 1 commit intomainfrom
17796-plan-compression
Mar 6, 2026
Merged

fix(plan): keep approved plan during chat compression#21284
abhipatel12 merged 1 commit intomainfrom
17796-plan-compression

Conversation

@ruomengz
Copy link
Contributor

@ruomengz ruomengz commented Mar 5, 2026

Summary

This PR ensures that approved implementation plans are preserved during chat history compression. When the conversation history grows too large and needs to be distilled into a <state_snapshot>, the model is now explicitly instructed to keep the plan's file path, step completion status, and any relevant user feedback.

Details

  • Updated PromptProvider to retrieve and pass the approved plan path (if any) to the history compression prompt.
  • Modified both modern (snippets.ts) and legacy (snippets.legacy.ts) compression prompts to include a new ### APPROVED PLAN PRESERVATION section when a plan is active.
  • This prevents the agent from "forgetting" its current progress on a plan after a compression event, which previously led to redundant work or lost context on the overall goal.

Related Issues

Fixes #17796

How to Validate

  1. Start a session that generates an approved plan.
  2. Force or wait for history compression (simulated via tests).
  3. Verify that the compression prompt now includes the ### APPROVED PLAN PRESERVATION section.
  4. Run the new tests: npm test -w @google/gemini-cli-core -- src/prompts/promptProvider.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

@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 addresses a critical issue where the system would lose context of an approved implementation plan during chat history compression. By explicitly instructing the model to preserve plan details like file path, step completion, and user feedback, the agent can maintain its progress and avoid redoing work, significantly improving the continuity and efficiency of long-running tasks.

Highlights

  • Approved Plan Preservation: Ensured that approved implementation plans are explicitly preserved during chat history compression, preventing loss of context and redundant work.
  • PromptProvider Update: Modified the PromptProvider to retrieve and pass the approved plan's file path to the history compression prompt.
  • Compression Prompt Modification: Updated both modern and legacy compression prompts to include a dedicated '### APPROVED PLAN PRESERVATION' section when an active plan is present, instructing the model to retain critical plan details.
  • New Test Coverage: Added new unit tests to verify that plan preservation instructions are correctly included or excluded in the compression prompt based on the presence of an approved plan path, covering both modern and legacy model scenarios.
Changelog
  • packages/core/src/prompts/promptProvider.test.ts
    • Added new test suite for getCompressionPrompt to validate plan preservation logic.
    • Included tests to confirm plan preservation instructions are present when an approved plan path is provided.
    • Added tests to confirm plan preservation instructions are absent when no approved plan path is provided.
    • Verified correct behavior for legacy models regarding plan preservation in compression prompts.
  • packages/core/src/prompts/promptProvider.ts
    • Updated getCompressionPrompt to pass the result of config.getApprovedPlanPath() to the active snippets' getCompressionPrompt method.
  • packages/core/src/prompts/snippets.legacy.ts
    • Modified getCompressionPrompt to accept an optional approvedPlanPath parameter.
    • Implemented conditional logic to append an '### APPROVED PLAN PRESERVATION' section to the prompt if approvedPlanPath is provided, detailing what plan information to preserve.
  • packages/core/src/prompts/snippets.ts
    • Modified getCompressionPrompt to accept an optional approvedPlanPath parameter.
    • Implemented conditional logic to append an '### APPROVED PLAN PRESERVATION' section to the prompt if approvedPlanPath is provided, detailing what plan information to preserve.
Activity
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.

@ruomengz ruomengz requested a review from jerop March 5, 2026 17:15
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 implements a mechanism to preserve the state of an approved plan during chat history compression by modifying the prompt provider to pass the plan path and updating prompt snippets. However, a prompt injection vulnerability was identified in getCompressionPrompt in both snippets.ts and snippets.legacy.ts. The approvedPlanPath is directly interpolated into the prompt string without sanitization, which could allow manipulation of the LLM's behavior if a malicious path is provided. It is recommended to properly escape or quote the path, or use returnDisplay if the path is for display purposes, to prevent such injections.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Size Change: +474 B (0%)

Total Size: 26 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.5 MB +474 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 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-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 5, 2026
@ruomengz ruomengz force-pushed the 17796-plan-compression branch from 15867e6 to 8286e27 Compare March 5, 2026 18:55
@ruomengz ruomengz requested a review from a team as a code owner March 5, 2026 18:55
@ruomengz ruomengz force-pushed the 17796-plan-compression branch from 8286e27 to 731da3e Compare March 5, 2026 18:55
@ruomengz ruomengz force-pushed the 17796-plan-compression branch 2 times, most recently from a70d5d0 to f19058f Compare March 5, 2026 21:10
@ruomengz ruomengz force-pushed the 17796-plan-compression branch from f19058f to b25627b Compare March 5, 2026 21:12
Copy link
Contributor

@jerop jerop left a comment

Choose a reason for hiding this comment

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

lgtm to me, looping in IQ workstream

@jerop jerop requested review from abhipatel12 and gundermanc March 5, 2026 21:35
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, thanks for adding!

@abhipatel12 abhipatel12 added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 06a176e Mar 6, 2026
27 checks passed
@abhipatel12 abhipatel12 deleted the 17796-plan-compression branch March 6, 2026 19:51
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 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 area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle plan awareness during chat compression

4 participants