server : fix 500 bad_function_call on validation errors with X-Conversation-Id (#25605)#25623
Open
AmariahAK wants to merge 2 commits into
Open
server : fix 500 bad_function_call on validation errors with X-Conversation-Id (#25605)#25623AmariahAK wants to merge 2 commits into
AmariahAK wants to merge 2 commits into
Conversation
…on-Id guard on_complete() against empty next_orig when set_next() was never called (validation failed before streaming setup), preventing std::bad_function_call from replacing a 400 JSON error with a 500 plain-text response
|
Hi @AmariahAK, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
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.
When POST /v1/chat/completions carries the X-Conversation-Id header and the request body fails validation (e.g. "backend_sampling": ""), the server returns 500 bad_function_call instead of 400. The same invalid body without the header correctly returns 400.
Root cause: server_res_spipe::set_req() attaches the stream pipe before validation. When validation throws, set_next() is never called, leaving next_orig empty. The error path still calls on_complete(), which invokes the empty std::function and throws std::bad_function_call. That escapes to httplib's exception handler, which replaces the 400 JSON body with 500 plain-text.
Fix: add !next_orig to the guard in server_res_spipe::on_complete() so it returns early when next_orig was never assigned.
AI usage disclosure: YES — AI was used to analyze the bug and suggest the fix. The change was reviewed and understood before committing.