-
Notifications
You must be signed in to change notification settings - Fork 14.5k
fix(cli): prevent duplicate SessionStart systemMessage render #25827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jacob314
merged 2 commits into
google-gemini:main
from
dimssu:fix/issue-25655-sessionstart-duplicate-systemmessage
May 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dimssu, I think there might be a small issue with removing that block.
The
outputFormat === 'json'check is specific to hook outputs, butresult.systemMessageinAppContainer.tsxcomes from a different flow (likeSessionStartEvent) and isn’t necessarily tied to hook-based JSON output.Because of that, relying only on the
HookSystemMessagelistener might miss some cases wheresystemMessageis set directly onresult. The previous logic ensured those messages were added to history regardless of hooks.This hook-based handling is here (which explains part of the behavior), and I can also see it being rendered after that:
hookEventHandler.ts (L462–L469)
So removing this could lead to some system messages not being shown. Maybe we should verify whether all
systemMessagecases are indeed covered by the hook event before removing it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, you're right. I traced it: plain-text hook outputs go through
convertPlainTextToHookOutputin hookRunner.ts, which does setsystemMessage, but the emit in hookEventHandler.ts:463 is gated byoutputFormat === 'json', so those never reach the listener. My patch would silently drop them.Side note while I was digging: BeforeAgent/BeforeTool plain-text hooks already don't render their systemMessage anywhere (no direct-render path for those either), so the same latent gap exists for them today.
My thinking: drop the
outputFormat === 'json'check in hookEventHandler so the event bus carries both formats. Then the AppContainer removal stays clean, and BeforeAgent/BeforeTool also start surfacing text-hook messages consistently — covers this bug without leaving the adjacent one. Let me know if that sounds reasonable or if you'd rather keep it narrower.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address this and then I will approve. Would also encourage you to get Gemini to write some tests to help verify we aren't missing cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jacob314. Just pushed the fix (force-pushed onto the same branch — head is now
cb65b25ac).On the approach: dropped the
outputFormat === 'json'gate inhookEventHandler.tsso theHookSystemMessageevent fires for both JSON and plain-text hooks. That way the AppContainer direct-render removal no longer regresses plain-text SessionStart hooks, and as a side effect plain-text BeforeAgent / BeforeTool hooks also start surfacing their messages (they silently dropped before).On tests: added three cases in
hookEventHandler.test.tsunder a newsystemMessage event emissionblock — JSON-format emission, text-format emission, and the no-systemMessage no-op. The existingAppContainer.test.tsxcase that guards the direct-render path from coming back is still there. Also re-ran the PTY repro locally for both a JSON hook and a plain-text hook; both render exactly once now.Happy to add more coverage if there's a specific case you'd like me to pin down.