Repository navigation
Conversation
bf128bd to
4d80be1
Compare
d102580 to
c48c2bb
Compare
| // onChange is called when circuit state changes. | ||
| // metrics is used to record circuit breaker reject counts (can be nil). | ||
| func NewProviderCircuitBreakers(provider string, cfg *config.CircuitBreaker, onChange func(endpoint, model string, from, to gobreaker.State), m *metrics.Metrics) *ProviderCircuitBreakers { | ||
| func NewProviderCircuitBreakersWithCallback(provider string, cfg *config.CircuitBreaker, onChange func(endpoint, model string, from, to gobreaker.State), m *metrics.Metrics) *ProviderCircuitBreakers { |
There was a problem hiding this comment.
Looks like this exported function is only used in tests?
There was a problem hiding this comment.
Yes IIRC the NewProviderCircuitBreakersWithCallback is test only. I could leave constructor as it was, where callback was created by caller but the production code always sets the same callback so it made sense to me to move it into the constructor.
Other option would be to export some DefaultCallback function and keep old function signature.
ssncferreira
left a comment
There was a problem hiding this comment.
Overall LGTM, I have a few questions and suggestions, but nothing blocking. Maybe some are already addressed in upstack PRs.
| @@ -0,0 +1,61 @@ | |||
| package client | |||
There was a problem hiding this comment.
Would it make more sense to call this file headers.go, given that the helpers are mostly on headers? And maybe moving some of the client_headers.go logic to here (except what is needed for interception)? I assume some of that logic will be needed for the reverse proxy. Would that make sense?
| { | ||
| name: "claude_code_header_takes_precedence", | ||
| client: aibridge.ClientClaudeCode, | ||
| client: client.ClientClaudeCode, |
There was a problem hiding this comment.
nit: could we rename these consts to look like client.ClaudeCode? Also, client.Client from above reads off 😕
| "context" | ||
|
|
||
| "cdr.dev/slog/v3" | ||
| "github.com/coder/coder/v2/aibridge/credential" |
There was a problem hiding this comment.
Couldn't we move all this logic to the new aibridge/credential/credential.go?
| t.Parallel() | ||
|
|
||
| gotType, gotMsg := categorizeInterceptionError(tc.cat, tc.err) | ||
| gotType, gotMsg := interceptionerror.Categorize(tc.cat, tc.err) |
There was a problem hiding this comment.
nit: should we update the name of the test to match the new function name?
| "time" | ||
| ) | ||
|
|
||
| const ( |
There was a problem hiding this comment.
Does this actor logic belong here? 🤔 Shouldn't it be in the actor_headers.go file?
c48c2bb to
bdf0943
Compare
Move the actor header prefix, name builders, matcher, and actor-to-header mapping out of utils and intercept into a dedicated headers package so request handlers can share them without depending on intercept.
7cec86a to
8e5c7c5
Compare
8e5c7c5 to
18de0b0
Compare
Moves shared client identification, credential handling, header processing, and error categorization into reusable packages for AI Gateway handlers. Existing callers use the destination packages directly; runtime behavior and serialized values are unchanged.
Code moves
Client, allClient*constants, andGuessClientaibridge/client.goaibridge/client/client.go; the type is nowclient.Typeand constants drop theClientprefix, e.g.client.ClaudeCodeGuessSessionID,cleanRef, and the Claude session-ID regexaibridge/session.goaibridge/client/session.goisWebSocketUpgradeaibridge/bridge.goaibridge/headers/headers.go, exported asIsWebSocketUpgradeextractAgentFirewallHeadersaibridge/bridge.goaibridge/headers/headers.go, exported asExtractAgentFirewallHeadersCredential,BYOK,AWSSigV4,CentralizedPool, their methods,AsBYOK,AsCentralizedPool, andWithCredentialInfoaibridge/intercept/credential.goaibridge/credential/credential.goCredentialKindand centralized/BYOK constantsaibridge/intercept/credential.goaibridge/credential/credential.go, renamedKind,KindCentralized, andKindBYOKAuthHeaderXAPIKeyandAuthHeaderAuthorizationaibridge/intercept/credential.goaibridge/headers/headers.goExtractBearerTokenaibridge/utils/auth.goaibridge/headers/headers.gohintFailoverKeyandhintAWSChainKeyaibridge/intercept/credential.goaibridge/credential/credential.go, exported asHintFailoverKeyandHintAWSChainKeycategorizeInterceptionError,errorCategorizer, and the error-message size limitaibridge/interception_error.goaibridge/interceptionerror/error.go, renamedCategorizeandErrorCategorizerhttp.Transportconfigurationaibridge/passthrough.goaibridge/utils/http.go, extracted asNewStreamingTransportActorIDHeader,ActorMetadataHeader,IsActorHeader, andheadersFromActoraibridge/intercept/actor_headers.goaibridge/headers/headers.go; the prefix is exported asActorHeaderPrefixPrepareClientHeaders,BuildUpstreamHeaders, and the stripped-header listsaibridge/intercept/client_headers.goaibridge/headers/headers.goaibridge/bridge.goaibridge/circuitbreaker/circuitbreaker.go, insideNewProviderCircuitBreakersTest moves
aibridge/client_test.goaibridge/client/client_test.goaibridge/session_test.goaibridge/client/session_test.goaibridge/bridge_internal_test.goaibridge/headers/headers_test.goaibridge/intercept/credential_test.goaibridge/credential/credential_test.goaibridge/interception_error_internal_test.goaibridge/interceptionerror/error_test.go; test names now matchCategorizeaibridge/intercept/actor_headers_internal_test.goaibridge/headers/headers_internal_test.goaibridge/intercept/client_headers_test.goaibridge/headers/headers_test.goaibridge/utils/auth_test.goaibridge/headers/headers_test.goAssociated test helpers moved with their tests. Moved cases and assertions are preserved. Added coverage checks public actor-header helpers and the extracted streaming transport configuration.
Related adjustments and review decisions
NewProviderCircuitBreakerstakes a logger instead of a callback and installs the existing logging/metrics callback internally. There is no exported callback-taking constructor. Tests use the production constructor; the state-change test now checks the open-state gauge and trip counter with provider/endpoint/model labels rather than capturing callback arguments.BuildUpstreamHeaderstakesSendActorHeadersas aboolinstead ofintercept.Config, soaibridge/headersdoes not importintercept.InterceptionRecord.CredentialKindusescredential.Kindinstead ofstring. Conversion happens at DRPC/logging boundaries.Refs AIGOV-615.
Generated by Coder Agents on behalf of @pawbana.