fix: silent failures for context optimizer

This commit is contained in:
2026-01-19 12:19:03 +01:00
parent f559170960
commit b03bd70b81
2 changed files with 88 additions and 3 deletions

View File

@@ -944,12 +944,28 @@ def api_optimize_context(model_name):
# Use the existing find_optimal_context function from context-optimizer.py
result = context_optimizer_module.find_optimal_context(model_name, max_turns=max_turns, overhead_gb=overhead_gb)
if not result or 'results' not in result:
if not result:
return jsonify({
'success': False,
'error': 'Optimization failed or no results returned'
})
# Check if optimization encountered an error
if 'error' in result:
return jsonify({
'success': False,
'error': result['error'],
'model': model_name,
'max_context': result.get('max_context', 0),
'current_context': result.get('current_ctx', 0)
})
if 'results' not in result or len(result['results']) == 0:
return jsonify({
'success': False,
'error': 'No test results available. Model may have failed to load.'
})
# Extract data from results
test_results = []
optimal_context = 0