fix(kosong): clamp uncached OpenAI input usage#2160
Open
morluto wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: fe59b40 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
No linked issue. This is a focused fix for a reproducible OpenAI-compatible usage edge case.
Problem
When a compatible endpoint reports cached-token details but omits the aggregate prompt/input token count, both OpenAI adapters default the aggregate to zero and then subtract the cache count. That produces a negative
inputOther, which cancels the reported cache usage when total input is calculated.Official OpenAI usage objects include the aggregate token fields, so this primarily hardens compatibility with partial responses from OpenAI-compatible endpoints.
What changed
Test plan
pnpm vitest run packages/kosong/test/kimi.test.ts packages/kosong/test/openai-responses.test.ts packages/agent-core-v2/test/kosong/provider/composition.test.ts(239 passed)pnpm vitest run --project kosong(1,336 passed)pnpm vitest run packages/agent-core-v2/test/agent/mcp/output.test.ts(39 passed)pnpm --filter @moonshot-ai/kosong typecheckpnpm --filter @moonshot-ai/agent-core-v2 typecheckpnpm --filter @moonshot-ai/agent-core-v2 lint:domainpnpm --filter @moonshot-ai/kosong buildpnpm --filter @moonshot-ai/agent-core-v2 buildChecklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.