Skip to content

fix: systemMessage visibility in interactive mode#23395

Open
dpavlin wants to merge 1 commit intogoogle-gemini:mainfrom
dpavlin:fix/system-message-visibility
Open

fix: systemMessage visibility in interactive mode#23395
dpavlin wants to merge 1 commit intogoogle-gemini:mainfrom
dpavlin:fix/system-message-visibility

Conversation

@dpavlin
Copy link

@dpavlin dpavlin commented Mar 21, 2026

Description

Currently, systemMessage notifications returned by hooks (BeforeAgent and AfterAgent) are only rendered by the Gemini CLI terminal if the hook returns decision: 'deny'. For all other hook results (e.g., adding additionalContext), any provided systemMessage is silently ignored by the client and never reaches the UI.

This PR introduces a first-class GeminiEventType.SystemMessage to the protocol, ensuring that these notifications are yielded by the GeminiClient and rendered dynamically in the terminal UI during an active turn.

Fixes #23427

Changes

packages/core

  • Protocol: Added GeminiEventType.SystemMessage to the ServerGeminiStreamEvent union.
  • Client: Updated GeminiClient to yield a SystemMessage event whenever a hook fires and returns a systemMessage, regardless of whether the execution is blocked.
  • Tests: Added comprehensive unit tests in client.test.ts to verify event yielding for both BeforeAgent and AfterAgent.

packages/cli

  • UI State: Introduced pendingSystemMessages state in useGeminiStream to track notifications during an active turn.
  • Rendering: Updated the pendingHistoryItems logic to include these messages, allowing them to render live above the Thinking block or model response.
  • Persistence: Ensured that pending system messages are committed to the permanent history once the turn completes.
  • Non-Interactive: Updated the headless CLI mode to output these messages to stderr with an [INFO] prefix.
  • Tests: Added UI unit tests in useGeminiStream.test.tsx to verify correct handling and display of the new event type.

@dpavlin dpavlin force-pushed the fix/system-message-visibility branch from 1eb11e7 to 7fa39be Compare March 21, 2026 16:50
@dpavlin dpavlin marked this pull request as ready for review March 21, 2026 16:59
@dpavlin dpavlin requested a review from a team as a code owner March 21, 2026 16:59
@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 addresses a critical visibility issue where system messages generated by agent hooks ('BeforeAgent' and 'AfterAgent') were often ignored by the client and not displayed in the user interface. By introducing a first-class 'GeminiEventType.SystemMessage' and updating both the core client and the CLI, these important notifications are now consistently yielded and rendered in real-time, significantly improving the user experience by providing immediate feedback on agent activities. This ensures that users are informed about background processes, such as prompt expansions, as they happen.

Highlights

  • Enhanced System Message Visibility: Introduced a dedicated 'GeminiEventType.SystemMessage' to ensure system messages from hooks are always rendered in the UI, not just when execution is denied.
  • Real-time UI Updates: Modified the CLI's interactive mode to dynamically display 'systemMessage' notifications above the 'Thinking' block or model response, providing immediate user feedback.
  • Non-Interactive CLI Output: Configured the headless CLI to output 'systemMessage' events to 'stderr' with an '[INFO]' prefix, maintaining visibility in non-interactive environments.
  • Improved Hook Integration: Updated the 'GeminiClient' to consistently yield 'SystemMessage' events from 'BeforeAgent' and 'AfterAgent' hooks, regardless of their decision.
  • Comprehensive Testing: Added new unit tests for both the core client and the CLI's UI stream handling to validate the new 'SystemMessage' event flow.
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.

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 effectively addresses the visibility of systemMessage from hooks by introducing a dedicated SystemMessage event type. The changes are well-implemented across the core client and the CLI's interactive UI, ensuring these messages are now rendered dynamically. The addition of comprehensive unit tests for both the client and UI hooks is a great way to verify the new behavior. I have one suggestion for the non-interactive CLI mode to improve consistency.

Note: Security Review did not run due to the size of the PR.

@gemini-cli gemini-cli bot added status/need-issue Pull requests that need to have an associated issue. area/core Issues related to User Interface, OS Support, Core Functionality and removed status/need-issue Pull requests that need to have an associated issue. labels Mar 21, 2026
@dpavlin dpavlin force-pushed the fix/system-message-visibility branch from 0d8e258 to 8898e07 Compare March 22, 2026 08:54
@dpavlin dpavlin force-pushed the fix/system-message-visibility branch from 8898e07 to 1d0528b Compare March 22, 2026 09:13
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: systemMessage from hooks is suppressed in interactive mode unless turn is blocked

1 participant