fix(llm-proxy): avoid disturbing response body when JSON parse fails#1923
Merged
chrarnoldus merged 1 commit intomainfrom Apr 2, 2026
Merged
fix(llm-proxy): avoid disturbing response body when JSON parse fails#1923chrarnoldus merged 1 commit intomainfrom
chrarnoldus merged 1 commit intomainfrom
Conversation
Read body text once via response.text() instead of using response.clone().json(). When the cloned response's .json() call failed (e.g. empty/invalid body), the original response.body stream was left in a disturbed/locked state, causing 'Response body object should not be disturbed or locked' TypeError. Fixes KILOCODE-WEB-1PNQ
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-2026-03-05 · 199,076 tokens |
Contributor
imanolmzd-svg
approved these changes
Apr 2, 2026
jeanduplessis
pushed a commit
that referenced
this pull request
Apr 2, 2026
…1923) Read body text once via response.text() instead of using response.clone().json(). When the cloned response's .json() call failed (e.g. empty/invalid body), the original response.body stream was left in a disturbed/locked state, causing 'Response body object should not be disturbed or locked' TypeError. Fixes KILOCODE-WEB-1PNQ Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
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
TypeError: Response body object should not be disturbed or locked(KILOCODE-WEB-1PNQ) in the LLM proxy rewrite layer. The threerewriteFreeModelResponse_*functions usedresponse.clone().json()to attempt JSON parsing, falling back to passingresponse.bodythrough on failure. When.json()failed on the clone, the original response body was left in a disturbed/locked state, making it unusable in the catch block.The fix reads the body once via
response.text()and then usesJSON.parse(). On parse failure, the already-read text string is passed through instead of the now-consumed body stream.Verification
pnpm typecheckpasses (exit code 0)pnpm format:checkpassesVisual Changes
N/A
Reviewer Notes
The same pattern was fixed in all three functions:
rewriteFreeModelResponse_ChatCompletions,rewriteFreeModelResponse_Messages, andrewriteFreeModelResponse_Responses. The Sentry issue only showed the ChatCompletions path, but the other two had the identical bug.