Skip to content

fix: show available sessions for invalid --resume identifiers#21797

Closed
sonwr wants to merge 1 commit intogoogle-gemini:mainfrom
sonwr:fix/resume-invalid-session-feedback
Closed

fix: show available sessions for invalid --resume identifiers#21797
sonwr wants to merge 1 commit intogoogle-gemini:mainfrom
sonwr:fix/resume-invalid-session-feedback

Conversation

@sonwr
Copy link
Copy Markdown

@sonwr sonwr commented Mar 10, 2026

When gemini --resume <id> receives an invalid identifier, the CLI already has the matching project sessions in memory but only tells the user to run --list-sessions.

This change includes a compact list of available sessions directly in the error output so the user can immediately retry with a valid index or UUID.

What changed

  • pass available sessions into the invalid resume SessionError
  • include a compact session summary in the error message
  • limit inline output to 10 sessions and point users to --list-sessions for the full list
  • add tests for inline session summaries and truncation behavior

Testing

  • npx vitest run packages/cli/src/utils/sessionUtils.test.ts packages/cli/src/gemini.test.tsx

Fixes #21764

@sonwr sonwr requested a review from a team as a code owner March 10, 2026 00:47
@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 significantly improves the user experience of the gemini CLI tool by providing immediate, actionable feedback when an invalid session identifier is used with the --resume command. Instead of simply stating the identifier is invalid and suggesting --list-sessions, the error message now directly presents a concise list of available sessions, allowing users to quickly correct their input without an extra step.

Highlights

  • Enhanced Error Messaging: The gemini --resume command now provides a compact list of available sessions directly within the error message when an invalid session identifier is used, improving user guidance.
  • Session List Truncation: Implemented logic to limit the inline display of available sessions to a maximum of 10, with a clear prompt to use --list-sessions for the complete list.
  • New Utility Function: A new helper function, formatAvailableSessions, was added to format and manage the display of session summaries within error messages.
  • Comprehensive Testing: New unit tests were introduced to verify the correct behavior of the enhanced error messages, including the display of session summaries and the truncation mechanism.
Changelog
  • packages/cli/src/utils/sessionUtils.test.ts
    • Added a second session to existing test data to verify multiple sessions are displayed.
    • Updated the invalid-uuid test to assert the presence of the new session summary in the error message.
    • Introduced a new test case to specifically verify the truncation logic for displaying a limited number of sessions.
  • packages/cli/src/utils/sessionUtils.ts
    • Modified the SessionError.invalidSessionIdentifier static method to accept an optional sessions array.
    • Updated the error message construction to dynamically include a formatted list of available sessions if provided.
    • Introduced MAX_SESSIONS_IN_INVALID_RESUME_MESSAGE constant to define the display limit.
    • Added a new private helper function formatAvailableSessions to generate the compact session summary string, including truncation logic.
    • Updated the SessionSelector.resolveSession method to pass the sortedSessions to the invalidSessionIdentifier error.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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
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 helpful usability improvement by showing available sessions on an invalid --resume identifier. The implementation is clean and well-tested. I've identified a minor bug where the error message can show duplicated text when the session list is truncated, and I've provided suggestions to fix this in both the implementation and the corresponding test.


if (sessions.length > visibleSessions.length) {
lines.push(
` ...and ${sessions.length - visibleSessions.length} more. Run --list-sessions to see the full list.`,
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

This line introduces a small bug where the error message can contain duplicated text. The phrase Run --list-sessions to see the full list. is added here, but it's also part of the main error message template in invalidSessionIdentifier. When the session list is truncated, the user will see this instruction twice.

To fix this, this line should only mention the count of remaining sessions. The instruction to run --list-sessions will still be present once in the final error message.

Suggested change
` ...and ${sessions.length - visibleSessions.length} more. Run --list-sessions to see the full list.`,
` ...and ${sessions.length - visibleSessions.length} more.`,
References
  1. Avoid displaying verbose validation descriptions directly to the user if they contain concatenated links or other unnecessary information. Instead, use a concise, generic message. This comment addresses duplicated text in an error message, making it more concise.

Comment on lines +425 to +427
expect((error as SessionError).message).toContain(
'...and 2 more. Run --list-sessions to see the full list.',
);
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

Following the suggested change to avoid duplicated text in the error message, this test assertion should be updated. Instead of checking for the combined sentence, it's better to check for the truncation message (...and 2 more.) and the general instruction (Run --list-sessions...) separately to ensure both are present and the output is correct.

Suggested change
expect((error as SessionError).message).toContain(
'...and 2 more. Run --list-sessions to see the full list.',
);
expect((error as SessionError).message).toContain('...and 2 more.');
expect((error as SessionError).message).toContain(
'Run --list-sessions to see the full list.',
);
References
  1. Avoid displaying verbose validation descriptions directly to the user if they contain concatenated links or other unnecessary information. Instead, use a concise, generic message. This test change reflects the application of this rule to the error message.

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Going to close this. The author of the original issue has a PR and they are the one assigned to the issue.

Will work on accepting their PR 👍

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.

Include available sessions in error when --resume gets invalid ID

2 participants