Skip to content

fix: add community config endpoint and fix provider routing#96

Merged
neuromechanist merged 4 commits intodevelopfrom
feature/fix-qwen-provider-issue
Jan 27, 2026
Merged

fix: add community config endpoint and fix provider routing#96
neuromechanist merged 4 commits intodevelopfrom
feature/fix-qwen-provider-issue

Conversation

@neuromechanist
Copy link
Copy Markdown
Member

Summary

Fixes two critical issues preventing the Qwen model from working:

  1. Missing config endpoint: Widget was calling GET /communities/{communityId} but that endpoint didn't exist
  2. Wrong provider format: Backend used {"only": [provider]} but OpenRouter requires {"order": [provider]}

Changes

Backend

  • Add GET /{community_id}/ endpoint to return community configuration (id, name, description, default_model, default_model_provider)
  • Fix OpenRouter provider routing in litellm_llm.py: change "only" to "order"

Frontend

  • Update widget to call /{communityId}/ instead of /communities/{communityId}
  • Remove hardcoded fallback model (openai/gpt-oss-120b)
  • Show proper error messages when config fetch fails

Documentation

  • Add .context/api-structure.md - comprehensive API implementation guide
    • Community-based routing pattern
    • Model selection logic
    • Common mistakes and how to avoid them
    • Testing recipes
  • Reorganize CLAUDE.md Key Documentation section by purpose

Testing

Tested locally:

  • GET /hed/ returns correct config with qwen/qwen3-235b-a22b-2507
  • OpenRouter API accepts {"order": ["DeepInfra/FP8"]} (tested with curl)

Impact

  • Widget will now show correct default model in settings
  • Backend will successfully route to DeepInfra/FP8 provider for Qwen model
  • Prevents similar routing/endpoint mistakes in the future

Closes #93

- Add GET /{community_id}/ endpoint to return community configuration
  including default_model and default_model_provider
- Fix OpenRouter provider routing: change "only" to "order"
  (OpenRouter rejects {"only": [provider]} but accepts {"order": [provider]})
- Update widget to call correct endpoint (/{communityId}/ not /communities/{communityId})
- Remove hardcoded fallback model from widget, show proper errors instead

Fixes the two main issues:
1. Widget showing old default model (openai/gpt-oss-120b)
2. Backend failing with "No allowed providers are available" error

Tested with curl - DeepInfra/FP8 provider now works correctly.
- Add .context/api-structure.md with comprehensive API implementation guide
  - Community-based routing pattern (/{community_id}/...)
  - Model selection logic and provider routing details
  - Common mistakes and how to avoid them (provider format, fallbacks, etc.)
  - Testing and adding new communities
- Reorganize CLAUDE.md Key Documentation section
  - Group by purpose (API, Security, Tools, Architecture, etc.)
  - Add clear directive on which doc to read for which task
  - Emphasize api-structure.md as starting point for API work

This prevents issues like the provider routing bug and /communities/
pattern mistake from happening again.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 26, 2026

🚀 Preview Deployment

Name Link
Preview URL https://feature-fix-qwen-provider-is.osa-demo.pages.dev
Branch feature/fix-qwen-provider-issue
Commit ba040d1

This preview will be updated automatically when you push new commits.

@neuromechanist
Copy link
Copy Markdown
Member Author

PR Review Summary

Overall Assessment: Conditional Approval - Core fixes are correct, but widget needs better error handling before merge.

Issues Found

Priority Issue Location Description
🔴 CRITICAL Widget silent failure frontend/osa-chat-widget.js:1353-1390 Widget continues operating when config fetch fails, leaving communityDefaultModel = null. Should disable widget completely.
🔴 CRITICAL Settings masks error frontend/osa-chat-widget.js:1408 Shows "Default (Community Setting)" when model is null, hiding the failure. Should show "ERROR: Not configured" and disable option.
🔴 CRITICAL Hint hides error frontend/osa-chat-widget.js:1432-1434 Model hint silently omitted when config fails. Should show red error text.
🟡 HIGH Broad exception handling src/api/routers/community.py:803-813 Catches all exceptions with generic "Internal server error". Should use specific handlers for auth errors, rate limits, timeouts.
🔵 MINOR Port number clarity .context/api-structure.md:314 Testing examples use dev port (38529) but default is prod (38528). Add clarifying comment.
🔵 MINOR Missing validation src/api/routers/community.py:949-974 Config endpoint doesn't validate default_model is non-null. Add validation before return.

What's Good ✅

  • ✅ Core fixes are correct (provider routing, config endpoint)
  • ✅ Excellent documentation with accurate examples
  • ✅ Follows CLAUDE.md guidelines (no hardcoded fallbacks)
  • ✅ All code examples tested and working

Recommendation

Fix the 3 critical widget issues before merging:

  1. Disable widget when config fetch fails (add disableWidget() function)
  2. Show error state in settings dropdown when model is null
  3. Show error state in model hint when model is null

The high-priority backend exception handling can be addressed in a follow-up PR as it's a pre-existing pattern across endpoints.


Review completed by: code-reviewer, comment-analyzer, silent-failure-hunter agents

Addresses critical PR review findings:

1. Add disableWidget() function that disables input/send button when config invalid
2. Call disableWidget() on all fetchCommunityDefaultModel() error paths:
   - Invalid community ID
   - HTTP errors (404, 500, etc.)
   - Missing default_model in response
   - Network/timeout errors
3. Show error state in settings modal dropdown when model is null
4. Show error state in model hint when model is null (red text)

This prevents the widget from appearing functional when it's actually broken,
making failures visible to users immediately rather than silently continuing
with null communityDefaultModel.

Fixes silent failure issues identified in PR #96 review.
Addresses minor PR review findings:

1. Add validation in GET /{community_id}/ endpoint to ensure default_model
   is non-null before returning (raises HTTP 500 with clear error if missing)
2. Clarify port number in testing examples (38529 is dev, 38528 is prod)

These changes improve error reporting for misconfigured communities and
prevent confusion when following the testing guide.
@neuromechanist
Copy link
Copy Markdown
Member Author

✅ All Critical Issues Addressed

Fixes Applied

Issue Status Commit
🔴 Widget silent failure ✅ FIXED b4ba858 - Added disableWidget() function that disables input/send button on config errors
🔴 Settings masks error ✅ FIXED b4ba858 - Shows "ERROR: Not configured" and disables dropdown option when model is null
🔴 Hint hides error ✅ FIXED b4ba858 - Shows red error text when model is null
🔵 Port clarity ✅ FIXED 335a269 - Added comment clarifying dev vs prod port
🔵 Missing validation ✅ FIXED 335a269 - Config endpoint validates default_model before return

High-Priority Issue

🟡 Broad exception handling - Deferred to follow-up PR as it's a pre-existing pattern across all endpoints


Status: Ready to merge

All critical widget error handling issues have been resolved. The widget now:

  • Disables itself completely when config fetch fails
  • Shows clear error states in all UI elements (dropdown, hint text)
  • Provides actionable error messages to users

The provider routing fix ("only" → "order") and new config endpoint will work once deployed to backend.

@neuromechanist neuromechanist merged commit 1b8929a into develop Jan 27, 2026
6 checks passed
@neuromechanist neuromechanist deleted the feature/fix-qwen-provider-issue branch January 27, 2026 00:05
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