mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4830] [Engine] /v1/responses: a text.format answer cut short ends incomplete, not 502 or response.failed #5200
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5200
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4830
Author: @gdevenyi
Created: 10/31/2026
Status: 🔄 Open
Base:
main← Head:api/responses-json-cap-incomplete📝 Commits (1)
e068079Responses: a text.format answer cut by max_output_tokens ends incomplete with the text so far, not 502 or response.failed; chat is unchanged📊 Changes
3 files changed (+107 additions, -3 deletions)
View changed files
📝
docs/DETAILS.md(+1 -1)📝
serve/responses.py(+4 -2)📝
serve/test_responses.py(+102 -0)📄 Description
Problem and result
On
/v1/responses, ajson_objectorjson_schemaanswer that hitsmax_output_tokensis an error. A plain-text answer with the same cap endsincomplete.max_output_tokens8, mock and real enginestructured_output_failedstatus: incomplete,incomplete_details: {"reason": "max_output_tokens"}response.failedresponse.incompletestatus: incompleteOpenAI's Structured Outputs guide reports this case as a response status, not an API error. Its example checks
response.status === "incomplete"andresponse.incomplete_details.reason === "max_output_tokens", then raises its own client-side error. Against Strata, that check was never reached.docs/DETAILS.mdalso says ofmax_output_tokens: "Running out ends the responseincomplete." I read the guide through a summarizing fetch tool, and only its first 100,000 of 136,310 characters. In that part it does not say what a cut response holds. Returning the text so far rests on what plain text does here, not on the guide.The 502 also costs GPU time. With the real
openaiSDK and its default retries, oneresponses.createcall ran 3 generations and then raisedInternalServerError. It now runs 1 generation and returns.No named client or user report was found. The case rests on the guide and on the retries.
Related discussion
No issue was opened. CONTRIBUTING lets a focused fix go straight to a PR, and this changes no setting. It does change a reply on an existing path, so say if you want an issue first.
Searches of issues and PRs for
structured_output_failed,finish_reason=length structured,text.format incompleteandjson_schema max_output_tokensfound no thread on this case. They ran before the final commit and were not repeated. Neighbours, none a duplicate:error: nullon failed validation.json_object, inserve/structured.py.Approach
When a JSON-format turn ends with finish
lengthand no tool call has started, the held text is released as a message item closedincomplete, and validation is skipped. The existing ending then sendsresponse.incomplete.The check rejects any finish other than
stop, so running it here could only fail, even if the text so far is whole JSON. An answer the model finished is still checked and still returns 502 if it is bad. The chat route andserve/structured.pyare not touched.docs/DETAILS.mdgets one sentence on thetext.formatrow, as the partial text is a new fact for users.Compatibility: a client that relied on the 502 for a cut answer now gets a 200, and must check
status.Validation
Revision tested: base
c62d5e3aplus commite0680791. Linux, Python 3.12.3. The runs use the mock engine, except the first item under Passed.Passed:
Real engine: RTX 5080 16 GB, engine 0.1.55 from release v0.2.9, Qwen3.8-Flash-Next IQ3_S, context 65536, real
openaiSDK 3.42.0, one server per side, with a local script that is not in the repo. Basec62d5e3aagainst branche0680791. Counts are runs that gave that result out of runs made; a dash means that case was not run on that side.c62d5e3ae0680791structured_output_failed, 6 of 6incomplete, reasonmax_output_tokens, 12 of 12responses.createstream, both formatsresponse.failed, 6 of 6response.incomplete, 12 of 12responses.streamwithtext.format, both formatsresponse.failed, 6 of 6response.incomplete, 6 of 6json_schema, non-streamincomplete, 4 of 4json_schema, streamresponse.failed, 1 of 1response.incomplete, 4 of 4json_object, non-stream and streamincomplete3 of 3,response.incomplete3 of 3completed, 12 of 12completed, 24 of 24completed, 12 of 12responses.create, default retries, cap 8InternalServerError, 1 callincomplete, 13 of 13 calls (thinking on and off, both formats)Branch only, all real engine:
status: incompleteand the text so far,{\n "name": "El. Thinking on: the cut lands in the thinking, so no text. Non-stream shows one reasoning item withstatus: incompleteand no message; stream shows one item withstatus: incompleteand no text deltas.response.failed. 24 of 24 answers checked at cap 512 parse as JSON.json_objectand a prompt asking for one plain word: 502structured_output_failedin 3 of 3 non-stream runs andresponse.failedin 3 of 3 stream runs.{"a":1}cut at 5 tokens still endedresponse.incomplete. The same prompt at cap 6 and above endedcompleted(8 of 8).responses.parseandresponses.streamwithtext_formatat cap 8 each raised a pydanticValidationErrorafter 1 generation, and at cap 512 each worked with 1 generation./v1/chat/completionswithjson_objectat cap 8 still gave 502, and at cap 512 endedstop, 1 run each.json_objectformat beside a tool: cap 8 cut inside the call gaveincompletewith afunction_callitem, and cap 60 and 512 gavecompleted, 1 run each, non-stream and stream.TracebackorERRORlines, and a plain request afterwards completed.Six tests for this change:
python -m unittest serve.test_responses.OverHttp.test_json_format_cut_by_the_cap_ends_incomplete serve.test_responses.OverHttp.test_json_format_cut_in_the_thinking_has_no_message serve.test_responses.OverHttp.test_json_format_finished_answer_is_still_checked serve.test_responses.OverHttp.test_json_format_cut_right_after_whole_json_is_still_incomplete serve.test_responses.OverHttp.test_json_format_cut_with_no_cap_ends_incomplete serve.test_responses.OverHttp.test_chat_json_format_cut_is_still_502Ran 6 tests, OK.serve/responses.pyfrom the base: four fail, each with a 502 instead of a 200. The other two pass, as they should: a finished answer is still checked, and chat's cut JSON still gives 502.Differential, base against branch, with a local script that is not in the repo. Ids, timestamps and timings were normalized. It sent 18 request shapes, each stream and non-stream, so 36 runs, on
/v1/responsesand/v1/chat/completions. They include plain text, a plain cap, completed JSON, malformed JSON, tools, a tool call cut after it started, and chat JSON with and without a cut.incompleteafter, and in the streamresponse.failedbefore,response.incompleteafter. Its message text isChecking.\n\n<tool_call>\n<function=exec, the same as plain text gives at that cap on the base.Real
openaiSDK 3.42.0 with default retries, with a local script that is not in the repo:responses.create:incomplete, reasonmax_output_tokens, the guide's check reached, 1 generation (base:InternalServerError502, 3 generations).responses.streamwithtext.format: ends inresponse.incomplete(base:response.failed).Failed:
python -m unittest serve.test_server serve.test_responses serve.test_anthropic_base_url serve.test_chat_tool_results serve.test_context_overflow serve.test_images:Ran 443 tests,FAILED (failures=1, skipped=1). The one failure isserve.test_server.GpuChoice.test_hip_ordinal('0,1' != '1,0'). The same command on the base givesRan 437 testsand the same single failure, so this change does not cause it. The 6 extra tests are the new ones.Not run:
--parallelabove the default.jsonschemais not installed in the test environment, so that part oftest_json_schema_text_formatreturned early. A completed answer that is not JSON was tested and still gives 502.Limits
responses.parse, andresponses.streamwithtext_format, now raise a client-side pydanticValidationErroron the partial JSON.responses.parseon the base raisedInternalServerErrorafter 3 generations, and now it costs 1.responses.streamwithtext_formatran 1 generation on the base and still does, but it now raises instead of ending inresponse.failed. From reading the SDK, its Responses parser has no status check, so this should not be specific to Strata. It was not tested against OpenAI.incomplete, and plain text already behaves this way. Clients must checkstatusbefore parsing.lengthfinish takes this path and reports reasonmax_output_tokens, even with no cap, as plain text does. A full context and the repeat stop were tested, so a runaway repeating answer in a JSON format is now a 200incomplete, not a 502.length. In a JSON format that engine fault should now give a 200incompleteinstead of a 502. This was not run.🤖 Generated with Claude Code
https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.