fix(antigravity): respect pinned auth in credits fallback, release deferred body on success
- findAllAntigravityCreditsCandidateAuths now filters by PinnedAuthMetadataKey to prevent credential isolation violations during credits fallback - Release deferredBody reference on success path to avoid holding large payloads in memory for the lifetime of the gin context
This commit is contained in:
@@ -134,6 +134,10 @@ func RecordAPIResponseMetadata(ctx context.Context, cfg *config.Config, status i
|
|||||||
// Success responses (2xx) skip this — their deferred body is dropped with gin context.
|
// Success responses (2xx) skip this — their deferred body is dropped with gin context.
|
||||||
if status >= http.StatusBadRequest {
|
if status >= http.StatusBadRequest {
|
||||||
materializeDeferredBodies(ginCtx, attempts)
|
materializeDeferredBodies(ginCtx, attempts)
|
||||||
|
} else {
|
||||||
|
for _, a := range attempts {
|
||||||
|
a.deferredBody = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureResponseIntro(attempt)
|
ensureResponseIntro(attempt)
|
||||||
|
|||||||
@@ -2903,10 +2903,11 @@ func (m *Manager) pickNextMixed(ctx context.Context, providers []string, model s
|
|||||||
return authCopy, executor, providerKey, nil
|
return authCopy, executor, providerKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) findAllAntigravityCreditsCandidateAuths(routeModel string) []creditsCandidateEntry {
|
func (m *Manager) findAllAntigravityCreditsCandidateAuths(routeModel string, opts cliproxyexecutor.Options) []creditsCandidateEntry {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
pinnedAuthID := pinnedAuthIDFromMetadata(opts.Metadata)
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
defer m.mu.RUnlock()
|
defer m.mu.RUnlock()
|
||||||
var candidates []creditsCandidateEntry
|
var candidates []creditsCandidateEntry
|
||||||
@@ -2914,6 +2915,9 @@ func (m *Manager) findAllAntigravityCreditsCandidateAuths(routeModel string) []c
|
|||||||
if auth == nil || auth.Disabled || auth.Status == StatusDisabled {
|
if auth == nil || auth.Disabled || auth.Status == StatusDisabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if pinnedAuthID != "" && auth.ID != pinnedAuthID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if !antigravityCreditsAvailableForModel(auth, routeModel) {
|
if !antigravityCreditsAvailableForModel(auth, routeModel) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -2981,7 +2985,7 @@ func shouldAttemptAntigravityCreditsFallback(m *Manager, lastErr error, provider
|
|||||||
|
|
||||||
func (m *Manager) tryAntigravityCreditsExecute(ctx context.Context, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, bool) {
|
func (m *Manager) tryAntigravityCreditsExecute(ctx context.Context, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, bool) {
|
||||||
routeModel := req.Model
|
routeModel := req.Model
|
||||||
candidates := m.findAllAntigravityCreditsCandidateAuths(routeModel)
|
candidates := m.findAllAntigravityCreditsCandidateAuths(routeModel, opts)
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return cliproxyexecutor.Response{}, false
|
return cliproxyexecutor.Response{}, false
|
||||||
@@ -3023,7 +3027,7 @@ func (m *Manager) tryAntigravityCreditsExecute(ctx context.Context, req cliproxy
|
|||||||
|
|
||||||
func (m *Manager) tryAntigravityCreditsExecuteStream(ctx context.Context, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (*cliproxyexecutor.StreamResult, bool) {
|
func (m *Manager) tryAntigravityCreditsExecuteStream(ctx context.Context, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (*cliproxyexecutor.StreamResult, bool) {
|
||||||
routeModel := req.Model
|
routeModel := req.Model
|
||||||
candidates := m.findAllAntigravityCreditsCandidateAuths(routeModel)
|
candidates := m.findAllAntigravityCreditsCandidateAuths(routeModel, opts)
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|||||||
Reference in New Issue
Block a user