diff --git a/backend/internal/service/account_scheduling_threshold_eval.go b/backend/internal/service/account_scheduling_threshold_eval.go index 07ed0db57d..4812fceca9 100644 --- a/backend/internal/service/account_scheduling_threshold_eval.go +++ b/backend/internal/service/account_scheduling_threshold_eval.go @@ -245,7 +245,7 @@ func openAIThresholdCandidate(extra map[string]any, window string) *accountSched } return &accountSchedulingThresholdCandidate{ window: window, - usedPercent: utilizationAsPercent(usedPercent), + usedPercent: schedulingPercentValue(usedPercent), until: parseSchedulingResetAt(extra[resetAtKey]), } } diff --git a/backend/internal/service/account_scheduling_threshold_eval_test.go b/backend/internal/service/account_scheduling_threshold_eval_test.go index 22a1efdf0c..74d3e96483 100644 --- a/backend/internal/service/account_scheduling_threshold_eval_test.go +++ b/backend/internal/service/account_scheduling_threshold_eval_test.go @@ -96,7 +96,7 @@ func TestEvaluateAccountSchedulingThreshold_AnthropicIgnoresExpiredFiveHourWindo require.True(t, wantUntil.Equal(*decision.Until)) } -func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSemantics(t *testing.T) { +func TestEvaluateAccountSchedulingThreshold_OpenAIPreservesPercentageSemantics(t *testing.T) { t.Parallel() now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC) @@ -104,17 +104,32 @@ func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSeman openAIAccount := &Account{ Platform: PlatformOpenAI, Extra: map[string]any{ - "codex_5h_used_percent": 0.91, + "codex_5h_used_percent": 1.0, "codex_5h_reset_at": openAIUntil.Format(time.RFC3339), }, } + candidate := openAIThresholdCandidate(openAIAccount.Extra, "5h") + require.NotNil(t, candidate) + require.Equal(t, 1.0, candidate.usedPercent) + openAIDecision := EvaluateAccountSchedulingThreshold(openAIAccount, map[string]int{ PlatformOpenAI: 90, }, now) + require.False(t, openAIDecision.ShouldPause) + openAIAccount.Extra["codex_5h_used_percent"] = 91.0 + openAIDecision = EvaluateAccountSchedulingThreshold(openAIAccount, map[string]int{ + PlatformOpenAI: 90, + }, now) require.True(t, openAIDecision.ShouldPause) require.Equal(t, 91.0, openAIDecision.UsedPercent) +} + +func TestEvaluateAccountSchedulingThreshold_AnthropicPreservesFractionalUtilizationSemantics(t *testing.T) { + t.Parallel() + + now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC) anthropicUntil := now.Add(5 * time.Hour) anthropicAccount := &Account{