#5115: fix: guard against undefined model.name in Ollama discovery (#5062)
agents
Cluster:
Ollama Model Enhancements
## Summary
- Fixes #5062 — `TypeError: Cannot read properties of undefined (reading 'includes')` in Ollama model discovery
- Adds `.filter()` before `.map()` in `discoverOllamaModels()` to skip model entries with missing or empty `name` fields
- Exports `discoverOllamaModels` for direct unit testing and adds test coverage for the edge case
## Test plan
- [x] `pnpm lint` passes (0 warnings, 0 errors)
- [x] `pnpm test` — all 192 related tests pass; new tests cover undefined, null, and empty-string model names
- [ ] Manual verification with an Ollama instance that returns malformed model data
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Guards Ollama model discovery against malformed `/api/tags` responses by filtering out entries with missing/empty `name` before deriving `id` and `reasoning` flags, preventing `TypeError` during `.includes()` checks. Also exports `discoverOllamaModels` and adds targeted Vitest coverage for invalid names and fetch failures, while keeping implicit provider resolution behavior unchanged.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge; changes are small and well-covered by tests.
- The runtime fix (filtering invalid `name` values) directly addresses the reported crash and is low risk. Main concerns are test fragility from mutating `process.env` and a type/interface mismatch that could confuse future maintainers, but neither is likely to break production behavior immediately.
- src/agents/models-config.providers.ollama.test.ts; src/agents/models-config.providers.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7278: feat(ollama): optimize local LLM support with auto-discovery and ti...
by alltomatos · 2026-02-02
85.1%
#4782: fix: Auto-discover Ollama models without requiring explicit API key
by spiceoogway · 2026-01-30
83.0%
#16098: fix: omit tools param for models without tool support, surface erro...
by claw-sylphx · 2026-02-14
82.9%
#11877: feat(ollama): auto-detect vision capability via /api/show
by Nina-VanKhan · 2026-02-08
80.5%
#21977: Preserve provider API for discovered Ollama models
by graysurf · 2026-02-20
79.2%
#18587: fix(ollama): improve timeout handling and cooldown logic for local ...
by manthis · 2026-02-16
78.4%
#9822: fix: allow local/custom model providers for sub-agent inference
by stammtobias91 · 2026-02-05
78.2%
#9257: this is my first fork
by demonking369 · 2026-02-05
77.9%
#7432: Comprehensive Ollama Support PR
by charlieduzstuf · 2026-02-02
76.7%
#21199: Models: suppress repeated vLLM/Ollama discovery warnings (#21037)
by itsishant · 2026-02-19
76.5%