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
681950da
"backend/internal/handler/vscode:/vscode.git/clone" did not exist on "ebac0dc628ef285623414c0ae579b8975f56e191"
Commit
681950da
authored
Feb 09, 2026
by
erio
Browse files
feat: add linear delay between Antigravity account failover switches
parent
a67d9337
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/gateway_handler.go
View file @
681950da
...
...
@@ -350,6 +350,11 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
}
switchCount
++
log
.
Printf
(
"Account %d: upstream error %d, switching account %d/%d"
,
account
.
ID
,
failoverErr
.
StatusCode
,
switchCount
,
maxAccountSwitches
)
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
!
sleepFailoverDelay
(
c
.
Request
.
Context
(),
switchCount
)
{
return
}
}
continue
}
// 错误响应已在Forward中处理,这里只记录日志
...
...
@@ -545,6 +550,11 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
}
switchCount
++
log
.
Printf
(
"Account %d: upstream error %d, switching account %d/%d"
,
account
.
ID
,
failoverErr
.
StatusCode
,
switchCount
,
maxAccountSwitches
)
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
!
sleepFailoverDelay
(
c
.
Request
.
Context
(),
switchCount
)
{
return
}
}
continue
}
// 错误响应已在Forward中处理,这里只记录日志
...
...
@@ -807,6 +817,21 @@ func (h *GatewayHandler) handleConcurrencyError(c *gin.Context, err error, slotT
fmt
.
Sprintf
(
"Concurrency limit exceeded for %s, please retry later"
,
slotType
),
streamStarted
)
}
// sleepFailoverDelay 账号切换线性递增延时:第1次0s、第2次1s、第3次2s…
// 返回 false 表示 context 已取消。
func
sleepFailoverDelay
(
ctx
context
.
Context
,
switchCount
int
)
bool
{
delay
:=
time
.
Duration
(
switchCount
-
1
)
*
time
.
Second
if
delay
<=
0
{
return
true
}
select
{
case
<-
ctx
.
Done
()
:
return
false
case
<-
time
.
After
(
delay
)
:
return
true
}
}
func
(
h
*
GatewayHandler
)
handleFailoverExhausted
(
c
*
gin
.
Context
,
failoverErr
*
service
.
UpstreamFailoverError
,
platform
string
,
streamStarted
bool
)
{
statusCode
:=
failoverErr
.
StatusCode
responseBody
:=
failoverErr
.
ResponseBody
...
...
backend/internal/handler/gemini_v1beta_handler.go
View file @
681950da
...
...
@@ -433,6 +433,11 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
lastFailoverErr
=
failoverErr
switchCount
++
log
.
Printf
(
"Gemini account %d: upstream error %d, switching account %d/%d"
,
account
.
ID
,
failoverErr
.
StatusCode
,
switchCount
,
maxAccountSwitches
)
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
!
sleepFailoverDelay
(
c
.
Request
.
Context
(),
switchCount
)
{
return
}
}
continue
}
// ForwardNative already wrote the response
...
...
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