You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug/Robustness] 400 Error: InternalError.Algo.InvalidParameter due to unclosed tool_calls after interruption #22808
[Bug/Robustness] 400 Error: InternalError.Algo.InvalidParameter due to unclosed tool_calls after interruption
Description
When using OpenCode with Alibaba DashScope (阿里云百炼) or similar providers, the session becomes permanently corrupted if an agent fails to provide a tool response following an assistant message that contains tool_calls.
This typically occurs in multi-agent workflows when:
An agent crashes or timed out after generating a tool call.
The system/process is interrupted or rebooted before the tool execution completes.
Upon restarting the session, the API returns a 400 Bad Request: "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'."
Root Cause
Alibaba DashScope's inference engine (and OpenAI's strict mode) enforces a strict transactional sequence for tool calls. If the conversation history sent to the API ends with a "dangling" tool_calls without corresponding tool results, the API rejects the entire payload.
Proposed Solution: The "Tombstone" Pattern (Preferred)
I recommend implementing a Self-Healing/Auto-Completion mechanism within the framework's message persistence or pre-request layer.
Logic:
Before dispatching the messages array to the LLM API, the framework should validate the integrity of the tool-call chain. If a dangling tool_call_id is detected, OpenCode should automatically inject a "Tombstone" (placeholder) message to close the loop.
Example Injected Payload:
{
"role": "tool",
"tool_call_id": "the_interrupted_call_id",
"content": "{\"error\": \"System interruption: The agent/tool failed to return a result in the previous session.\"}"
}
Plugins
No response
OpenCode version
1.4.6
Steps to reproduce
interrupt opencode when it is calling tool. (actually, I do not interrupt it,maybe the internal tool interrupt)
Screenshot and/or share link
"<400> InternalError.Algo.InvalidParameter: An assistant message with "tool_calls" must be followed by tool messages responding to each "tool_call_id"."
Steps to reproduce are missing — bug reports should include some context on how to trigger the issue
System information (OpenCode version, Operating System, Terminal) are all left as _No response_ — please provide your environment details so maintainers can investigate
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
Thank you for updating the issue! It now contains all the required information and looks good. We appreciate you including the error details, screenshot, and system information.
Activity
github-actions commentedon Apr 16, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
_No response_— please provide your environment details so maintainers can investigatePlease edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Apr 16, 2026
Thanks for updating the issue description — it now includes a clear explanation of the bug and root cause.
However, the following required fields are still left as
_No response_(placeholder text):Please edit the issue to fill in these fields. System information is important so maintainers can investigate and reproduce the problem.
github-actions commentedon Apr 16, 2026
Thank you for updating the issue! It now contains all the required information and looks good. We appreciate you including the error details, screenshot, and system information.
github-actions commentedon Jul 18, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.