Repository navigation
Conversation
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.
问题
有些上游会在每个 chunk 重复上报累计 usage(
prompt_tokens不变、completion_tokens递增),而readSSE与internal/relay两处都把每一帧Merge(逐字段相加)。后果:一次几百帧的流式回答,输入侧 token 被累加成 30~1400 倍的假数字 —— 1.2k 能变成六位数。面板数字随之失真,压缩阈值的判断也被推着走。
修复
Usage新增Absorb(*Usage):逐字段取较大值。message_deltaMerge(相加)保留原语义,只用于跨请求聚合(截断续写时 prompt 确实要付两次)。改动点:
internal/lane/http.go(readSSE)、internal/relay/relay.go。测试
新增
internal/lane/usage_absorb_test.go:三次重复累计帧喂进去,断言输入仍是 1200 而不是 3600;同时钉住Merge的可加语义没有被顺手改坏。go build ./.../go vet ./...通过;go test ./...全绿(internal/lane30.8s、internal/relay13.2s、internal/gateway23.9s)。Closes #105