fix(openai): drain error response body for HTTP connection reuse#2450
Merged
Conversation
esengine
pushed a commit
that referenced
this pull request
May 31, 2026
Surface previously-swallowed errors via slog across checkpoint dir/persist, controller snapshot (compact + rewind), model-switch snapshot, config load-for-edit, and MCP initialize parsing — silent failures (e.g. a checkpoint that never persisted) are now visible in logs without disrupting flow. Rebased over #2450/#2459: dropped the now-redundant serve.writeJSON change (already landed in #2459) and merged the openai readErr fallback with #2450's body drain. Thanks @HUQIANTAO.
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
After reading the limited (4KB) error body from a non-200 response, drain any remaining body to
io.Discardbefore closing. This ensures the HTTP/2 connection can be reused by Go's transport pool.Before
After
Motivation
Go's
http.Transportreuses connections only when the response body is fully drained. Without draining, each retry insendWithRetryopens a new TCP connection instead of reusing the existing one. This is especially impactful for the retry loop (up to 3 attempts on transient errors).