← Back to PRs

#23568: fix(agents): preserve multi-segment model IDs in splitModelRef

by arosstale open 2026-02-22 13:00 View on GitHub →
agents size: XS experienced-contributor
## Problem Fixes #23481. `splitModelRef` used `String.split("/", 2)` to separate the provider prefix from the model ID. JS's `split(sep, limit)` discards everything after the `limit`-th token, so: ``` "huggingface/mistralai/Mistral-7B-Instruct-v0.3".split("/", 2) // → ["huggingface", "mistralai"] ← "Mistral-7B-Instruct-v0.3" lost ``` The subagent spawn path then dispatched with model=`"mistralai"` instead of `"mistralai/Mistral-7B-Instruct-v0.3"`, causing API errors or wrong model selection for any HuggingFace org-scoped model ID. ## Fix Switch to `indexOf` so only the **first** slash is the boundary — matching the approach already used in `parseModelRef`: ```ts const slash = trimmed.indexOf("/"); const provider = trimmed.slice(0, slash); const model = trimmed.slice(slash + 1); // preserves "mistralai/Mistral-7B-Instruct-v0.3" ``` ## Tests New file `subagent-spawn.split-model-ref.test.ts` covers: - Simple `provider/model` - Multi-segment `huggingface/org/model` (regression case) - Deeply nested ID - No-slash (model only) - Empty / undefined inputs [AI-assisted] <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes critical bug where `splitModelRef` truncated multi-segment HuggingFace model IDs (e.g., `huggingface/mistralai/Mistral-7B-Instruct-v0.3`) by switching from `String.split("/", 2)` to `indexOf` approach that preserves everything after the first slash. This aligns with the existing `parseModelRef` implementation in `src/agents/model-selection.ts:144` for consistency. - Implementation correctly uses `indexOf` to split only on the first slash, preserving `org/model` format for HuggingFace models - Comprehensive test coverage including regression test for the exact issue reported in #23481 - CHANGELOG entry accurately describes the fix and impact - No breaking changes; backward compatible with existing single-segment model IDs <h3>Confidence Score: 5/5</h3> - Safe to merge with no risk - clean bug fix with comprehensive test coverage - The fix is straightforward, well-tested, and addresses a critical bug. The implementation matches the existing pattern in `parseModelRef` for consistency. All edge cases are covered by tests, and the change is backward compatible with existing single-segment model IDs. The only call site is in the same file at line 285, making the impact clear and contained. - No files require special attention <sub>Last reviewed commit: b539be7</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs