Skip to content

Commit 2f70944

Browse files
committed
fix: 取消官方账号余量预跳过限制
1 parent 4583437 commit 2f70944

3 files changed

Lines changed: 10 additions & 40 deletions

File tree

backend/internal/api/responses_handler.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
const officialCodexBaseURL = "https://chatgpt.com/backend-api/codex"
3434
const defaultCodexInstructions = "You are Codex, a coding agent based on GPT-5. You and the user share the same workspace and collaborate to achieve the user's goals. Be pragmatic, concise, and focus on completing the user's task."
35-
const thinResponsesOfficialLowRemainingThreshold = 3.0
3635
const thinResponsesCapacityCooldownWindow = 3 * time.Minute
3736
const thinResponsesRateLimitCooldownWindow = 1 * time.Minute
3837
const activeAccountFailoverRetryAttempts = 3
@@ -958,27 +957,9 @@ func (h *ResponsesHandler) skipReasonForThinCandidate(candidate routing.Candidat
958957
if candidate.Account.RoutingCooldownActive(now) && !candidate.Account.IsActive {
959958
return "routing_cooldown", true
960959
}
961-
if officialRemainingBelowThreshold(candidate) {
962-
return "official_remaining_below_3pct", true
963-
}
964960
return "", false
965961
}
966962

967-
func officialRemainingBelowThreshold(candidate routing.Candidate) bool {
968-
if !usesOfficialCodexAdapter(candidate.Account) {
969-
return false
970-
}
971-
primaryRemaining := 100 - candidate.Snapshot.PrimaryUsedPercent
972-
secondaryRemaining := 100 - candidate.Snapshot.SecondaryUsedPercent
973-
if candidate.Snapshot.PrimaryResetsAt != nil && primaryRemaining < thinResponsesOfficialLowRemainingThreshold {
974-
return true
975-
}
976-
if candidate.Snapshot.SecondaryResetsAt != nil && secondaryRemaining < thinResponsesOfficialLowRemainingThreshold {
977-
return true
978-
}
979-
return false
980-
}
981-
982963
func shouldCooldownThinCandidate(candidate routing.Candidate, reason string) bool {
983964
if reason == "routing_cooldown" {
984965
return false
@@ -1034,7 +1015,7 @@ func (h *ResponsesHandler) publishAccountRoutingStateChanged() {
10341015
func computeThinCandidateCooldownUntil(snapshot usage.Snapshot, reason string) *time.Time {
10351016
now := time.Now().UTC()
10361017
switch reason {
1037-
case "official_remaining_below_3pct", "usage_limited", "capacity_failed":
1018+
case "usage_limited", "capacity_failed":
10381019
resetAt := relevantOfficialResetAt(snapshot)
10391020
until := routing.ComputeCooldownUntil(now, routing.CooldownReasonCapacity, resetAt, thinResponsesCapacityCooldownWindow)
10401021
return &until
@@ -1058,17 +1039,7 @@ func latestRelevantResetAt(snapshot usage.Snapshot) *time.Time {
10581039
}
10591040

10601041
func relevantOfficialResetAt(snapshot usage.Snapshot) *time.Time {
1061-
var candidates []*time.Time
1062-
if snapshot.PrimaryResetsAt != nil && 100-snapshot.PrimaryUsedPercent < thinResponsesOfficialLowRemainingThreshold {
1063-
candidates = append(candidates, snapshot.PrimaryResetsAt)
1064-
}
1065-
if snapshot.SecondaryResetsAt != nil && 100-snapshot.SecondaryUsedPercent < thinResponsesOfficialLowRemainingThreshold {
1066-
candidates = append(candidates, snapshot.SecondaryResetsAt)
1067-
}
1068-
if len(candidates) == 0 {
1069-
return latestRelevantResetAt(snapshot)
1070-
}
1071-
return latestResetAtFor(candidates...)
1042+
return latestRelevantResetAt(snapshot)
10721043
}
10731044

10741045
func latestResetAtFor(candidates ...*time.Time) *time.Time {

backend/internal/api/responses_handler_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,14 +1653,14 @@ func TestResponsesHandlerThinModeFailsOverAfterThirdPartyForbiddenQuotaError(t *
16531653
}
16541654
}
16551655

1656-
func TestResponsesHandlerThinModeSkipsOfficialBelowRemainingThreshold(t *testing.T) {
1656+
func TestResponsesHandlerThinModeAttemptsOfficialWithLowWindowRemaining(t *testing.T) {
16571657
t.Parallel()
16581658

16591659
primaryCalls := 0
16601660
primary := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16611661
primaryCalls++
16621662
w.Header().Set("Content-Type", "application/json")
1663-
_, _ = io.WriteString(w, `{"id":"resp_should_not_run","object":"response","status":"completed","output_text":"should-not-run"}`)
1663+
_, _ = io.WriteString(w, `{"id":"resp_low_remaining","object":"response","status":"completed","output_text":"low-remaining-primary"}`)
16641664
}))
16651665
defer primary.Close()
16661666

@@ -1762,14 +1762,14 @@ func TestResponsesHandlerThinModeSkipsOfficialBelowRemainingThreshold(t *testing
17621762
if rec.Code != http.StatusOK {
17631763
t.Fatalf("status = %d, want %d, body=%s", rec.Code, http.StatusOK, rec.Body.String())
17641764
}
1765-
if !strings.Contains(rec.Body.String(), `"output_text":"threshold-fallback"`) {
1766-
t.Fatalf("body = %s, want threshold fallback output", rec.Body.String())
1765+
if !strings.Contains(rec.Body.String(), `"output_text":"low-remaining-primary"`) {
1766+
t.Fatalf("body = %s, want primary output", rec.Body.String())
17671767
}
1768-
if primaryCalls != 0 {
1769-
t.Fatalf("primaryCalls = %d, want 0", primaryCalls)
1768+
if primaryCalls != 1 {
1769+
t.Fatalf("primaryCalls = %d, want 1", primaryCalls)
17701770
}
1771-
if secondaryCalls != 1 {
1772-
t.Fatalf("secondaryCalls = %d, want 1", secondaryCalls)
1771+
if secondaryCalls != 0 {
1772+
t.Fatalf("secondaryCalls = %d, want 0", secondaryCalls)
17731773
}
17741774
}
17751775

frontend/src/features/accounts/AccountsPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const statusTextMap: Record<string, string> = {
104104
};
105105

106106
const routingCooldownTextMap: Record<string, string> = {
107-
official_remaining_below_3pct: "路由冷却",
108107
usage_limited: "路由冷却",
109108
capacity_failed: "路由冷却",
110109
rate_limited: "路由冷却",

0 commit comments

Comments
 (0)