Skip to content

Conversation

@DioNanos
Copy link

🐛 Bug Description

CCR crashes with TypeError: Cannot read properties of undefined when accessing config.Router properties without checking if config.Router exists first.

🔍 Root Cause

Multiple locations in the codebase access config.Router.xxx without verifying that config.Router is defined. This happens when:

  • No Router configuration is provided in config.json
  • First-time setup without Router section
  • Configuration files missing Router object

✅ Changes Made

Files Modified:

  • src/agents/image.agent.ts (line 59)
  • src/utils/router.ts (lines 161, 227)
  • src/utils/modelSelector.ts (line 122)

Fix Pattern:

All fixes follow defensive programming:

// Before
if (!config.Router.image)

// After  
if (!config.Router || !config.Router.image)

🧪 Testing

Tested with:

  • ✅ Qwen3 14B via CCR → Ollama
  • ✅ GLM-4 9B via Ollama (direct)
  • ✅ DeepSeek-R1 8B via Ollama (direct)
  • ✅ CCR health endpoint

All tests passed without crashes.

📝 Additional Notes

This is a defensive programming fix that prevents crashes when config.Router is undefined. No functionality changes, only safety improvements.

- Add config.Router existence check in image.agent.ts shouldHandle()
- Add config.Router check before accessing .background in router.ts
- Replace unsafe assertion with safe ternary for config.Router.default
- Add config.Router check in modelSelector.ts with fallback message

Fixes TypeError: Cannot read properties of undefined (reading 'image/default/background')

These crashes occurred when config.Router was undefined, typically when:
- No Router configuration was provided in config.json
- First-time setup without Router section
- Configuration files missing Router object

All fixes follow defensive programming pattern: check parent object
exists before accessing properties.

Tested with Ollama local models (Qwen3 14B, GLM-4 9B, DeepSeek-R1 8B)
and verified CCR health endpoint.
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.

1 participant