refactor(logging): rename FileBodySource.WriteTo to MergeTo; document stream cancel ownership - #177
Open
warelik wants to merge 2 commits into
Open
refactor(logging): rename FileBodySource.WriteTo to MergeTo; document stream cancel ownership#177warelik wants to merge 2 commits into
warelik wants to merge 2 commits into
Conversation
added 2 commits
August 13, 2026 14:54
Rename the internal FileBodySource.WriteTo method to MergeTo to eliminate the inspection-time collision with the io.WriterTo interface. The previous name made the type satisfy io.WriterTo, which is a correctness hazard: callers that pass a FileBodySource where an io.WriterTo is expected could silently misroute the merge path, and the extra interface conformance invited misuse in fmt.Sprintf and other writer-to sinks. MergeTo is behavior-identical: it merges all ordered parts into w and reports the first write error. Update the three call sites (middleware response merge, and the logging format section writers) accordingly. Twin of CPA PR #4943 commit 74609535. Verified independently: five post-edit files byte-identical to CPA, gofmt, -race, go vet, and full test suite/build all clean.
In callHostHTTPDoStream and callHostModelExecuteStream the derived streamCtx/cancel pair is handed to the stream bridge on the success path, so the bridge owns cancellation. On error paths the local code still calls cancel() explicitly, then returns without re-calling it. Add a blank-line comment documenting that the cancel function transfers ownership to the stream bridge on success, and bind it to the blank identifier to reflect that the success path is intentionally not cancelled locally. Comment/documentation plus a functional no-op; no behavior change. Twin of CPA PR #4943 commit 05971fbb. Verified independently: five post-edit files byte-identical to CPA, gofmt, -race, go vet, and full test suite/build all clean.
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
Fixes
go vetwarning aboutFileBodySource.WriteToshadowing theio.WriterTointerface method and documents the cancel-ownership transfer pattern in the plugin host stream bridge.Changes
1. Rename
FileBodySource.WriteTo→MergeTo(internal/logging)FileBodySource.WriteTo(w io.Writer) errorhas a different signature thanio.WriterTo.WriteTo(w io.Writer) (int64, error). This shadows the standard interface method and triggersgo vetwarnings. Renamed toMergeTo— semantically accurate (the method merges ordered log parts into a writer) and avoids the signature collision.Updated all 5 call sites:
request_logger_body_source.go— method definition +Bytes()helperrequest_logger_format.go—writeAPISectionWithSource,writePreformattedAPISectionWithSourceresponse_writer.go—mergeFileBodySource2. Document cancel-ownership in plugin host (
internal/pluginhost)host_callbacks.goandhost_model_stream_callbacks.goboth create acontext.WithCancelwhosecancelfunc transfers ownership to the stream bridge on the success path. Without a comment,go vet(and human reviewers) seecancelassigned but never called on the success path and flag it as a leak. Added_ = cancelwith a comment explaining the ownership transfer.Verification
go vet ./...cleango build ./...cleango test -count=1 ./internal/logging/... ./internal/pluginhost/... ./internal/api/middleware/...Mirror
CPA: router-for-me/CLIProxyAPI#4943 (identical changes)