Skip to content

fix: handle both string[] and object[] formats in provider-models cache#1509

Merged
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
rooftop-Owl:fix/category-delegation-cache-format-mismatch
Feb 5, 2026
Merged

fix: handle both string[] and object[] formats in provider-models cache#1509
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
rooftop-Owl:fix/category-delegation-cache-format-mismatch

Conversation

@rooftop-Owl
Copy link
Contributor

@rooftop-Owl rooftop-Owl commented Feb 5, 2026

Summary

Fixes category delegation failing when provider-models.json contains model objects with metadata instead of plain strings.

Root Cause: Line 196 in model-availability.ts assumes string[] format when iterating over cached models, but manually-populated caches (like Ollama) use object[] format with metadata ({id, provider, context, output}).

Impact:

  • delegate_task(category='quick') → ❌ "Model not configured for category"
  • delegate_task(subagent_type='explore') → ✅ Works (bypasses cache)

Changes

Core Fix (model-availability.ts)

// Before (line 196)
for (const modelId of modelIds) {
  modelSet.add(`${providerId}/${modelId}`)  // ❌ Breaks with objects
}

// After
for (const modelItem of modelIds) {
  const modelId = typeof modelItem === 'string' 
    ? modelItem 
    : (modelItem as any)?.id  // ✅ Handles both formats
  
  if (modelId) {
    modelSet.add(`${providerId}/${modelId}`)
  }
}

Type Safety (connected-providers-cache.ts)

interface ProviderModelsCache {
  models: Record<string, string[] | ModelMetadata[]>  // Now accepts both
  connected: string[]
  updatedAt: string
}

Test Coverage (model-availability.test.ts)

Added 4 test cases:

  • ✅ Handle object[] format with metadata (Ollama-style)
  • ✅ Handle mixed string[] and object[] across providers
  • ✅ Skip invalid entries gracefully
  • ✅ Backward compatibility with legacy string[] format

Testing

npm test -- src/shared/model-availability.test.ts
# ✅ 48 pass (including 4 new tests)

npm run typecheck
# ✅ No errors

Context

This fix enables category-based delegation to work with manually-populated Ollama model caches, which is the intended approach per Vercel AI SDK (no model.list() for local providers).

Related:

Backward Compatibility

✅ Fully backward compatible - handles both legacy string[] and new object[] formats without breaking existing deployments.


Summary by cubic

Fixes category delegation by supporting both string[] and object[] formats in provider-models.json. Prevents “Model not configured for category” errors with Ollama and other manually populated caches.

  • Bug Fixes
    • Parse both string[] and object[] when building available models; skip invalid entries.
    • Updated ProviderModelsCache types and added tests for object[], mixed formats, and legacy compatibility.

Written for commit bd3a3bc. Summary will update on new commits.

Category delegation fails when provider-models.json contains model objects
with metadata (id, provider, context, output) instead of plain strings.
Line 196 in model-availability.ts assumes string[] format, causing:
  - Object concatenation: `${providerId}/${modelId}` becomes "ollama/[object Object]"
  - Empty availableModels Set passed to resolveModelPipeline()
  - Error: "Model not configured for category"

This is the root cause of issue code-yeongyu#1508 where delegate_task(category='quick')
fails despite direct agent routing (delegate_task(subagent_type='explore'))
working correctly.

Changes:
- model-availability.ts: Add type check to handle both string and object formats
- connected-providers-cache.ts: Update ProviderModelsCache interface to accept both formats
- model-availability.test.ts: Add 4 test cases for object[] format handling

Direct agent routing bypasses fetchAvailableModels() entirely, explaining why
it works while category routing fails. This fix enables category delegation
to work with manually-populated Ollama model caches.

Fixes code-yeongyu#1508
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@code-yeongyu code-yeongyu merged commit 617d7f4 into code-yeongyu:dev Feb 5, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Category delegation fails to resolve Ollama models despite correct configuration

2 participants

Comments