Skip to content

fix(cli): gracefully handle --resume when no sessions exist#21429

Merged
SandyTao520 merged 2 commits intomainfrom
fix/resume-no-sessions-graceful-fallback
Mar 6, 2026
Merged

fix(cli): gracefully handle --resume when no sessions exist#21429
SandyTao520 merged 2 commits intomainfrom
fix/resume-no-sessions-graceful-fallback

Conversation

@SandyTao520
Copy link
Contributor

Summary

Running gemini -r (or --resume) in a directory with no previous sessions crashes with Error resuming session: No previous sessions found for this project. and exits with a fatal error code. This PR makes it gracefully fall back to starting a fresh session and displays the message as a startup warning in the UI instead.

Details

  • SessionSelector.resolveSession() was throwing a generic Error when no sessions existed. Changed it to use the existing SessionError.noSessionsFound() factory, which returns a typed SessionError with code NO_SESSIONS_FOUND.
  • In gemini.tsx, the --resume error handler now checks for SessionError with NO_SESSIONS_FOUND specifically: instead of calling process.exit(), it pushes a high-priority startup warning and continues with a fresh session. All other session errors (invalid ID, corrupt session, etc.) still exit as before.

Related Issues

How to Validate

  1. Navigate to a directory with no previous Gemini CLI sessions
  2. Run gemini -r
  3. Before: CLI crashes with an error and exits
  4. After: CLI starts a fresh session and shows a warning: "No previous sessions found for this project."

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

Instead of crashing with process.exit() when using -r/--resume in a
directory with no previous sessions, fall back to a normal fresh session
and display a startup warning in the UI.

- Use SessionError.noSessionsFound() in resolveSession() instead of a
  generic Error for proper error discrimination
- Catch NO_SESSIONS_FOUND specifically in gemini.tsx and push a startup
  warning instead of exiting
- Other session errors (invalid ID, etc.) still exit as before
@SandyTao520 SandyTao520 requested a review from a team as a code owner March 6, 2026 18:01
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Mar 6, 2026

Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@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 enhances the robustness and user experience of the Gemini CLI by improving how the --resume command operates. Previously, attempting to resume a non-existent session would cause the application to crash. The changes introduce a more graceful fallback mechanism, where the CLI now starts a fresh session and provides a clear warning to the user, ensuring a smoother workflow without abrupt terminations.

Highlights

  • Improved --resume command behavior: The gemini --resume command now gracefully handles cases where no previous sessions exist, preventing a crash and instead starting a new session with a warning.
  • Standardized session error handling: SessionSelector.resolveSession() now throws a specific SessionError.noSessionsFound() when no sessions are found, allowing for more granular error handling.
  • Enhanced error handling in gemini.tsx: The main gemini.tsx file was updated to specifically catch SessionError.noSessionsFound() and display a high-priority startup warning, while other session errors still result in an exit.
  • Added new test coverage: New tests were added to ensure the --resume command behaves as expected when no sessions are found, verifying it doesn't crash and emits the correct warning.
Changelog
  • packages/cli/src/gemini.test.tsx
    • Added a new test case should start normally with a warning when no sessions found for resume to verify the new behavior.
    • Modified the vi.mock call for sessionUtils.js to use importOriginal for better mocking practices.
  • packages/cli/src/gemini.tsx
    • Imported SessionError from sessionUtils.js.
    • Updated the try-catch block for resolveSession to specifically check for SessionError with code NO_SESSIONS_FOUND.
    • If NO_SESSIONS_FOUND error is caught, a high-priority startup warning is pushed, and the application continues.
    • Other SessionError types or generic errors still trigger an application exit.
  • packages/cli/src/utils/sessionUtils.test.ts
    • Added a new test case to ensure SessionSelector.resolveSession('latest') throws SessionError with NO_SESSIONS_FOUND when no sessions exist.
  • packages/cli/src/utils/sessionUtils.ts
    • Changed the error thrown in resolveSession from a generic Error('No previous sessions found for this project.') to SessionError.noSessionsFound() when sessions.length is zero.
Activity
  • No specific activity (comments, reviews, 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.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Size Change: -171 B (0%)

Total Size: 26 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.5 MB -171 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

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 gracefully handles the case where --resume is used without any existing sessions, preventing a CLI crash. This is achieved by introducing a typed SessionError and specifically handling the NO_SESSIONS_FOUND case to show a warning and start a fresh session. The changes are well-implemented and include corresponding tests. I've identified a minor redundancy in one of the new tests that could be improved for better maintainability.

Address PR review feedback by consolidating two separate resolveSession
calls into a single rejects.toSatisfy() assertion.
@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Mar 6, 2026
@SandyTao520 SandyTao520 added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 42d367d Mar 6, 2026
27 checks passed
@SandyTao520 SandyTao520 deleted the fix/resume-no-sessions-graceful-fallback branch March 6, 2026 19:15
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

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants