Agent mode intermittently swallows tool calls as raw <invoke> XML text instead of executing them (causes single-step halting)

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

During a multi-day, multi-batch coding task in Agent mode, the agent repeatedly exhibited “single-step halting”: it would run one test, fail, print a status message, and stop — requiring me to send “continue” over and over to advance one step at a time.

Inspecting the session transcript revealed the real cause: the model intermittently emitted its tool calls as raw … XML text inside the message body, instead of as structured tool-call events. Cursor does not parse XML text, so the tool call was never executed, and the turn ended as “successful” with the tool call dangling.

Evidence from the transcript (all numbers reproduced, not estimated):

  • 66 tool calls were emitted as raw XML text instead of executed (Read 31, Shell 21, Grep 11, StrReplace 2, other 1).
  • 44 occurrences of a dangling tag leaked into the message body (reasoning text exposed instead of kept internal).
  • 23,362 normally-executed tool_use events in the same session, vs only 66 swallowed — confirming this is intermittent, not a hard failure.

The agent itself diagnosed this during the session: it deliberately issued the simplest possible commands (echo “test”, echo “clean-test”, echo “second-test”, echo “final-test”, pwd) and all of them were ALSO swallowed as text and never executed. This rules out “command too complex” and confirms the tool-call mechanism itself was failing intermittently.

Steps to Reproduce

This bug is intermittent and probabilistic — I could not find a deterministic trigger. Here is what I observed and how to detect it:

  1. Run a long, multi-batch coding task in Agent mode (in my case: a multi-day task with many test runs, git diffs, and compilation logs).
  2. At some point, the agent stops after a single step — it runs one command, prints a status message, and halts, requiring repeated “continue” prompts.
  3. To confirm the cause: inspect the agent’s last message before it halted. If the message body contains raw … (or <tool_call>…</tool_call>) XML tags instead of a structured tool-use event, the tool call was swallowed.

A minimal self-test the agent itself performed (and which also got swallowed): issuing the simplest possible commands like echo “test”, echo “clean-test”, echo “final-test”, pwd — all of these were emitted as text and never executed.

Workaround that reliably recovered the session: switch to Plan mode (tool calls execute normally there), or start a fresh chat.

Expected Behavior

When the model emits a tool call, Cursor should execute it as a structured tool-use event. If the tool call is malformed or emitted as raw XML text, Cursor should either (1) parse and execute it best-effort, or (2) detect it and surface an error / retry the turn — rather than silently ending the turn as “successful” with the tool call dangling. The silent “successful turn with a dangling tool call” is the core failure mode: it makes the agent appear done when it actually never ran its tool.

Operating System

MacOS

Version Information

Version: 3.25.6
VS Code Extension API: 1.128.0
Commit: f0df777c412b670d09e3eaf214967d779e67c080
Date: 2026-10-14T22:46:28.448Z
Layout: Agent Window
Build Type: Stable
Release Track: Default
Electron: 42.10.0
Chromium: 148.0.7778.280
Node.js: 24.18.1
V8: 14.8.178.38-electron.0
xterm.js: 6.1.0-beta.291
OS: Darwin arm64 25.6.0

For AI issues: which model did you use?

DeepSeek v4 pro

Additional Information

What we ruled out:

  • Not a context-overload problem. A comparison session with the same model over the same period accumulated ~9.67M characters and did NOT degrade, while the degraded session accumulated ~10.56M characters. Nearly identical size, so raw context size is not the root cause.
  • Not a decision-logic problem. The agent was not “choosing” to stop — it was attempting to issue tool calls, but they were being swallowed.

Workarounds that worked:

  1. Switch to Plan mode — tool calls execute reliably there.
  2. Start a fresh chat and restate the task.
  3. Switch models.

Suggested fix direction:
When the model emits / <tool_call> XML in the message body, Cursor should either parse-and-execute it (best-effort recovery), or detect it and surface a clear error / retry the turn, rather than silently ending the turn as “successful” with the tool call dangling.

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

Hey @lcw, thanks for the report.

DeepSeek v4 pro isn’t one of Cursor’s built-in models, so in your setup it runs through your own API key and the endpoint you configured. Cursor runs a tool call when that endpoint returns it as a structured tool call (the tool_calls field of an OpenAI-compatible response).

When the reply comes back with the call written out as <invoke> text instead, there’s nothing for the agent to execute, so the turn ends there. The stray </thinking> tags point the same way: on those turns the endpoint isn’t separating the model’s reasoning and tool calls from the reply text.

So the most reliable fixes are on the endpoint side:

  • If you use a gateway or proxy in front of DeepSeek, check its settings for DeepSeek tool-call parsing and reasoning parsing. Tool calls should come back in tool_calls, and reasoning in a separate reasoning_content field, not inline in the reply text.
  • If it’s a self-hosted server (vLLM, SGLang or similar), enable its DeepSeek tool-call parser and reasoning parser for this model.
  • Try the same model through DeepSeek’s official API. If tool calls come back structured there, the gateway is the part to change.
  • If your endpoint offers a non-thinking variant of the model, give it a try. Thinking mode with tool calls depends on the endpoint handling the model’s reasoning between steps, and a non-thinking variant avoids that.

On the Cursor side:

  • The chat you’re working in has grown very large over several days. Starting a new chat with a short summary of where you are usually clears this up, as you found.
  • Plan mode or one of the built-in models keeps things moving while you adjust the endpoint.

If tool calls still come back as text after you’ve pointed Cursor at DeepSeek’s official API, let us know which base URL you’re using!

Hi @Colin, thanks for the clear explanation!

You hit the nail on the head — our upstream OpenAI-compatible gateway (ctyun hosting DeepSeek v4 pro) was intermittently leaking raw <invoke>...</invoke> XML blocks and stray </thinking> tags into message.content / delta.content with finish_reason: "stop", instead of separating them into structured tool_calls and reasoning_content.

Following your advice, we updated our local OpenAI-compatible proxy in front of the endpoint to:

  1. Strip inline <think>...</think> and dangling </thinking> tags from content into reasoning_content;
  2. Parse any leaked <invoke name="...">...</invoke> or <tool_call>...</tool_call> blocks in content into standard OpenAI tool_calls objects (id, type: "function", function: { name, arguments });
  3. Force finish_reason: "tool_calls" whenever tool calls are present in the turn.

Since deploying this normalization on the proxy side, the single-step halting has been 100% resolved.

(Minor UX suggestion for the Cursor team: even though this is an upstream parser issue, it might still be helpful if Cursor showed a subtle warning badge when a finish_reason: "stop" message body contains literal <invoke> or <tool_call> tags, so users know why the agent stopped.)

Thanks again — marking your reply as the solution!