parseTier returns a prefix tier for bare hyphenated tier names
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4k
- Forks
- 453
- Avg merge
- 12h 30m
- Merged PRs (30d)
- 46
Description
Summary
parseTier can return the wrong token-saver tier when knownTiers contains names where one tier is a word-prefix of another hyphenated tier. The fallback parser checks shorter tiers with a word-boundary regex before checking whether the cleaned judge output exactly equals the longer tier.
Code path
src/router/tokenSaver/parseTier.ts:3-20strips code fences, handles<tier>...</tier>, then falls back to iteratingknownTiers.src/router/tokenSaver/parseTier.ts:13-17uses\b${tier}\b, which treats-as a word boundary.src/router/tokenSaver/generateJudgePrompt.ts:25asks the judge to return<tier>NAME</tier>, butparseTierintentionally accepts non-tagged fallback text.src/router/config/schema.ts:25-30definesrouter.tokenSaver.tiersas user-configured tier names.
Steps to reproduce
On the current main code path, the following minimal call returns the shorter prefix tier:
import { parseTier } from "./src/router/tokenSaver/parseTier.js";
console.log(parseTier("a-a", ["a", "a-a"]));
Actual result:
"a"
Expected result:
"a-a"
A practical configuration can hit the same shape with tier names such as fast and fast-pro if the judge returns a bare tier name instead of the preferred tag wrapper.
Expected behavior
When the cleaned judge output is exactly a known tier name, that exact tier should take precedence over word-boundary substring matches.
Actual behavior
The fallback branch iterates knownTiers in order. Because a hyphen is a word boundary, "a-a" matches \ba\b and returns "a" before the parser reaches "a-a".
Existing coverage
I could not find an existing open or closed issue/PR covering this parseTier / token-saver tier-prefix collision.
Suggested fix
One focused fix is to check exact cleaned tier equality before the regex fallback, case-insensitively. Another option is to sort fallback candidates by descending length before applying word-boundary matching.
Suggested tests
parseTier("a-a", ["a", "a-a"])returns"a-a".parseTier("<tier>a-a</tier>", ["a", "a-a"])still returns"a-a".- A bare output like
"please use a-a"keeps the intended fallback behavior without selecting"a"first.
Submitted with Codex.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/router/tokenSaver/parseTier.ts:3-20 and reproduce the documented a-a case, then review how the fallback checks knownTiers. Add focused coverage for exact bare and tagged hyphenated names, plus the prose fallback, and confirm exact known-tier equality wins without breaking tagged parsing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100