Skip to content

Commit d05e86c

Browse files
Unexport CopilotRequestContext body channel in Go
The body channel is internal framework plumbing: the adapter drains it for HTTP requests and pumps it to CopilotWebSocketHandler.SendRequestMessage for WebSocket requests. It was exported only because Go exports by capitalisation; no other SDK surfaces the body channel on the request context. A consumer reading it directly (e.g. via RequestContextFrom) would race the adapter's pump goroutine and lose frames. Lowercase it to body to match the other SDKs and keep it internal to the adapter layer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2cbec1f commit d05e86c

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

go/copilot_request_handler.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ type CopilotRequestContext struct {
5757
Method string
5858
URL string
5959
Headers http.Header
60-
// Body yields request body frames as they arrive from the runtime. The
61-
// channel is closed when the body ends or the request is cancelled. For
62-
// WebSocket requests each frame's Binary flag distinguishes a binary frame
63-
// from a UTF-8 text frame; for HTTP it is always a body byte chunk.
64-
Body <-chan CopilotWebSocketMessage
60+
// body yields request body frames as they arrive from the runtime. It is
61+
// unexported framework plumbing: the adapter drains it for HTTP requests
62+
// and pumps it to [CopilotWebSocketHandler.SendRequestMessage] for
63+
// WebSocket requests. Consumers read the HTTP body via the standard
64+
// [http.Request] Body in a custom RoundTripper, or receive WebSocket frames
65+
// via SendRequestMessage — never from this channel directly (doing so would
66+
// race the adapter's pump goroutine and lose frames). The channel is closed
67+
// when the body ends or the request is cancelled. For WebSocket requests
68+
// each frame's Binary flag distinguishes a binary frame from a UTF-8 text
69+
// frame; for HTTP it is always a body byte chunk.
70+
body <-chan CopilotWebSocketMessage
6571
// Context is cancelled when the runtime cancels this in-flight request.
6672
Context context.Context
6773
}
@@ -181,7 +187,7 @@ func (h *CopilotRequestHandler) handleHTTP(rctx *CopilotRequestContext, sink *re
181187
}
182188

183189
func buildHTTPRequest(rctx *CopilotRequestContext) (*http.Request, error) {
184-
body := drainBody(rctx.Body)
190+
body := drainBody(rctx.body)
185191
method := strings.ToUpper(rctx.Method)
186192
var bodyReader io.Reader
187193
if len(body) > 0 && method != http.MethodGet && method != http.MethodHead {
@@ -278,7 +284,7 @@ func (h *CopilotRequestHandler) handleWebSocket(rctx *CopilotRequestContext, sin
278284
defer close(clientDone)
279285
for {
280286
select {
281-
case frame, ok := <-rctx.Body:
287+
case frame, ok := <-rctx.body:
282288
if !ok {
283289
return
284290
}
@@ -619,7 +625,7 @@ func (a *copilotRequestAdapter) HttpRequestStart(params *rpc.LlmInferenceHTTPReq
619625
URL: params.URL,
620626
Headers: headers,
621627
Transport: transport,
622-
Body: bodyCh,
628+
body: bodyCh,
623629
Context: ctx,
624630
}
625631
sink := &responseSink{requestID: params.RequestID, adapter: a, exchange: exchange}

0 commit comments

Comments
 (0)