mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
fix(composite): 恢复 antigravity 混合调度开关并按归属层级执行 account_model 否决
- antigravity 混合调度开关:平台默认映射让 antigravity 账号对 Claude / Gemini 模型 构成强声明,组合分组因此绕过混合调度开关。改为未开启混合调度的 antigravity 账号只按 管理员显式配置的映射构成声明(与 main 的 composite 声明及非 composite 混合调度同语义), 归属解析、池准入、account_model 否决三处一致生效。 - account_model 否决层级:否决与池模型门由「任意强度声明」放宽导致同平台通配 catch-all 账号冒领显式绑定的公开模型。归属记录构成时采用的声明层级(有强声明为显式, 否则通配),经路由决策写入 ctx;三个否决点与两个池模型门改用 CompositeAccountMeetsClaimTier,无层级信息时保持任意强度语义。
This commit is contained in:
1 parent
672ea007c8
commit
fce2d45a36
15 files changed
+196
-34
No files matched your search
@@ -20,6 +20,10 @@ const (
|
||||
// CompositeRouteSource 标识 composite 解析结果来自显式路由还是内置模型探测。
|
||||
CompositeRouteSource Key = "ctx_composite_route_source"
|
||||
|
||||
// CompositeRequiredClaimStrength 是 composite 账号归属(account_model / account_pool)
|
||||
// 构成时采用的声明层级:账号须达到该层级才能承接请求。
|
||||
CompositeRequiredClaimStrength Key = "ctx_composite_required_claim_strength"
|
||||
|
||||
// CompositeCandidatePlatforms 是 composite 多平台候选池(account_pool 决策)
|
||||
// 的参与平台集合(去重升序)。与 ResolvedTargetPlatform 互斥写入:池决策不
|
||||
// 固定单一目标平台,选号期间不得被最终账号平台覆盖。
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
|
||||
)
|
||||
|
||||
// CompositeClaimStrength 表达账号对某模型的声明强度。ownership 据此分层:
|
||||
// 存在强声明平台时池/单平台仅由强声明平台构成,完全无强声明才回退通配命中
|
||||
@@ -32,6 +37,12 @@ func CompositeAccountClaimStrength(account *Account, model string) CompositeClai
|
||||
}
|
||||
|
||||
mapping := account.GetModelMapping()
|
||||
if account.Platform == PlatformAntigravity && !account.IsMixedSchedulingEnabled() {
|
||||
// 平台默认映射(Claude / Gemini 模型)只在开启混合调度时才让 antigravity 账号
|
||||
// 服务这些模型,与非 composite 的混合调度开关同一语义;未开启时只有管理员在
|
||||
// 账号上显式配置的映射构成声明。
|
||||
mapping = stringMappingFromRaw(account.Credentials["model_mapping"])
|
||||
}
|
||||
if len(mapping) == 0 {
|
||||
// 规则B:空 mapping 仅受控 native 声明。OpenAI OAuth 空 mapping 仍受
|
||||
// isOpenAIOAuthServableModel 约束(IsModelSupported 内部处理)。
|
||||
@@ -105,3 +116,19 @@ func compositeClaimStrengthForTarget(mapped string, exact bool) CompositeClaimSt
|
||||
func CompositeAccountClaimsModel(account *Account, model string) bool {
|
||||
return CompositeAccountClaimStrength(account, model) != CompositeClaimNone
|
||||
}
|
||||
|
||||
// CompositeAccountMeetsClaimTier 是选号期的 composite 归属判定(account_model 否决与
|
||||
// 账号池模型门共用):账号对公开模型的声明强度须达到构成本次归属时采用的层级。存在
|
||||
// 强声明平台时只有强声明账号可承接,通配 catch-all 账号不得冒领显式绑定的公开模型;
|
||||
// ctx 无层级信息时任意强度均可(等价 CompositeAccountClaimsModel)。
|
||||
func CompositeAccountMeetsClaimTier(ctx context.Context, account *Account, model string) bool {
|
||||
strength := CompositeAccountClaimStrength(account, model)
|
||||
if strength == CompositeClaimNone {
|
||||
return false
|
||||
}
|
||||
if ctx == nil {
|
||||
return true
|
||||
}
|
||||
required, ok := ctx.Value(ctxkey.CompositeRequiredClaimStrength).(CompositeClaimStrength)
|
||||
return !ok || strength >= required
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// antigravity 账号的平台默认映射(Claude / Gemini 模型)只在开启混合调度时构成
|
||||
// composite 声明;未开启时只认管理员显式配置的映射,与非 composite 混合调度开关同语义。
|
||||
func TestCompositeClaimAntigravityDefaultMappingRequiresMixedScheduling(t *testing.T) {
|
||||
const model = "claude-sonnet-4-5"
|
||||
mixedOff := &Account{ID: 1, Platform: PlatformAntigravity, Type: AccountTypeOAuth}
|
||||
require.Equal(t, CompositeClaimNone, CompositeAccountClaimStrength(mixedOff, model))
|
||||
require.False(t, CompositeAccountClaimsModel(mixedOff, model))
|
||||
|
||||
mixedOn := &Account{ID: 2, Platform: PlatformAntigravity, Type: AccountTypeOAuth, Extra: map[string]any{"mixed_scheduling": true}}
|
||||
require.Equal(t, CompositeClaimExplicit, CompositeAccountClaimStrength(mixedOn, model))
|
||||
|
||||
explicitMixedOff := &Account{ID: 3, Platform: PlatformAntigravity, Type: AccountTypeOAuth,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{"team-alias": "claude-opus-4-8"}}}
|
||||
require.Equal(t, CompositeClaimExplicit, CompositeAccountClaimStrength(explicitMixedOff, "team-alias"))
|
||||
require.Equal(t, CompositeClaimNone, CompositeAccountClaimStrength(explicitMixedOff, model), "默认映射条目不因存在自定义映射而生效")
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// 存在强声明平台时,account_model 否决与池模型门只放行强声明账号:同平台的通配
|
||||
// catch-all 账号不得冒领管理员显式绑定的公开模型(main 上该否决为精确匹配)。
|
||||
func TestCompositeAccountMeetsClaimTierFollowsOwnershipTier(t *testing.T) {
|
||||
const publicModel = "grok-public"
|
||||
explicit := &Account{ID: 1, Platform: PlatformGrok, Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{publicModel: "grok-4.3"}}}
|
||||
wildcard := &Account{ID: 2, Platform: PlatformGrok, Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{"*": "grok-3-mini"}}}
|
||||
none := &Account{ID: 3, Platform: PlatformGrok, Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{"other": "grok-3"}}}
|
||||
|
||||
strongCtx := WithCompositeRouteDecision(context.Background(), CompositeRouteDecision{
|
||||
Matched: true, Source: CompositeRouteSourceAccount, PublicModel: publicModel,
|
||||
TargetPlatform: PlatformGrok, UpstreamModel: publicModel, RequiredClaimStrength: CompositeClaimExplicit,
|
||||
})
|
||||
require.True(t, CompositeAccountMeetsClaimTier(strongCtx, explicit, publicModel))
|
||||
require.False(t, CompositeAccountMeetsClaimTier(strongCtx, wildcard, publicModel))
|
||||
require.False(t, CompositeAccountMeetsClaimTier(strongCtx, none, publicModel))
|
||||
|
||||
// 无强声明、按通配回退构成归属时,通配账号可承接。
|
||||
wildcardCtx := WithCompositeRouteDecision(context.Background(), CompositeRouteDecision{
|
||||
Matched: true, Source: CompositeRouteSourceAccount, PublicModel: publicModel,
|
||||
TargetPlatform: PlatformGrok, UpstreamModel: publicModel, RequiredClaimStrength: CompositeClaimWildcard,
|
||||
})
|
||||
require.True(t, CompositeAccountMeetsClaimTier(wildcardCtx, wildcard, publicModel))
|
||||
require.False(t, CompositeAccountMeetsClaimTier(wildcardCtx, none, publicModel))
|
||||
|
||||
// 无层级信息:任意强度均可(等价 CompositeAccountClaimsModel)。
|
||||
require.True(t, CompositeAccountMeetsClaimTier(context.Background(), wildcard, publicModel))
|
||||
|
||||
// 池决策同样携带层级。
|
||||
poolCtx := WithCompositeRouteDecision(context.Background(), CompositeRouteDecision{
|
||||
Matched: true, Source: CompositeRouteSourceAccountPool, PublicModel: publicModel,
|
||||
CandidatePlatforms: []string{PlatformGrok, PlatformOpenAI}, RequiredClaimStrength: CompositeClaimExplicit,
|
||||
})
|
||||
require.False(t, CompositeAccountMeetsClaimTier(poolCtx, wildcard, publicModel))
|
||||
}
|
||||
|
||||
func TestResolveCompositeModelOwnershipRecordsClaimTier(t *testing.T) {
|
||||
const group = int64(11)
|
||||
strongRepo := &compositeOwnershipScopedRepo{records: []compositeOwnershipScopedRecord{
|
||||
{groupID: group, platform: PlatformGrok, schedulable: true, account: mappingAccount(1, PlatformGrok, "alias", "grok-4.3")},
|
||||
{groupID: group, platform: PlatformOpenAI, schedulable: true, account: Account{ID: 2, Platform: PlatformOpenAI, Credentials: map[string]any{"model_mapping": map[string]any{"*": "gpt-5"}}}},
|
||||
}}
|
||||
ownership, err := (&GatewayService{accountRepo: strongRepo}).resolveCompositeModelOwnership(context.Background(), group, "alias")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PlatformGrok, ownership.TargetPlatform)
|
||||
require.Equal(t, CompositeClaimExplicit, ownership.RequiredClaimStrength)
|
||||
|
||||
wildcardRepo := &compositeOwnershipScopedRepo{records: []compositeOwnershipScopedRecord{
|
||||
{groupID: group, platform: PlatformOpenAI, schedulable: true, account: Account{ID: 2, Platform: PlatformOpenAI, Credentials: map[string]any{"model_mapping": map[string]any{"*": "gpt-5"}}}},
|
||||
}}
|
||||
ownership, err = (&GatewayService{accountRepo: wildcardRepo}).resolveCompositeModelOwnership(context.Background(), group, "alias")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PlatformOpenAI, ownership.TargetPlatform)
|
||||
require.Equal(t, CompositeClaimWildcard, ownership.RequiredClaimStrength)
|
||||
}
|
||||
|
||||
func TestCompositeRouteResolverPropagatesClaimTier(t *testing.T) {
|
||||
const group = int64(12)
|
||||
resolver, _ := newOllamaOwnershipResolver(
|
||||
compositeOwnershipScopedRecord{groupID: group, platform: PlatformGrok, schedulable: true,
|
||||
account: mappingAccount(1, PlatformGrok, "alias", "grok-4.3")},
|
||||
compositeOwnershipScopedRecord{groupID: group, platform: PlatformGrok, schedulable: true,
|
||||
account: Account{ID: 2, Platform: PlatformGrok, Credentials: map[string]any{"model_mapping": map[string]any{"*": "grok-3-mini"}}}},
|
||||
)
|
||||
decision, err := resolver.Resolve(context.Background(), group, "alias", CompositeRouteEndpointResponses)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeRouteSourceAccount, decision.Source)
|
||||
require.Equal(t, CompositeClaimExplicit, decision.RequiredClaimStrength)
|
||||
|
||||
ctx := WithCompositeRouteDecision(context.Background(), decision)
|
||||
require.True(t, CompositeAccountMeetsClaimTier(ctx, &Account{ID: 1, Platform: PlatformGrok,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{"alias": "grok-4.3"}}}, "alias"))
|
||||
require.False(t, CompositeAccountMeetsClaimTier(ctx, &Account{ID: 2, Platform: PlatformGrok,
|
||||
Credentials: map[string]any{"model_mapping": map[string]any{"*": "grok-3-mini"}}}, "alias"))
|
||||
}
|
||||
@@ -42,6 +42,9 @@ type CompositeModelOwnership struct {
|
||||
Matched bool
|
||||
Ambiguous bool
|
||||
CandidatePlatforms []string
|
||||
// RequiredClaimStrength 是构成归属时采用的声明层级:存在强声明平台时为
|
||||
// CompositeClaimExplicit,否则为 CompositeClaimWildcard。
|
||||
RequiredClaimStrength CompositeClaimStrength
|
||||
}
|
||||
|
||||
type CompositeModelOwnershipResolver func(context.Context, int64, string) (CompositeModelOwnership, error)
|
||||
@@ -91,6 +94,9 @@ type CompositeRouteDecision struct {
|
||||
CandidatePlatforms []string `json:"candidate_platforms,omitempty"`
|
||||
Route *CompositeModelRoute `json:"route,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// RequiredClaimStrength 仅账号归属决策携带:选号时账号对公开模型的声明须达到
|
||||
// 该层级(见 CompositeAccountMeetsClaimTier)。
|
||||
RequiredClaimStrength CompositeClaimStrength `json:"-"`
|
||||
}
|
||||
|
||||
// isCompositePoolDecision reports whether the decision carries a multi-platform
|
||||
|
||||
@@ -96,7 +96,7 @@ func WithCompositeRouteDecision(ctx context.Context, decision CompositeRouteDeci
|
||||
if source := strings.TrimSpace(decision.Source); source != "" {
|
||||
ctx = context.WithValue(ctx, ctxkey.CompositeRouteSource, source)
|
||||
}
|
||||
return ctx
|
||||
return withCompositeRequiredClaimStrength(ctx, decision.RequiredClaimStrength)
|
||||
}
|
||||
ctx = WithResolvedTargetPlatform(ctx, decision.TargetPlatform)
|
||||
if model := strings.TrimSpace(decision.UpstreamModel); model != "" {
|
||||
@@ -108,7 +108,14 @@ func WithCompositeRouteDecision(ctx context.Context, decision CompositeRouteDeci
|
||||
if source := strings.TrimSpace(decision.Source); source != "" {
|
||||
ctx = context.WithValue(ctx, ctxkey.CompositeRouteSource, source)
|
||||
}
|
||||
return ctx
|
||||
return withCompositeRequiredClaimStrength(ctx, decision.RequiredClaimStrength)
|
||||
}
|
||||
|
||||
func withCompositeRequiredClaimStrength(ctx context.Context, strength CompositeClaimStrength) context.Context {
|
||||
if strength <= CompositeClaimNone {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, ctxkey.CompositeRequiredClaimStrength, strength)
|
||||
}
|
||||
|
||||
func ResolvedUpstreamModelFromContext(ctx context.Context) (string, bool) {
|
||||
|
||||
@@ -48,11 +48,11 @@ func TestResolveCompositeModelOwnershipKeepsProviderAccountsIsolated(t *testing.
|
||||
|
||||
deepSeekOwnership, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "reasoning-alias")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true}, deepSeekOwnership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, deepSeekOwnership)
|
||||
|
||||
openAIOwnership, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "gpt-public")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, openAIOwnership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, openAIOwnership)
|
||||
}
|
||||
|
||||
// Scenario: 通配映射按既有通配语义声明;映射目标为空的别名不构成声明;
|
||||
@@ -80,7 +80,7 @@ func TestResolveCompositeModelOwnershipHonorsWildcardMappings(t *testing.T) {
|
||||
for _, model := range []string{"gpt-5", "unknown-alias"} {
|
||||
ownership, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, model)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, ownership, "model=%s", model)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimWildcard}, ownership, "model=%s", model)
|
||||
}
|
||||
|
||||
// 映射目标为空的条目不构成声明,也无其他平台可声明。
|
||||
@@ -92,7 +92,7 @@ func TestResolveCompositeModelOwnershipHonorsWildcardMappings(t *testing.T) {
|
||||
// 否则 grok 请求会被改写成 gpt-5(回归)。
|
||||
ownership, err = svc.resolveCompositeModelOwnership(context.Background(), groupID, "grok-public")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformGrok, Matched: true}, ownership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformGrok, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, ownership)
|
||||
}
|
||||
|
||||
func TestResolveCompositeModelOwnershipAllowsSamePlatformAndRejectsCrossPlatformAliases(t *testing.T) {
|
||||
@@ -108,7 +108,7 @@ func TestResolveCompositeModelOwnershipAllowsSamePlatformAndRejectsCrossPlatform
|
||||
|
||||
samePlatform, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "shared-openai")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, samePlatform)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, samePlatform)
|
||||
|
||||
// 跨平台同名别名:返回稳定候选池(去重升序),不再是裸 Ambiguous。
|
||||
ambiguous, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "ambiguous")
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestCompositePoolOwnershipDeepseekNativePlusOpenCodeMapping(t *testing.T) {
|
||||
// 仅 deepseek 空 mapping 声明时保持 single(既有语义)。
|
||||
single, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "deepseek-v4-pro")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true}, single)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, single)
|
||||
}
|
||||
|
||||
// 声明强度分层:有强声明平台时通配 catch-all 平台不混池;完全无强声明才
|
||||
@@ -125,7 +125,7 @@ func TestCompositePoolOwnershipClaimStrengthTiering(t *testing.T) {
|
||||
})
|
||||
ownership, err := grokFirst.resolveCompositeModelOwnership(context.Background(), groupID, "grok-public")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformGrok, Matched: true}, ownership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformGrok, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, ownership)
|
||||
|
||||
// 无任何强声明:deepseek/zhipu 均只有通配命中 → 使用通配 fallback 平台集合。
|
||||
wildcardOnly := svc([]Account{
|
||||
@@ -145,11 +145,12 @@ func TestCompositePoolOwnershipClaimStrengthTiering(t *testing.T) {
|
||||
require.True(t, fallback.Matched)
|
||||
require.Empty(t, fallback.TargetPlatform)
|
||||
require.Equal(t, []string{PlatformDeepseek, PlatformZhipu}, fallback.CandidatePlatforms)
|
||||
require.Equal(t, CompositeClaimWildcard, fallback.RequiredClaimStrength)
|
||||
|
||||
// 仅单个平台通配命中 → fallback single。
|
||||
singleWildcard, err := wildcardOnly.resolveCompositeModelOwnership(context.Background(), groupID, "zhipu-x")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformZhipu, Matched: true}, singleWildcard)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformZhipu, Matched: true, RequiredClaimStrength: CompositeClaimWildcard}, singleWildcard)
|
||||
}
|
||||
|
||||
// e. 显式 route 优先于 pool,route 的 UpstreamModel 改写语义不变。
|
||||
@@ -254,7 +255,7 @@ func TestCompositePoolOwnershipUnaffectedByTransientAccountState(t *testing.T) {
|
||||
repo.accounts = []Account{repo.accounts[0]}
|
||||
single, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "deepseek-chat")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true}, single)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, single)
|
||||
|
||||
// 配置移除全部声明 → 能力消失(0 候选,回退 detector/unknown 原逻辑)。
|
||||
repo.accounts = nil
|
||||
|
||||
@@ -117,12 +117,13 @@ func (r *CompositeRouteResolver) Resolve(ctx context.Context, groupID int64, mod
|
||||
// TargetPlatform 为空,不回退 generic/detector,也不在此猜单平台;
|
||||
// 选择期由统一 OpenAI 兼容 selector 按既有 priority/load/sticky 决定。
|
||||
return CompositeRouteDecision{
|
||||
Matched: true,
|
||||
Source: CompositeRouteSourceAccountPool,
|
||||
GroupID: groupID,
|
||||
PublicModel: model,
|
||||
CandidatePlatforms: normalizeCompositeCandidatePlatforms(ownership.CandidatePlatforms),
|
||||
Endpoint: endpoint,
|
||||
Matched: true,
|
||||
Source: CompositeRouteSourceAccountPool,
|
||||
GroupID: groupID,
|
||||
PublicModel: model,
|
||||
CandidatePlatforms: normalizeCompositeCandidatePlatforms(ownership.CandidatePlatforms),
|
||||
Endpoint: endpoint,
|
||||
RequiredClaimStrength: ownership.RequiredClaimStrength,
|
||||
}, nil
|
||||
} else if ownership.Ambiguous {
|
||||
// 旧形态保护:Ambiguous=true 但未携带候选集合(老 mock / 异常输入)
|
||||
@@ -136,13 +137,14 @@ func (r *CompositeRouteResolver) Resolve(ctx context.Context, groupID int64, mod
|
||||
return decision, nil
|
||||
}
|
||||
return CompositeRouteDecision{
|
||||
Matched: true,
|
||||
Source: CompositeRouteSourceAccount,
|
||||
GroupID: groupID,
|
||||
PublicModel: model,
|
||||
TargetPlatform: platform,
|
||||
UpstreamModel: model,
|
||||
Endpoint: endpoint,
|
||||
Matched: true,
|
||||
Source: CompositeRouteSourceAccount,
|
||||
GroupID: groupID,
|
||||
PublicModel: model,
|
||||
TargetPlatform: platform,
|
||||
UpstreamModel: model,
|
||||
Endpoint: endpoint,
|
||||
RequiredClaimStrength: ownership.RequiredClaimStrength,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ func TestResolveCompositeModelOwnershipCachesConfigState(t *testing.T) {
|
||||
|
||||
first, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "company-model")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true}, first)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformDeepseek, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, first)
|
||||
require.Equal(t, int64(1), repo.listByGroupCalls.Load())
|
||||
|
||||
// TTL 内命中缓存,不再查库。
|
||||
@@ -639,7 +639,7 @@ func TestResolveCompositeModelOwnershipCachesConfigState(t *testing.T) {
|
||||
}}
|
||||
refreshed, err := svc.resolveCompositeModelOwnership(context.Background(), groupID, "company-model")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, refreshed)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, refreshed)
|
||||
require.Equal(t, int64(4), repo.listByGroupCalls.Load())
|
||||
}
|
||||
|
||||
|
||||
@@ -1249,7 +1249,7 @@ func (s *GatewayService) gatewaySchedulingModelSupported(ctx context.Context, ac
|
||||
return true
|
||||
}
|
||||
if GenericCompositePoolActive(ctx) {
|
||||
return CompositeAccountClaimsModel(account, requestedModel)
|
||||
return CompositeAccountMeetsClaimTier(ctx, account, requestedModel)
|
||||
}
|
||||
return s.isModelSupportedByAccountWithContext(ctx, account, requestedModel)
|
||||
}
|
||||
@@ -2717,7 +2717,7 @@ func summarizeSelectionFailureStats(stats selectionFailureStats) string {
|
||||
// 对于 Antigravity 平台,会先获取映射后的最终模型名(包括 thinking 后缀)再检查支持
|
||||
func (s *GatewayService) isModelSupportedByAccountWithContext(ctx context.Context, account *Account, requestedModel string) bool {
|
||||
if source, ok := CompositeRouteSourceFromContext(ctx); ok && source == CompositeRouteSourceAccount {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountClaimsModel(account, publicModel) {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountMeetsClaimTier(ctx, account, publicModel) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1553,11 +1553,16 @@ func (s *GatewayService) resolveCompositeModelOwnership(ctx context.Context, gro
|
||||
}
|
||||
|
||||
claimedPlatforms := strongPlatforms
|
||||
requiredStrength := CompositeClaimExplicit
|
||||
if len(claimedPlatforms) == 0 {
|
||||
claimedPlatforms = wildcardPlatforms
|
||||
requiredStrength = CompositeClaimWildcard
|
||||
}
|
||||
|
||||
ownership := CompositeModelOwnership{}
|
||||
if len(claimedPlatforms) > 0 {
|
||||
ownership.RequiredClaimStrength = requiredStrength
|
||||
}
|
||||
switch len(claimedPlatforms) {
|
||||
case 1:
|
||||
for platform := range claimedPlatforms {
|
||||
|
||||
@@ -1809,7 +1809,7 @@ func (s *defaultOpenAIAccountScheduler) isAccountRequestCompatibleReason(ctx con
|
||||
return false, "account_nil"
|
||||
}
|
||||
if source, ok := CompositeRouteSourceFromContext(ctx); ok && source == CompositeRouteSourceAccount {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountClaimsModel(account, publicModel) {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountMeetsClaimTier(ctx, account, publicModel) {
|
||||
return false, "account_model_not_owned"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1305,7 +1305,7 @@ func TestOpenAIGatewayService_SelectAccountWithScheduler_AccountModelRouteOnlyUs
|
||||
repo := schedulerTestOpenAIAccountRepo{accounts: []Account{owner, nonOwner}}
|
||||
ownership, err := (&GatewayService{accountRepo: repo}).resolveCompositeModelOwnership(ctx, groupID, "team-alias")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, ownership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, ownership)
|
||||
ctx = WithCompositeRouteDecision(ctx, CompositeRouteDecision{
|
||||
Matched: true, Source: CompositeRouteSourceAccount, GroupID: groupID,
|
||||
PublicModel: "team-alias", TargetPlatform: ownership.TargetPlatform, UpstreamModel: "team-alias",
|
||||
@@ -3975,7 +3975,7 @@ func TestOpenAIGatewayService_SelectAccountWithScheduler_LegacyAccountModelRoute
|
||||
repo := schedulerTestOpenAIAccountRepo{accounts: []Account{owner, nonOwner}}
|
||||
ownership, err := (&GatewayService{accountRepo: repo}).resolveCompositeModelOwnership(ctx, groupID, "team-alias")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true}, ownership)
|
||||
require.Equal(t, CompositeModelOwnership{TargetPlatform: PlatformOpenAI, Matched: true, RequiredClaimStrength: CompositeClaimExplicit}, ownership)
|
||||
ctx = WithCompositeRouteDecision(ctx, CompositeRouteDecision{
|
||||
Matched: true, Source: CompositeRouteSourceAccount, GroupID: groupID,
|
||||
PublicModel: "team-alias", TargetPlatform: ownership.TargetPlatform, UpstreamModel: "team-alias",
|
||||
|
||||
@@ -358,7 +358,7 @@ func openAISchedulingModelSupported(ctx context.Context, account *Account, reque
|
||||
return true
|
||||
}
|
||||
if openAICompositePoolActive(ctx) {
|
||||
return CompositeAccountClaimsModel(account, requestedModel) || account.IsOpenAIPassthroughEnabled()
|
||||
return CompositeAccountMeetsClaimTier(ctx, account, requestedModel) || account.IsOpenAIPassthroughEnabled()
|
||||
}
|
||||
return account.IsModelSupported(requestedModel)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func openAICompatibleAccountEligibilityFailureReasonBeforeProfit(ctx context.Con
|
||||
return "account_nil"
|
||||
}
|
||||
if source, ok := CompositeRouteSourceFromContext(ctx); ok && source == CompositeRouteSourceAccount {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountClaimsModel(account, publicModel) {
|
||||
if publicModel, modelOK := RequestedPublicModelFromContext(ctx); modelOK && !CompositeAccountMeetsClaimTier(ctx, account, publicModel) {
|
||||
return "account_model_not_owned"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user