Repository navigation
fix(harness-pi): resolve compound provider/id model ids under their scoped provider - #18334
Conversation
f5c989b to
bfb278f
Compare
…coped provider createPiModelResolver only matched catalog entries by flat id/name, so a compound id like "xai/grok-4.3" matched nothing and the model was silently dropped, falling back to Pi's own hardcoded default (which tries vercel-ai-gateway before xai and fails with "No API key found"). Add a provider-scoped resolution tier that splits on the first slash and matches against the catalog's provider field, run before the existing flat tiers. Kept as ordered tiers rather than one predicate because routing proxies (vercel-ai-gateway, openrouter) can carry another provider's id verbatim as their own flat id, and an OR'd predicate would let catalog array order decide the winner.
bfb278f to
c0de15b
Compare
Bugfix reviewOutcome: changes-required Fixes issueStatus: fully-addresses The new scoped tier correctly resolves xai/grok-4.3 to the native xai entry while retaining the existing AI Gateway preference when gateway credentials are present. Side effectsRisk: medium The unconditional scoped tier can reroute legitimate proxy model IDs to an unauthenticated native provider. Concerns:
PerformanceRisk: low Compound IDs add one additional linear catalog scan, with no additional retained data or unbounded allocation. Backwards compatibilityRisk: none The change neither reads nor modifies persisted credentials, model configuration files, session data, or other stored formats. Breaking changesRisk: medium Public types and exports are unchanged, but existing accepted compound model inputs can now select a different provider and fail authentication. Concerns:
ArchitectureRisk: low The implementation remains localized within harness-pi and introduces no cross-package source imports or dependency-boundary violations. Change scopeStatus: minimal The resolver change, regression tests, and patch changeset are directly related to the reported model-resolution bug. SecurityRisk: none The change adds only in-memory string matching and does not introduce credential exposure, network access, parsing, or injection surfaces. TestingStatus: needs-more The tests cover native xAI resolution, catalog ordering, gateway precedence, and flat fallback, but omit authenticated non-gateway proxy collisions. Concerns:
VerificationReviewed the complete three-file diff and installed Pi 0.80.10 resolver/catalog behavior. The harness-pi suite passed all 126 tests, focused type checking completed successfully, formatting and lint checks were clean, and diff validation found no whitespace errors. Catalog inspection exposed the untested authenticated-OpenRouter routing regression. |
felixarntz
left a comment
There was a problem hiding this comment.
@fdarian Thank you for the PR!
Following the above agent feedback, I added a test, and it actually identified a flaw in the current solution: despite a gateway's auth being configured (in the test OpenRouter), the code still chooses the direct OpenAI model. So this needs to be fixed. I'm happy to add this.
Background
I have pi authenticated with xai on my machine. Passing
xai/grok-4.3to HarnessAgent apparently routed to vercel-ai-gateway, meanwhilexai/grok-4.3is a valid pi's modelId (<provider-id>/<provider-model-id>). For examplepi --model "xai/grok-4.3" -p "hello"is a valid expected syntax for grok-4.3 from xai provider.Summary
Compound
<provider>/<model-id>ids were only matched literally, against a provider's flatid. That happens to work for routing proxies likevercel-ai-gateway, which store the compound string as their own id, but never for a native provider likexai, whose entry isprovider: "xai"+id: "grok-4.3". Soxai/grok-4.3silently landed on the gateway entry instead. Added provider-scoped matching so these resolve to the provider the id actually names.End-to-End Verification
Added unit tests in
packages/harness-pi/src/pi-model-resolver.test.tsfor compoundprovider/idandprovider/nameresolution, the gateway and scoped tiers against each other in both catalog orderings, and fallthrough to flat matching.pnpm test:node(packages/harness-pi): 126 tests passed.pnpm type-check:full(root): passed.Checklist
pnpm changesetin the project root)Related Issues
Related to #18155, #18147, #18153 (see the collapsed summary above for how each relates).