Skip to content

Commit 5e1daae

Browse files
Enhance error handling in OrchestrationManager and PlanPage for improved user feedback
1 parent ed1fd7e commit 5e1daae

File tree

2 files changed

+73
-30
lines changed

2 files changed

+73
-30
lines changed

src/backend/v3/orchestration/orchestration_manager.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import List, Optional
77

88
from common.config.app_config import config
9-
from common.models.messages_kernel import TeamConfiguration
9+
from common.models.messages_kernel import TeamConfiguration, AgentMessage, AgentType
1010
from semantic_kernel.agents.orchestration.magentic import MagenticOrchestration
1111
from semantic_kernel.agents.runtime import InProcessRuntime
1212
from azure.core.exceptions import ResourceNotFoundError
@@ -22,6 +22,7 @@
2222
from v3.magentic_agents.magentic_agent_factory import MagenticAgentFactory
2323
from v3.models.messages import WebsocketMessageType
2424
from v3.orchestration.human_approval_manager import HumanApprovalMagenticManager
25+
from common.database.database_factory import DatabaseFactory
2526

2627

2728
class OrchestrationManager:
@@ -182,14 +183,41 @@ async def run_orchestration(self, user_id, input_task) -> None:
182183
)
183184
self.logger.info(f"Final result sent via WebSocket to user {user_id}")
184185

186+
except ResourceNotFoundError as e:
187+
self.logger.error(f"Agent not found: {e}")
188+
self.logger.info(f"Error: {e}")
189+
self.logger.info(f"Error type: {type(e).__name__}")
190+
if hasattr(e, "__dict__"):
191+
self.logger.info(f"Error attributes: {e.__dict__}")
192+
self.logger.info("=" * 50)
193+
194+
error_content = "The agent is currently unavailable. Please check if it was deleted or recreated.\n\nIf yes, please create a new plan from the home page."
195+
196+
self.logger.info(f"🔴 Sending error message to user {user_id}: {error_content}")
197+
198+
await connection_config.send_status_update_async(
199+
{
200+
"type": WebsocketMessageType.ERROR_MESSAGE,
201+
"data": {
202+
"content": error_content,
203+
"status": "error",
204+
"timestamp": asyncio.get_event_loop().time(),
205+
},
206+
},
207+
user_id,
208+
message_type=WebsocketMessageType.ERROR_MESSAGE,
209+
)
210+
211+
self.logger.info(f"✅ Error message sent via WebSocket to user {user_id}")
212+
185213
except Exception as e:
186214
self.logger.error(f"Error processing final result: {e}")
187215
# Send error message to user
188216
await connection_config.send_status_update_async(
189217
{
190218
"type": WebsocketMessageType.ERROR_MESSAGE,
191219
"data": {
192-
"content": "An error occurred while processing the final response.",
220+
"content": "An error occurred while processing the final response.\n\nPlease try creating a new plan from the home page.",
193221
"status": "error",
194222
"timestamp": asyncio.get_event_loop().time(),
195223
},
@@ -198,26 +226,6 @@ async def run_orchestration(self, user_id, input_task) -> None:
198226
message_type=WebsocketMessageType.ERROR_MESSAGE,
199227
)
200228

201-
except ResourceNotFoundError as e:
202-
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)
208-
await connection_config.send_status_update_async(
209-
{
210-
"type": WebsocketMessageType.ERROR_MESSAGE,
211-
"data": {
212-
"content": "The agent is currently unavailable. Please check if it was deleted or recreated.",
213-
"status": "error",
214-
"timestamp": asyncio.get_event_loop().time(),
215-
},
216-
},
217-
user_id,
218-
message_type=WebsocketMessageType.ERROR_MESSAGE,
219-
)
220-
221229
except RuntimeError as e:
222230
if "did not return any response" in str(e):
223231
self.logger.error(f"Agent failed: {e}")
@@ -226,7 +234,7 @@ async def run_orchestration(self, user_id, input_task) -> None:
226234
{
227235
"type": WebsocketMessageType.ERROR_MESSAGE,
228236
"data": {
229-
"content": "I'm having trouble connecting to the agent right now. Please try again later.",
237+
"content": "I'm having trouble connecting to the agent right now.\n\nPlease try creating a new plan from the home page or try again later.",
230238
"status": "error",
231239
"timestamp": asyncio.get_event_loop().time(),
232240
},
@@ -246,7 +254,7 @@ async def run_orchestration(self, user_id, input_task) -> None:
246254
{
247255
"type": WebsocketMessageType.ERROR_MESSAGE,
248256
"data": {
249-
"content": "Something went wrong. Please try again later.",
257+
"content": "Something went wrong.\n\nPlease try creating a new plan from the home page or try again later.",
250258
"status": "error",
251259
"timestamp": asyncio.get_event_loop().time(),
252260
},
@@ -262,19 +270,25 @@ async def run_orchestration(self, user_id, input_task) -> None:
262270
if hasattr(e, "__dict__"):
263271
self.logger.info(f"Error attributes: {e.__dict__}")
264272
self.logger.info("=" * 50)
265-
# Always send error to frontend
273+
274+
error_content = "Something went wrong.\n\nPlease try creating a new plan from the home page or try again later."
275+
276+
self.logger.info(f"🔴 Sending error message to user {user_id}: {error_content}")
277+
266278
await connection_config.send_status_update_async(
267279
{
268280
"type": WebsocketMessageType.ERROR_MESSAGE,
269281
"data": {
270-
"content": "Something went wrong. Please try again later.",
282+
"content": error_content,
271283
"status": "error",
272284
"timestamp": asyncio.get_event_loop().time(),
273285
},
274286
},
275287
user_id,
276288
message_type=WebsocketMessageType.ERROR_MESSAGE,
277289
)
290+
291+
self.logger.info(f"✅ Error message sent via WebSocket to user {user_id}")
278292

279293
finally:
280294
await runtime.stop_when_idle()

src/frontend/src/pages/PlanPage.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,35 @@ const PlanPage: React.FC = () => {
399399
useEffect(() => {
400400
const unsubscribe = webSocketService.on(WebsocketMessageType.ERROR_MESSAGE, (errorMessage: any) => {
401401
console.log('❌ Received ERROR_MESSAGE:', errorMessage);
402-
const errorContent = errorMessage?.data?.content || "Something went wrong. Please try again later.";
402+
console.log('❌ Error message data:', errorMessage?.data);
403+
404+
// Try multiple ways to extract the error message
405+
let errorContent = "An unexpected error occurred. Please try again later.";
406+
407+
// Check for double-nested data structure
408+
if (errorMessage?.data?.data?.content) {
409+
const content = errorMessage.data.data.content.trim();
410+
if (content.length > 0) {
411+
errorContent = content;
412+
}
413+
} else if (errorMessage?.data?.content) {
414+
const content = errorMessage.data.content.trim();
415+
if (content.length > 0) {
416+
errorContent = content;
417+
}
418+
} else if (errorMessage?.content) {
419+
const content = errorMessage.content.trim();
420+
if (content.length > 0) {
421+
errorContent = content;
422+
}
423+
} else if (typeof errorMessage === 'string') {
424+
const content = errorMessage.trim();
425+
if (content.length > 0) {
426+
errorContent = content;
427+
}
428+
}
429+
430+
console.log('❌ Final error content to display:', errorContent);
403431

404432
const errorAgentMessage: AgentMessageData = {
405433
agent: 'system',
@@ -416,6 +444,7 @@ const PlanPage: React.FC = () => {
416444
setShowBufferingText(false);
417445
setIsProcessing(false);
418446
setShowProcessingMessage(false);
447+
setSubmittingChatDisableInput(false);
419448
scrollToBottom();
420449
showToast(errorContent, "error");
421450
});
@@ -466,8 +495,8 @@ const PlanPage: React.FC = () => {
466495

467496
// WebSocket connection with proper error handling and v3 backend compatibility
468497
useEffect(() => {
469-
if (planId && continueWithWebsocketFlow) {
470-
console.log('🔌 Connecting WebSocket:', { planId, continueWithWebsocketFlow });
498+
if (planId) {
499+
console.log('🔌 Connecting WebSocket:', { planId });
471500

472501
const connectWebSocket = async () => {
473502
try {
@@ -525,7 +554,7 @@ const PlanPage: React.FC = () => {
525554
webSocketService.disconnect();
526555
};
527556
}
528-
}, [planId, loading, continueWithWebsocketFlow]);
557+
}, [planId]);
529558

530559
// Force spinner off whenever network error occurs
531560
useEffect(() => {

0 commit comments

Comments
 (0)