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
72b08f9c
"git@web.lueluesay.top:chenxi/sub2api.git" did not exist on "33db7a0fb6f26b3a5f111cb3a1c7ec890d1b62c5"
Commit
72b08f9c
authored
Feb 09, 2026
by
erio
Browse files
fix: ensure sticky session failover triggers cache billing exemption
parent
681950da
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/gateway_handler.go
View file @
72b08f9c
...
...
@@ -341,7 +341,7 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
if
errors
.
As
(
err
,
&
failoverErr
)
{
failedAccountIDs
[
account
.
ID
]
=
struct
{}{}
lastFailoverErr
=
failoverErr
if
failoverErr
.
ForceCacheBilling
{
if
need
ForceCacheBilling
(
hasBoundSession
,
failoverErr
)
{
forceCacheBilling
=
true
}
if
switchCount
>=
maxAccountSwitches
{
...
...
@@ -541,7 +541,7 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
if
errors
.
As
(
err
,
&
failoverErr
)
{
failedAccountIDs
[
account
.
ID
]
=
struct
{}{}
lastFailoverErr
=
failoverErr
if
failoverErr
.
ForceCacheBilling
{
if
need
ForceCacheBilling
(
hasBoundSession
,
failoverErr
)
{
forceCacheBilling
=
true
}
if
switchCount
>=
maxAccountSwitches
{
...
...
@@ -817,6 +817,12 @@ func (h *GatewayHandler) handleConcurrencyError(c *gin.Context, err error, slotT
fmt
.
Sprintf
(
"Concurrency limit exceeded for %s, please retry later"
,
slotType
),
streamStarted
)
}
// needForceCacheBilling 判断 failover 时是否需要强制缓存计费
// 粘性会话切换账号、或上游明确标记时,将 input_tokens 转为 cache_read 计费
func
needForceCacheBilling
(
hasBoundSession
bool
,
failoverErr
*
service
.
UpstreamFailoverError
)
bool
{
return
hasBoundSession
||
(
failoverErr
!=
nil
&&
failoverErr
.
ForceCacheBilling
)
}
// sleepFailoverDelay 账号切换线性递增延时:第1次0s、第2次1s、第3次2s…
// 返回 false 表示 context 已取消。
func
sleepFailoverDelay
(
ctx
context
.
Context
,
switchCount
int
)
bool
{
...
...
backend/internal/handler/gemini_v1beta_handler.go
View file @
72b08f9c
...
...
@@ -422,7 +422,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
var
failoverErr
*
service
.
UpstreamFailoverError
if
errors
.
As
(
err
,
&
failoverErr
)
{
failedAccountIDs
[
account
.
ID
]
=
struct
{}{}
if
failoverErr
.
ForceCacheBilling
{
if
need
ForceCacheBilling
(
hasBoundSession
,
failoverErr
)
{
forceCacheBilling
=
true
}
if
switchCount
>=
maxAccountSwitches
{
...
...
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