fix: stabilize session hash + add user-level session limit#634
Open
rikouu wants to merge 3 commits intoWei-Shaw:mainfrom
Open
fix: stabilize session hash + add user-level session limit#634rikouu wants to merge 3 commits intoWei-Shaw:mainfrom
rikouu wants to merge 3 commits intoWei-Shaw:mainfrom
Conversation
Bug fix:
- GenerateSessionHash fallback now uses ClientIP+APIKeyID instead of
message content, preventing the same user from being counted as
multiple sessions across conversation turns
New feature:
- Add user-level active session limit (max_sessions field on User)
- Redis key: session_limit:user:{userID} (reuses existing Lua scripts)
- checkAndRegisterUserSession called before account selection
- Default 0 = no limit (backward compatible)
修复活跃会话计算bug + 新增用户级会话数限制
Bug修复:
- GenerateSessionHash 的 fallback 改为使用 ClientIP+APIKeyID
避免同一用户每轮对话被计为不同会话,虚增活跃会话数
新功能:
- User 新增 max_sessions 字段(默认0=不限制)
- Redis key: session_limit:user:{userID}
- 在账号选择前执行用户级会话检查
f096573 to
86338db
Compare
- Add max_sessions field to admin user create/edit forms and user list table - Wire max_sessions through handler → service → DTO → frontend types - Add i18n translations (en: 'Max Sessions', zh: '最大会话数') - Return HTTP 429 with friendly message when user session limit exceeded (was: 503 with generic "No available accounts" error) - Error message now guides users to close sessions or wait before retrying
86338db to
ac9e5af
Compare
Replace generic "no available accounts" with specific messages: - "no schedulable accounts in pool" (all accounts disabled/rate-limited) - "N accounts filtered (reasons)" (accounts exist but filtered out) - "all accounts at capacity" (accounts valid but busy) - "no matching accounts in pool" (legacy path, no match) Also: pass error detail through in openai handler (was hidden as "Service temporarily unavailable") and add missing UserSessionLimitError check to openai handler for 429 response. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
你好,想跟进一下这个 PR。session hash 的 fallback 用了消息内容来计算,导致同一个用户每轮对话都被算成不同会话,活跃会话数虚高,session limit 基本形同虚设。希望能抽空看一下,有任何需要调整的地方随时说 🙏 |
Owner
|
你的请求主要来源是非claude code客户端吗? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses two issues with session management and adds admin UI support:
1. Fix: Session Hash Stability
The
GenerateSessionHashfallback previously used message content, causing the same user to be counted as multiple sessions across conversation turns. Now usesClientIP+APIKeyIDas a stable fallback.2. Feature: User-Level Session Limit (
max_sessions)max_sessionsfield on User model (DB column, default 0 = unlimited)session_limit:user:{userID}3. Admin Panel UI for
max_sessionsCompatibility
max_sessions = 0(no limit) — fully backward compatiblemain(v0.1.86)