From 420251ca9dade96c3128e56b63a7a0dc53d7c8b6 Mon Sep 17 00:00:00 2001 From: anvyle Date: Wed, 15 Apr 2026 20:19:03 +0200 Subject: [PATCH] fix(copilot): clean up stream registry on enqueue failure in auto-approve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If enqueue_copilot_turn failed after stream_registry.create_session, the session was left in "running" state in Redis — locking the session until the TTL expired. Now calls mark_session_completed on failure so the session is released immediately. Co-Authored-By: Claude Sonnet 4.6 --- .../backend/copilot/tools/decompose_goal.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/autogpt_platform/backend/backend/copilot/tools/decompose_goal.py b/autogpt_platform/backend/backend/copilot/tools/decompose_goal.py index d9c6e5b265..d6ed20df12 100644 --- a/autogpt_platform/backend/backend/copilot/tools/decompose_goal.py +++ b/autogpt_platform/backend/backend/copilot/tools/decompose_goal.py @@ -119,13 +119,21 @@ async def _run_auto_approve( tool_name="chat", turn_id=turn_id, ) - await enqueue_copilot_turn( - session_id=session_id, - user_id=user_id, - message=AUTO_APPROVE_MESSAGE, - turn_id=turn_id, - is_user_message=True, - ) + try: + await enqueue_copilot_turn( + session_id=session_id, + user_id=user_id, + message=AUTO_APPROVE_MESSAGE, + turn_id=turn_id, + is_user_message=True, + ) + except Exception: + # If enqueueing fails, mark the session completed so it doesn't + # stay stuck in "running" state in the stream registry forever. + await stream_registry.mark_session_completed( + session_id, error_message="Auto-approve enqueue failed" + ) + raise logger.info("decompose_goal auto-approve fired for session %s", session_id) except asyncio.CancelledError: raise