Repository navigation
Conversation
The ValidationError handler logged that the model was being skipped but then fell through to `costs.append(cost)`. An invalid first row raised UnboundLocalError, and an invalid row after a valid one re-appended the previous model. Continue to the next row instead. Adds regression tests for an invalid row in the first and middle positions. Fixes AgentOps-AI#1460 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Fixes #1460.
load_model_costs()catchespydantic.ValidationErrorand printsModel ... has invalid data. Skipping., but then falls through tocosts.append(cost)anyway:costwas never assigned, so the loader raisesUnboundLocalErrorand collector config generation stops.coststill holds the previous model, so that model is appended a second time.The fix adds
continuein theexceptbranch so invalid rows are actually skipped, which is what the log message already says happens.Impact on real data
Run against the
tokencostmodel_prices.jsoninstalled locally (384 rows currently fail validation, mostly zero input cost):So on today's data, every generated collector config contains 384 duplicate model entries. If the first row of the file ever becomes invalid, config generation fails outright.
Tests
I added
TestLoadModelCostsInvalidRowstobuilder/tests/test_model_cost.py. It pointsget_tokencost_pathat a temporarymodel_prices.jsonviamonkeypatchand covers:test_invalid_first_row_is_skipped: invalid row first, then two valid rowstest_invalid_middle_row_does_not_duplicate_previous: valid, invalid, validRun from
app/opentelemetry-collectorwith Python 3.12 and pydantic 2.14.1:Before the fix (new tests only; the 11 existing tests passed):
After the fix:
🤖 Generated with Claude Code