copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Agent gets stuck in endless loop of "Model call failed"

Open rolfwr opened this issue 2 months ago • 2 comments

Describe the bug

Unexpected failure loop shown in terminal output:

✓ write_bash
   ↪ 200 lines...

 ● Great! Now let's test if our new tool works:

 ✓ $ cd /home/rolfwr/mimir/alt && npx env-cmd esr server/tools/src/cmds/download-dynamodb-stream.ts /tmp/dynamodb-stream-test --max-hours=2 2>&1 | head -50
   ↪ 10 lines...

 ● The table exists but doesn't have a stream enabled according to the describe
   response. Let me check the actual table structure:

 ✗ $ cd /home/rolfwr/mimir/alt && npx env-cmd aws dynamodb describe-table --table-name mb10-mimir-prod-genericTable 2>&1 | grep -i stream | head -10
   Operation aborted by user

 > A point of clarification. The table we care about, which has streams enabled is "mb10-mimir-prod-item".

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:154F760:195108A:68F23588)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:1550F49:1952BF3:68F2358A)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:15529EB:1954AF1:68F23591)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:15544FC:1956AB8:68F2359A)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:1556D5E:19598B7:68F235A2)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 85D4:239294:155C27F:195FB5D:68F235AD)

 > You seem to have gotten stuck.

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 985E:107A64:12E48E5:162D645:68F23643)

 ✗ Model call failed: {"message":"messages.192: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Each `tool_use` block must have a 
   corresponding `tool_result` block in the next message.","code":"invalid_request_body"} (Request ID: 985E:107A64:12E5D57:162EE4A:68F23644)

Problem persists after exiting out of copilot and re-running copilot with --continue option.

Affected version

0.0.343 Commit: 5847051

Steps to reproduce the behavior

Reproducing it using "copilot --continue" would require a way of exporting whatever persistent state that "--continue" operates on.

Expected behavior

Copilot does not go into endless loop of reporting ✗ Model call failed: {"message":"messages.192: tool_useids were found withouttool_resultblocks immediately after: toolu_01UvmZN5EkHfndM9X2qekRsA. Eachtool_useblock must have a correspondingtool_result block in the next message.","code":"invalid_request_body"} (Request ID: 847A:20242C:13286FE:1670E7E:68F2366E)

Or if it gets into this state, there is a way to reset it and get it back on track.

Additional context

No response

rolfwr avatar Oct 17 '25 12:10 rolfwr

Experiencing this a lot too after recently updating - it seems to happen when you abort an in progress command. So to reproduce I think you just need to get it to run a script that takes a while and then abort it. Type your comment. It then fails.

driskell avatar Oct 17 '25 19:10 driskell

Image

I am getting same. To reproduce bug

  1. Give some prompt
  2. When tool call such as search or read is used, stop it from further generating
  3. Add prompts further below that (stopping is intentional to refine prompt directing copilot to look correct place)

As in screenshot, just when tool ended, I pressed stop. When I typed further prompts, got infinite error loops.

Suggested solution: Mark tool call as failed when stop button is pressed, in chat history database.

TechyAditya avatar Nov 18 '25 16:11 TechyAditya