Repository navigation
fix(core): replace fuzzy requestedExplicitly logic with glob matching in read-many-files - #29457
villahernandez-coder wants to merge 14 commits into
Conversation
|
📊 PR Size: size/L
|
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 bug where binary assets were incorrectly inlined due to overly permissive fuzzy matching. It replaces this logic with a strict, glob-based evaluation system. Additionally, it enhances the stability of the CLI by introducing atomic file operations, protecting against prototype pollution, and improving handling of file access and authentication across app relaunches and platform-specific 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 introduces several robustness, security, and environment-handling improvements across the CLI and core packages. Key changes include: supporting a GEMINI_CLI_AUTH_OVERRIDE environment variable to propagate authentication selection across application relaunches; implementing atomic file writes and read retries in commentJson and oauth2 to prevent corruption and handle transient file locks; adding prototype pollution protection when updating JSON settings; bypassing the native keychain on WSL and headless Linux environments to avoid libsecret lockups; and refining the ReadManyFilesTool to only include binary assets (images, PDFs, audio) when they are explicitly requested by name or extension rather than implicitly matched by broad glob patterns. I have no additional feedback to provide as no review comments were submitted.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several robustness and security improvements across the codebase. Key changes include adding prototype pollution protection and atomic file writes in JSON settings utilities, implementing retry mechanisms for reading OAuth credentials, bypassing native keychains in WSL/headless Linux environments to prevent lockups, and refining the read-many-files tool to prevent binary assets (images, PDFs, audio) from being implicitly matched by broad glob patterns. Additionally, it supports propagating authentication overrides across process relaunches. The reviewer suggests extending the binary asset check in the read-many-files tool to also cover 'video' files to prevent potential context bloat and memory issues.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several robustness and feature enhancements, including authentication type overrides via environment variables during relaunch, bypassing native keychains in WSL/headless Linux to prevent lockups, adding video file support to the file-reading tool, and implementing safer file operations (atomic writes, retries, and prototype pollution prevention). Feedback on these changes highlights two key issues in the file utility implementation: first, using Atomics.wait on the main thread throws a TypeError in Node.js, resulting in an inefficient CPU-intensive busy-wait loop; second, using Date.now() for temporary file naming is prone to collisions during rapid sequential writes, which can be resolved by appending a random suffix.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several robust enhancements across the CLI and Core packages. Key updates include support for overriding the selected authentication type via the GEMINI_CLI_AUTH_OVERRIDE environment variable across process relaunches, security improvements in JSON settings writing (such as prototype pollution prevention and atomic writes), a retry mechanism for reading OAuth credentials to handle transient filesystem errors, WSL and headless Linux detection to bypass native keychains and avoid libsecret lockups, and refined asset matching in the ReadManyFilesTool using picomatch to prevent broad globs from implicitly matching binary assets (including video). I have no feedback to provide as there are no review comments.
Note: Security Review did not run due to the size of the PR.
🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements and bug fixes across the codebase. It updates temporary file path generation in writeAtomicSync and cacheCredentials to append a random alphanumeric string, preventing potential collisions. It enhances readOAuthCredsWithRetry to support a callback function for maxRetries, allowing dynamic re-evaluation. Additionally, it refactors asset handling in ReadManyFilesTool by adding support for video files and introducing a robust isAssetExplicitlyRequested helper using picomatch to accurately determine if asset files (images, PDFs, audio, and video) are explicitly requested by name or extension rather than implicitly matched by broad glob patterns. Comprehensive unit tests have been added to verify these changes. There are no review comments, so I have no feedback to provide.
- Introduce optional AssetRequestCache parameter in isAssetExplicitlyRequested using mnemonist LRUCache - Instantiate assetRequestCache per ReadManyFilesToolInvocation to cache compiled matchers and scan results - Add unit test verifying cache population and reuse
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for video files to the ReadManyFilesTool and introduces a robust isAssetExplicitlyRequested helper function to prevent asset files from being implicitly matched by broad glob patterns. It also integrates an LRUCache to cache compiled matchers and scan results. The review feedback highlights a potential cache key collision in isAssetExplicitlyRequested where raw pattern keys could collide with prefixed keys like scan: and matcher:, suggesting prefixing pattern matcher keys with pattern: and updating the corresponding test assertions.
- Prefix compiled pattern matcher cache keys with 'pattern:' to avoid collisions with 'scan:' and 'matcher:' entries - Update unit test assertions in read-many-files.test.ts to expect the prefixed cache key
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the ReadManyFilesTool to support video files as assets and introduces a more robust isAssetExplicitlyRequested helper to determine if asset files (images, PDFs, audio, and video) are explicitly requested by name or extension rather than implicitly matched by broad glob patterns. It also integrates an LRUCache to cache compiled glob matchers and scan results for better performance. The review feedback points out a potential cross-platform issue where platform-dependent path.extname and path.basename are used on paths before normalization, and suggests using path.posix on the normalized path instead to ensure consistent behavior across POSIX and Windows environments.
…itlyRequested - Use path.posix.extname and path.posix.basename on normalizedFilePath instead of platform-dependent path methods on raw filePath - Add test case verifying Windows-style backslashes in filePath and relativePathForDisplay
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances the ReadManyFilesTool by adding support for video files and introducing a more robust, cached helper function isAssetExplicitlyRequested to determine if asset files (images, PDFs, audio, and video) are explicitly requested by name or extension rather than implicitly matched by broad glob patterns. Comprehensive unit tests have been added to validate these changes. Feedback on the code suggests using the project's robust resolveToRealPath utility for workspace directory path comparisons to ensure consistent path resolution across different environments.
…son in read-many-files - Import and use resolveToRealPath in isAssetExplicitlyRequested for canonical path comparison - Handle cross-platform path resolution consistently across POSIX and Windows environments
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust mechanism (isAssetExplicitlyRequested) to determine if asset files (images, PDFs, audio, and now video files) are explicitly requested by name or extension rather than implicitly matched by broad glob patterns. It also integrates picomatch and LRUCache to optimize pattern matching. The review feedback highlights a critical performance optimization to avoid redundant synchronous I/O operations (resolveToRealPathSafe) inside the loop by pre-resolving workspace directories.
…icitlyRequested - Pre-resolve workspaceDirs and the file directory once at the beginning of isAssetExplicitlyRequested - Avoid redundant synchronous fs.realpathSync / resolveToRealPathSafe calls inside pattern matching loops
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the isAssetExplicitlyRequested helper function to determine if an asset file (image, PDF, audio, or video) is explicitly requested by name or extension rather than implicitly matched by a broad glob pattern. It also adds support for video files, integrates caching of compiled matchers using an LRU cache to optimize performance, and includes comprehensive unit tests validating these changes under various glob patterns, path separators, and casing scenarios. I have no feedback to provide as there are no review comments to address.
Findings🔴 Critical / High PriorityNone identified. The implementation is mathematically sound, avoids ReDoS, eliminates false-positive binary inlining, and passes all edge cases. 🟡 Improvements
🟢 Nitpicks
|
|
This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
Fixes a critical context-bloat bug (b/561554390 / #29045) in
read-many-fileswhere binary assets (images, PDFs, audio) were incorrectly treated as "explicitly requested" due to naiveString.prototype.includes()fuzzy substring matching on file stems and extensions, causing inadvertent base64 inlining.Details
isAssetExplicitlyRequested()utilizing the repository's standard glob library (picomatch, zero new dependencies).*,**/*,src/**,**/*report*/**,assets/*) no longer trigger explicit binary inlining. An asset is only treated as explicitly requested if an include pattern matches the file AND explicitly targets either:1. A specific extension (e.g.,
*.png,**/*.png,assets/*.PNG,*.{png,jpg}) matching the file's extension case-insensitively.2. A specific non-wildcard filename stem/path (e.g.,
assets/logo.png,logo.png,myExactImage.png,report-final.pdf).\to/) across include patterns and file paths to adhere to repository standards on Windows and POSIX.picomatch(patternExt, { nocase: true }).read-many-files.test.tscovering false-positive rejection (**/*report*/**vsreports/quarterlyreport.png), explicit binary requests (assets/logo.png), path separators (assets\logo.png), case-insensitivity (assets/*.PNG,assets/Logo.png), and unit tests forisAssetExplicitlyRequested.Related Issues
Fixes #29045
How to Validate
Run unit test suite for
read-many-files:npm test -w @google/gemini-cli-core -- src/tools/read-many-files.test.ts
Run typecheck and linting across the workspace:
npm run typecheck
npm run lint
Run core package unit tests:
npm test -w @google/gemini-cli-core
Pre-Merge Checklist