fix: use canonical stop reason mapping in redis stream finalizer (#9600)

fix: derive run status from StopReasonType mapping
This commit is contained in:
jnjpng
2026-02-20 15:58:51 -08:00
committed by Caren Thomas
parent ae24bd1034
commit 9155b4fa86

View File

@@ -361,25 +361,10 @@ async def create_background_stream_processor(
# Update run status to reflect terminal outcome
if run_manager and actor and final_stop_reason:
# Map stop_reason to run status
if final_stop_reason in [
StopReasonType.error.value,
StopReasonType.llm_api_error.value,
StopReasonType.invalid_tool_call.value,
StopReasonType.invalid_llm_response.value,
StopReasonType.no_tool_call.value,
]:
run_status = RunStatus.failed
elif final_stop_reason == StopReasonType.cancelled.value:
run_status = RunStatus.cancelled
elif final_stop_reason in [
StopReasonType.end_turn.value,
StopReasonType.max_steps.value,
StopReasonType.tool_rule.value,
StopReasonType.requires_approval.value,
]:
run_status = RunStatus.completed
else:
# Resolve stop_reason using canonical enum mapping to avoid drift.
try:
run_status = StopReasonType(final_stop_reason).run_status
except ValueError:
logger.warning(f"Unknown stop_reason '{final_stop_reason}' for run {run_id}, defaulting to completed")
run_status = RunStatus.completed