fix(cli): don't crash when an @-mention captures a non-path blob#25980
fix(cli): don't crash when an @-mention captures a non-path blob#25980ifitisit wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
The @-command regex in atCommandProcessor is greedy: pasting JSON-like content into the prompt (or a model hallucinating a tool call whose path argument got concatenated with source code) lets the regex capture a multi-kilobyte string. checkPermissions then fed that string straight into resolveToRealPath -> fs.realpathSync, which threw ENAMETOOLONG. The error escaped checkPermissions as an unhandled promise rejection, crashing the entire interactive session. Wrap the resolveToRealPath call in checkPermissions with a try/catch and skip the entry on failure. Permission gating is a pre-flight check, so "can't resolve a path" is the right signal to drop it; if the user really did mean a real file, downstream code will surface a clearer error than a crash. Add two regression tests on checkPermissions: - a single 8KB @-segment that triggers ENAMETOOLONG from realpathSync - a real @-mention alongside a giant pasted blob, asserting the real file still surfaces while the bogus mention is skipped The first test fails on main with the exact error reported in google-gemini#22029. Fixes google-gemini#22029 Refs google-gemini#25910, google-gemini#25923
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 stability issue where the CLI would crash due to an unhandled promise rejection when an @-mention incorrectly captured non-path content, such as a large JSON blob. By wrapping the path resolution process in a safety check, the application now gracefully skips invalid inputs instead of terminating the interactive session. 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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of the @-command processing by wrapping path resolution in a try-catch block. This prevents the CLI from crashing when the greedy regex captures long, non-path strings such as pasted JSON blobs, which previously triggered ENAMETOOLONG errors. Corresponding regression tests have been added to ensure that invalid paths are skipped while valid file references continue to work correctly. I have no feedback to provide as there were no review comments to evaluate.
Summary
Pasting JSON-like content into the interactive prompt (or having a model hallucinate a tool call whose path argument got concatenated with source code) crashed the CLI with an unhandled promise rejection:
The
@-command regex inatCommandProcessoris greedy — it captures everything up to the next ASCII delimiter, including pasted JSON containing/and".checkPermissionsthen fed that multi-kilobyte string intoresolveToRealPath→fs.realpathSync, which threwENAMETOOLONG. Nothing caught it, and the entire interactive session died.Details
Wrap the
resolveToRealPathcall incheckPermissionswith atry/catchand skip the entry on failure. Permission gating is a pre-flight check (it answers "does the user need to approve a read?"), so "can't resolve a path" is the right signal to drop it. If the user really did mean a real file, downstream rendering will surface a clearer error than a crash.The
paths.tsbehavior is intentionally left unchanged —robustRealpathstill throws onENAMETOOLONG/EINVAL, so other internal callers (which receive paths from controlled config sources, not raw user input) keep their strict semantics.Related Issues
Fixes #22029
Refs #25910, #25923
How to Validate
npm install && npm run build --workspace=@google/gemini-cli-coretry/catchinatCommandProcessor.tsmakes the first test fail with the exactENAMETOOLONG: name too long, lstat …from Pasting something and throwing me error #22029.npm start): launch the CLI, paste an@followed by a multi-line JSON blob (e.g. the snippet from Pasting something and throwing me error #22029), submit. Before this PR the session crashed; after, the prompt submits cleanly and the bogus mention is just dropped.Pre-Merge Checklist
checkPermissions, the first of which fails onmain