Skip to content

Crash with ENAMETOOLONG when model hallucinates a file path containing source code #25910

Description

@orlandohohmeier

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 #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: 4d73f34
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalearea/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitykind/bugpriority/p2Important but can be addressed in a future release.status/bot-triaged

    Type

    Projects

    Status
    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions