Skip to content

fix(codex): 修复 WebSocket 普通账号额度停滞 - #656

Merged
tbphp merged 6 commits into
mainfrom
tbphp/fix-codex-ws-passive-quota
Sep 15, 2026
Merged

tbphp merged 6 commits into
mainfrom
tbphp/fix-codex-ws-passive-quota

Conversation

@tbphp

@tbphp tbphp commented Sep 14, 2026

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

变更内容 / Change Content

  • Bug 修复 / Bug fix
  • 新功能 / New feature
  • 其他改动 / Other changes

Codex WebSocket 的顶层 rate_limits 可能没有来源标识:普通模型请求返回账号额度,Spark 请求则可能重复附加额度。原实现丢弃无来源的顶层窗口,导致普通账号百分比停留在旧值。

现在逐窗口比较同一事件中的顶层与全部附加额度。周期相同且原始 reset_at 或同事件的 reset_after_seconds 对齐(允许 1 秒精度差)时,丢弃顶层副本;确实没有附加窗口,或能在共同时间基准下排除全部附加副本时,按兼容规则归属普通账号。缺少共同基准、周期损坏或副本判断冲突时跳过未知顶层;明确来源仍直接更新。来源比较不使用本地接收时间,已归属额度的展示时间仍支持相对倒计时换算。

每个来源和窗口独立校验:用量损坏不会抹掉用于来源比较的原始时间信息,也不会阻断其他有效窗口。非额度事件先做轻量类型检查,只有额度事件完整解析。整个过程不新增上游请求、历史周期推断、账号缓存或配置;被动更新只更新唯一匹配的已有窗口,不创建或删除窗口。

验证:

  • make check,包含全量后端测试、Go vet、编译及前端静态检查与构建。
  • 真实普通模型/Spark 样本回放、HTTP/WS 合并对照、跨周期、多个附加来源、空字段、字段损坏、逐窗口去重和复用连接的既有测试通过。
  • 新增共同/混合时间基准、字段互换、5 秒延迟、判断冲突回归,以及最终合并保留主账号 93% 且刷新 Spark 的验证。
  • 1 MiB 非额度事件本地基准:额外分配由约 5 MiB 降至 32 B/次;类型字段位于首部和尾部均验证,性能数据仅代表该解析函数。
  • 用户此前已完成真实账号普通模型/Spark、HTTP/WS、新旧环境 A/B;本轮异常边界使用离线测试,未重复真实账号测试。

自查清单 / Checklist

  • 我已运行 make check,或在说明中写明无法运行的原因和未验证范围。 / I ran make check, or documented why it could not run and what remains unverified.
  • 本 PR 范围聚焦,未包含无关改动。 / This PR is focused and contains no unrelated changes.
  • 我已更新必要的公开文档或发布说明。 / I updated any required public documentation or release notes.
  • 我已确认提交、日志和测试数据不包含敏感信息。 / I confirmed that commits, logs, and fixtures contain no sensitive data.
  • 如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.

Copilot AI lite review requested due to automatic review settings September 14, 2026 15:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T16:24:58.015240Z 6ff818b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: c6b3b203-fe00-4162-be6d-6d61d806e325

📥 Commits

Reviewing files that changed from the base of the PR and between ebfd675 and a515613.

📒 Files selected for processing (3)
  • internal/subscription/passive_quota_websocket_test.go
  • internal/subscription/providers/codex/websocket_quota.go
  • internal/subscription/providers/codex/websocket_quota_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

本次变更调整 Codex WebSocket 额度窗口的解析、保留、匹配和去重规则。解析器现在按窗口周期及重置时间识别顶层账号窗口和附加窗口,并隔离损坏字段。被动快照测试覆盖跨重置周期更新、账户额度保护和窗口来源清理。WebSocket 会话测试覆盖窗口数量变化、复用会话刷新账号百分比,以及 Spark-only 事件。

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to a5156

The WebSocket quota updates keep account and named quota windows separate, with ambiguous updates safely ignored. No unresolved merge risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 标题准确概括了本次修复的主要内容,即修复 Codex WebSocket 普通账号额度停滞问题。
Description check ✅ Passed 描述包含关联 Issue、变更内容、详细实现说明、验证结果和完整自查清单。关联 Issue 标注为“无”,其余模板要求均已覆盖。

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tbphp tbphp self-assigned this Sep 14, 2026
@tbphp tbphp added the bug Something isn't working label Sep 14, 2026
@tbphp tbphp added this to the v2.0.0 milestone Sep 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6dcddb595e

ℹ️ 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".

Comment thread internal/subscription/passive_quota_flush.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 5bdacbb9-05d2-4821-bb48-dccd9c49dc67

📥 Commits

Reviewing files that changed from the base of the PR and between 91df89e and 6dcddb5.

📒 Files selected for processing (6)
  • internal/execution/cpa/websocket_quota_test.go
  • internal/subscription/passive_quota_flush.go
  • internal/subscription/passive_quota_websocket_test.go
  • internal/subscription/providers/codex/websocket_quota.go
  • internal/subscription/providers/codex/websocket_quota_test.go
  • internal/subscription/providers/observation/snapshot.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread internal/subscription/passive_quota_flush.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ff818b056

ℹ️ 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".

Comment thread internal/subscription/passive_quota_flush.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 3dc90928-cbec-4525-9626-a0c57e389142

📥 Commits

Reviewing files that changed from the base of the PR and between 6ff818b and c3b2eee.

📒 Files selected for processing (4)
  • internal/subscription/passive_quota_flush.go
  • internal/subscription/passive_quota_websocket_test.go
  • internal/subscription/providers/codex/websocket_quota.go
  • internal/subscription/providers/codex/websocket_quota_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread internal/subscription/providers/codex/websocket_quota.go Outdated
@tbphp
tbphp merged commit df72bbb into main Sep 15, 2026
11 checks passed
@tbphp
tbphp deleted the tbphp/fix-codex-ws-passive-quota branch September 15, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants