Agent and Plugin Blueprint Registration Fix
Version Implemented: 0.229.001
Issue Description
The application was experiencing a critical issue where agent and plugin API endpoints were returning 404 (NOT FOUND) errors instead of properly functioning. Users reported that agents and actions were not loading as global or personal components, even though they were enabled in the system settings.
Symptoms
The following console errors were observed in the browser:
GET https://127.0.0.1:5000/api/orchestration_types 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/orchestration_settings 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/admin/agent/settings 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/admin/agents 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/user/plugins 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/admin/plugins/settings 404 (NOT FOUND)
GET https://127.0.0.1:5000/api/admin/plugins 404 (NOT FOUND)
Additionally, frontend JavaScript errors indicated that agent and plugin data could not be loaded:
- "Failed to load actions: Error: Failed to load actions"
- "Error loading admin agent data: Error: Failed to load orchestration types"
Root Cause Analysis
The issue was caused by duplicate Flask app instances being created in the application:
- Primary Flask app created in
app.pyat line 56 - Conflicting Flask app created in
config.pyat line 87
When app.py imported from config.py using from config import *, it inadvertently imported the Flask app instance from config.py, which overwrote the properly configured app instance from app.py.
The Problem Sequence
app.pycreates a Flask app instance and registers blueprintsapp.pyimportsfrom config import *- This import overwrites the configured Flask app with the unconfigured one from
config.py - The blueprints that were registered to the original app instance are lost
- API endpoints return 404 because the routes don't exist on the new app instance
Technical Details
Files Modified
- config.py: Removed duplicate Flask app creation and converted to configuration constants
- app.py: Updated to use configuration constants from config.py
Code Changes
config.py (Lines 87-95)
Before:
app = Flask(__name__)
app.config['EXECUTOR_TYPE'] = 'thread'
app.config['EXECUTOR_MAX_WORKERS'] = 30
executor = Executor()
executor.init_app(app)
app.config['SESSION_TYPE'] = 'filesystem'
app.config['VERSION'] = "0.228.001"
Session(app)
After:
# Flask app configuration constants
EXECUTOR_TYPE = 'thread'
EXECUTOR_MAX_WORKERS = 30
SESSION_TYPE = 'filesystem'
VERSION = "0.228.002"
app.py (Lines 57-64)
Before:
app.config['EXECUTOR_TYPE'] = 'thread'
app.config['EXECUTOR_MAX_WORKERS'] = 30
executor = Executor()
executor.init_app(app)
app.config['SESSION_TYPE'] = 'filesystem'
app.config['VERSION'] = "0.226.102"
After:
app.config['EXECUTOR_TYPE'] = EXECUTOR_TYPE
app.config['EXECUTOR_MAX_WORKERS'] = EXECUTOR_MAX_WORKERS
executor = Executor()
executor.init_app(app)
app.config['SESSION_TYPE'] = SESSION_TYPE
app.config['VERSION'] = VERSION
Validation
Test Results
After implementing the fix, all previously failing API endpoints now return proper HTTP status codes:
| Endpoint | Before Fix | After Fix |
|---|---|---|
/api/orchestration_types |
404 NOT FOUND | 401 Unauthorized |
/api/orchestration_settings |
404 NOT FOUND | 401 Unauthorized |
/api/admin/agents |
404 NOT FOUND | 401 Unauthorized |
/api/admin/agent/settings |
404 NOT FOUND | 401 Unauthorized |
/api/user/plugins |
404 NOT FOUND | 401 Unauthorized |
/api/admin/plugins/settings |
404 NOT FOUND | 401 Unauthorized |
/api/admin/plugins |
404 NOT FOUND | 401 Unauthorized |
The 401 (Unauthorized) responses indicate that the endpoints are now properly registered and accessible, but require authentication - which is the expected behavior.
Blueprint Registration Verification
The fix ensures that all required blueprints are properly registered:
- ✅
admin_plugins- Admin plugin management endpoints - ✅
dynamic_plugins- Dynamic plugin endpoints - ✅
admin_agents- Admin agent management endpoints - ✅
plugin_validation- Plugin validation endpoints - ✅
migration- Database migration endpoints - ✅
plugin_logging- Plugin logging endpoints
Impact
User Experience Improvements
- Agents: Global and personal agents now load correctly in the admin interface
- Actions/Plugins: Plugin management interface is fully functional
- Admin Settings: Agent orchestration settings are accessible
- User Workspace: Personal agents and plugins display properly
System Stability
- Eliminates Flask app instance conflicts
- Ensures consistent configuration across the application
- Prevents silent blueprint registration failures
- Maintains proper separation of concerns between configuration and application logic
Prevention
To prevent similar issues in the future:
- Single Responsibility: Keep Flask app creation in one location (
app.py) - Configuration Constants: Use configuration constants instead of app instances in shared modules
- Import Testing: Regularly test that blueprints are properly registered
- Code Review: Review any changes to Flask app initialization carefully
Testing
A functional test has been created at functional_tests/test_agents_plugins_blueprint_fix.py to ensure this issue doesn't regress. The test verifies:
- All critical API endpoints return non-404 status codes
- Required blueprints are properly registered
- Flask app structure is correct
Related Issues
This fix resolves the core infrastructure issue that was preventing agents and plugins from functioning. Users should now be able to:
- Access agent management interfaces
- Configure global and personal agents
- Manage plugin settings
- View orchestration options
If users continue to experience issues with specific agent or plugin functionality after this fix, those would be separate issues requiring individual investigation.