feat(v1): prefer reported usage for nudge calculations - #15
Merged
ranxianglei merged 1 commit intoAug 13, 2026
Merged
Conversation
Merged
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 E:V1 优先使用 OpenCode provider usage
Summary
V1 在存在有效、最新且与当前 user model 匹配的 OpenCode provider usage 时,直接使用该快照驱动 kernel;否则继续使用现有文本估算:
这与 PI 的“真实值优先、估算兜底”原则一致,不取两者最大值。V2 没有经过验证的稳定 usage 接口,本 PR 保持估算路径不变。
What changed
tokens、summary、error、provider/model 字段类型和 usage 提取逻辑。time.created选择最新 assistant;相同时间按id选择,不依赖消息数组顺序。input + output + reasoning + cache.read + cache.write:每个分量必须是有限非负数,总和必须大于 0;缺失、负数、NaN、Infinity、全零均回退估算。createdAt >= assistant.time.created的 block,认为快照早于或伴随最近一次压缩并回退估算;压缩后出现更新的 provider assistant 后自动恢复 usage。estimatedTokens,debug 日志记录 estimated、reported、最终 tokenCount、来源和回退原因。processTurn结果。bili_status仅在这些输入仍完全匹配时复用 transform 结果,否则回退当前文本估算。runPipelineV2继续只使用estimateTokens。Known limitations
bili_status的 nudge usage/growth 可以复用最近一次 V1 transform 的最终 tokenCount;CONTEXT BREAKDOWN主体仍由 kernel 对可见文本估算,不能视为 provider Meter 的逐项拆分。Tests
新增 usage extraction、模型匹配、时间/id 排序、无效最新快照、压缩新鲜度、reported 大于/小于估算、V1 压缩后恢复、turn cache/status 输入匹配、dropSession/LRU eviction 等测试。
本分支当前测试为 38/38;另已验证:
npm run typechecknpm testnpm run buildbash scripts/ci/check-pr.sh 2026-08-13_v1-reported-usage upstream/mastergit diff --checkScope
acp-kernel。2026-08-13_v1-reported-usagefeat(v1): prefer reported usage for nudge calculations