Skip to content

Gemini acp write_file Tool Failure #18076

@sodiumjoe

Description

@sodiumjoe

What happened?

The Gemini CLI's write_file tool consistently fails with a JavaScript error "Cannot read properties of undefined (reading 'indexOf')" when used in conjunction with the agentic.nvim Neovim plugin. This error occurs specifically within the gemini-cli Node.js process when processing incoming notifications from the vscode-ide-companion (which acts as the gemini-acp bridge). The failure is particularly noticeable when attempting to write to new files via the diff interaction.

[2026-02-01 13:29:30] [agentic.acp.acp_client:235] Gemini ACP response:  {
  jsonrpc = "2.0",
  method = "session/update",
  params = {
    sessionId = "eb30a893-13bb-4870-b63a-835a2465ae45",
    update = {
      content = { {
          content = {
            text = "Cannot read properties of undefined (reading 'indexOf')",
            type = "text"
          },
          type = "content"
        } },
      sessionUpdate = "tool_call_update",
      status = "failed",
      toolCallId = "write_file-1769981340295"
    }
  }
}

Root Cause

The vscode-ide-companion (acting as the gemini-acp bridge) is inadvertently sending malformed data to gemini-cli. Specifically, in its diff-manager.ts file, when the acceptDiff or cancelDiff methods are invoked after a user interaction with a diff view, it constructs IdeDiffAcceptedNotificationSchema or IdeDiffRejectedNotificationSchema notifications. The content field within these notifications is populated directly from rightDoc.getText(). If vscode.TextDocument.getText() returns undefined (which can happen in certain edge cases for newly created, unsaved, or ambiguous document states within VS Code), this undefined value is passed as the content. The gemini-cli's Model Context Protocol (MCP) SDK client, upon receiving this notification, attempts to perform a string operation (like .indexOf) on this undefined content field, leading to the "Cannot read properties of undefined (reading 'indexOf')" runtime error.

Proposed Solution

Modify packages/vscode-ide-companion/src/diff-manager.ts to ensure that the content field in the IdeDiffAcceptedNotificationSchema and IdeDiffRejectedNotificationSchema notifications is always a string. This can be achieved by providing a default empty string value if rightDoc.getText() returns undefined or another falsy value.

Specific Change (Example):
In packages/vscode-ide-companion/src/diff-manager.ts, within the acceptDiff and cancelDiff methods, change:
const modifiedContent = rightDoc.getText();
to:
`

What did you expect to happen?

write_file tool works correctly

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

> /about
│ CLI Version                                                            0.26.0                                                                                                                              │
│ Git Commit                                                             a380b4219                                                                                                                           │
│ Model                                                                  auto-gemini-2.5                                                                                                                     │
│ Sandbox                                                                no sandbox                                                                                                                          │
│ OS                                                                     darwin                                                                                                                              │

Login information

google account oauth

Anything else we need to know?

No response

Metadata

Metadata

Assignees

Labels

area/extensionsIssues related to Gemini CLI extensions capabilitystatus/need-triageIssues that need to be triaged by the triage automation.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions