Skip to content

fix(usage): 修正 OpenAI 5h 用量窗口 used%/remaining% 颠倒#2918

Open
wucm667 wants to merge 1 commit into
Wei-Shaw:mainfrom
wucm667:fix/openai-5h-usage-window-inverted
Open

fix(usage): 修正 OpenAI 5h 用量窗口 used%/remaining% 颠倒#2918
wucm667 wants to merge 1 commit into
Wei-Shaw:mainfrom
wucm667:fix/openai-5h-usage-window-inverted

Conversation

@wucm667
Copy link
Copy Markdown
Contributor

@wucm667 wucm667 commented May 31, 2026

背景

OpenAI Codex 5h 用量窗口的上游百分比是 remaining% 语义,但 7d 窗口是 used% 语义。现有归一化逻辑把 5h 原始值直接写入 codex_5h_used_percent,导致 issue 中的 “5h 剩余 6%” 被前端按 used 6% 展示,而 7d 的 used 93% 展示保持正确。

预检已确认当前没有同类修复 PR;#2873 在 v0.1.133 中引入的 5h/7d auto-pause 会读取同一组规范字段,因此这次修复也会让调度阈值继续使用统一的 used% 语义。

改动

  • OpenAICodexUsageSnapshot.Normalize() 中把 5h 上游 remaining% 归一为 canonical used%,即 codex_5h_used_percent = 100 - remaining
  • 保留 codex_primary_* / codex_secondary_* 原始字段,方便继续排查上游 header;7d 现有 used% 行为不变。
  • 补充/调整后端测试,覆盖 issue 实测数据:5h remaining 6% -> utilization 94%,7d used 93% -> utilization 93%。

测试

  • cd backend && go test -tags=unit ./...
  • cd backend && golangci-lint run ./...

Fixes #2904

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Account usage window shows inverted values for 5h period (used% vs remaining%)

1 participant