# Feedback Service Fix
## Issue
The feedback service was throwing an error: `unsupported operand type(s) for +=: 'NoneType' and 'int'` when trying to update metrics.
## Root Cause
The error occurred when:
1. Database records had NULL values in integer columns (total_calls, success_count, etc.)
2. SQLAlchemy tried to perform `+=` operations on these NULL values
3. Using the same session for both execution logging and metrics updates caused conflicts
## Solution
The fix includes:
1. **Separate Sessions**: Metrics updates now use a separate database session to avoid conflicts
2. **Explicit None Handling**: All database values are checked for None and converted to defaults before use
3. **Assignment Instead of +=**: Changed from `metrics.total_calls += 1` to `metrics.total_calls = new_total` to avoid None issues
4. **Better Error Handling**: Added try-except blocks to prevent feedback service errors from breaking tool execution
## Changes Made
### `fccs_agent/services/feedback_service.py`
- Renamed `_update_metrics()` to `_update_metrics_separate_session()`
- Uses a separate session for metrics updates
- Explicitly handles None values before calculations
- Uses assignment operations instead of +=
### `fccs_agent/agent.py`
- Added error handling to prevent feedback service errors from breaking tool execution
- Feedback service initialization failures are now non-fatal
## Testing
Run the test script to verify the fix:
```bash
python scripts/test_feedback_service.py
```
## Applying the Fix
**Important**: If you're using the MCP server, you need to restart it to pick up the changes:
1. Stop the MCP server (if running)
2. Clear Python cache (optional but recommended):
```bash
find . -type d -name __pycache__ -exec rm -r {} +
find . -type f -name "*.pyc" -delete
```
3. Restart the MCP server:
```bash
python -m cli.mcp_server
```
Or if using Claude Desktop, restart Claude Desktop to reload the MCP server.
## Verification
After restarting, test with:
```bash
python scripts/test_feedback_service.py
```
The test should show:
- [OK] Feedback service initialized
- [OK] Execution logged
- [OK] Metrics retrieved
- [OK] Multiple executions logged
- [OK] Updated metrics