microsoft / microsoft/vscode

kimi-k2.7-code generates tool_use IDs that block subsequent requests to Anthropic with HTTP 400

Open
#327,597 2 comments 0 reactions 1 assignee Assigned to @Giuspepe View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Issue Description
When using `kimi-k2.7-code` during an agentic Copilot session, tool calls generate IDs containing dots and colons (e.g. `functions.list_dir:0`).

When switching models or replaying conversation history to an Anthropic endpoint (like Claude 4.6 Sonnet), the API rejects the request with HTTP 400:
`invalid_request_error: messages.X.content.Y.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'`

Because VS Code preserves the conversation history with the un-sanitized Kimi IDs, all subsequent requests in that session fail permanently until a new chat session is started.

### Expected Behavior
VS Code / Copilot extension should sanitize outgoing `tool_use.id` strings in message history (e.g., replacing invalid characters with `_` or re-mapping IDs) to ensure compliance with Anthropic's `^[a-zA-Z0-9_-]+$` regex constraint before sending history payloads.

- Copilot Chat Extension Version: 0.55.0
- VS Code Version: 1.130.0
- OS Version: macOS 26.5.2
- Feature: Agent mode (Code agent)
- Selected model: kimi-k2.7-code (model that produces the invalid IDs); error surfaces when any subsequent request is made in the same session
- Logs:
```
Sorry, your request failed. Please try again.

Client Request Id: 3a35965a-8ca7-4f10-9fe3-9e856b98fe19

GH Request Id: FAE9:BB6DC:808FD0:8F4CBC:6A6718AA

Reason: Request Failed: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.69.content.0.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'"},"request_id":"req_vrtx_011CdSFwojHENqbKTfaoaucd"}
```

Debug log evidence from session {SESSION_UUID}/main.jsonl:

`kimi-k2.7-code` generated the following `tool_use` IDs in agent responses:
```
functions.list_dir:0
functions.list_dir:1
functions.grep_search:2
functions.read_file:3
functions.create_file:15
```
These IDs contain `.` (dot) and `:` (colon), which violate the pattern required by Anthropic `^[a-zA-Z0-9_-]+$`.

---

**Steps to Reproduce:**

1. Open a VS Code Copilot Chat panel in **Agent / Code mode**.
2. Select **`kimi-k2.7-code`** as the model.
3. Send a prompt that causes the agent to make multiple tool calls (e.g. any coding task that reads files or runs searches). Observe that kimi completes the turns successfully - the IDs are accepted by kimi's own endpoint.
4. Switch to an Anthropic model, eg. `claude-sonnet-4.6`
5. Send a **follow-up user message** in the same session (any message).
6. Observe: the request fails immediately with HTTP 400 — no `llm_request` is logged; VS Code shows _"Sorry, your request failed. Please try again."_
7. Clicking **"Try Again"** fails identically as long as the session history is unchanged.
---

**Root cause (from log analysis):**

`kimi-k2.7-code` uses the ID format `functions.:` (e.g. `functions.list_dir:0`). When VS Code replays this conversation history to the GitHub Copilot API endpoint for any subsequent request, the Anthropic API validates all `tool_use.id` values in the history and rejects the payload.

**Expected behaviour:** The Copilot extension should sanitize `tool_use.id` values when replaying cross-model conversation history, replacing any characters outside `[a-zA-Z0-9_-]` with `_`. This is a one-liner fix on the client side.

**Workaround:** Start a new chat session after the error occurs; "Try Again" alone is not sufficient unless VS Code switches models automatically.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.