Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
86d63f91
"backend/internal/vscode:/vscode.git/clone" did not exist on "8e69957bb19ccb10a3e485259c5ec0c6319321be"
Commit
86d63f91
authored
Jan 20, 2026
by
song
Browse files
feat(antigravity): 支持秒级 fallback 冷却时间
parent
c43aa22c
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/antigravity_gateway_service.go
View file @
86d63f91
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"net"
"net"
"net/http"
"net/http"
"os"
"os"
"strconv"
"strings"
"strings"
"sync/atomic"
"sync/atomic"
"time"
"time"
...
@@ -30,8 +31,9 @@ const (
...
@@ -30,8 +31,9 @@ const (
)
)
const
(
const
(
antigravityScopeRateLimitEnv
=
"GATEWAY_ANTIGRAVITY_429_SCOPE_LIMIT"
antigravityScopeRateLimitEnv
=
"GATEWAY_ANTIGRAVITY_429_SCOPE_LIMIT"
antigravityBillingModelEnv
=
"GATEWAY_ANTIGRAVITY_BILL_WITH_MAPPED_MODEL"
antigravityBillingModelEnv
=
"GATEWAY_ANTIGRAVITY_BILL_WITH_MAPPED_MODEL"
antigravityFallbackSecondsEnv
=
"GATEWAY_ANTIGRAVITY_FALLBACK_COOLDOWN_SECONDS"
)
)
// antigravityRetryLoopParams 重试循环的参数
// antigravityRetryLoopParams 重试循环的参数
...
@@ -1541,6 +1543,18 @@ func antigravityUseMappedModelForBilling() bool {
...
@@ -1541,6 +1543,18 @@ func antigravityUseMappedModelForBilling() bool {
return
v
==
"1"
||
v
==
"true"
||
v
==
"yes"
||
v
==
"on"
return
v
==
"1"
||
v
==
"true"
||
v
==
"yes"
||
v
==
"on"
}
}
func
antigravityFallbackCooldownSeconds
()
(
time
.
Duration
,
bool
)
{
raw
:=
strings
.
TrimSpace
(
os
.
Getenv
(
antigravityFallbackSecondsEnv
))
if
raw
==
""
{
return
0
,
false
}
seconds
,
err
:=
strconv
.
Atoi
(
raw
)
if
err
!=
nil
||
seconds
<=
0
{
return
0
,
false
}
return
time
.
Duration
(
seconds
)
*
time
.
Second
,
true
}
func
(
s
*
AntigravityGatewayService
)
handleUpstreamError
(
ctx
context
.
Context
,
prefix
string
,
account
*
Account
,
statusCode
int
,
headers
http
.
Header
,
body
[]
byte
,
quotaScope
AntigravityQuotaScope
)
{
func
(
s
*
AntigravityGatewayService
)
handleUpstreamError
(
ctx
context
.
Context
,
prefix
string
,
account
*
Account
,
statusCode
int
,
headers
http
.
Header
,
body
[]
byte
,
quotaScope
AntigravityQuotaScope
)
{
// 429 使用 Gemini 格式解析(从 body 解析重置时间)
// 429 使用 Gemini 格式解析(从 body 解析重置时间)
if
statusCode
==
429
{
if
statusCode
==
429
{
...
@@ -1553,6 +1567,9 @@ func (s *AntigravityGatewayService) handleUpstreamError(ctx context.Context, pre
...
@@ -1553,6 +1567,9 @@ func (s *AntigravityGatewayService) handleUpstreamError(ctx context.Context, pre
fallbackMinutes
=
s
.
settingService
.
cfg
.
Gateway
.
AntigravityFallbackCooldownMinutes
fallbackMinutes
=
s
.
settingService
.
cfg
.
Gateway
.
AntigravityFallbackCooldownMinutes
}
}
defaultDur
:=
time
.
Duration
(
fallbackMinutes
)
*
time
.
Minute
defaultDur
:=
time
.
Duration
(
fallbackMinutes
)
*
time
.
Minute
if
override
,
ok
:=
antigravityFallbackCooldownSeconds
();
ok
{
defaultDur
=
override
}
ra
:=
time
.
Now
()
.
Add
(
defaultDur
)
ra
:=
time
.
Now
()
.
Add
(
defaultDur
)
if
useScopeLimit
{
if
useScopeLimit
{
log
.
Printf
(
"%s status=429 rate_limited scope=%s reset_in=%v (fallback)"
,
prefix
,
quotaScope
,
defaultDur
)
log
.
Printf
(
"%s status=429 rate_limited scope=%s reset_in=%v (fallback)"
,
prefix
,
quotaScope
,
defaultDur
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment