refactor: extract readRequestBody and parseBoolQueryParam helpers#745
Open
ericcurtin wants to merge 1 commit intomainfrom
Open
refactor: extract readRequestBody and parseBoolQueryParam helpers#745ericcurtin wants to merge 1 commit intomainfrom
ericcurtin wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
Configure, the change frombackend, err = h.scheduler.ConfigureRunner(...)tobackend, err := ...introduces variable shadowing, so the outerbackendvalue will not be updated after the call; this should be reverted to an assignment (=) to preserve the original behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Configure`, the change from `backend, err = h.scheduler.ConfigureRunner(...)` to `backend, err := ...` introduces variable shadowing, so the outer `backend` value will not be updated after the call; this should be reverted to an assignment (`=`) to preserve the original behavior.
## Individual Comments
### Comment 1
<location path="pkg/inference/scheduling/http_handler.go" line_range="429" />
<code_context>
}
- backend, err = h.scheduler.ConfigureRunner(r.Context(), backend, configureRequest, r.UserAgent())
+ backend, err := h.scheduler.ConfigureRunner(r.Context(), backend, configureRequest, r.UserAgent())
if err != nil {
if errors.Is(err, errRunnerAlreadyActive) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid shadowing the outer `backend`/`err` here to prevent subtle bugs
This line used to reassign the existing `backend`/`err`; switching to `:=` creates new inner-scope variables and leaves the outer ones unchanged. Any code after this block will still see the old values, which changes the previous behavior and can introduce hard-to-spot bugs. Unless a new inner scope is intended, please use `backend, err = ...` to match the original semantics.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request effectively refactors duplicated code into two new helper functions, readRequestBody and parseBoolQueryParam, improving code maintainability. The refactoring is well-executed. However, I've identified a potential logic issue in the new parseBoolQueryParam function (which was also present in the original code) regarding the handling of boolean query parameters without explicit values. I've suggested a fix to make the API behavior more intuitive.
doringeman
approved these changes
Mar 16, 2026
Deduplicate the MaxBytesReader+ReadAll error-handling block (repeated 4x in scheduling/http_handler.go) into a readRequestBody helper, and the bool query-param parsing block (repeated 2x in models/http_handler.go) into a parseBoolQueryParam helper. Signed-off-by: Eric Curtin <eric.curtin@docker.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.
Deduplicate the MaxBytesReader+ReadAll error-handling block (repeated 4x in scheduling/http_handler.go) into a readRequestBody helper, and the bool query-param parsing block (repeated 2x in models/http_handler.go) into a parseBoolQueryParam helper.