Skip to content

fix(session): ignore malformed model costs - #43248

Merged
nexxeln merged 1 commit into
devfrom
cost-field-validation
Aug 18, 2026
Merged

fix(session): ignore malformed model costs#43248
nexxeln merged 1 commit into
devfrom
cost-field-validation

Conversation

@nexxeln

Copy link
Copy Markdown
Member

Summary

  • treat malformed or non-finite model cost fields as zero during usage accounting
  • preserve valid pricing components and existing finite-price behavior
  • add a regression test for provider-supplied object values

Closes#43098

Testing

  • bun test test/session/compaction.test.ts --test-name-pattern "SessionNs.getUsage"
  • bun typecheck in packages/opencode
  • full workspace typecheck from the pre-push hook

@macurandb

Copy link
Copy Markdown

Question rather than a bug report — is the numeric-string case intentional?

finite() takes a number, so a cost field that arrives as a numeric string now prices at 0, where ?? 0 used to hand it straight to decimal.js, which parses it fine:

cost.inputbeforeafter
"3"30
"1e3"10000
{}threw0 ✅

If the answer is "a string violates the declared Schema.Finite, so we don't support it", that's a perfectly good answer and I'll drop it — the crash was the real problem and that's fixed. I'm asking because the failure mode flipped from loud to silent (an under-reported cost rather than an aborted turn), and because the same shape just landed in packages/core via #43251, so whichever way you want it, it probably wants to be the same in both.

Happy to send a patch if you'd like the string path kept.

alltomatos pushed a commit to alltomatos/opencode that referenced this pull request Aug 18, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DecimalError] Invalid argument: [object Object] — non-numeric provider cost field aborts the turn (fatal on opencode acp)

2 participants

@nexxeln@macurandb