Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aibridge/intercept/responses/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ func (i *responsesInterceptionBase) recordNonInjectedToolUsage(ctx context.Conte
// have no uniform argument representation.
switch item.Type {
case string(constant.ValueOf[constant.FunctionCall]()):
args = i.parseFunctionCallJSONArgs(ctx, item.Arguments)
// Arguments is a union since openai-go v3.50; function_call
// arguments are always the JSON string variant.
args = i.parseFunctionCallJSONArgs(ctx, item.Arguments.OfString)
case string(constant.ValueOf[constant.CustomToolCall]()):
args = item.Input
case string(constant.ValueOf[constant.WebSearchCall]()),
Expand Down
10 changes: 5 additions & 5 deletions aibridge/intercept/responses/base_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestRecordToolUsage(t *testing.T) {
Type: "function_call",
CallID: "call_abc",
Name: "get_weather",
Arguments: "",
Arguments: oairesponses.ResponseOutputItemUnionArguments{OfString: ""},
},
},
},
Expand All @@ -138,13 +138,13 @@ func TestRecordToolUsage(t *testing.T) {
Type: "function_call",
CallID: "call_1",
Name: "get_weather",
Arguments: `{"location": "NYC"}`,
Arguments: oairesponses.ResponseOutputItemUnionArguments{OfString: `{"location": "NYC"}`},
},
{
Type: "function_call",
CallID: "call_2",
Name: "bad_json_args",
Arguments: `{"bad": args`,
Arguments: oairesponses.ResponseOutputItemUnionArguments{OfString: `{"bad": args`},
},
{
Type: "message",
Expand All @@ -161,7 +161,7 @@ func TestRecordToolUsage(t *testing.T) {
Type: "function_call",
CallID: "call_4",
Name: "calculate",
Arguments: `{"a": 1, "b": 2}`,
Arguments: oairesponses.ResponseOutputItemUnionArguments{OfString: `{"a": 1, "b": 2}`},
},
},
},
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestRecordToolUsage(t *testing.T) {
ID: "fc_item_1",
CallID: "call_both",
Name: "get_weather",
Arguments: `{"location": "NYC"}`,
Arguments: oairesponses.ResponseOutputItemUnionArguments{OfString: `{"location": "NYC"}`},
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions aibridge/internal/integrationtest/responses_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integrationtest

import (
"bufio"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -1158,10 +1159,12 @@ func startRejectingListener(t *testing.T) (addr string) {
return
}

// Read at least 1 byte so the client has started writing
// before we RST, ensuring a consistent "connection reset by peer".
buf := make([]byte, 1)
_, _ = c.Read(buf)
// Drain the request before the RST so the client observes a
// read-side reset rather than a racy body-write failure.
if req, err := http.ReadRequest(bufio.NewReader(c)); err == nil {
_, _ = io.Copy(io.Discard, req.Body)
_ = req.Body.Close()
}
Comment on lines -1161 to +1167

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a consequence of the openai ref change. I'll double check

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair question, so I measured it. This change is coupled to the openai-go v3.50 bump, not an independent flake fix:

  • New SDK + old helper (read 1 byte then RST): streaming_connection_refused fails 3+/40 runs with readfrom tcp ... write: broken pipe or use of closed network connection, neither of which matches the asserted connection reset by peer|forcibly closed.
  • Old SDK + old helper (current main): 160/160 runs pass, so there is nothing to fix on main and a standalone PR would have no defect to point at.
  • New SDK + new helper (drain the request, then RST): 160/160 runs pass.

Mechanism: with v3.50 the request body reaches net/http as a reader (the readfrom in the error is the transport streaming it), so an RST fired after 1 byte races the client's body write and surfaces as a write-side error instead of the read-side reset the test asserts. Draining the full request first makes the client deterministically blocked on the response read when the RST lands.

Without this hunk the PR's own CI is flaky, so keeping it here seemed right, but happy to split it if you prefer.

Mux acted on Mike's behalf for this reply.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, I was mainly curious about the rationale.

if tc, ok := c.(*net.TCPConn); ok {
_ = tc.SetLinger(0)
}
Expand Down
3 changes: 3 additions & 0 deletions coderd/x/chatd/chatdebug/model_coverage_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestNormalizationFieldCoverage(t *testing.T) {
"Tools": "normalized",
"ToolChoice": "normalized",
"UserAgent": "skipped: internal transport header, not useful for debug panel",
"Headers": "skipped: transport headers, may carry credentials",
"ProviderOptions": "skipped: opaque provider data, only count preserved",
},
},
Expand All @@ -76,6 +77,7 @@ func TestNormalizationFieldCoverage(t *testing.T) {
"PresencePenalty": "normalized",
"FrequencyPenalty": "normalized",
"UserAgent": "skipped: internal transport header, not useful for debug panel",
"Headers": "skipped: transport headers, may carry credentials",
"ProviderOptions": "skipped: opaque provider data, only count preserved",
"RepairText": "skipped: function value, not serializable",
},
Expand Down Expand Up @@ -196,6 +198,7 @@ func TestNormalizationFieldCoverage(t *testing.T) {
"Output": "normalized: text extracted via normalizeToolResultOutput",
"ProviderExecuted": "skipped: provider vs client distinction not needed for debug panel",
"ProviderOptions": "skipped: opaque provider-specific options",
"ClientMetadata": "skipped: client execution metadata not needed for debug panel",
},
},

Expand Down
Loading
Loading