Normalize blank tool-call content - #3
Open
Yiivgeny wants to merge 6 commits into
Open
Conversation
…ddleware feat(quality): add inference quality metrics middleware
…: 429 / 500 retires under the hood without early error return
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.
Summary
Fix native tool-call request normalization for OpenAI-compatible clients that send assistant tool-call messages with blank
content.Current
maincontains a compatibility bug: when a client sends an assistant message withtool_callsandcontentas an empty or whitespace-only string, Gonka upstream can reject the request with:{"error":{"message":"messages[1].content: must not be empty"}}This request shape is produced by the latest version of
opencodeduring tool/skill calls.Problem
OpenAI-compatible tool-call turns may contain an assistant message like:
{ "role": "assistant", "content": "", "tool_calls": [...] }or:
{ "role": "assistant", "content": " ", "tool_calls": [...] }Gonka upstream accepts
content: nullfor this case, but rejects blank string content, at least for Qwen.Reproduction
Against a proxy running current
main:Expected: request is normalized and forwarded successfully.
Actual:
{"error":{"message":"messages[1].content: must not be empty"}}The same issue is currently visible on the public proxy:
https://proxy.gonka.gg/v1returns the samemessages[1].content: must not be emptyerror for Qwen whencontentis""or whitespace-only. The same request succeeds whencontentis changed tonull.Fix
In native tool-call mode, normalize assistant messages that have
tool_callsand blank stringcontentto:This preserves the OpenAI-compatible tool-call shape while avoiding Gonka upstream’s blank-content validation error.
Validation
go test ./internal/apigo test ./...content: ""now returns200content: " "now returns200