Skip to content

fix(cli): make useLogger follow the active session ID after /clear#27907

Open
i-anubhav-anand wants to merge 1 commit into
google-gemini:mainfrom
i-anubhav-anand:fix/27280-logger-stale-session-id
Open

fix(cli): make useLogger follow the active session ID after /clear#27907
i-anubhav-anand wants to merge 1 commit into
google-gemini:mainfrom
i-anubhav-anand:fix/27280-logger-stale-session-id

Conversation

@i-anubhav-anand

Copy link
Copy Markdown

Summary

Fixes #27280.

useLogger() builds the Logger from config.getSessionId(), but its effect dependency array is only [config]. /clear mints a new session ID on the same config object (resetNewSessionState), so the dependency never changes and the effect never re-runs. The logger keeps writing under the old session ID, so the log files disagree with the current chat session — misleading when debugging.

Fix

Read the session ID into a value and include it in the dependency array, so the logger is re-created with the new ID whenever the active session changes (after /clear, or any future session reset). Minimal change; the happy path (no session change) is unaffected.

Testing

  • Extended useLogger.test.tsx with a test that changes the session ID and re-renders, asserting the logger is re-created with the new ID. Verified it fails before this change (logger keeps the stale ID) and passes after.
  • npx vitest run src/ui/hooks/useLogger.test.tsx → 2 passed.
  • eslint (incl. react-hooks/exhaustive-deps) and npm run typecheck (packages/cli) clean.

useLogger() created the Logger from config.getSessionId() but its effect
depended only on [config]. /clear mints a new session ID on the same
config object, so the dependency never changed and the logger kept
writing under the old session ID — making logs disagree with the current
chat session and misleading when debugging.

Depend on the session ID value as well, so the logger is re-created with
the new ID whenever it changes.

Fixes google-gemini#27280
@i-anubhav-anand i-anubhav-anand requested a review from a team as a code owner June 14, 2026 11:41
@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 addresses a bug where the logger failed to track session changes after a /clear command. By explicitly capturing the session ID and adding it to the useEffect dependency array, the logger now correctly re-initializes whenever the active session ID changes, ensuring log consistency with the current chat session.

Highlights

  • Dependency Update: Updated the useEffect hook in useLogger to include the current session ID in its dependency array, ensuring the logger is re-initialized when the session changes.
  • Bug Fix: Resolved an issue where the logger would persist with a stale session ID after a /clear command because the previous dependency array only tracked the stable config object.
  • Test Coverage: Added a new test case to useLogger.test.tsx to verify that the logger correctly updates its session ID upon re-rendering after a session reset.
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 the 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 counterproductive. 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.

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 github-actions Bot added the size/s A small PR label Jun 14, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 38
  • Additions: +36
  • Deletions: -2
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the useLogger hook in packages/cli to extract and depend on the sessionId from the configuration object. This ensures that the logger is re-created when the session ID changes (such as after a /clear command), preventing logs from being written under a stale session ID. A corresponding unit test has been added to verify this behavior. I have no feedback to provide as there are no review comments.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality labels Jun 14, 2026
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 priority/p3 Backlog - a good idea but not currently a priority. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logger keeps stale session ID after /clear

1 participant