Skip to content

Fix model mapping to prefer the longest matching prefix#14

Merged
MartinForReal merged 2 commits into
mainfrom
fix/longest-prefix-model-mapping
Jun 9, 2026
Merged

Fix model mapping to prefer the longest matching prefix#14
MartinForReal merged 2 commits into
mainfrom
fix/longest-prefix-model-mapping

Conversation

@MartinForReal

Copy link
Copy Markdown
Owner

Problem

With a config such as:

model_mappings:
  prefix:
    claude-opus-4.7-xhigh: claude-opus-4.7-xhigh

an incoming model claude-opus-4.7-xhigh was rewritten to claude-opus-4.7-1m instead of being kept as claude-opus-4.7-xhigh.

Root cause

translate() iterated the prefix BTreeMap in sorted key order and returned the first starts_with match. The default mappings already contain claude-opus-4.7, which sorts before (and is a prefix of) claude-opus-4.7-xhigh, so the shorter, less-specific entry always won.

Fix

Select the longest (most specific) matching prefix instead of the first one. Adds a longest_prefix_wins regression test.

Prefix lookups iterated the BTreeMap in sorted key order and returned the first match, so a specific entry like claude-opus-4.7-xhigh was shadowed by the shorter claude-opus-4.7 prefix and mapped to claude-opus-4.7-1m. Select the longest (most specific) matching prefix instead, and add a regression test.
…t versions

- Interactive first-run setup wizard (src/setup.rs): GitHub sign-in, live model catalog, model-mapping prompts; runs on --setup or first launch in a terminal, skipped when headless

- --claudecode now patches ~/.claude/settings.json (merges env.ANTHROPIC_BASE_URL, preserves existing settings via serde_json preserve_order)

- Forward anthropic-beta: context-1m-2025-08-07 on /v1/messages for models whose catalog advertises a >200K context window

- Update mimicked client versions to the latest Copilot Chat extension: copilot 0.48.1, vscode 1.123.0, api 2025-05-01

- Refine README: setup wizard, env token fallbacks, 1M context, updated headers and version-refresh sources
@MartinForReal MartinForReal merged commit ead7453 into main Jun 9, 2026
1 check failed
@MartinForReal MartinForReal deleted the fix/longest-prefix-model-mapping branch June 9, 2026 10:06
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