Repository navigation
fix(gateway): UsageCapture.finish() disjoint input + DeepSeek cache-hit spelling (rant 2026-08-23T14:05:02) - #130
Merged
Conversation
…it spelling (rant 2026-08-23T14:05:02)
4 tasks done
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.
Summary
Fix incomplete P0 cache-billing fix from PR #128 (rant
2026-08-23T08:20:38): PR #128 only patchedsrc/sse.rs(cross-protocol conversion path), but the same-protocol passthrough path —UsageCapture::finish()insrc/gateway.rs— was missed. Per host's rant2026-08-23T14:05:02, cached tokens were double-counted into the total (observed: per-call uncached 241,776 instead of 112, total ≈2× on dev).Root cause (
gateway.rsopenai branch offinish())inputwas set to the fullprompt_tokens(includes cache-hit portion) — not disjointcachedonly recognized OpenAI'sprompt_tokens_details.cached_tokensspelling — DeepSeek's native top-levelprompt_cache_hit_tokenswas dropped (which made the miss even worse on DeepSeek responses)Changes
UsageCapture::finish()openai branch: cached extraction now three-spelling compatible with the same priority asextract_cache_read_tokensinsse.rs— DeepSeek nativeprompt_cache_hit_tokens→ OpenAIprompt_tokens_details.cached_tokens(input - cached).max(0.0)— matches the already-fixed logic insse.rs;maxguards underflowusage_capture_parses_openai_and_anthropic):{"prompt_tokens":100,"prompt_cache_hit_tokens":90,"completion_tokens":50}→ input=10, cached=90prompt_tokens_details.cached_tokens=90→ input=10, cached=90cache_read_input_tokens=70→ input=10, cached=70Expected effect (correct behavior, not a bug)
Related
2026-08-23T14:05:02.990820+08:00(P0 缓存计费修复不完整:UsageCapture.finish() 同协议透传路径漏改)326d00f)Tests
cargo test145/145 pass (incl. new cached cases)cargo fmt --checkcleancargo clippy --all-targetsclean