-
Notifications
You must be signed in to change notification settings - Fork 142
feat: 支持按供应商配置 Session TTL(Fixes #603) #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat: 支持按供应商配置 Session TTL(Fixes #603) #609
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthrough在 providers 表新增可选整数列 Changes
估计代码审查工作量🎯 4 (复杂) | ⏱️ ~60 分钟 可能相关的问题
可能相关的 PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro Cache: Disabled due to Reviews > Disable Cache setting 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✏️ Tip: You can disable this entire section by setting Comment |
Summary of ChangesHello @YangQing-Lin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在通过引入供应商级别的 Session TTL 配置,提升系统在多供应商场景下的灵活性和可控性。此前,所有 Session 均使用统一的全局 TTL,限制了不同供应商对会话粘性或上下文缓存窗口的个性化需求。现在,系统能够根据每个供应商的特定设置来管理 Session 的生命周期,从而更好地适应各种业务场景,同时通过合理的范围限制避免极端配置带来的潜在风险。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
这个 Pull Request 增加了一个很实用的功能,允许为每个供应商单独配置 Session TTL,提高了多供应商环境下的灵活性。代码实现非常全面,涵盖了数据库、后端逻辑、API 集成和前端 UI 的修改。代码结构清晰,并且为新逻辑编写了单元测试,值得称赞。
我的审查意见主要包含两点关于代码简化的建议,旨在移除冗余逻辑,以提高代码的可读性和可维护性。总的来说,这是一次高质量的贡献。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review Summary
No significant issues identified in this PR. The implementation of provider-specific Session TTL is well-structured, follows existing codebase patterns, and includes proper error handling with logging throughout.
PR Size: XL
- Lines changed: 2835 (2775 additions, 60 deletions)
- Files changed: 28
Note on PR size: This is an XL PR primarily due to the auto-generated Drizzle snapshot file (drizzle/meta/0055_snapshot.json ~2400 lines). The actual code changes are moderate and focused. Consider splitting future PRs if they involve multiple unrelated features.
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean (all error paths logged appropriately)
- Type safety - Clean (proper nullable types, validation schema with 60-3600 range)
- Documentation accuracy - Clean
- Test coverage - Adequate (new tests for
resolveSessionTtlcovering fallback, clamping, and invalid global TTL) - Code clarity - Good (follows existing patterns)
Implementation Highlights
- Database: New nullable
session_ttlcolumn added via proper Drizzle migration workflow - Validation: Schema enforces integer type with 60-3600 second range
- TTL Resolution:
resolveSessionTtl()properly handles null/undefined with global fallback and clamping - i18n: All 5 languages (en, ja, ru, zh-CN, zh-TW) have proper translations
- Backward Compatibility: Existing providers with
NULLsession_ttl continue using globalSESSION_TTL
Automated review by Claude AI
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Greptile encountered an error while reviewing this PR. Please reach out to support@greptile.com for assistance. |
目标 / 背景
当前 Session 的 Redis 绑定/续期统一使用全局
SESSION_TTL(默认 300s)。在多供应商场景下,不同上游对“会话粘性/上下文缓存窗口”的需求不同:因此需要允许在 Provider 维度覆写 Session TTL,并在 Redis 侧按绑定的 Provider TTL 进行过期控制。(#603)
方案概述
providers表新增可空字段session_ttl(秒)。session_ttl。变更点
数据库
providers.session_ttl(integer, nullable):drizzle/0055_normal_johnny_storm.sql后端(Provider 配置贯通)
src/lib/validation/schemas.ts:Create/Update Provider schema 增加session_ttl,并强制为整数且范围 60~3600。src/types/provider.ts:新增Provider.sessionTtl、ProviderDisplay.sessionTtl,并在CreateProviderData/UpdateProviderData支持session_ttl?: number | null。src/repository/provider.ts/src/repository/_shared/transformers.ts:DB ↔ 领域模型映射新增sessionTtl。Session / Redis 行为
src/lib/session-manager.tsresolveSessionTtl(providerTtl):provider ttl 优先;否则使用全局SESSION_TTL(无效则 300);最终 clamp 到 60~3600。resolveSessionTtlForSession(sessionId):读取session:{id}:provider绑定的 providerId,回查 Provider 配置得到最终 ttl,用于刷新。bindSessionToProvider/updateSessionBindingSmart/updateSessionWithCodexCacheKey:写入/续期session:{id}:provider时使用该 ttl。src/lib/session-tracker.tsrefreshSession(sessionId, keyId, providerId, ttlSeconds):用传入 ttl 刷新session:{id}:provider、session:{id}:key、session:{id}:last_seen的过期时间(原先固定 300s)。Proxy 集成点
src/app/v1/_lib/proxy/forwarder.ts:成功后绑定 Session 到 Provider 时把provider.sessionTtl传给SessionManager.updateSessionBindingSmart(...)。src/app/v1/_lib/proxy/response-handler.tsprovider.sessionTtl。SessionManager.resolveSessionTtlForSession(sessionId)获取 ttl,并调用SessionTracker.refreshSession(..., ttlSeconds)进行滑动续期。管理后台 UI + i18n
src/app/[locale]/settings/providers/_components/forms/provider-form.tsxmessages/{en,ja,ru,zh-CN,zh-TW}/settings/providers/form/{sections,errors}.json测试
tests/unit/session-manager.test.ts:覆盖SessionManager.resolveSessionTtl的兜底与 clamp 行为。tests/unit/settings/providers/model-multi-select-custom-models-ui.test.tsx:修复测试中误用未定义的loadTestMessages(与本 PR 功能无关,但会导致单测失败)。兼容性与默认行为
session_ttl默认为NULL,行为不变(继续使用全局SESSION_TTL作为 session 绑定续期基准)。迁移与部署
drizzle/0055_normal_johnny_storm.sqlAUTO_MIGRATE=true:启动时自动应用;否则手动执行bun run db:migrate。验证与测试
已在本地执行并通过:
bun run buildbun run lint(Checked 775 files,无错误)bun run lint:fix(Checked 775 files,无可自动修复项)bun run typecheckbun run test(Test Files 137 passed (137),Tests 878 passed (878),Duration 42.79s)风险与回滚
session_ttl配得过长会增强 session 粘性、降低 provider 切换频率;已通过 60~3600 的范围限制避免极端配置。providers.session_ttl。