Skip to content

Commit 444e9fe

Browse files
committed
Normalize paid free model check statuses
1 parent 03902e6 commit 444e9fe

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

internal/adminapi/adminapi_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,26 @@ func TestFailedModelCheckKeepsTransientFailuresDegraded(t *testing.T) {
403403
}
404404
}
405405

406+
func TestLoadModelChecksNormalizesPaidFreeModelErrors(t *testing.T) {
407+
s := newTestServer(t)
408+
checks := map[string]modelCheckStatus{
409+
modelCheckKey("openrouter", "minimax/minimax-m2.5:free"): {
410+
Status: "free_degraded",
411+
Error: "api error (HTTP 404): This model is unavailable for free. The paid version is available now.",
412+
},
413+
}
414+
data, err := json.Marshal(checks)
415+
if err != nil {
416+
t.Fatal(err)
417+
}
418+
s.settings = &fakeSettingsStore{values: map[string]string{settingKeyModelChecks: string(data)}}
419+
420+
got := s.modelCheckStatus(context.Background(), "openrouter", "minimax/minimax-m2.5:free")
421+
if got.Status != "free_blocked" {
422+
t.Fatalf("status = %s, want free_blocked", got.Status)
423+
}
424+
}
425+
406426
func TestFreeModelCheckCandidatesSkipFreshChecks(t *testing.T) {
407427
s, _ := newTGModelTestServer(t)
408428
fresh := time.Now().Add(-time.Hour).Format(time.RFC3339)

internal/adminapi/model_checks.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (s *Server) loadModelChecks(ctx context.Context) map[string]modelCheckStatu
8989
s.logger.Warn("model checks cache parse failed", "err", err)
9090
return nil
9191
}
92+
normalizeModelChecks(out)
9293
return out
9394
}
9495

@@ -218,6 +219,15 @@ func isBlockedModelCheckError(message string) bool {
218219
return false
219220
}
220221

222+
func normalizeModelChecks(checks map[string]modelCheckStatus) {
223+
for key, check := range checks {
224+
if check.Status == "free_degraded" && isBlockedModelCheckError(check.Error) {
225+
check.Status = "free_blocked"
226+
checks[key] = check
227+
}
228+
}
229+
}
230+
221231
func (s *Server) startModelCheckScheduler() {
222232
if s.settings == nil || s.capStore == nil || s.cfgRef == nil {
223233
return

0 commit comments

Comments
 (0)