gemini-cli - 💡(How to fix) Fix Crash with ENAMETOOLONG when model hallucinates a file path containing source code [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25910Fetched 2026-04-25 06:22:30
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
labeled ×1

I was using Gemini to browse the TypeScript Go Codebase and discuss an unrelated performance question regarding the LSP implementation. Earlier turns in the session successfully used grep_search, read_file, list_directory, write_file, and run_shell_command against this workspace.

Error Message

Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/orlandohohmeier/Scratchspace/typescript-go/excalidraw/common"; │ │ import { deepCopyElement } from "@excalidraw/element";

...

at Module.lstatSync (node:fs:1686:25) at robustRealpath (chunk-FNPZLVJU.js:41920:27) at resolveToRealPath (chunk-FNPZLVJU.js:41907:10) at checkPermissions (chunk-APBWRLCM.js:62745:30) at interactiveCli-F6YUYJT5.js:32983:37 at Object.handleSubmit (interactiveCli-F6YUYJT5.js:18499:9)

Root Cause

I'd argue this is the same as https://github.com/google-gemini/gemini-cli/issues/25692 and caused by a hallucinated path even though the issue assumes it's related by a Next.js compiler error.

Code Example

[pasted the contents of https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/actions/actionAddToLibrary.ts]

---

Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/orlandohohmeier/Scratchspace/typescript-go/excalidraw/common";import { deepCopyElement } from "@excalidraw/element";    

...

  at Module.lstatSync (node:fs:1686:25)
  at robustRealpath (chunk-FNPZLVJU.js:41920:27)
  at resolveToRealPath (chunk-FNPZLVJU.js:41907:10)
  at checkPermissions (chunk-APBWRLCM.js:62745:30)
  at interactiveCli-F6YUYJT5.js:32983:37
  at Object.handleSubmit (interactiveCli-F6YUYJT5.js:18499:9)
RAW_BUFFERClick to expand / collapse

What happened?

The CLI crashed with a promise rejection during an interactive session. The model produced a tool call whose file path argument was not a valid path — it had been concatenated with a large chunk of TypeScript source code (~60 lines). lstatSync naturally threw ENAMETOOLONG. This happen repeatedly when prompting Gemini like this:

Wait, i was seeing the LSP hangs for "textDocument/documentSymbol" for this 66 lines:

```
[pasted the contents of https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/actions/actionAddToLibrary.ts]
```

The model synthesized a path that pointed into a subdirectory that does not exist in my workspace, and appended a full source code after the directory segment, separated only by a quote character:

Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/orlandohohmeier/Scratchspace/typescript-go/excalidraw/common";  │
│    import { deepCopyElement } from "@excalidraw/element";    

...

  at Module.lstatSync (node:fs:1686:25)
  at robustRealpath (chunk-FNPZLVJU.js:41920:27)
  at resolveToRealPath (chunk-FNPZLVJU.js:41907:10)
  at checkPermissions (chunk-APBWRLCM.js:62745:30)
  at interactiveCli-F6YUYJT5.js:32983:37
  at Object.handleSubmit (interactiveCli-F6YUYJT5.js:18499:9)

I'd argue this is the same as https://github.com/google-gemini/gemini-cli/issues/25692 and caused by a hallucinated path even though the issue assumes it's related by a Next.js compiler error.

Context

I was using Gemini to browse the TypeScript Go Codebase and discuss an unrelated performance question regarding the LSP implementation. Earlier turns in the session successfully used grep_search, read_file, list_directory, write_file, and run_shell_command against this workspace.

What did you expect to happen?

  • Validate/sanitize path arguments before passing them to fs.lstatSync — reject obvious non-paths (embedded newlines, length > PATH_MAX, unbalanced quotes). I'd argue this is security relevant and needs to be fixed soon.
  • Handle the promise rejection and surface them as a recoverable tool error, not a crash. Preferably as a structured error to the model so it can retry with a valid path instead of the session dying without needing human intervention.

Client information

  • CLI Version: 0.39.1
  • Git Commit: 4d73f3413
  • Session ID: 04023fb0-5b0d-448c-8ea8-e8a64a0ca377
  • Operating System: darwin v25.8.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 382.7 MB
  • Terminal Name: ghostty 1.3.1
  • Terminal Background: #282c34
  • Kitty Keyboard Protocol: Supported

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

Validate and sanitize file path arguments before passing them to fs.lstatSync to prevent crashes due to invalid paths.

Guidance

  • Check the path argument for obvious non-paths, such as embedded newlines, length exceeding PATH_MAX, or unbalanced quotes, and reject them before calling fs.lstatSync.
  • Handle promise rejections from fs.lstatSync and surface them as recoverable tool errors, allowing the model to retry with a valid path.
  • Consider implementing input validation and sanitization for all file system operations to prevent similar issues.
  • Review the model's path generation logic to prevent hallucinated paths, as seen in this case where a full source code was appended to a directory segment.

Notes

The issue seems to be related to a known problem (https://github.com/google-gemini/gemini-cli/issues/25692), but the root cause is likely a combination of invalid path generation and lack of input validation.

Recommendation

Apply a workaround by validating and sanitizing file path arguments before passing them to fs.lstatSync, as this will prevent crashes due to invalid paths and allow the model to recover from errors.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix Crash with ENAMETOOLONG when model hallucinates a file path containing source code [1 participants]