fix(providers): handle empty assistant replies and missing tool results for strict OpenAI endpoints - #33
Open
hw0rld wants to merge 1 commit into
Conversation
…ts for strict OpenAI endpoints
DeepSeek rejects two message shapes that Wallbreaker could produce, crashing
engagements with HTTP 400:
1. Empty assistant messages: when the target returns a reasoning-only reply
(no content), query_target/continue_target persisted an assistant message
with empty content. DeepSeek rejects this with 'Invalid assistant message:
content or tool_calls must be set'. Fix: never persist an empty assistant
message in the target thread; when a reply is empty, fold the recovered CoT
into the message or use a marker. Also skip empty assistant messages in the
OpenAI wire serializer as a defense-in-depth guard.
2. Unfinished tool-call rounds on resume: a crashed session can end with an
assistant message carrying tool_calls but no recorded tool results. DeepSeek
rejects the next request ('An assistant message with tool_calls must be
followed by tool messages responding to each tool_call_id'). Fix: the OpenAI
wire serializer inserts placeholder tool results for any missing tool_call_id
so resumed sessions stay valid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two HTTP 400 crashes when running against strict OpenAI-compatible
endpoints (DeepSeek). Both crashes killed live engagements and made resumed
sessions unusable.
Bug 1: empty assistant messages
When the target returns a reasoning-only reply (content empty, CoT present),
query_target/continue_targetpersisted an assistant message with emptycontent into the target thread. DeepSeek rejects the next request with:
Fix:
tools/target.py_persist_thread: an empty reply no longer appends an emptyassistant message to the thread.
tools/target.py_continue_target: an empty reply folds the recovered CoTinto the message body, or uses a small marker when even CoT is missing.
providers/openai_provider.py_messages_to_wire: defense-in-depth — skipassistant messages with neither text nor tool calls (also covers resumed
sessions that already contain poisoned history).
Bug 2: unfinished tool-call rounds on resume
A session that crashed mid-tool-execution can end with an assistant message
carrying
tool_callsbut no recorded tool results. Resuming and sending thenext turn makes DeepSeek reject the request with:
Fix:
providers/openai_provider.py: new_complete_missing_tool_results()insertsplaceholder tool results for any missing
tool_call_idwhen serializing tothe wire, so recovered sessions stay valid.
Verification
200 OK.pytest tests -k "target or continue or provider or session": 223 passed.test_tui_autocompleteresume picker,test_tg5_hardenmissinghypothesis) fail identically onmainbefore thischange.
Impact
Token cost is negligible (placeholders are a few tokens; empty replies now carry
the already-recovered CoT instead of nothing). No behavior change for healthy
threads.