Bug: JSON SyntaxError On Tool Call In Agent Mode (@workspace) Only When Using Custom Gemini Model (v0.26.5)
Bug: JSON SyntaxError on Tool Call in Agent Mode (@workspace) Only When Using Custom Gemini Model (v0.26.5)
As a developer, using GitHub Copilot Chat in Agent Mode can be a game-changer for productivity. However, when targeting a custom Gemini Pro model configured via API key, a JSON parsing error occurs within the extension. This prevents the request from completing successfully. In this article, we will delve into the issue, explore the steps to reproduce it, and discuss the expected and actual results.
The issue was encountered on the following environment:
- VS Code Version: 1.99.3 (user setup)
- Electron: 34.3.2
- ElectronBuildId: 11161073
- Chromium: 132.0.6834.210
- Node.js: 20.18.3
- V8: 13.2.152.41-electron.0
- SO: Windows_NT x64 10.0.26100
- GitHub Copilot Chat Extension Version: 0.26.5
- OS: Windows (Inferred from logs)
When using GitHub Copilot Chat in Agent Mode (e.g., with @workspace) and targeting a custom Gemini Pro model configured via API key, a JSON parsing error occurs within the extension. This prevents the request from completing successfully. The issue seems related to how the extension prepares data for internal "tool calls" when gathering workspace context specifically for the Gemini model integration.
Crucially, this error does not occur when using the default Copilot models (e.g., GPT-4o, Claude 3.5 Sonnet). Complex @workspace requests targeting these default models complete successfully without any JSON errors, even when requiring multiple contexts.
To reproduce the issue, follow these steps:
- Configure GitHub Copilot Chat to use a custom Gemini Pro model via API key: This requires user-specific setup.
- Open a software development project in VS Code: Any project will do, but it's best to use a project with a complex structure.
- Open the GitHub Copilot Chat view: This can be done by clicking on the Copilot Chat icon in the VS Code sidebar.
- Initiate an Agent Mode request that requires broad workspace context: For example, use the command
@workspace Can you explain the main components of the authentication flow in this project?
- Check the VS Code Output window, filtered to "GitHub Copilot Chat": This is where the error will be displayed.
The agent mode request targeting the custom Gemini model should be processed successfully. Copilot Chat should provide a relevant response based on the workspace context analysis, without any internal parsing errors.
The request fails. The following SyntaxError appears in the "GitHub Copilot Chat" output channel, indicating malformed JSON was generated for a tool call:
[error] SyntaxError: Unexpected non-whitespace character after JSON at position 42 (line 1 column 43)
at JSON.parse (<anonymous>)
at a (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:479:6982)
at X$.callback (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:462:5512)
at E (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:3142)
at r.processSSEInner (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:4804)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at r.processSSE (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:550)
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:100323
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:99812: Got invalid JSON for tool call: {"query":"src/app/+store/auth/*.store.ts"}{"query":"src/app/**/*interceptor.ts"}{"query":"src/app/services/ui.service.ts"}{"endLineNumberBaseZero":1000,"filePath":"c:\\Users\\gemay\\Path-To-Project\\src\\app\\app.config.ts","startLineNumberBaseZero":0}
[error] Error: Invalid JSON for tool call
at a (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:479:7171)
at X$.callback (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:462:5512)
at E (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:3142)
at r.processSSEInner (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:4804)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at r.processSSE (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:550)
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:100323
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:99812
- The malformed JSON ("query""query""query""filePath") clearly shows multiple JSON objects concatenated without proper formatting (e.g., not within a JSON array).
- This issue is specific to version 0.26.5 when interacting with custom Gemini models.
In conclusion, the JSON SyntaxError on tool call in Agent Mode (@workspace) only when using a custom Gemini model (v0.26.5) is a critical issue that prevents the request from completing successfully. The error is related to how the extension prepares data for internal "tool calls" when gathering workspace context specifically for the Gemini model integration. This issue is specific to version 0.26.5 when interacting with custom Gemini models.
Q&A: Bug: JSON SyntaxError on Tool Call in Agent Mode (@workspace) Only When Using Custom Gemini Model (v0.26.5)
Q: What is the issue with GitHub Copilot Chat in Agent Mode?
A: The issue is that when using GitHub Copilot Chat in Agent Mode (e.g., with @workspace) and targeting a custom Gemini Pro model configured via API key, a JSON parsing error occurs within the extension. This prevents the request from completing successfully.
Q: What is the expected behavior?
A: The agent mode request targeting the custom Gemini model should be processed successfully. Copilot Chat should provide a relevant response based on the workspace context analysis, without any internal parsing errors.
Q: What is the actual behavior?
A: The request fails. The following SyntaxError appears in the "GitHub Copilot Chat" output channel, indicating malformed JSON was generated for a tool call.
Q: What is the cause of the issue?
A: The issue seems related to how the extension prepares data for internal "tool calls" when gathering workspace context specifically for the Gemini model integration.
Q: Is this issue specific to a particular version of GitHub Copilot Chat?
A: Yes, this issue is specific to version 0.26.5 when interacting with custom Gemini models.
Q: What are the steps to reproduce the issue?
A: To reproduce the issue, follow these steps:
- Configure GitHub Copilot Chat to use a custom Gemini Pro model via API key.
- Open a software development project in VS Code.
- Open the GitHub Copilot Chat view.
- Initiate an Agent Mode request that requires broad workspace context.
- Check the VS Code Output window, filtered to "GitHub Copilot Chat".
Q: What is the error message?
A: The error message is:
[error] SyntaxError: Unexpected non-whitespace character after JSON at position 42 (line 1 column 43)
at JSON.parse (<anonymous>)
at a (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:479:6982)
at X$.callback (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:462:5512)
at E (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:3142)
at r.processSSEInner (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:4804)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at r.processSSE (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:550)
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:100323
at c:\Usersgemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:99812: Got invalid JSON for tool call: {"query":"src/app/+store/auth/*.store.ts"}{"query":"src/app/**/*interceptor.ts"}{"query":"src/app/services/ui.service.ts"}{"endLineNumberBaseZero":1000,"filePath":"c:\\Users\\gemay\\Path-To-Project\\src\\app\\app.config.ts","startLineNumberBaseZero":0}
[error] Error: Invalid JSON for tool call
at a (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:479:7171)
at X$.callback (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:462:5512)
at E (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:3142)
at r.processSSEInner (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:4804)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at r.processSSE (c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:480:550)
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:100323
at c:\Users\gemay\.vscode\extensions\github.copilot-chat-0.26.5\dist\extension.js:408:99812
Q: What is the malformed JSON?
A: The malformed JSON is:
{"query":"src/app/+store/auth/*.store.ts"}{"query":"src/app/**/*interceptor.ts"}{"query":"src/app/services/ui.service.ts"}{"endLineNumberBaseZero":1000,"filePath":"c:\\Users\\gemay\\Path-To-Project\\src\\app\\app.config.ts","startLineNumberBaseZero":0}
This clearly shows multiple JSON objects concatenated without proper formatting (e.g., not within a JSON array).