-
-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Steps to Reproduce
1.Was having Sapphire SSH into machine
2.Closed the connection - claudecode was making a fix for pipewire, did not want both in there at once
3. I went back into conversation, it would error out, with a Err 400 Invalid Request
What Happened
As stated above. Tool use was in progress, iin the middle of doing something, I shut down the server and restarted sapphire. This led to me openeing the same chat and trying to continue, only to not be able to.
This is a Claude API conversation format error. When Claude responds with a tool_use block (requesting to call a tool), the API requires the very next message to contain a tool_result block with the matching ID. Something in Sapphire's message history has a tool_use without its corresponding
tool_result, so Claude rejects the whole conversation at message index 40.
What You Expected
Continue where we left off. Trim the chat so that it closes correctly at the end of the API when shutdown happens.
Logs attached
System Info
- OS / Distro: Kubuntu 25.10
- CPU:
- RAM:
- GPU / VRAM:
- Sapphire version / commit:
- LLM backend (e.g. QWQ32B, Qwen3, Claude): Claude Opus 4.6
Logs
2026-03-10 23:07:42,736 - core.chat.llm_providers.claude - INFO - [THINK] Claude extended thinking enabled (budget: 10000)
2026-03-10 23:07:42,736 - core.chat.llm_providers.claude - INFO - [CACHE] Tool caching active on last tool (TTL: 1h)
2026-03-10 23:07:42,878 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 400 Bad Request"
2026-03-10 23:07:42,878 - core.chat.chat_streaming - ERROR - [ERR] [STREAMING] Iteration 1 failed: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after:
toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use block must have a corresponding tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
Traceback (most recent call last):
File "/home/cisco/projects/sapphire/core/chat/chat_streaming.py", line 223, in chat_stream
for event in self.current_stream:
File "/home/cisco/projects/sapphire/core/chat/llm_providers/claude.py", line 365, in chat_completion_stream
with stream_ctx as stream:
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/lib/streaming/_messages.py", line 167, in enter
raw_stream = self.__api_request()
^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1364, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1137, in request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after: toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use block must have a corresponding
tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
2026-03-10 23:07:42,878 - core.chat.chat_streaming - INFO - [CLEANUP] Stream closed
2026-03-10 23:07:42,878 - core.chat.chat_streaming - ERROR - [ERR] [STREAMING FATAL] Unhandled error: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after:
toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use block must have a corresponding tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
Traceback (most recent call last):
File "/home/cisco/projects/sapphire/core/chat/chat_streaming.py", line 223, in chat_stream
for event in self.current_stream:
File "/home/cisco/projects/sapphire/core/chat/llm_providers/claude.py", line 365, in chat_completion_stream
with stream_ctx as stream:
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/lib/streaming/_messages.py", line 167, in enter
raw_stream = self.__api_request()
^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1364, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1137, in request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after: toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use block must have a corresponding
tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
2026-03-10 23:07:42,878 - core.chat.chat_streaming - INFO - [CLEANUP] [STREAMING FINALLY] Cleaning up, cancel_flag=False
2026-03-10 23:07:42,878 - core.routes.chat - ERROR - STREAMING ERROR: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after: toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use
block must have a corresponding tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
Traceback (most recent call last):
File "/home/cisco/projects/sapphire/core/routes/chat.py", line 222, in generate
for event in system.llm_chat.chat_stream(data['text'], prefill=prefill, skip_user_message=skip_user_message, images=images, files=files):
File "/home/cisco/projects/sapphire/core/chat/chat_streaming.py", line 223, in chat_stream
for event in self.current_stream:
File "/home/cisco/projects/sapphire/core/chat/llm_providers/claude.py", line 365, in chat_completion_stream
with stream_ctx as stream:
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/lib/streaming/_messages.py", line 167, in enter
raw_stream = self.__api_request()
^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1364, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/miniconda3/envs/sapphire/lib/python3.11/site-packages/anthropic/_base_client.py", line 1137, in request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.40: tool_use ids were found without tool_result blocks immediately after: toolu_01XbysKLwgiAyPBLbiLq3cfR. Each tool_use block must have a corresponding
tool_result block in the next message.'}, 'request_id': 'req_011CYvZBZTfESkFmA9UFG3Xc'}
What is this error. I was not having this problem before
(paste logs here)