Spaces:
Sleeping
Sleeping
Commit
·
6f8bb0b
1
Parent(s):
dd547c8
Fix: Properly detect and report pipeline failures
Browse files- Check pipeline result status before marking as success/failure
- Set hasError=true when pipeline fails or partially completes
- Show appropriate error messages for failed components
- Update pipeline status to 'failed' instead of 'completed' for errors
- Extract component-level error details for better user feedback
- api_routes_v2.py +55 -8
api_routes_v2.py
CHANGED
|
@@ -1234,10 +1234,22 @@ async def chat_unified(
|
|
| 1234 |
prefer_bedrock=bool(prefer_bedrock),
|
| 1235 |
)
|
| 1236 |
session_manager.update_session(chat_id, {"pipeline_result": result, "state": "initial"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
# V3: Update pipeline status in S3
|
| 1238 |
pipeline_id = proposed.get("pipeline_id")
|
| 1239 |
if pipeline_id:
|
| 1240 |
-
|
|
|
|
|
|
|
| 1241 |
_record_model_attribution(
|
| 1242 |
pipeline_id=pipeline_id,
|
| 1243 |
session_id=chat_id,
|
|
@@ -1246,11 +1258,45 @@ async def chat_unified(
|
|
| 1246 |
is_fallback=False
|
| 1247 |
)
|
| 1248 |
|
| 1249 |
-
#
|
| 1250 |
-
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1254 |
# Add output_id and download_url from pipeline_manager
|
| 1255 |
if pipeline_id:
|
| 1256 |
try:
|
|
@@ -1264,7 +1310,7 @@ async def chat_unified(
|
|
| 1264 |
print(f"Warning: Could not get output_id/download_url: {e}")
|
| 1265 |
|
| 1266 |
api_data = {
|
| 1267 |
-
"type":
|
| 1268 |
"result": result,
|
| 1269 |
"pipeline": proposed
|
| 1270 |
}
|
|
@@ -1275,7 +1321,8 @@ async def chat_unified(
|
|
| 1275 |
api_data=api_data,
|
| 1276 |
state="initial",
|
| 1277 |
output=output,
|
| 1278 |
-
final_output=final_output
|
|
|
|
| 1279 |
)
|
| 1280 |
except Exception as e:
|
| 1281 |
session_manager.update_session(chat_id, {"state": "initial"})
|
|
|
|
| 1234 |
prefer_bedrock=bool(prefer_bedrock),
|
| 1235 |
)
|
| 1236 |
session_manager.update_session(chat_id, {"pipeline_result": result, "state": "initial"})
|
| 1237 |
+
|
| 1238 |
+
# Check if pipeline actually succeeded or failed
|
| 1239 |
+
pipeline_status = result.get("status", "unknown")
|
| 1240 |
+
completed_steps = result.get("completed_steps", 0)
|
| 1241 |
+
total_steps = result.get("total_steps", 0)
|
| 1242 |
+
has_error = result.get("error") is not None or pipeline_status in ["failed", "partial"]
|
| 1243 |
+
|
| 1244 |
+
# Determine if this is a real success or a failure
|
| 1245 |
+
is_success = (pipeline_status == "completed" and completed_steps == total_steps and not has_error)
|
| 1246 |
+
|
| 1247 |
# V3: Update pipeline status in S3
|
| 1248 |
pipeline_id = proposed.get("pipeline_id")
|
| 1249 |
if pipeline_id:
|
| 1250 |
+
# Mark as failed if not successful, otherwise completed
|
| 1251 |
+
final_status = "completed" if is_success else "failed"
|
| 1252 |
+
_update_pipeline_status(pipeline_id, chat_id, final_status, result=result)
|
| 1253 |
_record_model_attribution(
|
| 1254 |
pipeline_id=pipeline_id,
|
| 1255 |
session_id=chat_id,
|
|
|
|
| 1258 |
is_fallback=False
|
| 1259 |
)
|
| 1260 |
|
| 1261 |
+
# Build response based on actual success/failure
|
| 1262 |
+
if is_success:
|
| 1263 |
+
# Extract user-facing output
|
| 1264 |
+
result_text = _extract_user_facing_text(result)
|
| 1265 |
+
friendly = f"🎉 Pipeline completed successfully!"
|
| 1266 |
+
output = {"component_summary": "Pipeline executed successfully", "steps": total_steps}
|
| 1267 |
+
final_output = {"text": result_text}
|
| 1268 |
+
api_type = "pipeline_completed"
|
| 1269 |
+
exception_msg = None
|
| 1270 |
+
else:
|
| 1271 |
+
# Pipeline failed or partially completed
|
| 1272 |
+
error_msg = result.get("error", "Pipeline execution incomplete")
|
| 1273 |
+
|
| 1274 |
+
# Check for component-level errors
|
| 1275 |
+
failed_components = []
|
| 1276 |
+
for comp in result.get("components_executed", []):
|
| 1277 |
+
if comp.get("status") == "failed" or comp.get("error"):
|
| 1278 |
+
failed_components.append({
|
| 1279 |
+
"tool_name": comp.get("tool_name", comp.get("tool", "unknown")),
|
| 1280 |
+
"error": comp.get("error", comp.get("result", {}).get("error", "Unknown error"))
|
| 1281 |
+
})
|
| 1282 |
+
|
| 1283 |
+
if failed_components:
|
| 1284 |
+
# Show specific component error
|
| 1285 |
+
first_error = failed_components[0]
|
| 1286 |
+
friendly = f"❌ Pipeline failed: {first_error['tool_name']} - {first_error['error']}"
|
| 1287 |
+
else:
|
| 1288 |
+
friendly = f"⚠️ Pipeline partially completed: {error_msg}"
|
| 1289 |
+
|
| 1290 |
+
output = {
|
| 1291 |
+
"component_summary": f"Pipeline {pipeline_status}",
|
| 1292 |
+
"steps": total_steps,
|
| 1293 |
+
"completed": completed_steps,
|
| 1294 |
+
"failed": total_steps - completed_steps
|
| 1295 |
+
}
|
| 1296 |
+
final_output = {"text": f"Pipeline execution {pipeline_status} with {completed_steps}/{total_steps} steps completed"}
|
| 1297 |
+
api_type = "pipeline_failed" if pipeline_status == "failed" else "pipeline_partial"
|
| 1298 |
+
exception_msg = error_msg
|
| 1299 |
+
|
| 1300 |
# Add output_id and download_url from pipeline_manager
|
| 1301 |
if pipeline_id:
|
| 1302 |
try:
|
|
|
|
| 1310 |
print(f"Warning: Could not get output_id/download_url: {e}")
|
| 1311 |
|
| 1312 |
api_data = {
|
| 1313 |
+
"type": api_type,
|
| 1314 |
"result": result,
|
| 1315 |
"pipeline": proposed
|
| 1316 |
}
|
|
|
|
| 1321 |
api_data=api_data,
|
| 1322 |
state="initial",
|
| 1323 |
output=output,
|
| 1324 |
+
final_output=final_output,
|
| 1325 |
+
exception=exception_msg # This will set hasError=True when not None
|
| 1326 |
)
|
| 1327 |
except Exception as e:
|
| 1328 |
session_manager.update_session(chat_id, {"state": "initial"})
|