fix: clean thoughtSignature for all clients, not just CLI
Previously, thoughtSignature cleanup only applied to Gemini CLI requests (detected via x-gemini-api-privileged-user-id header or tmp dir pattern). This caused 400 errors for non-CLI clients when session cache expired and they sent stale signatures. Remove the isGeminiCLIRequest guard so all clients benefit from proactive thoughtSignature cleanup on session binding miss.
This commit is contained in:
@@ -30,13 +30,6 @@ import (
|
|||||||
// 匹配格式: /Users/xxx/.gemini/tmp/[64位十六进制哈希]
|
// 匹配格式: /Users/xxx/.gemini/tmp/[64位十六进制哈希]
|
||||||
var geminiCLITmpDirRegex = regexp.MustCompile(`/\.gemini/tmp/([A-Fa-f0-9]{64})`)
|
var geminiCLITmpDirRegex = regexp.MustCompile(`/\.gemini/tmp/([A-Fa-f0-9]{64})`)
|
||||||
|
|
||||||
func isGeminiCLIRequest(c *gin.Context, body []byte) bool {
|
|
||||||
if strings.TrimSpace(c.GetHeader("x-gemini-api-privileged-user-id")) != "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return geminiCLITmpDirRegex.Match(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GeminiV1BetaListModels proxies:
|
// GeminiV1BetaListModels proxies:
|
||||||
// GET /v1beta/models
|
// GET /v1beta/models
|
||||||
func (h *GatewayHandler) GeminiV1BetaListModels(c *gin.Context) {
|
func (h *GatewayHandler) GeminiV1BetaListModels(c *gin.Context) {
|
||||||
@@ -316,7 +309,6 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
|
|||||||
|
|
||||||
// 判断是否真的绑定了粘性会话:有 sessionKey 且已经绑定到某个账号
|
// 判断是否真的绑定了粘性会话:有 sessionKey 且已经绑定到某个账号
|
||||||
hasBoundSession := sessionKey != "" && sessionBoundAccountID > 0
|
hasBoundSession := sessionKey != "" && sessionBoundAccountID > 0
|
||||||
isCLI := isGeminiCLIRequest(c, body)
|
|
||||||
cleanedForUnknownBinding := false
|
cleanedForUnknownBinding := false
|
||||||
|
|
||||||
maxAccountSwitches := h.maxAccountSwitchesGemini
|
maxAccountSwitches := h.maxAccountSwitchesGemini
|
||||||
@@ -344,10 +336,10 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
|
|||||||
log.Printf("[Gemini] Sticky session account switched: %d -> %d, cleaning thoughtSignature", sessionBoundAccountID, account.ID)
|
log.Printf("[Gemini] Sticky session account switched: %d -> %d, cleaning thoughtSignature", sessionBoundAccountID, account.ID)
|
||||||
body = service.CleanGeminiNativeThoughtSignatures(body)
|
body = service.CleanGeminiNativeThoughtSignatures(body)
|
||||||
sessionBoundAccountID = account.ID
|
sessionBoundAccountID = account.ID
|
||||||
} else if sessionKey != "" && sessionBoundAccountID == 0 && isCLI && !cleanedForUnknownBinding && bytes.Contains(body, []byte(`"thoughtSignature"`)) {
|
} else if sessionKey != "" && sessionBoundAccountID == 0 && !cleanedForUnknownBinding && bytes.Contains(body, []byte(`"thoughtSignature"`)) {
|
||||||
// 无缓存绑定但请求里已有 thoughtSignature:常见于缓存丢失/TTL 过期后,CLI 继续携带旧签名。
|
// 无缓存绑定但请求里已有 thoughtSignature:常见于缓存丢失/TTL 过期后,客户端继续携带旧签名。
|
||||||
// 为避免第一次转发就 400,这里做一次确定性清理,让新账号重新生成签名链路。
|
// 为避免第一次转发就 400,这里做一次确定性清理,让新账号重新生成签名链路。
|
||||||
log.Printf("[Gemini] Sticky session binding missing for CLI request, cleaning thoughtSignature proactively")
|
log.Printf("[Gemini] Sticky session binding missing, cleaning thoughtSignature proactively")
|
||||||
body = service.CleanGeminiNativeThoughtSignatures(body)
|
body = service.CleanGeminiNativeThoughtSignatures(body)
|
||||||
cleanedForUnknownBinding = true
|
cleanedForUnknownBinding = true
|
||||||
sessionBoundAccountID = account.ID
|
sessionBoundAccountID = account.ID
|
||||||
|
|||||||
Reference in New Issue
Block a user