Skip to content

Conversation

@circlepen
Copy link

Summary

If the session turns exceed threshold or detect a new topic, ask user to compress or start new session.

Details

Add new config variable renewSessionTurnsThreshold.
If session turns exceed the threshold, pop up a dialog, let user choose to compress conversation
or start a new session.

TODO: Add detection for user query, if the new query is in different topic to previous ones, then pop up a dialog
to let user choose to compress conversation or start a new session.

Related Issues

How to Validate

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

Add new config variable renewSessionTurnsThreshold.
If session turns exceed the threshold, pop up a dialog,
let user choose to compress conversation or start a new session.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @circlepen, 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 CLI's conversational experience by introducing a mechanism to manage long-running sessions. It adds a configurable threshold for conversation turns, after which users are prompted with a dialog to either compress their current chat or begin a new one. This helps maintain context and prevent conversations from becoming unwieldy, improving overall usability and efficiency.

Highlights

  • New Configuration Option: Introduced a new configuration variable, model.renewSessionTurnsThreshold, which allows users to define the maximum number of conversation turns before being prompted to manage their session. Setting it to -1 disables the feature.
  • Session Management Dialog: A new UI dialog, RenewSessionDialog, will now pop up in the CLI when the session turn threshold is exceeded. This dialog offers users the choice to either compress the current conversation or start a new session.
  • Core Logic for Session Renewal: The core client logic has been updated to track session turn counts and emit a RenewSession event when the configured threshold is met, pausing the stream until user input is received from the dialog.
  • UI Integration: The useGeminiStream hook and DialogManager in the CLI have been updated to handle the new RenewSession event and display the appropriate dialog, integrating the user's choice back into the session flow.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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
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 new feature to prompt users when a session's turn count exceeds a configured threshold. The implementation is solid, but I've identified a couple of areas for improvement. There's a consistent naming convention violation for the new state variable RenewSessionConfirmationRequest, which should be camelCased for consistency with the rest of the codebase. Additionally, there's an opportunity to refactor the logic for resetting the session turn count to make it more explicit and robust. My detailed comments provide specific suggestions for these changes.

handleApprovalModeChange,
activePtyId,
loopDetectionConfirmationRequest,
RenewSessionConfirmationRequest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with other state variables and to follow React/JavaScript naming conventions, this should be renewSessionConfirmationRequest (camelCase).

Suggested change
RenewSessionConfirmationRequest,
renewSessionConfirmationRequest,

!!customDialog ||
confirmUpdateExtensionRequests.length > 0 ||
!!loopDetectionConfirmationRequest ||
!!RenewSessionConfirmationRequest ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency and adherence to naming conventions, this should be renewSessionConfirmationRequest.

Suggested change
!!RenewSessionConfirmationRequest ||
!!renewSessionConfirmationRequest ||

confirmationRequest,
confirmUpdateExtensionRequests,
loopDetectionConfirmationRequest,
RenewSessionConfirmationRequest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency and adherence to naming conventions, this should be renewSessionConfirmationRequest.

Suggested change
RenewSessionConfirmationRequest,
renewSessionConfirmationRequest,

Comment on lines +91 to +98
if (uiState.RenewSessionConfirmationRequest) {
return (
<RenewSessionDialog
maxSessionTurns={
settings.merged.model?.renewSessionTurnsThreshold ?? -1
}
onComplete={uiState.RenewSessionConfirmationRequest.onComplete}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency and adherence to naming conventions, RenewSessionConfirmationRequest should be renewSessionConfirmationRequest.

Suggested change
if (uiState.RenewSessionConfirmationRequest) {
return (
<RenewSessionDialog
maxSessionTurns={
settings.merged.model?.renewSessionTurnsThreshold ?? -1
}
onComplete={uiState.RenewSessionConfirmationRequest.onComplete}
/>
if (uiState.renewSessionConfirmationRequest) {
return (
<RenewSessionDialog
maxSessionTurns={
settings.merged.model?.renewSessionTurnsThreshold ?? -1
}
onComplete={uiState.renewSessionConfirmationRequest.onComplete}
/>

confirmationRequest: ConfirmationRequest | null;
confirmUpdateExtensionRequests: ConfirmationRequest[];
loopDetectionConfirmationRequest: LoopDetectionConfirmationRequest | null;
RenewSessionConfirmationRequest: RenewSessionConfirmationRequest | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with other properties in this interface and to follow TypeScript/JavaScript naming conventions, this property should be named renewSessionConfirmationRequest (camelCase).

Suggested change
RenewSessionConfirmationRequest: RenewSessionConfirmationRequest | null;
renewSessionConfirmationRequest: RenewSessionConfirmationRequest | null;

Comment on lines +215 to +220
const [RenewSessionConfirmationRequest, setRenewSessionConfirmationRequest] =
useState<{
onComplete: (result: {
userSelection: 'compress_session' | 'new_session';
}) => void;
} | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

React state variables should follow camelCase naming conventions for consistency with the rest of the codebase (e.g., loopDetectionConfirmationRequest). Please rename RenewSessionConfirmationRequest to renewSessionConfirmationRequest.

Suggested change
const [RenewSessionConfirmationRequest, setRenewSessionConfirmationRequest] =
useState<{
onComplete: (result: {
userSelection: 'compress_session' | 'new_session';
}) => void;
} | null>(null);
const [renewSessionConfirmationRequest, setRenewSessionConfirmationRequest] =
useState<{
onComplete: (result: {
userSelection: 'compress_session' | 'new_session';
}) => void;
} | null>(null);

Comment on lines +753 to +783
const handleRenewSessionEvent = useCallback((): void => {
if (RenewSessionConfirmationRequest) {
return;
}

if (pendingHistoryItemRef.current) {
addItem(pendingHistoryItemRef.current, Date.now());
setPendingHistoryItem(null);
}
geminiClient.resetSessionTurnCount();

setRenewSessionConfirmationRequest({
onComplete: (result: {
userSelection: 'compress_session' | 'new_session';
}) => {
setRenewSessionConfirmationRequest(null);

if (result.userSelection === 'compress_session') {
void handleSlashCommandRef.current('/compress');
} else if (result.userSelection === 'new_session') {
void handleSlashCommandRef.current('/clear');
}
},
});
}, [
addItem,
geminiClient,
RenewSessionConfirmationRequest,
pendingHistoryItemRef,
setPendingHistoryItem,
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a couple of improvements that can be made here:

  1. Naming Convention: The state variable RenewSessionConfirmationRequest should be renamed to renewSessionConfirmationRequest to follow camelCase conventions and for consistency with other similar variables in the codebase.
  2. Logic Correction: The call to geminiClient.resetSessionTurnCount() should be moved inside the onComplete handler. Resetting the turn count should be a direct consequence of the user's action. Specifically, it should be tied to the compress_session action, as the /clear command (for new_session) already handles resetting the turn count. This makes the logic clearer and more robust.

The suggested code applies these changes.

  const handleRenewSessionEvent = useCallback((): void => {
    if (renewSessionConfirmationRequest) {
      return;
    }

    if (pendingHistoryItemRef.current) {
      addItem(pendingHistoryItemRef.current, Date.now());
      setPendingHistoryItem(null);
    }

    setRenewSessionConfirmationRequest({
      onComplete: (result: {
        userSelection: 'compress_session' | 'new_session';
      }) => {
        setRenewSessionConfirmationRequest(null);

        if (result.userSelection === 'compress_session') {
          geminiClient.resetSessionTurnCount();
          void handleSlashCommandRef.current('/compress');
        } else if (result.userSelection === 'new_session') {
          void handleSlashCommandRef.current('/clear');
        }
      },
    });
  }, [
    addItem,
    geminiClient,
    renewSessionConfirmationRequest,
    pendingHistoryItemRef,
    setPendingHistoryItem,
  ]);

handleApprovalModeChange,
activePtyId,
loopDetectionConfirmationRequest,
RenewSessionConfirmationRequest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency and adherence to naming conventions, this should be renewSessionConfirmationRequest.

Suggested change
RenewSessionConfirmationRequest,
renewSessionConfirmationRequest,

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.

1 participant