#23568: fix(agents): preserve multi-segment model IDs in splitModelRef
agents
size: XS
experienced-contributor
Cluster:
Model Management Enhancements
## 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
#20712: fix(subagents): prioritize agent runtime default model over global ...
by sourcesavant · 2026-02-19
80.6%
#23542: fix/hf inference
by Josephrp · 2026-02-22
78.8%
#21088: fix: sessions_sspawn model override ignored for sub-agents
by Slats24 · 2026-02-19
78.3%
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
77.9%
#19328: Fix: preserve modelOverride in agent handler (#5369)
by CodeReclaimers · 2026-02-17
77.1%
#11562: Fix #10883: Enforce subagent model configuration
by divol89 · 2026-02-08
76.9%
#11198: fix(models): strip @profile suffix from model selection
by mcaxtr · 2026-02-07
76.9%
#23286: fix: use configured model in llm-slug-generator instead of hardcoded …
by wsman · 2026-02-22
76.8%
#6673: fix: preserve allowAny flag in createModelSelectionState for custom...
by tenor0 · 2026-02-01
76.6%
#13626: fix(model): propagate provider model properties in fallback resolution
by mcaxtr · 2026-02-10
76.5%