Share one recursive tree-walker across the models.dev pricing collectors - #390
Merged
TheGreatAxios merged 1 commit intoAug 8, 2026
Conversation
collectModelPricing, collectModelReasoning, and collectModelContextWindows each recursed the same untyped JSON tree independently and re-derived the model id the same way, so a payload-shape change needed the same fix applied three times. They had also drifted: the pricing collector was the only one that didn't handle a top-level array payload, silently dropping pricing for any tree shaped that way while reasoning and context-window extraction worked fine. walkModelNodes now does the traversal and id resolution once, yielding (id, node) pairs that each parser extracts its own field from.
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
src/cost/pricing-fetcher.ts(previouslycollectModelPricing,collectModelReasoning,collectModelContextWindows) with a singlewalkModelNodesgenerator that yields(id, node)pairs; each parser now only extracts its own field from the shared traversal.collectModelPricingdidn't handle a top-level array payload the way the other two collectors did, silently dropping pricing data for a tree shaped that way.Test plan
parseModelsDevPricing walks a top-level array payload the same way the other collectors do) demonstrating the divergence, intests/unit/pricing-fetcher.test.tsbun run typecheck(pre-existing unrelated arktype-version errors only, none touching the changed lines)bun run buildbun run test(4139/4140 pass; the one failure,src/agent/lsp-availability.test.ts, is an environment-dependent pre-existing test unrelated to this change)