diff --git a/internal/runtime/executor/antigravity_executor.go b/internal/runtime/executor/antigravity_executor.go index f0116faa..0baba498 100644 --- a/internal/runtime/executor/antigravity_executor.go +++ b/internal/runtime/executor/antigravity_executor.go @@ -45,6 +45,7 @@ const ( defaultAntigravityAgent = "antigravity/1.104.0 darwin/arm64" antigravityAuthType = "antigravity" refreshSkew = 3000 * time.Second + tokenRefreshTimeout = 30 * time.Second ) var ( @@ -914,7 +915,13 @@ func (e *AntigravityExecutor) ensureAccessToken(ctx context.Context, auth *clipr if accessToken != "" && expiry.After(time.Now().Add(refreshSkew)) { return accessToken, nil, nil } - updated, errRefresh := e.refreshToken(ctx, auth.Clone()) + refreshCtx := context.Background() + if ctx != nil { + if rt, ok := ctx.Value("cliproxy.roundtripper").(http.RoundTripper); ok && rt != nil { + refreshCtx = context.WithValue(refreshCtx, "cliproxy.roundtripper", rt) + } + } + updated, errRefresh := e.refreshToken(refreshCtx, auth.Clone()) if errRefresh != nil { return "", nil, errRefresh } @@ -944,7 +951,7 @@ func (e *AntigravityExecutor) refreshToken(ctx context.Context, auth *cliproxyau httpReq.Header.Set("User-Agent", defaultAntigravityAgent) httpReq.Header.Set("Content-Type", "application/x-www-form-urlencoded") - httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0) + httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, tokenRefreshTimeout) httpResp, errDo := httpClient.Do(httpReq) if errDo != nil { return auth, errDo diff --git a/sdk/cliproxy/auth/conductor.go b/sdk/cliproxy/auth/conductor.go index c480d965..7839fa1e 100644 --- a/sdk/cliproxy/auth/conductor.go +++ b/sdk/cliproxy/auth/conductor.go @@ -1536,6 +1536,9 @@ func (m *Manager) markRefreshPending(id string, now time.Time) bool { } func (m *Manager) refreshAuth(ctx context.Context, id string) { + if ctx == nil { + ctx = context.Background() + } m.mu.RLock() auth := m.auths[id] var exec ProviderExecutor @@ -1548,6 +1551,10 @@ func (m *Manager) refreshAuth(ctx context.Context, id string) { } cloned := auth.Clone() updated, err := exec.Refresh(ctx, cloned) + if err != nil && errors.Is(err, context.Canceled) { + log.Debugf("refresh canceled for %s, %s", auth.Provider, auth.ID) + return + } log.Debugf("refreshed %s, %s, %v", auth.Provider, auth.ID, err) now := time.Now() if err != nil {