Skip to content

Comments

fix(cli): filter subagent sessions from resume history#19698

Merged
abhipatel12 merged 2 commits intomainfrom
abhi/subagent-history
Feb 21, 2026
Merged

fix(cli): filter subagent sessions from resume history#19698
abhipatel12 merged 2 commits intomainfrom
abhi/subagent-history

Conversation

@abhipatel12
Copy link
Collaborator

Summary

Prevent subagent session histories from being surfaced in the /resume list by marking them as subagent sessions and filtering them out during session retrieval. This ensures the session browser remains clean and only shows main conversations that users actually want to resume.

Details

  • Session Classification: Introduced a kind field ('main' | 'subagent') to the ConversationRecord interface in packages/core.
  • Persistence: Updated ChatRecordingService to persist this field in the session JSON files.
  • Subagent Marking: Updated LocalAgentExecutor to mark its internal GeminiChat sessions as 'subagent'.
  • CLI Filtering: Enhanced the CLI's sessionUtils.ts to filter out any session marked as 'subagent'.
  • Backward Compatibility: Ensured that sessions without a kind field (legacy sessions) are treated as 'main'.
  • Testing: Added unit tests in both core and cli to verify classification and filtering logic.

Related Issues

Related to the reported bug where internal subagent sessions were appearing in the resumable sessions list.

How to Validate

  1. Run a command that uses a subagent (e.g., cli_help by asking "how do I use hooks?").
  2. Check the session list using the /resume command or gemini --list-sessions.
  3. Verify that the subagent session is not listed.
  4. Verify that the main session is still listed and resumable.
  5. Run unit tests to ensure no regressions:
    • npm test -w @google/gemini-cli-core -- src/services/chatRecordingService.test.ts
    • npm test -w @google/gemini-cli -- src/utils/sessionUtils.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

@abhipatel12 abhipatel12 requested a review from a team as a code owner February 20, 2026 20:05
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, 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 an issue where internal subagent sessions were appearing in the user's resumable session list. It introduces a new 'kind' field to classify sessions as either 'main' or 'subagent', ensuring that only main conversations are displayed in the /resume command and session browser, thereby improving the user experience by keeping the session history clean and relevant.

Highlights

  • Session Classification: Introduced a 'kind' field ('main' | 'subagent') to the ConversationRecord interface to differentiate between main user conversations and internal subagent operations.
  • Persistence: Updated the ChatRecordingService to correctly persist the new 'kind' field within session JSON files.
  • Subagent Marking: Modified LocalAgentExecutor to explicitly mark its internal GeminiChat sessions as 'subagent', preventing them from being surfaced to the user.
  • CLI Filtering: Enhanced the CLI's session utility functions to filter out and exclude any sessions identified as 'subagent' from the /resume list.
  • Backward Compatibility: Ensured that existing legacy sessions without a 'kind' field are automatically treated as 'main' sessions for seamless integration.
  • Improved Error Handling: Standardized error message formatting in LocalAgentExecutor tests and implementation using getErrorMessage.
  • Comprehensive Testing: Added new unit tests in both core and cli packages to validate the correct classification and filtering logic for sessions.
Changelog
  • packages/cli/src/utils/sessionUtils.test.ts
    • Added a new test case to verify that sessions explicitly marked as 'subagent' are correctly excluded from the listed sessions.
  • packages/cli/src/utils/sessionUtils.ts
    • Implemented a check within getAllSessionFiles to filter out and return null for any ConversationRecord where the kind property is 'subagent'.
  • packages/core/src/agents/local-executor.test.ts
    • Updated error message assertions to use getErrorMessage for consistent error handling.
    • Imported getErrorMessage utility.
  • packages/core/src/agents/local-executor.ts
    • Imported getErrorMessage for standardized error reporting.
    • Modified the GeminiChat constructor call to pass 'subagent' as the kind for internal agent chats.
    • Removed redundant LlmRole import.
  • packages/core/src/core/geminiChat.ts
    • Added a kind parameter to the GeminiChat constructor, defaulting to 'main'.
    • Passed the kind parameter to the ChatRecordingService.initialize method.
  • packages/core/src/services/chatRecordingService.test.ts
    • Added a test to confirm that the kind property is correctly recorded in the session file when specified during initialization.
  • packages/core/src/services/chatRecordingService.ts
    • Extended the ConversationRecord interface with an optional kind property ('main' | 'subagent').
    • Added a private kind property to the ChatRecordingService class.
    • Updated the initialize method to accept and store the kind parameter, also ensuring it's loaded when resuming a session.
    • Included the kind property when creating new ConversationRecord objects.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request since its creation.
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 Feb 20, 2026

Size Change: +543 B (0%)

Total Size: 25.2 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +543 B (0%)
./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

The pull request successfully implements a mechanism to filter subagent sessions from the resume history in the CLI. By introducing a kind field to the ConversationRecord and ensuring it is persisted and checked during session retrieval, the user experience is improved by keeping the session list focused on main conversations. The changes are well-integrated across the core and cli packages, and the inclusion of unit tests ensures both the new functionality and backward compatibility for legacy sessions.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 20, 2026
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 20, 2026
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 21, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 21, 2026
Mark recorded chat sessions as either 'main' or 'subagent' using a new 'kind' field in the session JSON. Updated LocalAgentExecutor to mark subagent sessions explicitly and enhanced the CLI's session discovery to skip them. Added tests to verify classification and filtering.
@abhipatel12 abhipatel12 force-pushed the abhi/subagent-history branch from 74042da to 9d144b7 Compare February 21, 2026 17:25
@abhipatel12 abhipatel12 force-pushed the abhi/subagent-history branch from 9d144b7 to 315fda8 Compare February 21, 2026 17:31
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 21, 2026
Merged via the queue into main with commit d2d345f Feb 21, 2026
27 checks passed
@abhipatel12 abhipatel12 deleted the abhi/subagent-history branch February 21, 2026 17:52
SH20RAJ added a commit to SH20RAJ/gemini-cli that referenced this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants