Skip to content

fix(session): include available sessions in --resume error for invalid identifier#1

Open
Zahed-Riyaz wants to merge 40 commits intomainfrom
invalid-sessions
Open

fix(session): include available sessions in --resume error for invalid identifier#1
Zahed-Riyaz wants to merge 40 commits intomainfrom
invalid-sessions

Conversation

@Zahed-Riyaz
Copy link
Owner

Summary

When --resume is given an identifier that doesn't match any session (e.g. --resume 99 when only 3 sessions exist, or a typo'd UUID), the CLI now prints a compact list of available sessions directly in the error output before exiting. Previously the user had to run a separate --list-sessions command to find valid identifiers.

Details

Before:

Error resuming session: Invalid session identifier "99".
  Use --list-sessions to see available sessions, then use --resume {number}, --resume {uuid}, or --resume latest.

After:

Error resuming session: Invalid session identifier "99".

Available sessions for this project:
  1. Fix bug in auth (2 days ago)
  2. Refactor database schema (5 hours ago)
  3. Update documentation (Just now)

Use --resume 1, --resume 2, --resume 3, or --resume latest.

Implementation:

  • Extended SessionError.invalidSessionIdentifier(identifier, sessions?) to accept an optional SessionInfo[]. When provided, it formats a compact inline summary (index, display name truncated to 60 chars, relative time) and emits valid --resume N hints.
  • SessionSelector.findSession() already has sortedSessions in scope when it throws — the only change needed there is passing it to the error factory.
  • Output is capped at 10 entries; if more exist, a Run --list-sessions for the full list. note is appended.
  • Callers that don't pass sessions (e.g. generic error paths) continue to receive the original fallback message — no breaking change.

Related Issues

Related to google-gemini#21429 (follow-up: this PR addresses the UX gap left open after that fix).

How to Validate

  1. Start the CLI in a project directory that has at least one session (gemini then exit).
  2. Run gemini --resume 99 (or any out-of-range number). Verify the error output lists available sessions with indices and relative times, and ends with valid --resume N hints — without needing a separate --list-sessions invocation.
  3. Run gemini --resume not-a-real-uuid. Confirm the same inline list appears.
  4. Run gemini --resume (no value) in a directory with sessions — should still resolve to latest as before (no change to that path).
  5. Run gemini --resume latest in an empty project — should still start a fresh session with a warning (no change to that path).
  6. Run gemini --list-sessions — output and behavior unchanged.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) — no doc changes required; behavior is self-describing
  • Added/updated tests (if needed) — added 8 new tests in sessionUtils.test.ts covering unit-level formatting and integration via SessionSelector.findSession
  • Noted breaking changes (if any) — none; sessions parameter is optional, all existing call sites unaffected
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

ame2en and others added 14 commits March 9, 2026 20:13
Co-authored-by: Sam Roberts <158088236+g-samroberts@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
….md (google-gemini#20679)

Co-authored-by: Sam Roberts <158088236+g-samroberts@users.noreply.github.com>
…mini#20689)

Co-authored-by: Chris Williams <chrisjwilliams@google.com>
Co-authored-by: Chris Williams <diodesign@gmail.com>
Co-authored-by: Sam Roberts <158088236+g-samroberts@users.noreply.github.com>
Zahed-Riyaz and others added 15 commits March 10, 2026 06:51
Replace .length/.slice() with grapheme-aware cpLen/cpSlice from
textUtils to avoid splitting multi-byte characters (e.g. emojis) when
truncating session display names in the --resume error message.

Adds a test case with emoji-only display names to cover this path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.