fix(cli): prevent ghost text wrapping infinite loop at narrow widths - #29239
fix(cli): prevent ghost text wrapping infinite loop at narrow widths#29239Anurag-M1 wants to merge 1 commit into
Conversation
Fixes google-gemini#19985 When inputWidth is narrower than a single character's rendered width (e.g. wide CJK or emoji characters in narrow terminal widths), splitIndex remains 0 in getGhostTextLines and wordToProcess never shrinks, causing an infinite while loop that pegs CPU at 100% and freezes the prompt. Force-advance by at least one code point when splitIndex is 0 so the hard-split loop is guaranteed to terminate. Adds a regression unit test.
|
📊 PR Size: size/S
|
Summary of ChangesHello, 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 issue where the CLI input prompt would enter an infinite loop and freeze the terminal when rendering ghost text in extremely narrow widths. By forcing the string processing loop to advance even when a character's width exceeds the available space, the fix ensures stability in constrained terminal environments. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request fixes an infinite loop issue in InputPrompt.tsx that occurs when the inputWidth is narrower than a single codepoint (e.g., when dealing with wide characters). It introduces a guard to force-advance by one codepoint when splitIndex remains 0. Additionally, a regression test has been added in InputPrompt.test.tsx to verify this behavior and prevent future freezes. There are no review comments, so I have no feedback to provide.
Fixes #19985
Description
In
packages/cli/src/ui/components/InputPrompt.tsx,getGhostTextLinesattempts to wrap words using a while loop:When
inputWidthis narrower than a single character's rendered width (such as wide CJK or emoji characters with width 2 in narrow terminals whereinputWidth <= 1),splitIndexstays0. BecausewordToProcess = cpSlice(wordToProcess, splitIndex)fails to shrink, the loop spins indefinitely at 100% CPU and freezes the terminal prompt.Solution
Added a safeguard after the character width loop:
This guarantees that
wordToProcessshrinks by at least one code point per iteration, ensuring the hard-split loop always terminates.Testing
packages/cli/src/ui/components/InputPrompt.test.tsxunderdescribe('ghost text wrapping')verifying that rendering with narrowinputWidth = 1and wide character ghost text completes without hanging.InputPrompt.test.tsxpass cleanly.npm run typecheck --workspace @google/gemini-clipassed with 0 errors.eslintpassed with 0 warnings.