Skip to content

Share one recursive tree-walker across the models.dev pricing collectors - #390

Merged
TheGreatAxios merged 1 commit into
mainfrom
cl-5681-three-near-identical-recursive-tree-walkers-in-pricing
Aug 8, 2026
Merged

Share one recursive tree-walker across the models.dev pricing collectors#390
TheGreatAxios merged 1 commit into
mainfrom
cl-5681-three-near-identical-recursive-tree-walkers-in-pricing

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the three independent recursive walkers in src/cost/pricing-fetcher.ts (previously collectModelPricing, collectModelReasoning, collectModelContextWindows) with a single walkModelNodes generator that yields (id, node) pairs; each parser now only extracts its own field from the shared traversal.
  • Fixes a real divergence: collectModelPricing didn'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

  • Added a failing-first test (parseModelsDevPricing walks a top-level array payload the same way the other collectors do) demonstrating the divergence, in tests/unit/pricing-fetcher.test.ts
  • bun run typecheck (pre-existing unrelated arktype-version errors only, none touching the changed lines)
  • bun run build
  • bun 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)

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.
@linear-code

linear-code Bot commented Aug 8, 2026

Copy link
Copy Markdown

CL-5681

@TheGreatAxios
TheGreatAxios merged commit 7d992d8 into main Aug 8, 2026
3 checks passed
Sign up for free to 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.

1 participant