← Back to PRs

#5115: fix: guard against undefined model.name in Ollama discovery (#5062)

by TheWildHustle open 2026-01-31 02:41 View on GitHub →
agents
## 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