Skip to content

Commit 1e20aaf

Browse files
Enhance error handling and logging in plan approval and orchestration manager
1 parent 3fb7416 commit 1e20aaf

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
lines changed

src/backend/v3/api/router.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,14 @@ async def plan_approval(human_feedback: messages.PlanApprovalResponse, request:
405405
print("Plan approval processed:", result)
406406

407407
except ValueError as ve:
408-
print(f"ValueError processing plan approval: {ve}")
408+
# print(f"ValueError processing plan approval: {ve}")
409+
logger.error(f"ValueError processing plan approval: {ve}")
409410
await connection_config.send_status_update_async(
410411
{
411412
"type": WebsocketMessageType.ERROR_MESSAGE,
412413
"data": {
413-
"content": f"Approval failed: {str(ve)}",
414+
# "content": f"Approval failed: {str(ve)}",
415+
"content": "Approval failed due to invalid input.",
414416
"status": "error",
415417
"timestamp": asyncio.get_event_loop().time(),
416418
},
@@ -420,12 +422,18 @@ async def plan_approval(human_feedback: messages.PlanApprovalResponse, request:
420422
)
421423

422424
except Exception as e:
423-
print(f"Error processing plan approval: {e}")
425+
# print(f"Error processing plan approval: {e}")
426+
# await connection_config.send_status_update_async(
427+
# {
428+
# "type": WebsocketMessageType.ERROR_MESSAGE,
429+
# "data": {
430+
# "content": f"Failed to process approval: {str(e)}",
431+
logger.error("Error processing plan approval", exc_info=True)
424432
await connection_config.send_status_update_async(
425433
{
426434
"type": WebsocketMessageType.ERROR_MESSAGE,
427435
"data": {
428-
"content": f"Failed to process approval: {str(e)}",
436+
"content": "An unexpected error occurred while processing the approval.",
429437
"status": "error",
430438
"timestamp": asyncio.get_event_loop().time(),
431439
},
@@ -460,7 +468,8 @@ async def plan_approval(human_feedback: messages.PlanApprovalResponse, request:
460468
{
461469
"type": WebsocketMessageType.ERROR_MESSAGE,
462470
"data": {
463-
"content": f"Approval error: {str(e)}",
471+
# "content": f"Approval error: {str(e)}",
472+
"content": "An error occurred while processing your approval request.",
464473
"status": "error",
465474
"timestamp": asyncio.get_event_loop().time(),
466475
},

src/backend/v3/orchestration/orchestration_manager.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ async def run_orchestration(self, user_id, input_task) -> None:
200200

201201
except ResourceNotFoundError as e:
202202
self.logger.error(f"Agent not found: {e}")
203+
self.logger.info(f"Error: {e}")
204+
self.logger.info(f"Error type: {type(e).__name__}")
205+
if hasattr(e, "__dict__"):
206+
self.logger.info(f"Error attributes: {e.__dict__}")
207+
self.logger.info("=" * 50)
203208
await connection_config.send_status_update_async(
204209
{
205210
"type": WebsocketMessageType.ERROR_MESSAGE,
@@ -231,6 +236,11 @@ async def run_orchestration(self, user_id, input_task) -> None:
231236
)
232237
else:
233238
self.logger.exception("Unexpected RuntimeError")
239+
self.logger.info(f"Error: {e}")
240+
self.logger.info(f"Error type: {type(e).__name__}")
241+
if hasattr(e, "__dict__"):
242+
self.logger.info(f"Error attributes: {e.__dict__}")
243+
self.logger.info("=" * 50)
234244
# Fallback error message
235245
await connection_config.send_status_update_async(
236246
{
@@ -247,6 +257,11 @@ async def run_orchestration(self, user_id, input_task) -> None:
247257

248258
except Exception as e:
249259
self.logger.error(f"🚨 Unexpected error during orchestration: {e}")
260+
self.logger.info(f"Error: {e}")
261+
self.logger.info(f"Error type: {type(e).__name__}")
262+
if hasattr(e, "__dict__"):
263+
self.logger.info(f"Error attributes: {e.__dict__}")
264+
self.logger.info("=" * 50)
250265
# Always send error to frontend
251266
await connection_config.send_status_update_async(
252267
{

src/frontend/src/pages/PlanPage.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ const PlanPage: React.FC = () => {
5757
const [streamingMessageBuffer, setStreamingMessageBuffer] = useState<string>("");
5858
const [showBufferingText, setShowBufferingText] = useState<boolean>(false);
5959
const [agentMessages, setAgentMessages] = useState<AgentMessageData[]>([]);
60-
const formatErrorMessage = (content: string): string => {
60+
// const formatErrorMessage = (content: string): string => {
61+
// return `⚠️ ${content}`;
62+
// };
63+
const formatErrorMessage = useCallback((content: string): string => {
6164
return `⚠️ ${content}`;
62-
};
65+
}, []);
6366
// Plan approval state - track when plan is approved
6467
const [planApproved, setPlanApproved] = useState<boolean>(false);
6568

@@ -413,7 +416,6 @@ const PlanPage: React.FC = () => {
413416

414417
setAgentMessages(prev => [...prev, errorAgentMessage]);
415418
setShowProcessingPlanSpinner(false);
416-
setSubmittingChatDisableInput(false);
417419
setShowBufferingText(false);
418420
setIsProcessing(false);
419421
setShowProcessingMessage(false);
@@ -422,7 +424,7 @@ const PlanPage: React.FC = () => {
422424
});
423425

424426
return () => unsubscribe();
425-
}, [scrollToBottom, showToast]);
427+
}, [scrollToBottom, showToast, formatErrorMessage, networkError]);
426428

427429
//WebsocketMessageType.AGENT_MESSAGE
428430
useEffect(() => {
@@ -531,7 +533,7 @@ const PlanPage: React.FC = () => {
531533
// Force spinner off whenever network error occurs
532534
useEffect(() => {
533535
if (networkError) {
534-
console.log('🛑 [NETWORK ERROR DETECTED] Forcing spinner OFF');
536+
console.log('[NETWORK ERROR DETECTED] Forcing spinner OFF');
535537
setShowProcessingPlanSpinner(false);
536538
setIsProcessing(false);
537539
setShowProcessingMessage(false);
@@ -540,20 +542,20 @@ const PlanPage: React.FC = () => {
540542
}, [networkError]);
541543

542544
// Enable input when clarification message is present
543-
useEffect(() => {
544-
if (clarificationMessage) {
545-
console.log('✅ Clarification message present - enabling input');
546-
setSubmittingChatDisableInput(false);
547-
}
548-
}, [clarificationMessage]);
545+
// useEffect(() => {
546+
// if (clarificationMessage) {
547+
// console.log('✅ Clarification message present - enabling input');
548+
// setSubmittingChatDisableInput(false);
549+
// }
550+
// }, [clarificationMessage]);
549551

550552
useEffect(() => {
551553
const handleOffline = () => {
552-
console.log('🔴 Network disconnected - stopping all processing');
554+
console.log('Network disconnected - stopping all processing');
553555
// Set a flag to show network error and stop all processing states
554556
setNetworkError(true);
555557
setShowProcessingMessage(false);
556-
console.log('🛑 [OFFLINE] Setting showProcessingPlanSpinner = false');
558+
console.log('[OFFLINE] Setting showProcessingPlanSpinner = false');
557559
setShowProcessingPlanSpinner(false);
558560
setIsProcessing(false);
559561
setShowBufferingText(false);
@@ -599,14 +601,14 @@ const PlanPage: React.FC = () => {
599601
setAgentMessages(planResult.messages);
600602

601603
// Check if the last message is a clarification request
602-
const lastMessage = planResult.messages[planResult.messages.length - 1];
603-
if (lastMessage?.agent === AgentType.GROUP_CHAT_MANAGER &&
604-
lastMessage?.agent_type === AgentMessageType.AI_AGENT &&
605-
lastMessage?.content) {
606-
// This is likely a clarification request, enable input
607-
console.log('📝 Found clarification message in loaded plan, enabling input');
608-
setSubmittingChatDisableInput(false);
609-
}
604+
// const lastMessage = planResult.messages[planResult.messages.length - 1];
605+
// if (lastMessage?.agent === AgentType.GROUP_CHAT_MANAGER &&
606+
// lastMessage?.agent_type === AgentMessageType.AI_AGENT &&
607+
// lastMessage?.content) {
608+
// // This is likely a clarification request, enable input
609+
// console.log('📝 Found clarification message in loaded plan, enabling input');
610+
// setSubmittingChatDisableInput(false);
611+
// }
610612
}
611613
if (planResult?.mplan) {
612614
setPlanApprovalRequest(planResult.mplan);
@@ -643,7 +645,6 @@ const PlanPage: React.FC = () => {
643645
const timeoutId = setTimeout(() => {
644646
dismissToast(id);
645647
setShowProcessingPlanSpinner(false);
646-
setSubmittingChatDisableInput(false);
647648
setProcessingApproval(false);
648649
setNetworkError(true);
649650
setIsProcessing(false);

0 commit comments

Comments
 (0)