Skip to content

Commit 36bc51d

Browse files
committed
fix clearing metadata-only inspection errors
1 parent f928719 commit 36bc51d

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

‎cliproxyapi-pro-core/patches/account_inspection_scheduler.go‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,10 +2627,10 @@ func (s *accountInspectionScheduler) clearInspectionAuthError(ctx context.Contex
26272627
return
26282628
}
26292629
auth := s.h.authByIndex(account.AuthIndex)
2630-
if auth == nil || auth.Status != coreauth.StatusError || auth.LastError == nil {
2630+
if auth == nil {
26312631
return
26322632
}
2633-
if auth.LastError.Code != "inspection_http_error" && auth.LastError.Code != "inspection_probe_error" && auth.LastError.Code != "antigravity_deep_probe_error" && auth.LastError.Code != "token_refresh_error" {
2633+
if !isInspectionAuthErrorCode(authInspectionLastErrorCode(auth)) {
26342634
return
26352635
}
26362636
err := s.updateInspectionAuth(ctx, account.AuthIndex, func(auth *coreauth.Auth) {
@@ -2649,6 +2649,29 @@ func (s *accountInspectionScheduler) clearInspectionAuthError(ctx context.Contex
26492649
}
26502650
}
26512651

2652+
func authInspectionLastErrorCode(auth *coreauth.Auth) string {
2653+
if auth == nil {
2654+
return ""
2655+
}
2656+
if auth.LastError != nil {
2657+
return strings.TrimSpace(auth.LastError.Code)
2658+
}
2659+
raw, ok := auth.Metadata["last_error"].(map[string]any)
2660+
if !ok {
2661+
return ""
2662+
}
2663+
return stringFromAny(raw["code"])
2664+
}
2665+
2666+
func isInspectionAuthErrorCode(code string) bool {
2667+
switch strings.TrimSpace(code) {
2668+
case "inspection_http_error", "inspection_probe_error", "antigravity_deep_probe_error", "token_refresh_error":
2669+
return true
2670+
default:
2671+
return false
2672+
}
2673+
}
2674+
26522675
func (s *accountInspectionScheduler) syncInspectionAuthStatus(ctx context.Context, account accountInspectionAccount, status int) {
26532676
if isAccountErrorStatus(status) {
26542677
message := fmt.Sprintf("HTTP %d", status)

‎cliproxyapi-pro-core/patches/account_inspection_scheduler_test.go‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,56 @@ func TestSyncInspectionAuthErrorPersistsLastErrorMetadata(t *testing.T) {
341341
}
342342
}
343343

344+
func TestClearInspectionAuthErrorClearsMetadataOnlyError(t *testing.T) {
345+
manager := coreauth.NewManager(nil, nil, nil)
346+
registered, err := manager.Register(context.Background(), &coreauth.Auth{
347+
Provider: "antigravity",
348+
ID: "antigravity-user",
349+
FileName: "antigravity-user.json",
350+
Status: coreauth.StatusActive,
351+
StatusMessage: "",
352+
Unavailable: false,
353+
Metadata: map[string]any{
354+
"email": "user@example.com",
355+
"last_error": map[string]any{
356+
"code": "inspection_probe_error",
357+
"http_status": 0,
358+
"message": "antigravity quota unavailable",
359+
"retryable": false,
360+
},
361+
},
362+
})
363+
if err != nil {
364+
t.Fatalf("Register auth error = %v", err)
365+
}
366+
367+
scheduler := &accountInspectionScheduler{h: &Handler{authManager: manager}}
368+
scheduler.clearInspectionAuthError(context.Background(), accountFromAuth(registered))
369+
370+
var got *coreauth.Auth
371+
for _, auth := range manager.List() {
372+
if auth.ID == registered.ID {
373+
got = auth
374+
break
375+
}
376+
}
377+
if got == nil {
378+
t.Fatal("updated auth not found")
379+
}
380+
if got.LastError != nil {
381+
t.Fatalf("LastError = %#v, want nil", got.LastError)
382+
}
383+
if _, ok := got.Metadata["last_error"]; ok {
384+
t.Fatalf("metadata last_error = %#v, want removed", got.Metadata["last_error"])
385+
}
386+
if got.Status != coreauth.StatusActive || got.StatusMessage != "" || got.Unavailable {
387+
t.Fatalf("status = %q message=%q unavailable=%v, want active/empty/false", got.Status, got.StatusMessage, got.Unavailable)
388+
}
389+
if got.Metadata["email"] != "user@example.com" {
390+
t.Fatalf("metadata email = %#v, want preserved", got.Metadata["email"])
391+
}
392+
}
393+
344394
func TestAutoActionConfirmationDelaysExecution(t *testing.T) {
345395
scheduler := &accountInspectionScheduler{}
346396
result := testInspectionResult("quota", accountInspectionActionDisable, false, nil, true, "")

0 commit comments

Comments
 (0)