Skip to content

fix: align UserQuotaSnapshot type with getUserLimitUsage return type#508

Closed
github-actions[bot] wants to merge 2 commits intofix/daily-quota-timezone-consistencyfrom
claude-fix-pr-507-20661769269
Closed

fix: align UserQuotaSnapshot type with getUserLimitUsage return type#508
github-actions[bot] wants to merge 2 commits intofix/daily-quota-timezone-consistencyfrom
claude-fix-pr-507-20661769269

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jan 2, 2026

CI Auto-Fix for PR #507

Original PR: #507
Failed CI Run: PR Build Check

Problem

The CI failed with a TypeScript type mismatch error in src/app/[locale]/dashboard/quotas/users/page.tsx:75:

Type '{ rpm: { current: number; limit: number | null; window: "per_minute"; }; dailyCost: { current: number; limit: number | null; resetAt: Date; }; } | null' is not assignable to type 'UserQuotaSnapshot | null'.

Root Cause

The getUserLimitUsage action returns quota data with:

  • rpm.limit: number | null
  • dailyCost.limit: number | null
  • dailyCost.resetAt: Date (required)

But the UserQuotaSnapshot interface expected:

  • rpm.limit: number (not nullable)
  • dailyCost.limit: number (not nullable)
  • dailyCost.resetAt?: Date (optional)

Fix Applied

File Change Type
src/app/[locale]/dashboard/quotas/users/_components/types.ts Updated UserQuotaSnapshot interface to match actual data structure Type definition alignment

Changes made:

  • rpm.limit: numberrpm.limit: number \| null
  • dailyCost.limit: numberdailyCost.limit: number \| null
  • dailyCost.resetAt?: DatedailyCost.resetAt: Date

Verification

bun run typecheck passes
bun run lint passes
✅ No logic changes made
✅ Minimal, targeted type fix only


Auto-generated by Claude AI

Greptile Summary

Fixes TypeScript type mismatch between UserQuotaSnapshot interface and getUserLimitUsage action return type. The action returns quota limits as nullable (number | null) and resetAt as required, but the interface expected non-nullable limits and optional resetAt.

Changes:

  • rpm.limit: numbernumber | null
  • dailyCost.limit: numbernumber | null
  • dailyCost.resetAt: Date?Date (now required)

This aligns the type definition with the actual runtime data structure returned by getUserLimitUsage() in src/actions/users.ts:1233-1295, which retrieves user quota data where limits can be null (unlimited) and resetAt is always present from getDailyResetTime().

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a pure type definition fix with no runtime logic changes
  • Score of 5 reflects that this is a straightforward type alignment fix that corrects a TypeScript compilation error. The changes are minimal (3 field type adjustments), accurately reflect the actual runtime data structure, and have been validated by passing typecheck and lint. No logic changes were made, only type definitions updated to match reality.
  • No files require special attention

Important Files Changed

Filename Overview
src/app/[locale]/dashboard/quotas/users/_components/types.ts Aligned UserQuotaSnapshot type with getUserLimitUsage return type - made limits nullable and resetAt required

Sequence Diagram

sequenceDiagram
    participant Page as UsersQuotaPage
    participant Action as getUserLimitUsage
    participant DB as Database
    participant Type as UserQuotaSnapshot
    
    Page->>Action: getUserLimitUsage(userId)
    Action->>DB: findUserById(userId)
    DB-->>Action: User data
    Action->>DB: sumUserCostToday(userId)
    DB-->>Action: dailyCost (number)
    Action->>Action: Build response with<br/>limit: number | null<br/>resetAt: Date
    Action-->>Page: { rpm, dailyCost }
    Page->>Type: Assign to quota: UserQuotaSnapshot
    Note over Page,Type: ✅ Type alignment fixed:<br/>limits now nullable<br/>resetAt now required
Loading

NightYuYyy and others added 2 commits January 3, 2026 00:13
## 问题描述
用户反馈个人页面显示的用户层级每日限额和Key层级每日限额不一致。

## 根本原因
- **Key层级**: 正确使用 `getTimeRangeForPeriodWithMode()` 根据配置的 `dailyResetTime` 和 `dailyResetMode` 计算时间范围
- **用户层级**: 使用 `sumUserCostToday()` 简单的日期比较 `created_at::date = CURRENT_DATE`,完全忽略了用户的 `dailyResetTime` 配置

## 修复内容

### 1. src/actions/my-usage.ts
- **getMyQuota()**: 改用 `getTimeRangeForPeriodWithMode()` + `sumUserCostInTimeRange()` 计算用户每日消费
- **getMyTodayStats()**: 改用时间范围查询替代日期比较

### 2. src/repository/statistics.ts
- 标记 `sumUserCostToday()` 为 `@deprecated`,提供迁移路径说明

## 影响范围
- ✅ 个人用量页面 (/my-usage) - 用户层级每日限额显示
- ✅ 今日统计卡片 - Key层级今日消费统计
- ✅ 限额检查 - 用户和Key的每日限额使用相同时间范围逻辑

## 性能优化
从 `(created_at AT TIME ZONE timezone)::date` 表达式比较
改为 `created_at >= startTime AND created_at < endTime` 直接索引范围扫描
预期性能提升: 80%+

## 测试
- ✅ TypeScript类型检查通过
- ✅ Biome代码检查通过
- ✅ Codex AI代码审核通过 (评分: 8.2/10)

Co-reviewed-by: Codex AI
Fixed:
- Updated UserQuotaSnapshot.rpm.limit to accept number | null (was number)
- Updated UserQuotaSnapshot.dailyCost.limit to accept number | null (was number)
- Made UserQuotaSnapshot.dailyCost.resetAt required (was optional)

This aligns the interface with the actual return type from getUserLimitUsage action,
resolving the TypeScript type mismatch error in page.tsx:75.

CI Run: https://github.com/ding113/claude-code-hub/actions/runs/20661769269
@NightYuYyy NightYuYyy force-pushed the fix/daily-quota-timezone-consistency branch from a231eec to e73ade0 Compare January 2, 2026 21:35
@ding113 ding113 closed this Jan 3, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 3, 2026
@ding113 ding113 deleted the claude-fix-pr-507-20661769269 branch January 27, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

Comments