fix(fim): set has_error on microdollar_usage for upstream errors#2581
Merged
chrarnoldus merged 2 commits intomainfrom Apr 20, 2026
Merged
fix(fim): set has_error on microdollar_usage for upstream errors#2581chrarnoldus merged 2 commits intomainfrom
chrarnoldus merged 2 commits intomainfrom
Conversation
FIM parse functions never checked the HTTP status code, so 4xx/5xx responses from Mistral/Inception never set has_error=true in microdollar_usage. Mirror the pattern used by regular chat completions: initialise reportedError from statusCode>=400 in the streaming path, and include statusCode>=400 in the hasError expression for non-streaming.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 245,776 tokens |
alex-alecu
approved these changes
Apr 20, 2026
markijbema
approved these changes
Apr 20, 2026
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
FIM (fill-in-the-middle) requests to Mistral/Inception were never recording
has_error = trueinmicrodollar_usage, even when the upstream provider returned a 4xx/5xx HTTP response.Root cause:
parseMistralFimUsageFromStringandparseMistralFimUsageFromStreamhad no access to the HTTP status code. The regular chat-completion parsers already mirror this pattern: the streaming parser initialisesreportedError = statusCode >= 400, and the non-streaming parser includesstatusCode >= 400in thehasErrorexpression.Changes:
statusCode: numberparameter to both FIM parse functionshasError: !json.model || statusCode >= 400(mirrorsparseMicrodollarUsageFromString)let reportedError = statusCode >= 400(mirrorsparseMicrodollarUsageFromStream)countAndStoreFimUsageextractsusageContext.status_code ?? 0and passes it to both parsersVerification
processUsage.ts(lines 647 and 760)numberparam, boolean expression unchanged)Visual Changes
N/A
Reviewer Notes
status_codeonMicrodollarUsageContextisnumber | null; the?? 0fallback means a missing status code does not falsely sethas_error. In practicestatus_codeis always set beforecountAndStoreFimUsageis called (route.ts:249).