fix(gateway): harden digest logging and align antigravity ops
- avoid panic by using safe UUID prefix truncation in Gemini digest fallback logs\n- remove unconditional Antigravity 429 full-body debug logs and honor log truncation config\n- align Antigravity quick preset mappings to opus 4.6-thinking targets only\n- restore scope rate-limit aggregation/output in ops availability stats
This commit is contained in:
@@ -120,3 +120,24 @@ func TestGeminiCLITmpDirRegex(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeShortPrefix(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
n int
|
||||
want string
|
||||
}{
|
||||
{name: "空字符串", input: "", n: 8, want: ""},
|
||||
{name: "长度小于截断值", input: "abc", n: 8, want: "abc"},
|
||||
{name: "长度等于截断值", input: "12345678", n: 8, want: "12345678"},
|
||||
{name: "长度大于截断值", input: "1234567890", n: 8, want: "12345678"},
|
||||
{name: "截断值为0", input: "123456", n: 0, want: "123456"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.Equal(t, tt.want, safeShortPrefix(tt.input, tt.n))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
|
||||
sessionBoundAccountID = foundAccountID
|
||||
geminiSessionUUID = foundUUID
|
||||
log.Printf("[Gemini] Digest fallback matched: uuid=%s, accountID=%d, chain=%s",
|
||||
foundUUID[:8], foundAccountID, truncateDigestChain(geminiDigestChain))
|
||||
safeShortPrefix(foundUUID, 8), foundAccountID, truncateDigestChain(geminiDigestChain))
|
||||
|
||||
// 关键:如果原 sessionKey 为空,使用 prefixHash + uuid 作为 sessionKey
|
||||
// 这样 SelectAccountWithLoadAwareness 的粘性会话逻辑会优先使用匹配到的账号
|
||||
@@ -650,6 +650,15 @@ func truncateDigestChain(chain string) string {
|
||||
return chain[:50] + "..."
|
||||
}
|
||||
|
||||
// safeShortPrefix 返回字符串前 n 个字符;长度不足时返回原字符串。
|
||||
// 用于日志展示,避免切片越界。
|
||||
func safeShortPrefix(value string, n int) string {
|
||||
if n <= 0 || len(value) <= n {
|
||||
return value
|
||||
}
|
||||
return value[:n]
|
||||
}
|
||||
|
||||
// derefGroupID 安全解引用 *int64,nil 返回 0
|
||||
func derefGroupID(groupID *int64) int64 {
|
||||
if groupID == nil {
|
||||
|
||||
Reference in New Issue
Block a user