fix(copilot): align overage fallback with parser shape split - #16
Merged
Conversation
linletian
commented
Aug 2, 2026
linletian
left a comment
Owner
Author
There was a problem hiding this comment.
评审:与 PR15 高度重复,净增量仅 Parser legacy 修复
背景
本分支基于 580bc73(#14 合并后),创建于 PR15 合并之前。它是 PR15 评审意见(07-31 #1 双计 bug + #7 parser legacy 丢 - remaining)的同题独立实现——当时作者尚不知道 PR15 分支会一并修复。PR15 现已合并进 main。
✅ 改动正确性(PR16 自身)
- RefreshService fallback 分流:
remaining < 0 ? entitlement - remaining : max(0, entitlement - remaining) + overageCount—— 正确,与已合并的f571dea公式逐字一致(两分支独立达成相同结论) - Parser legacy 恢复
- remaining(entitlement - remaining + overageCount):本 PR 的净增量,采纳 07-31 评审 #7。remaining > 0且 overage 时正确(fixture 100/30/5 → 75%,旧公式会算 105% 高估);remaining == 0时与旧公式等价、零成本 - 误导注释删除:"NOT a provider-agnostic extension point" 直接回应评审 #5,质量好
- 测试:
testLegacyOverageWithPositiveRemainingSubtractsRemaining(parser)与testCopilotOverageFallbackWithoutCreditsUsedDoesNotDoubleCount(service)均正确且通过(本分支实测:358 个测试中仅 Kimi 的testUnparseableWeeklyResetTimeDoesNotDeclareFiveHourPolicy失败——那是 PR156bae5d3已修的预存在问题,本分支基线未包含) - 文档:§5/§7/§8/§9 + provider-interfaces 同步更新到位
🔴 问题(合并前必须处理)
1. 与 main 冲突是真实的,且解决方向不能错
用正确基线(main=5586320)跑 merge-tree 模拟,2 个冲突文件:
RefreshService.swift:冲突仅在注释与哨兵写法,核心公式两侧已一致。main 侧含评审 #4 的Int?哨兵 + 契约注释(cadab12从0630250吸收);本分支仍是?? "0") ?? 0数值守卫。冲突解决必须取 main 侧——两边都能编译,错误选择会静默回退评审 #4 的成果RefreshServiceMappingTests.swift:testCopilotOverageWithoutCreditsUsed(main)vstestCopilotOverageFallbackWithoutCreditsUsedDoesNotDoubleCount(本分支)—— 断言完全相同的重复测试,二选一即可
2. 文档 §10.1 描述过时
§10.1 声称两项修复(RefreshService fallback + parser legacy)都由本分支完成。实际 RefreshService fallback 已由 PR15/f571dea 修复。rebase 后需改写:本分支只贡献 parser legacy 一项。
3. 必须 rebase/merge main
分支缺 PR15 的 6bae5d3 fixture 修复,当前基线测试集是红的(1 失败)。直接合并会丢失 PR15 全部成果。
🟡 建议
- rebase main 后,RefreshService.swift 冲突取 main 侧(保留
Int?+ 契约注释);本分支的 "NOT an extension point" 注释要点已由 main 侧契约注释覆盖,无需保留双份 - service 层重复测试保留一个
- Parser legacy 修复 + 测试 + 文档是干净的净增量,自动合并无冲突(merge-tree 验证 4 个文件 merged 干净)
结论
Request changes:方向正确、修复正确,但 90% 内容与已合并的 PR15 重复。合并路径:rebase main → 冲突取 main 侧 → 仅保留 Parser legacy 净增量 → 修正 §10.1。或者更简单:关闭本 PR,把 Parser legacy 修复作为独立小 commit 提到新 PR。
Post-merge review (PR #15) found two divergences from the strategy in docs/copilot-overage-stuck-at-100-percent.md §7: - RefreshService's fallback kept `max(0, entitlement - remaining) + overageCount` unconditionally, double-counting overage in the new API shape when `credits_used` is absent (panel text 120/100 vs the parser's 110% bar). Now mirrors the parser: `remaining < 0` ⇒ `entitlement - remaining`, else add `overageCount`. - Parser legacy branch dropped `- remaining` in 6a85578; restored (equivalent at remaining == 0, correct when > 0). Also replace the misleading comment claiming the numeric guard is a provider-agnostic extension point — the block sits inside the githubCopilot branch, no other supplier can reach it. Tests: testCopilotOverageFallbackWithoutCreditsUsedDoesNotDoubleCount, testLegacyOverageWithPositiveRemainingSubtractsRemaining.
linletian
force-pushed
the
fix/copilot-overage-fallback-double-count
branch
from
August 2, 2026 10:00
c41e882 to
7b8474f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
PR #14 合并后,PR #15 的评审发现两处实现与
docs/copilot-overage-stuck-at-100-percent.md§7 策略不一致,其中 RefreshService fallback 双计已由 PR #15(f571dea)修复。本 PR 收敛为仅剩的净增量:Parser legacy 分支的- remaining修复。改动
CopilotResponseParser.swiftentitlement - remaining + overageCount(6a85578误改为entitlement + overageCount,仅在remaining == 0时等价)CopilotResponseParserTests.swifttestLegacyOverageWithPositiveRemainingSubtractsRemaining(100/30/5 → 75%,旧公式会算 105% 高估)docs/copilot-overage-stuck-at-100-percent.mddocs/provider-interfaces/copilot.md风险
remaining通常被夹到 0,此修复在remaining == 0时与旧公式完全同解,仅防御remaining > 0且 overage 的边界(成本为零)验证