@@ -345,6 +345,9 @@ type GatewayCache interface {
345345 // DeleteSessionAccountID 删除粘性会话绑定,用于账号不可用时主动清理
346346 // Delete sticky session binding, used to proactively clean up when account becomes unavailable
347347 DeleteSessionAccountID (ctx context.Context , groupID int64 , sessionHash string ) error
348+ // DeleteStickySessionsByAccount 删除指定账号在指定分组中的所有粘性会话
349+ // Delete all sticky sessions for the given account in the given group
350+ DeleteStickySessionsByAccount (ctx context.Context , groupID int64 , accountID int64 ) error
348351}
349352
350353// derefGroupID safely dereferences *int64 to int64, returning 0 if nil
@@ -1403,7 +1406,7 @@ func (s *GatewayService) SelectAccountWithLoadAwareness(ctx context.Context, gro
14031406 if clearSticky {
14041407 _ = s .cache .DeleteSessionAccountID (ctx , derefGroupID (groupID ), sessionHash )
14051408 }
1406- if ! clearSticky && s . isAccountInGroup (account , groupID ) &&
1409+ if ! clearSticky && isAccountInGroup (account , groupID ) &&
14071410 s .isAccountAllowedForPlatform (account , platform , useMixed ) &&
14081411 (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) &&
14091412 account .IsSchedulableForModelWithContext (ctx , requestedModel ) &&
@@ -1857,7 +1860,7 @@ func (s *GatewayService) isAccountAllowedForPlatform(account *Account, platform
18571860
18581861// isAccountInGroup checks if the account belongs to the specified group.
18591862// Returns true if groupID is nil (no group restriction) or account belongs to the group.
1860- func ( s * GatewayService ) isAccountInGroup (account * Account , groupID * int64 ) bool {
1863+ func isAccountInGroup (account * Account , groupID * int64 ) bool {
18611864 if groupID == nil {
18621865 return true // 无分组限制
18631866 }
@@ -2397,7 +2400,7 @@ func (s *GatewayService) selectAccountForModelWithPlatform(ctx context.Context,
23972400 if clearSticky {
23982401 _ = s .cache .DeleteSessionAccountID (ctx , derefGroupID (groupID ), sessionHash )
23992402 }
2400- if ! clearSticky && s . isAccountInGroup (account , groupID ) && account .Platform == platform && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
2403+ if ! clearSticky && isAccountInGroup (account , groupID ) && account .Platform == platform && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
24012404 if s .debugModelRoutingEnabled () {
24022405 logger .LegacyPrintf ("service.gateway" , "[ModelRoutingDebug] legacy routed sticky hit: group_id=%v model=%s session=%s account=%d" , derefGroupID (groupID ), requestedModel , shortSessionHash (sessionHash ), accountID )
24032406 }
@@ -2497,7 +2500,7 @@ func (s *GatewayService) selectAccountForModelWithPlatform(ctx context.Context,
24972500 if clearSticky {
24982501 _ = s .cache .DeleteSessionAccountID (ctx , derefGroupID (groupID ), sessionHash )
24992502 }
2500- if ! clearSticky && s . isAccountInGroup (account , groupID ) && account .Platform == platform && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
2503+ if ! clearSticky && isAccountInGroup (account , groupID ) && account .Platform == platform && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
25012504 return account , nil
25022505 }
25032506 }
@@ -2604,7 +2607,7 @@ func (s *GatewayService) selectAccountWithMixedScheduling(ctx context.Context, g
26042607 if clearSticky {
26052608 _ = s .cache .DeleteSessionAccountID (ctx , derefGroupID (groupID ), sessionHash )
26062609 }
2607- if ! clearSticky && s . isAccountInGroup (account , groupID ) && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
2610+ if ! clearSticky && isAccountInGroup (account , groupID ) && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
26082611 if account .Platform == nativePlatform || (account .Platform == PlatformAntigravity && account .IsMixedSchedulingEnabled ()) {
26092612 if s .debugModelRoutingEnabled () {
26102613 logger .LegacyPrintf ("service.gateway" , "[ModelRoutingDebug] legacy mixed routed sticky hit: group_id=%v model=%s session=%s account=%d" , derefGroupID (groupID ), requestedModel , shortSessionHash (sessionHash ), accountID )
@@ -2706,7 +2709,7 @@ func (s *GatewayService) selectAccountWithMixedScheduling(ctx context.Context, g
27062709 if clearSticky {
27072710 _ = s .cache .DeleteSessionAccountID (ctx , derefGroupID (groupID ), sessionHash )
27082711 }
2709- if ! clearSticky && s . isAccountInGroup (account , groupID ) && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
2712+ if ! clearSticky && isAccountInGroup (account , groupID ) && (requestedModel == "" || s .isModelSupportedByAccountWithContext (ctx , account , requestedModel )) && account .IsSchedulableForModelWithContext (ctx , requestedModel ) {
27102713 if account .Platform == nativePlatform || (account .Platform == PlatformAntigravity && account .IsMixedSchedulingEnabled ()) {
27112714 return account , nil
27122715 }
0 commit comments