Skip to content

fix(core): silently skip GEMINI.md paths that are directories (EISDIR)#25662

Open
martin-hsu-test wants to merge 2 commits intogoogle-gemini:mainfrom
martin-hsu-test:fix/memory-discovery-eisdir
Open

fix(core): silently skip GEMINI.md paths that are directories (EISDIR)#25662
martin-hsu-test wants to merge 2 commits intogoogle-gemini:mainfrom
martin-hsu-test:fix/memory-discovery-eisdir

Conversation

@martin-hsu-test
Copy link
Copy Markdown

Summary

When a directory named GEMINI.md exists anywhere in the workspace tree, memory discovery currently surfaces a confusing Could not read GEMINI.md warning because fs.readFile throws EISDIR on directories. Directories with that name are valid in some project structures and should simply be ignored.

This PR detects EISDIR specifically in the readGeminiMdFiles catch block and skips silently with a debug log, while preserving the warning behaviour for genuinely unexpected read errors.

Fixes #16282

Implementation

packages/core/src/utils/memoryDiscovery.ts — extend the existing catch block:

const isEISDIR =
  error instanceof Error &&
  (error as NodeJS.ErrnoException).code === 'EISDIR';

if (isEISDIR) {
  // Skip silently — a directory at this path is a legitimate case.
  debugLogger.debug('[DEBUG] [MemoryDiscovery] Skipping directory at GEMINI.md path:', filePath);
} else {
  // ... existing warn behaviour ...
}

The return value is unchanged ({ filePath, content: null }) so downstream consumers continue to see the same shape.

Tests

Two new tests in memoryDiscovery.test.ts:

  1. Direct unit testreadGeminiMdFiles returns { content: null } (without throwing) when given a directory path
  2. End-to-end testloadServerHierarchicalMemory returns empty memory when a GEMINI.md directory exists in the workspace

Test results:

✓ packages/core/src/utils/memoryDiscovery.test.ts (44 tests) 107ms
Test Files  1 passed (1)
     Tests  44 passed (44)

tsc --noEmit and eslint both pass with zero output.

Relationship to #22852

This supersedes #22852 (closed 2026-04-09 due to test failures and 23 days of inactivity). Credit to @shathwik30 for the original work; the production-code shape here uses the same NodeJS.ErrnoException type guard that @gemini-code-assist suggested on that PR.

What's different in this PR:

  • Tests are written from scratch against the current memoryDiscovery.ts and verified to pass locally before submission
  • Added a direct readGeminiMdFiles unit test (alongside the e2e test) to keep the failure surface narrow and easy to debug for future contributors
  • The end-to-end test asserts only memoryContent === '', which is the user-visible contract the issue actually cares about, rather than relying on fileCount semantics that could shift

When a directory named GEMINI.md exists in the workspace tree, the memory
discovery process previously logged a confusing 'Could not read GEMINI.md'
warning because fs.readFile throws EISDIR on directories. Directories with
that name are valid in some project structures and should simply be ignored.

Detect EISDIR specifically in the readGeminiMdFiles catch block and skip
silently with a debug log, while preserving the warning behaviour for
genuinely unexpected read errors.

Adds two tests:
- a direct readGeminiMdFiles test asserting null content (no throw) when
  given a directory path
- an end-to-end loadServerHierarchicalMemory test asserting empty memory
  when a GEMINI.md directory is present in the workspace

Fixes google-gemini#16282

Supersedes google-gemini#22852 (closed due to test failures and inactivity); the
production fix here uses the same NodeJS.ErrnoException type guard that
gemini-code-assist suggested on that PR, with fresh tests written from
scratch against the current code.
@martin-hsu-test martin-hsu-test requested a review from a team as a code owner April 19, 2026 17:04
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 an issue where the memory discovery process incorrectly flagged directories named GEMINI.md as read errors. By identifying the EISDIR error code during file reading, the system now treats these directories as expected edge cases rather than failures, improving the user experience by removing unnecessary warnings.

Highlights

  • Error Handling: Updated the readGeminiMdFiles function to explicitly catch and silently ignore EISDIR errors, preventing misleading warnings when a directory is named GEMINI.md.
  • Testing: Added comprehensive unit and end-to-end tests to verify that GEMINI.md directories are handled gracefully without throwing errors.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces graceful handling for cases where a directory exists at a path expected to be a GEMINI.md file. The readGeminiMdFiles function in packages/core now specifically catches EISDIR errors, logging a debug message instead of a warning to prevent user confusion. Additionally, new test cases have been added to memoryDiscovery.test.ts to verify that these directories are correctly ignored without throwing exceptions. I have no feedback to provide.

…directory

The original issue (google-gemini#16282) describes two scenarios beyond 'just don't
warn': directories named GEMINI.md should be 'ignored in favor of actual
files', and the fix should 'handle symlinks more robustly'. Add two
tests asserting these behaviours hold:

- a higher-level real GEMINI.md still loads when a lower-level path of
  the same name is a directory
- a symlink whose target is a directory is silently skipped exactly
  like a plain directory (skipped on Windows when symlink creation
  requires elevated privileges)
@martin-hsu-test
Copy link
Copy Markdown
Author

Pushed a follow-up commit (1236565) adding two tests that cover the broader contract from the issue:

  • Fallback to actual files: when a higher-level GEMINI.md is a real file but a lower-level path of the same name is a directory, the real file is still discovered and loaded. This validates the 'ignored in favor of actual files' wording in [Core] Handle EISDIR error when GEMINI.md is a directory during memory discovery #16282.
  • Symlink to directory: a symlink whose target is a directory triggers the same EISDIR path on read and is skipped silently, validating the 'handles symlinks more robustly' point. The test self-skips on Windows setups without symlink-creation privilege.

All 46 memoryDiscovery tests still pass locally; lint clean.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] Handle EISDIR error when GEMINI.md is a directory during memory discovery

1 participant