fix(subscription): 移除额度快照时间失效 - #454
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: QUIET Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough本次变更移除配额观测的 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 365babd274
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR removes the time-based “freshness” expiry for subscription quota snapshots (fresh_until_ms), so the system keeps the last successfully synced quota state until a new sync happens, and physically drops the retired column via a new DB migration.
Changes:
- Remove
fresh_until_msfrom backend models/API, frontend DTO projection, and UI labels; add migration0003_remove_observation_fresh_until(SQLite rebuild + MySQL/Postgres drop column). - Update subscription account UI to show a “pending refresh” hint after a quota window ends, and rename diagnostics to “last quota sync”.
- Tighten quota window usage aggregation to use the snapshot’s recorded
[start, end)boundaries, reusing hourly stats for full hours and request logs for both boundary fragments.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| web/src/i18n/locales/zh-CN/group.ts | Add pending-refresh hint text; rename quota sync diagnostic label. |
| web/src/i18n/locales/ja-JP/group.ts | Add pending-refresh hint text; rename quota sync diagnostic label. |
| web/src/i18n/locales/en-US/group.ts | Add pending-refresh hint text; rename quota sync diagnostic label. |
| web/src/features/groups/credentials/SubscriptionAccountCard.vue | Remove time-based staleness gating; show pending refresh tooltip; adjust reset-credit display logic. |
| web/src/app/resources/credentials.ts | Stop projecting fresh_until_ms into the web resource DTO. |
| web/src/api/control/types.ts | Remove fresh_until_ms from CredentialObservationDto. |
| internal/storage/models/subscription.go | Drop FreshUntilMS field from CredentialObservation model. |
| internal/storage/migrations/0003_remove_observation_fresh_until.go | New migration to drop the retired fresh_until_ms column (+ validators). |
| internal/storage/migrations/0003_remove_observation_fresh_until_test.go | Test that migration drops the column and preserves rows/idempotency. |
| internal/storage/migration.go | Add ValidateCurrent hook; register migration 0003; validate applied chain with current validator when present. |
| internal/storage/migration_test.go | Update expected migration registry IDs to include 0003. |
| internal/storage/migration_recovery_test.go | Add MySQL resume coverage for 0003; broaden external incremental migration test to include all migrations. |
| internal/storage/db_test.go | Update expected schema migration ledger to include 0003. |
| internal/storage/database_integration_test.go | Assert fresh_until_ms is absent after lifecycle migrations; expect 0001–0003 ledger. |
| internal/state/runtime_view.go | Replace FreshQuotaRemaining with ObservedQuotaRemaining; drop QuotaFreshUntil from runtime view. |
| internal/state/registry.go | Remove quotaFreshUntil tracking; simplify SetCredentialQuotaObservation signature/validation. |
| internal/state/registry_test.go | Update tests for new quota-observation semantics (no time expiry). |
| internal/scheduler/inspect_test.go | Update test naming/fixtures for removed QuotaFreshUntil. |
| internal/requestlog/credential_window_usage.go | Fix hourly window end alignment; merge request-log usage for both start/end boundaries. |
| internal/requestlog/credential_window_usage_test.go | Add coverage ensuring both boundary fragments use exact request logs. |
| internal/control/health.go | Use observed quota remaining without time-based expiry gating. |
| internal/control/health_quota_test.go | Update expectations to include all recorded low-quota credentials. |
| internal/control/credentials.go | Update observation presentation call site for removed freshness parameter. |
| internal/control/credential_reset_credits.go | Clear quota observation without fresh_until state. |
| internal/control/credential_observations.go | Remove TTL-based freshness logic; stop emitting/using fresh_until_ms; use recorded window [start,end) for usage enrichment. |
| internal/control/credential_observations_test.go | Update/add tests for “no time expiry” semantics and recorded window boundaries. |
| internal/control/credential_mutations.go | Update observation presentation call site for removed freshness parameter. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (2)
internal/control/credential_observations.go-618-618 (1)
618-618: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win拒绝非正数的
ResetAtMS。Line 618 只排除
nil。它会接受0和负数的ResetAtMS。enrichCredentialObservationUsage在 Line 736-738 已将这些值定义为不可用窗口。time.UnixMilli(0)不是零值time.Time,因此无效边界仍会写入注册表和健康检查响应。在选择账户额度窗口前,要求
ResetAtMS > 0。同时增加零值和负值的测试。建议修改
- if window.Scope != "account" || window.ResetAtMS == nil { + if window.Scope != "account" || window.ResetAtMS == nil || *window.ResetAtMS <= 0 {internal/storage/migrations/0003_remove_observation_fresh_until.go-37-37 (1)
37-37: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win修复
staticcheck的QF1008错误。将
db.Dialector.Name()改为db.Name(),避免make check失败。Source: Linters/SAST tools
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: a287a2ba-780c-499b-9af5-09340ebac900
📒 Files selected for processing (27)
internal/control/credential_mutations.gointernal/control/credential_observations.gointernal/control/credential_observations_test.gointernal/control/credential_reset_credits.gointernal/control/credentials.gointernal/control/health.gointernal/control/health_quota_test.gointernal/requestlog/credential_window_usage.gointernal/requestlog/credential_window_usage_test.gointernal/scheduler/inspect_test.gointernal/state/registry.gointernal/state/registry_test.gointernal/state/runtime_view.gointernal/storage/database_integration_test.gointernal/storage/db_test.gointernal/storage/migration.gointernal/storage/migration_recovery_test.gointernal/storage/migration_test.gointernal/storage/migrations/0003_remove_observation_fresh_until.gointernal/storage/migrations/0003_remove_observation_fresh_until_test.gointernal/storage/models/subscription.goweb/src/api/control/types.tsweb/src/app/resources/credentials.tsweb/src/features/groups/credentials/SubscriptionAccountCard.vueweb/src/i18n/locales/en-US/group.tsweb/src/i18n/locales/ja-JP/group.tsweb/src/i18n/locales/zh-CN/group.ts
💤 Files with no reviewable changes (3)
- web/src/api/control/types.ts
- web/src/app/resources/credentials.ts
- internal/storage/models/subscription.go
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (1)
web/src/i18n/locales/en-US/core.ts-247-247 (1)
247-247: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win修正英文到期提示。
the nearest expires缺少名词。此文本会直接显示在首页。请改为the nearest one expires。建议修改
- resetCreditExpiring: '{group} has {count} reset credits expiring soon; the nearest expires', + resetCreditExpiring: '{group} has {count} reset credits expiring soon; the nearest one expires',
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 5f25373c-b16c-4182-8b11-9ba9c7980550
📒 Files selected for processing (21)
internal/control/credential_observations_test.gointernal/control/credential_reset_credits.gointernal/control/health.gointernal/control/health_quota_test.gointernal/control/health_reset_credits.gointernal/subscription/providers/codex/observation.gointernal/subscription/providers/codex/observation_test.gointernal/subscription/providers/observation/snapshot.goweb/src/api/control/types.tsweb/src/app/resources/credentials.tsweb/src/app/resources/health.tsweb/src/features/groups/credentials/GroupCredentialsTab.vueweb/src/features/groups/credentials/SubscriptionAccountCard.vueweb/src/features/home/HomeAttention.vueweb/src/features/home/attention.tsweb/src/i18n/locales/en-US/core.tsweb/src/i18n/locales/en-US/group.tsweb/src/i18n/locales/ja-JP/core.tsweb/src/i18n/locales/ja-JP/group.tsweb/src/i18n/locales/zh-CN/core.tsweb/src/i18n/locales/zh-CN/group.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b735b97a9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/storage/migrations/0003_remove_observation_fresh_until.go (1)
21-23: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift补齐 MySQL CHECK 约束删除的版本兼容处理。
当
DontSupportDropConstraint为true时,credentialObservation0003未声明chk_credential_observation_fresh_until,GORM 会跳过DROP CHECK。此外,MySQL 8.0.16–8.0.18 支持 CHECK 约束,但不支持DROP CONSTRAINT;当前驱动仍会生成通用语句,导致迁移失败。请补充同名 CHECK 定义,显式处理这些版本,并为每个支持的 MySQL 版本增加包含实际 CHECK 约束的集成测试。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 1b8e02b4-27c6-4ef3-8ade-dfa4cc7108b4
📒 Files selected for processing (2)
internal/storage/migrations/0003_remove_observation_fresh_until.goweb/src/i18n/locales/en-US/core.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a40e955b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/storage/migrations/0003_remove_observation_fresh_until.go (1)
73-119: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win在 SQLite 表重建中使用单个事务。
第 114-118 行将复制、删除和重命名作为独立的自动提交操作执行。
如果DROP TABLE credential_observations成功后ALTER TABLE ... RENAME失败,正式表会缺失。后续Up0003会立即失败,现有观测数据无法由迁移流程恢复。请用
db.Transaction包裹全部重建语句,并通过事务句柄执行每个Exec。建议修复
func rebuildSQLiteCredentialObservations0003(db *gorm.DB) error { statements := []string{ // ... } - for _, statement := range statements { - if err := db.Exec(statement).Error; err != nil { - return fmt.Errorf("rebuild SQLite credential observations: %w", err) + return db.Transaction(func(tx *gorm.DB) error { + for _, statement := range statements { + if err := tx.Exec(statement).Error; err != nil { + return fmt.Errorf("rebuild SQLite credential observations: %w", err) + } } - } - return nil + return nil + }) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 135da3b3-a8e8-4856-b63b-28967629d269
📒 Files selected for processing (4)
internal/storage/migration_recovery_test.gointernal/storage/migrations/0003_remove_observation_fresh_until.gointernal/storage/migrations/0003_remove_observation_fresh_until_internal_test.gointernal/storage/migrations/0003_remove_observation_fresh_until_test.go
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 588d579db1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d184de435
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
关联 Issue / Related Issue
N/A
变更内容 / Change Content
fresh_until_ms运行时、管理 API 和前端字段,并通过0003迁移从 SQLite、MySQL、PostgreSQL 物理删除数据库列。[start, end),整小时复用聚合数据,两侧边界读取请求日志;缺少有效窗口时间时不展示统计。兼容性与迁移影响:管理 API 不再返回
fresh_until_ms;应用启动时0003_remove_observation_fresh_until会删除已有数据库列并保留观测数据。验证:
make check自查清单 / Checklist
make check,或在说明中写明无法运行的原因和未验证范围。 / I ranmake check, or documented why it could not run and what remains unverified.Summary by CodeRabbit
新功能
问题修复