Skip to content

feat(cli): prompt to resume session when first prompt matches history#24720

Closed
JayadityaGit wants to merge 1 commit intogoogle-gemini:mainfrom
JayadityaGit:feature/session-resume-prompt
Closed

feat(cli): prompt to resume session when first prompt matches history#24720
JayadityaGit wants to merge 1 commit intogoogle-gemini:mainfrom
JayadityaGit:feature/session-resume-prompt

Conversation

@JayadityaGit
Copy link
Copy Markdown
Contributor

@JayadityaGit JayadityaGit commented Apr 5, 2026

Screenshot from 2026-04-06 01-24-29

Summary

This PR adds a session resume prompt when the user's first prompt in a new session matches the first prompt of a previous historical session. This improves the user experience by proactively offering to resume ongoing conversations.

Details

  • Intercepts the very first prompt in AppContainer.tsx.
  • Scans ~/.gemini/tmp/chats for sessions where the first user message exactly matches the current input.
  • Displays a new interactive dialog SessionResumePromptDialog allowing the user to choose between resuming the old session or starting a new one.
  • Updated dialogsVisible to correctly manage UI state during the prompt.

Related Issues

Closes #24719

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:
    • Linux
      • npm run

@JayadityaGit JayadityaGit requested a review from a team as a code owner April 5, 2026 19:56
@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 enhances the user experience by proactively identifying when a new session's initial prompt duplicates the start of a previous conversation. By intercepting the first submission, the application now offers users a seamless way to resume historical sessions, reducing friction and improving workflow continuity.

Highlights

  • Session Resume Prompt: Introduced an interactive dialog that appears when a user's first prompt in a new session matches the first message of a previous session, allowing them to resume or start fresh.
  • UI State Management: Updated UI state and action contexts to handle the new session resume request flow, including the addition of the SessionResumePromptDialog component.
  • AppContainer Integration: Modified AppContainer.tsx to intercept the initial prompt submission, scan historical session files, and trigger the resume dialog when a match is detected.
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.

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.

@JayadityaGit JayadityaGit marked this pull request as draft April 5, 2026 19:57
@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Apr 5, 2026
Copy link
Copy Markdown
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 a session resume prompt that appears when a user's first message in a new session matches the first message of an existing session. The implementation includes state management in UIStateContext, a new SessionResumePromptDialog component, and logic in AppContainer to intercept submissions and check for matches. Feedback was provided regarding the matching logic: the cleanMessage utility should be used to ensure consistent comparison between raw input and sanitized session data, and findLast should be used to prioritize the most recent matching session over older ones.

import { registerCleanup, runExitCleanup } from '../utils/cleanup.js';
import { relaunchApp } from '../utils/processUtils.js';
import type { SessionInfo } from '../utils/sessionUtils.js';
import { type SessionInfo, getSessionFiles } from '../utils/sessionUtils.js';
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.

high

The cleanMessage utility is required to correctly compare the user's input with the stored session messages, as the latter are sanitized before being saved. Please add it to the imports from sessionUtils.js.

Suggested change
import { type SessionInfo, getSessionFiles } from '../utils/sessionUtils.js';
import { type SessionInfo, getSessionFiles, cleanMessage } from '../utils/sessionUtils.js';
References
  1. Always treat user-provided data as untrusted and apply proper validation and sanitization at the point of use, even if it is believed to have been filtered or sanitized upstream.

Comment on lines +1365 to +1367
const matchingSession = sessions.find(
(s) => s.firstUserMessage === trimmed && !s.isCurrentSession,
);
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.

high

There are two issues with the current matching logic:

  1. Matching Accuracy: The firstUserMessage in SessionInfo is processed using cleanMessage (which collapses whitespace and removes non-printable characters). Comparing it directly against trimmed will fail if the user's input contains multiple spaces or newlines. You should apply cleanMessage to the input before comparison.
  2. Match Priority: sessions.find returns the first match found. Since getSessionFiles returns sessions sorted by startTime ascending (oldest first), this will match the oldest session. Users typically expect to resume the most recent relevant conversation. Using findLast ensures the most recent matching session is prioritized.

Note: findLast is supported in Node.js 20+.

            const cleaned = cleanMessage(submittedValue);
            const matchingSession = sessions.findLast(
              (s) => s.firstUserMessage === cleaned && !s.isCurrentSession,
            );
References
  1. Always treat user-provided data as untrusted and apply proper validation and sanitization at the point of use, even if it is believed to have been filtered or sanitized upstream.
  2. When selecting an item from a list where simple IDs may not be unique, use a guaranteed unique identifier, such as an index or a composite key, to avoid ambiguity when retrieving the selected item with methods like Array.prototype.find().

@JayadityaGit
Copy link
Copy Markdown
Contributor Author

JayadityaGit commented Apr 5, 2026

This is a feature where FOR THE VERY FIRST PROMPT of a NEW SESSION if the user prompts the same old prompt which is corresponding to the previous sessions then there will be a dialog which asks the user either to resume or start new again

Usually to resume a session we need to use /chat

But there are three main possibilties the user prompts their first prompt matching the old previous session (which at present starts as new request)

  1. using up and down arrow keys which gives previous prompts

  2. using CTRL+R which gives list of previous prompts

  3. or literally typed a prompt which matches exactly with the previous saved session

Remember this interception check only happens with the very FIRST PROMPT of a new session (VERY IMPORTANT)

I feel like this is going to upgrade the "resume previous session feature (/chat)" which save time and also save costs.

As of now i am marking this as draft i will work on this further if the communtiy shows interest.

@jacob314 (tagging for visibility)

@JayadityaGit JayadityaGit changed the title feat: prompt to resume session when first prompt matches history feat(cli): prompt to resume session when first prompt matches history Apr 6, 2026
@JayadityaGit
Copy link
Copy Markdown
Contributor Author

JayadityaGit commented Apr 11, 2026

Closing it because thoughts from @scidomino really had an impact on my vision in a positive way 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: prompt to resume session when first prompt matches history

1 participant