When an external terminal (PuTTY) fails during long-running commands and falls back to the integrated terminal, duplicate tool results are generated for the same tool_use_id, causing an API protocol violation that puts Roo into an unrecoverable "doom loop" that breaks unattended access.
This affects users running unattended/autonomous workflows with external terminal configurations (e.g., PuTTY) when the external terminal host fails during long-running operations (5+ hours). The fallback mechanism to integrated terminal triggers a race condition that creates duplicate tool_result blocks, violating the Anthropic API protocol.
N/A - This is an edge case that occurred during production use. The issue is reproducible by simulating external terminal failure during long-running commands.
{
"error": {
"timestamp": "2026-01-05T05:51:10.811Z",
"version": "3.38.2",
"provider": "bedrock",
"model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
"details": "Unknown Error: The number of toolResult blocks at messages.31.content exceeds the number of toolUse blocks of previous turn."
},
"history": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "<task>\n[REDACTED: Large task description with implementation details]\n</task>"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED: Project file structure]\n</environment_details>"
}
],
"ts": 1767572765406
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED: Assistant reasoning about orchestrator task delegation]",
"summary": []
},
{
"type": "text",
"text": "I'll coordinate this migration task by first getting an architectural plan, then executing it incrementally with testing between steps."
},
{
"type": "tool_use",
"id": "tooluse_PnIzU0bpR_a6x_DZ2Ecxyw",
"name": "new_task",
"input": {
"mode": "architect",
"message": "[REDACTED: Task delegation message]",
"todos": "[ ] Read files\n[ ] Review references\n[ ] Analyze implementation\n[ ] Create migration plan\n[ ] Signal completion"
}
}
],
"ts": 1767572800206
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_PnIzU0bpR_a6x_DZ2Ecxyw",
"content": "Subtask completed.\n\nResult:\n[REDACTED: Detailed architectural plan]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED: Environment details]\n</environment_details>"
}
],
"ts": 1767572975593
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED: Planning next steps]",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_ny96idEmSkuNX0DUebTWBQ",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[-] Task 2\n[ ] Task 3\n[ ] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767572985455
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_ny96idEmSkuNX0DUebTWBQ",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767572985656
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED: Reasoning about executing plan]",
"summary": []
},
{
"type": "text",
"text": "Now executing Phase 1 of the migration."
},
{
"type": "tool_use",
"id": "tooluse_feOGGK5MQneQeNyWn3LiGg",
"name": "new_task",
"input": {
"mode": "code",
"message": "[REDACTED: Code modification instructions]",
"todos": "[ ] Read file\n[ ] Update code\n[ ] Complete task"
}
}
],
"ts": 1767573000981
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_feOGGK5MQneQeNyWn3LiGg",
"content": "Subtask completed.\n\nResult:\n[REDACTED: File modification results]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573054659
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_FORPY8fsS7ucI11KTUBp9g",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[x] Task 2\n[-] Task 3\n[ ] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767573062147
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_FORPY8fsS7ucI11KTUBp9g",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573062327
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "text",
"text": "Proceeding to next phase."
},
{
"type": "tool_use",
"id": "tooluse_EyDV-CT2QFqdavs4HzHc-A",
"name": "new_task",
"input": {
"message": "[REDACTED: Code modification instructions]",
"mode": "code",
"todos": "[ ] Read file\n[ ] Update code\n[ ] Complete"
}
}
],
"ts": 1767573081694
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_EyDV-CT2QFqdavs4HzHc-A",
"content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573135034
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_AY755nWbR--el0tqPJlOSg",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[-] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767573141785
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_AY755nWbR--el0tqPJlOSg",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573141919
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "text",
"text": "Proceeding to next phase."
},
{
"type": "tool_use",
"id": "tooluse_7rdkHyHnSjKfkhb-J7gEFg",
"name": "new_task",
"input": {
"message": "[REDACTED: Code modification instructions]",
"mode": "code",
"todos": "[ ] Read file\n[ ] Update code\n[ ] Complete"
}
}
],
"ts": 1767573156797
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_7rdkHyHnSjKfkhb-J7gEFg",
"content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573205740
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_akDNjcnQSvK7qLZzNsxuWg",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[-] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767573213080
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_akDNjcnQSvK7qLZzNsxuWg",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573213239
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "text",
"text": "Proceeding to final code update phase."
},
{
"type": "tool_use",
"id": "tooluse_-qHP2tTSTWSNL19dpMtpTQ",
"name": "new_task",
"input": {
"message": "[REDACTED: Code modification instructions]",
"mode": "code",
"todos": "[ ] Read file\n[ ] Update code\n[ ] Complete"
}
}
],
"ts": 1767573228017
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_-qHP2tTSTWSNL19dpMtpTQ",
"content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573286474
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_bcGI0mPoTNGCgrQ9NFwWsQ",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[x] Task 5\n[-] Task 6\n[ ] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767573293932
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_bcGI0mPoTNGCgrQ9NFwWsQ",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573294136
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "text",
"text": "Phase 6: Running the linter to verify all changes are syntactically correct."
},
{
"type": "tool_use",
"id": "tooluse_Ok7Bkcl8RyCT2lEfRtkygg",
"name": "execute_command",
"input": {
"command": "npm run lint",
"cwd": "/path/to/project"
}
}
],
"ts": 1767573299656
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_Ok7Bkcl8RyCT2lEfRtkygg",
"content": "Command executed in terminal within working directory. Command execution was not successful, inspect the cause and adjust as needed.\nExit code: 2\nOutput:\n\n[REDACTED: Linter output with project-specific warnings and TypeScript errors in other files]"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573333822
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "The linter ran and found TypeScript errors in OTHER files not related to our changes. Our modified files have no errors.",
"summary": []
},
{
"type": "text",
"text": "The linter shows no errors in our modified files. Now let's test the scenario."
},
{
"type": "tool_use",
"id": "tooluse_i3O-8SusSKuQWllVCHcdqw",
"name": "update_todo_list",
"input": {
"todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[x] Task 5\n[x] Task 6\n[-] Task 7\n[ ] Task 8"
}
}
],
"ts": 1767573342204
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_i3O-8SusSKuQWllVCHcdqw",
"content": "Todo list updated successfully."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767573342409
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "[REDACTED]",
"summary": []
},
{
"type": "text",
"text": "Now running the test to verify the migration works correctly."
},
{
"type": "tool_use",
"id": "tooluse_-SZO09niSuehB1YFk4pX3Q",
"name": "execute_command",
"input": {
"command": "npm run test:eval scenario-name",
"cwd": "/path/to/project"
}
}
],
"ts": 1767573348006
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_-SZO09niSuehB1YFk4pX3Q",
"content": "Command is still running in terminal from '/path/to/project'.\n\n\nYou will be updated on the terminal status and new output in the future."
},
{
"type": "text",
"text": "<environment_details>\n# Actively Running Terminals\n## Terminal 1 (Active)\n### Working Directory: `/path/to/project`\n### Original command: `npm run test:eval scenario-name`\n\n[REDACTED: Other environment details]\n</environment_details>"
}
],
"ts": 1767592162165
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "The test command is still running. I should wait for it to complete.",
"summary": []
},
{
"type": "text",
"text": "Let me check the status of the running test:"
},
{
"type": "tool_use",
"id": "tooluse_cXZ3_VlASVOFI3iG1Ypdow",
"name": "execute_command",
"input": {
"command": "echo \"Waiting for test to complete...\"",
"cwd": "/path/to/project"
}
}
],
"ts": 1767592168782
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_cXZ3_VlASVOFI3iG1Ypdow",
"content": "Command executed in terminal within working directory. Exit code: 0\nOutput:\nWaiting for test to complete..."
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767592174398
},
{
"role": "assistant",
"content": [
{
"type": "reasoning",
"text": "The test is still running. Let me check if there's any test process.",
"summary": []
},
{
"type": "tool_use",
"id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g",
"name": "execute_command",
"input": {
"command": "ps aux | grep -i \"npm.*test:eval\" | grep -v grep || echo \"No test processes found\"",
"cwd": "/path/to/project"
}
}
],
"ts": 1767592178982
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g",
"content": "Command executed in terminal within working directory. Exit code: 0\nOutput:\nNo test processes found"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767592179756
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g",
"content": "{\"status\":\"approved\",\"message\":\"The user approved this operation and provided the following context\",\"feedback\":\"Run again\"}"
},
{
"type": "text",
"text": "<environment_details>\n[REDACTED]\n</environment_details>"
}
],
"ts": 1767592234718
}
]
}
While switching to integrated terminal was suggested as a workaround, it doesn't support custom shells, which breaks workflows requiring:
Therefore, fixing the external terminal fallback mechanism is necessary for these use cases.
Multiple PRs attempted to fix tool_result issues during November-December 2025 native tool protocol rollout:
This pattern suggests the native tool protocol rollout exposed multiple edge cases in tool result handling, including this terminal fallback race condition.
This context explains why unattended access broke suddenly in January 2026 despite the codebase being stable for months.
Terminal Fallback Causes Duplicate Tool Results and "Doom Loop"
Problem (one or two sentences)
When an external terminal (PuTTY) fails during long-running commands and falls back to the integrated terminal, duplicate tool results are generated for the same tool_use_id, causing an API protocol violation that puts Roo into an unrecoverable "doom loop" that breaks unattended access.
Context (who is affected and when)
This affects users running unattended/autonomous workflows with external terminal configurations (e.g., PuTTY) when the external terminal host fails during long-running operations (5+ hours). The fallback mechanism to integrated terminal triggers a race condition that creates duplicate tool_result blocks, violating the Anthropic API protocol.
Reproduction Steps
Environment/Setup:
Exact Actions:
npm run test:eval scenario-name)What Was Observed:
tooluse_-SZO09niSuehB1YFk4pX3Qps aux | grep...with tool_use_id:tooluse_QZ-pU8v2QKO8L8fHoJRI2gtooluse_QZ-pU8v2QKO8L8fHoJRI2gExpected Result
Actual Result
Variations Tried
N/A - This is an edge case that occurred during production use. The issue is reproducible by simulating external terminal failure during long-running commands.
App Version
v3.38.2
API Provider
Amazon Bedrock
Model Used
anthropic.claude-sonnet-4-5-20250929-v1:0
Roo Code Task Links
N/A - Task was running in unattended mode when failure occurred
Relevant Logs or Errors
Full Error Object
{ "error": { "timestamp": "2026-01-05T05:51:10.811Z", "version": "3.38.2", "provider": "bedrock", "model": "anthropic.claude-sonnet-4-5-20250929-v1:0", "details": "Unknown Error: The number of toolResult blocks at messages.31.content exceeds the number of toolUse blocks of previous turn." }, "history": [ { "role": "user", "content": [ { "type": "text", "text": "<task>\n[REDACTED: Large task description with implementation details]\n</task>" }, { "type": "text", "text": "<environment_details>\n[REDACTED: Project file structure]\n</environment_details>" } ], "ts": 1767572765406 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED: Assistant reasoning about orchestrator task delegation]", "summary": [] }, { "type": "text", "text": "I'll coordinate this migration task by first getting an architectural plan, then executing it incrementally with testing between steps." }, { "type": "tool_use", "id": "tooluse_PnIzU0bpR_a6x_DZ2Ecxyw", "name": "new_task", "input": { "mode": "architect", "message": "[REDACTED: Task delegation message]", "todos": "[ ] Read files\n[ ] Review references\n[ ] Analyze implementation\n[ ] Create migration plan\n[ ] Signal completion" } } ], "ts": 1767572800206 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_PnIzU0bpR_a6x_DZ2Ecxyw", "content": "Subtask completed.\n\nResult:\n[REDACTED: Detailed architectural plan]" }, { "type": "text", "text": "<environment_details>\n[REDACTED: Environment details]\n</environment_details>" } ], "ts": 1767572975593 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED: Planning next steps]", "summary": [] }, { "type": "tool_use", "id": "tooluse_ny96idEmSkuNX0DUebTWBQ", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[-] Task 2\n[ ] Task 3\n[ ] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8" } } ], "ts": 1767572985455 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_ny96idEmSkuNX0DUebTWBQ", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767572985656 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED: Reasoning about executing plan]", "summary": [] }, { "type": "text", "text": "Now executing Phase 1 of the migration." }, { "type": "tool_use", "id": "tooluse_feOGGK5MQneQeNyWn3LiGg", "name": "new_task", "input": { "mode": "code", "message": "[REDACTED: Code modification instructions]", "todos": "[ ] Read file\n[ ] Update code\n[ ] Complete task" } } ], "ts": 1767573000981 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_feOGGK5MQneQeNyWn3LiGg", "content": "Subtask completed.\n\nResult:\n[REDACTED: File modification results]" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573054659 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "tool_use", "id": "tooluse_FORPY8fsS7ucI11KTUBp9g", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[x] Task 2\n[-] Task 3\n[ ] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8" } } ], "ts": 1767573062147 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_FORPY8fsS7ucI11KTUBp9g", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573062327 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "text", "text": "Proceeding to next phase." }, { "type": "tool_use", "id": "tooluse_EyDV-CT2QFqdavs4HzHc-A", "name": "new_task", "input": { "message": "[REDACTED: Code modification instructions]", "mode": "code", "todos": "[ ] Read file\n[ ] Update code\n[ ] Complete" } } ], "ts": 1767573081694 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_EyDV-CT2QFqdavs4HzHc-A", "content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573135034 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "tool_use", "id": "tooluse_AY755nWbR--el0tqPJlOSg", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[-] Task 4\n[ ] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8" } } ], "ts": 1767573141785 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_AY755nWbR--el0tqPJlOSg", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573141919 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "text", "text": "Proceeding to next phase." }, { "type": "tool_use", "id": "tooluse_7rdkHyHnSjKfkhb-J7gEFg", "name": "new_task", "input": { "message": "[REDACTED: Code modification instructions]", "mode": "code", "todos": "[ ] Read file\n[ ] Update code\n[ ] Complete" } } ], "ts": 1767573156797 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_7rdkHyHnSjKfkhb-J7gEFg", "content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573205740 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "tool_use", "id": "tooluse_akDNjcnQSvK7qLZzNsxuWg", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[-] Task 5\n[ ] Task 6\n[ ] Task 7\n[ ] Task 8" } } ], "ts": 1767573213080 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_akDNjcnQSvK7qLZzNsxuWg", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573213239 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "text", "text": "Proceeding to final code update phase." }, { "type": "tool_use", "id": "tooluse_-qHP2tTSTWSNL19dpMtpTQ", "name": "new_task", "input": { "message": "[REDACTED: Code modification instructions]", "mode": "code", "todos": "[ ] Read file\n[ ] Update code\n[ ] Complete" } } ], "ts": 1767573228017 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_-qHP2tTSTWSNL19dpMtpTQ", "content": "Subtask completed.\n\nResult:\n[REDACTED: Modification results]" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573286474 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "tool_use", "id": "tooluse_bcGI0mPoTNGCgrQ9NFwWsQ", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[x] Task 5\n[-] Task 6\n[ ] Task 7\n[ ] Task 8" } } ], "ts": 1767573293932 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_bcGI0mPoTNGCgrQ9NFwWsQ", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573294136 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "text", "text": "Phase 6: Running the linter to verify all changes are syntactically correct." }, { "type": "tool_use", "id": "tooluse_Ok7Bkcl8RyCT2lEfRtkygg", "name": "execute_command", "input": { "command": "npm run lint", "cwd": "/path/to/project" } } ], "ts": 1767573299656 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_Ok7Bkcl8RyCT2lEfRtkygg", "content": "Command executed in terminal within working directory. Command execution was not successful, inspect the cause and adjust as needed.\nExit code: 2\nOutput:\n\n[REDACTED: Linter output with project-specific warnings and TypeScript errors in other files]" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573333822 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "The linter ran and found TypeScript errors in OTHER files not related to our changes. Our modified files have no errors.", "summary": [] }, { "type": "text", "text": "The linter shows no errors in our modified files. Now let's test the scenario." }, { "type": "tool_use", "id": "tooluse_i3O-8SusSKuQWllVCHcdqw", "name": "update_todo_list", "input": { "todos": "[x] Task 1\n[x] Task 2\n[x] Task 3\n[x] Task 4\n[x] Task 5\n[x] Task 6\n[-] Task 7\n[ ] Task 8" } } ], "ts": 1767573342204 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_i3O-8SusSKuQWllVCHcdqw", "content": "Todo list updated successfully." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767573342409 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "[REDACTED]", "summary": [] }, { "type": "text", "text": "Now running the test to verify the migration works correctly." }, { "type": "tool_use", "id": "tooluse_-SZO09niSuehB1YFk4pX3Q", "name": "execute_command", "input": { "command": "npm run test:eval scenario-name", "cwd": "/path/to/project" } } ], "ts": 1767573348006 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_-SZO09niSuehB1YFk4pX3Q", "content": "Command is still running in terminal from '/path/to/project'.\n\n\nYou will be updated on the terminal status and new output in the future." }, { "type": "text", "text": "<environment_details>\n# Actively Running Terminals\n## Terminal 1 (Active)\n### Working Directory: `/path/to/project`\n### Original command: `npm run test:eval scenario-name`\n\n[REDACTED: Other environment details]\n</environment_details>" } ], "ts": 1767592162165 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "The test command is still running. I should wait for it to complete.", "summary": [] }, { "type": "text", "text": "Let me check the status of the running test:" }, { "type": "tool_use", "id": "tooluse_cXZ3_VlASVOFI3iG1Ypdow", "name": "execute_command", "input": { "command": "echo \"Waiting for test to complete...\"", "cwd": "/path/to/project" } } ], "ts": 1767592168782 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_cXZ3_VlASVOFI3iG1Ypdow", "content": "Command executed in terminal within working directory. Exit code: 0\nOutput:\nWaiting for test to complete..." }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767592174398 }, { "role": "assistant", "content": [ { "type": "reasoning", "text": "The test is still running. Let me check if there's any test process.", "summary": [] }, { "type": "tool_use", "id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g", "name": "execute_command", "input": { "command": "ps aux | grep -i \"npm.*test:eval\" | grep -v grep || echo \"No test processes found\"", "cwd": "/path/to/project" } } ], "ts": 1767592178982 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g", "content": "Command executed in terminal within working directory. Exit code: 0\nOutput:\nNo test processes found" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767592179756 }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "tooluse_QZ-pU8v2QKO8L8fHoJRI2g", "content": "{\"status\":\"approved\",\"message\":\"The user approved this operation and provided the following context\",\"feedback\":\"Run again\"}" }, { "type": "text", "text": "<environment_details>\n[REDACTED]\n</environment_details>" } ], "ts": 1767592234718 } ] }Key observation: The same
tool_use_id(tooluse_QZ-pU8v2QKO8L8fHoJRI2g) received TWOtool_resultblocks - one from the command execution, and another from user approval. This violates the API protocol requiring exactly one tool_result per tool_use.Root Cause Analysis
The Problem
A race condition between terminal fallback and user approval generates duplicate
tool_resultblocks for the sametool_use_id, violating the Anthropic API protocol and causing an unrecoverable state.Specific Mechanism
Terminal Fallback Trigger
ShellIntegrationErroris thrownRace Condition
ask("command_output")Duplicate Generation
pushToolResult()callback addstool_resultblocks to conversation historytool_use_idtool_use_idtool_resultblocks for 1tool_useblock → API errorWhy Existing Safeguards Failed
Existing
validateAndFixToolResultIds()function has de-duplication logic embedded within position-matching flow, but doesn't explicitly filter duplicatetool_resultblocks with the sametool_use_idbefore other processing.Recommended Fix
Surgical Single-File Solution
Approach: Add explicit de-duplication step to
validateAndFixToolResultIds()that filters duplicatetool_resultblocks before any other processing.File Modified: Only
src/core/task/validateToolResultIds.tsImplementation: Insert new logic after extracting
tool_resultblocks (after line 83):How This Fixes the Bug
Bug Scenario:
With This Fix:
tool_resultwithtooluse_QZ-pU8v2QKO8L8fHoJRI2g: Not seen → keep → add to Settool_resultwith same ID: Already in Set → filter outtool_resultremains for the 1tool_useblockAdvantages
Impact
Additional Notes
Why Integrated Terminal Isn't a Full Solution
While switching to integrated terminal was suggested as a workaround, it doesn't support custom shells, which breaks workflows requiring:
Therefore, fixing the external terminal fallback mechanism is necessary for these use cases.
Testing Recommendations
validateToolResultIds.spec.tsfor exact duplicate scenarioHistorical Context
When Was This Bug Introduced?
Type: Latent bug exposed by architectural change
Timeline:
Why Did This Surface Now?
Root Cause: Switch from XML to Native Tool Protocol as Default
XML Tool Protocol (Pre-December 2025)
Native Tool Protocol (Post-December 2025)
tool_resultpertool_use_idRelated Issues During Native Tool Rollout
Multiple PRs attempted to fix tool_result issues during November-December 2025 native tool protocol rollout:
validateAndFixToolResultIds())This pattern suggests the native tool protocol rollout exposed multiple edge cases in tool result handling, including this terminal fallback race condition.
Why Existing Fixes Didn't Catch This
The validation function
validateAndFixToolResultIds()was introduced in v3.36.3 (Dec 9, 2025) and has de-duplication logic embedded within its position-matching flow (lines 146-183). However:Implications
This context explains why unattended access broke suddenly in January 2026 despite the codebase being stable for months.