Repository navigation
fix(session): port upstream malformed model cost guard (anomalyco/opencode#43248) - #1613
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
25 of 71 tasks
This branch has not been deployed
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.
Issue for this PR
Closes #1573
Type of change
What does this PR do?
Session.getUsagemultiplies token counts by the model'scostfields withdecimal.js. When a provider or models.dev entry carries a malformed cost (an object, a string orNaN),new Decimal(...).mul(...)throwsDecimalErrorand the whole turn fails after the model already answered.Ported from upstream anomalyco/opencode#43248: each cost field goes through a
finite()guard, so a non-finite value counts as 0 instead of throwing. Valid fields are still billed. Wrapped inaltimate_changemarkers taggedupstream_fix:.Note:
session/session.tshas a secondgetUsagecopy that nothing imports (callers usesession/index.ts), so it is left untouched.How did you verify your code works?
New test in
test/session/session-getusage.test.tssetsinput: {},cache.read: NaN,cache.write: "x"and checks the output cost is still billed (1.5). It throws onmainand passes on this branch.bun typecheckandbun run script/upstream/analyze.ts --markers --base origin/main --strictare clean.Cost side effects
None. No new model calls, queries or resources. Malformed cost fields now count as 0 in the usage total instead of failing the turn.
Screenshots / recordings
N/A, no UI change.
Checklist
Written by Devin
Summary by cubic
Fixes
Session.getUsageso malformed model cost fields (objects, strings, orNaN) are treated as 0 instead of throwingDecimalErrorand failing the turn. Valid cost fields are still billed. Adds a test covering malformed cost input.Written for commit 29ebce2. Summary will update on new commits.