Skip to content

server : fix 500 bad_function_call on validation errors with X-Conversation-Id (#25605)#25623

Open
AmariahAK wants to merge 2 commits into
ggml-org:masterfrom
AmariahAK:master
Open

server : fix 500 bad_function_call on validation errors with X-Conversation-Id (#25605)#25623
AmariahAK wants to merge 2 commits into
ggml-org:masterfrom
AmariahAK:master

Conversation

@AmariahAK

Copy link
Copy Markdown

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.

AmariahAK and others added 2 commits July 13, 2026 16:25
…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
@AmariahAK AmariahAK requested a review from a team as a code owner July 13, 2026 13:47
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Hi @AmariahAK, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant