Skip to content

ModelPrice prefix matching should sort by descending prefix length #1

Description

@n0rvyn

Symptom

ModelPrice.builtInDefaults comment says "ordered longest-prefix-first" but the array is not actually sorted by prefix length. Currently only the gpt-4o-mini / gpt-4o overlap is handled correctly by manual positioning. Future additions could introduce prefix shadowing bugs silently.

Prior Hypotheses

N/A — not a bug

Related Files

  • ModelProxy/Models/ModelPrice.swift:21-41builtInDefaults array
  • ModelProxy/Models/ModelPrice.swift:44-53lookup() uses .first with prefix matching

Notes

Two options:

  1. Sort the array programmatically by descending prefix length at lookup time (or use a computed property)
  2. Add a unit test that asserts no entry's prefix is a prefix of a later entry's prefix (catches shadowing at compile/test time)

Option 2 is lighter and catches the actual failure mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions