fix(core): fall back when ripgrep execution fails#27568
Conversation
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 improves the robustness of the search functionality by introducing a graceful fallback mechanism for the ripgrep tool. When ripgrep fails due to environmental issues, the system now automatically switches to the legacy GrepTool to ensure search operations can still complete. The changes also include necessary updates to support file-specific searches within the legacy grep path, ensuring that users receive consistent results even when the primary search tool is unavailable. 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
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
Code Review
This pull request enhances the GrepTool to support searching explicit file paths in addition to directories, and introduces a fallback mechanism in RipGrepTool to use GrepTool when ripgrep is unavailable or fails. Feedback on the changes suggests optimizing GrepTool by reusing the fs.Stats object from the validation step to avoid a redundant filesystem stat call when determining search targets.
| const stats = await fsPromises.stat(searchDirAbs); | ||
| searchTargets = stats.isFile() | ||
| ? [{ directory: path.dirname(searchDirAbs), filePath: searchDirAbs }] | ||
| : [{ directory: searchDirAbs }]; |
There was a problem hiding this comment.
There is a redundant fsPromises.stat call here. The file stats for searchDirAbs were already fetched and validated in the block above (around line 166). Calling stat again on the same path introduces unnecessary filesystem I/O, which can degrade performance in large workspaces or slow filesystems.
To avoid this, you can declare let stats: fs.Stats | null = null; at the top of the execute method (around line 147), assign the result of fsPromises.stat(searchDirAbs) to it in the validation block (around line 166) instead of using a local const stats, and then reuse it here.
searchTargets = stats && stats.isFile()
? [{ directory: path.dirname(searchDirAbs), filePath: searchDirAbs }]
: [{ directory: searchDirAbs }];There was a problem hiding this comment.
Done in 26c214d. The validation stat result is now reused when constructing file-scoped grep targets, so the fallback path no longer stats the same path twice.
Summary
GrepToolwhen the registered ripgrep tool hits execution-environment failures, including missingrgand exit 64.no_ignorestill fail instead of changing semantics silently.SearchTextcalls can still fall back throughgit grep, systemgrep, or the JS scanner.Fixes #27503.
Test plan
npm run test --workspace @google/gemini-cli-core -- src/tools/grep.test.ts src/tools/ripGrep.test.tsnpm run typecheck --workspace @google/gemini-cli-corenpx eslint packages/core/src/tools/grep.ts packages/core/src/tools/grep.test.ts packages/core/src/tools/ripGrep.ts packages/core/src/tools/ripGrep.test.ts --max-warnings 0