2222logger = logging .getLogger (__name__ )
2323
2424
25- def handle_database_error (
26- operation : str , resource_id : str , error : Exception
27- ) -> HTTPException :
28- """Centralized database error handling for review operations."""
29- logger .error (f"Database error during { operation } for { resource_id } : { str (error )} " )
30- return HTTPException (
31- status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
32- detail = f"Internal server error during { operation } " ,
33- )
34-
35-
3625router = APIRouter (
3726 tags = ["executions" , "review" , "private" ],
3827 dependencies = [Security (autogpt_auth_lib .requires_user )],
@@ -114,19 +103,14 @@ async def list_pending_reviews_for_execution(
114103 """
115104
116105 # Verify user owns the graph execution before returning reviews
117- try :
118- graph_exec = await get_graph_execution_meta (
119- user_id = user_id , execution_id = graph_exec_id
106+ graph_exec = await get_graph_execution_meta (
107+ user_id = user_id , execution_id = graph_exec_id
108+ )
109+ if not graph_exec :
110+ raise HTTPException (
111+ status_code = status .HTTP_403_FORBIDDEN ,
112+ detail = "Access denied to graph execution" ,
120113 )
121- if not graph_exec :
122- raise HTTPException (
123- status_code = status .HTTP_403_FORBIDDEN ,
124- detail = "Access denied to graph execution" ,
125- )
126- except HTTPException :
127- raise # Re-raise HTTP exceptions as-is
128- except Exception as e :
129- raise handle_database_error ("graph ownership verification" , graph_exec_id , e )
130114
131115 return await get_pending_reviews_for_execution (graph_exec_id , user_id )
132116
@@ -147,79 +131,64 @@ async def process_review_action(
147131 detail = "At least one review must be provided" ,
148132 )
149133
150- try :
151- # Build review decisions map
152- review_decisions = {}
153- for review in request .reviews :
154- if review .approved :
155- review_decisions [review .node_exec_id ] = (
156- ReviewStatus .APPROVED ,
157- review .reviewed_data ,
158- review .message ,
159- )
160- else :
161- review_decisions [review .node_exec_id ] = (
162- ReviewStatus .REJECTED ,
163- None ,
164- review .message ,
165- )
166-
167- # Process all reviews
168- updated_reviews = await process_all_reviews_for_execution (
169- user_id = user_id ,
170- review_decisions = review_decisions ,
171- )
134+ # Build review decisions map
135+ review_decisions = {}
136+ for review in request .reviews :
137+ if review .approved :
138+ review_decisions [review .node_exec_id ] = (
139+ ReviewStatus .APPROVED ,
140+ review .reviewed_data ,
141+ review .message ,
142+ )
143+ else :
144+ review_decisions [review .node_exec_id ] = (
145+ ReviewStatus .REJECTED ,
146+ None ,
147+ review .message ,
148+ )
172149
173- # Count results
174- approved_count = sum (
175- 1
176- for review in updated_reviews .values ()
177- if review .status == ReviewStatus .APPROVED
178- )
179- rejected_count = sum (
180- 1
181- for review in updated_reviews .values ()
182- if review .status == ReviewStatus .REJECTED
183- )
150+ # Process all reviews
151+ updated_reviews = await process_all_reviews_for_execution (
152+ user_id = user_id ,
153+ review_decisions = review_decisions ,
154+ )
184155
185- # Resume execution if we processed some reviews
186- if updated_reviews :
187- # Get graph execution ID from any processed review
188- first_review = next (iter (updated_reviews .values ()))
189- graph_exec_id = first_review .graph_exec_id
190-
191- # Check if any pending reviews remain for this execution
192- still_has_pending = await has_pending_reviews_for_graph_exec (graph_exec_id )
193-
194- if not still_has_pending :
195- # Resume execution
196- try :
197- await add_graph_execution (
198- graph_id = first_review .graph_id ,
199- user_id = user_id ,
200- graph_exec_id = graph_exec_id ,
201- )
202- logger .info (f"Resumed execution { graph_exec_id } " )
203- except Exception as e :
204- logger .error (
205- f"Failed to resume execution { graph_exec_id } : { str (e )} "
206- )
207-
208- return ReviewResponse (
209- approved_count = approved_count ,
210- rejected_count = rejected_count ,
211- failed_count = 0 ,
212- error = None ,
213- )
156+ # Count results
157+ approved_count = sum (
158+ 1
159+ for review in updated_reviews .values ()
160+ if review .status == ReviewStatus .APPROVED
161+ )
162+ rejected_count = sum (
163+ 1
164+ for review in updated_reviews .values ()
165+ if review .status == ReviewStatus .REJECTED
166+ )
214167
215- except ValueError as e :
216- raise HTTPException (
217- status_code = status .HTTP_400_BAD_REQUEST ,
218- detail = str (e ),
219- )
220- except Exception as e :
221- logger .error (f"Error processing reviews: { str (e )} " )
222- raise HTTPException (
223- status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
224- detail = "Internal server error while processing reviews" ,
225- )
168+ # Resume execution if we processed some reviews
169+ if updated_reviews :
170+ # Get graph execution ID from any processed review
171+ first_review = next (iter (updated_reviews .values ()))
172+ graph_exec_id = first_review .graph_exec_id
173+
174+ # Check if any pending reviews remain for this execution
175+ still_has_pending = await has_pending_reviews_for_graph_exec (graph_exec_id )
176+
177+ if not still_has_pending :
178+ # Resume execution
179+ try :
180+ await add_graph_execution (
181+ graph_id = first_review .graph_id ,
182+ user_id = user_id ,
183+ graph_exec_id = graph_exec_id ,
184+ )
185+ logger .info (f"Resumed execution { graph_exec_id } " )
186+ except Exception as e :
187+ logger .error (f"Failed to resume execution { graph_exec_id } : { str (e )} " )
188+
189+ return ReviewResponse (
190+ approved_count = approved_count ,
191+ rejected_count = rejected_count ,
192+ failed_count = 0 ,
193+ error = None ,
194+ )
0 commit comments