Skip to content

Commit 9910f1e

Browse files
resolve the pylint issue
1 parent 7374e77 commit 9910f1e

File tree

4 files changed

+51
-55
lines changed

4 files changed

+51
-55
lines changed

src/backend/v3/config/settings.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ def __init__(self):
8686
20 # Maximum number of replanning rounds 20 needed to accommodate complex tasks
8787
)
8888

89-
# Event-driven notification system for approvals and clarifications
89+
# Event-driven notification system for approvals and clarifications
9090
self._approval_events: Dict[str, asyncio.Event] = {}
9191
self._clarification_events: Dict[str, asyncio.Event] = {}
92-
92+
9393
# Default timeout for waiting operations (5 minutes)
9494
self.default_timeout: float = 300.0
9595

9696
def get_current_orchestration(self, user_id: str) -> MagenticOrchestration:
9797
"""get existing orchestration instance."""
9898
return self.orchestrations.get(user_id, None)
99-
99+
100100
def set_approval_pending(self, plan_id: str) -> None:
101101
"""Set an approval as pending and create an event for it."""
102102
self.approvals[plan_id] = None
@@ -115,31 +115,31 @@ def set_approval_result(self, plan_id: str, approved: bool) -> None:
115115
async def wait_for_approval(self, plan_id: str, timeout: Optional[float] = None) -> bool:
116116
"""
117117
Wait for an approval decision with timeout.
118-
118+
119119
Args:
120120
plan_id: The plan ID to wait for
121121
timeout: Timeout in seconds (defaults to default_timeout)
122-
122+
123123
Returns:
124124
The approval decision (True/False)
125-
125+
126126
Raises:
127127
asyncio.TimeoutError: If timeout is exceeded
128128
KeyError: If plan_id is not found in approvals
129129
"""
130130
if timeout is None:
131131
timeout = self.default_timeout
132-
132+
133133
if plan_id not in self.approvals:
134134
raise KeyError(f"Plan ID {plan_id} not found in approvals")
135-
135+
136136
if self.approvals[plan_id] is not None:
137137
# Already has a result
138138
return self.approvals[plan_id]
139-
139+
140140
if plan_id not in self._approval_events:
141141
self._approval_events[plan_id] = asyncio.Event()
142-
142+
143143
try:
144144
await asyncio.wait_for(self._approval_events[plan_id].wait(), timeout=timeout)
145145
return self.approvals[plan_id]
@@ -161,7 +161,7 @@ async def wait_for_approval(self, plan_id: str, timeout: Optional[float] = None)
161161
# cleaning up successful approvals
162162
if plan_id in self.approvals and self.approvals[plan_id] is None:
163163
self.cleanup_approval(plan_id)
164-
164+
165165
def set_clarification_pending(self, request_id: str) -> None:
166166
"""Set a clarification as pending and create an event for it."""
167167
self.clarifications[request_id] = None
@@ -180,31 +180,31 @@ def set_clarification_result(self, request_id: str, answer: str) -> None:
180180
async def wait_for_clarification(self, request_id: str, timeout: Optional[float] = None) -> str:
181181
"""
182182
Wait for a clarification response with timeout.
183-
183+
184184
Args:
185185
request_id: The request ID to wait for
186186
timeout: Timeout in seconds (defaults to default_timeout)
187-
187+
188188
Returns:
189189
The clarification response
190-
190+
191191
Raises:
192192
asyncio.TimeoutError: If timeout is exceeded
193193
KeyError: If request_id is not found in clarifications
194194
"""
195195
if timeout is None:
196196
timeout = self.default_timeout
197-
197+
198198
if request_id not in self.clarifications:
199199
raise KeyError(f"Request ID {request_id} not found in clarifications")
200-
200+
201201
if self.clarifications[request_id] is not None:
202202
# Already has a result
203203
return self.clarifications[request_id]
204-
204+
205205
if request_id not in self._clarification_events:
206206
self._clarification_events[request_id] = asyncio.Event()
207-
207+
208208
try:
209209
await asyncio.wait_for(self._clarification_events[request_id].wait(), timeout=timeout)
210210
return self.clarifications[request_id]

src/backend/v3/magentic_agents/proxy_agent.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,37 +280,37 @@ async def _wait_for_user_clarification(
280280
# request_id=request_id,
281281
# answer=orchestration_config.clarifications[request_id],
282282
# )
283-
283+
284284
"""
285285
Wait for user clarification response using event-driven pattern with timeout handling.
286-
286+
287287
Args:
288288
request_id: The request ID to wait for clarification
289-
289+
290290
Returns:
291291
UserClarificationResponse: Clarification result with request ID and answer
292-
292+
293293
Raises:
294294
asyncio.TimeoutError: If timeout is exceeded (300 seconds default)
295295
"""
296-
# logger.info(f"Waiting for user clarification for request: {request_id}")
297-
296+
# logger.info(f"Waiting for user clarification for request: {request_id}")
297+
298298
# Initialize clarification as pending using the new event-driven method
299299
orchestration_config.set_clarification_pending(request_id)
300-
300+
301301
try:
302302
# Wait for clarification with timeout using the new event-driven method
303303
answer = await orchestration_config.wait_for_clarification(request_id)
304-
305-
#logger.info(f"Clarification received for request {request_id}: {answer}")
304+
305+
# logger.info(f"Clarification received for request {request_id}: {answer}")
306306
return UserClarificationResponse(
307307
request_id=request_id,
308308
answer=answer,
309309
)
310310
except asyncio.TimeoutError:
311311
# Enhanced timeout handling - notify user via WebSocket and cleanup
312312
logger.debug(f"Clarification timeout for request {request_id} - notifying user and terminating process")
313-
313+
314314
# Create timeout notification message
315315
from v3.models.messages import TimeoutNotification, WebsocketMessageType
316316
timeout_notification = TimeoutNotification(
@@ -320,7 +320,7 @@ async def _wait_for_user_clarification(
320320
timestamp=time.time(),
321321
timeout_duration=orchestration_config.default_timeout
322322
)
323-
323+
324324
# Send timeout notification to user via WebSocket
325325
try:
326326
await connection_config.send_status_update_async(
@@ -331,25 +331,25 @@ async def _wait_for_user_clarification(
331331
logger.info(f"Timeout notification sent to user {self.user_id} for clarification {request_id}")
332332
except Exception as e:
333333
logger.error(f"Failed to send timeout notification: {e}")
334-
334+
335335
# Clean up this specific request
336336
orchestration_config.cleanup_clarification(request_id)
337-
337+
338338
# Return None to indicate silent termination
339339
# The timeout naturally stops this specific wait operation without affecting other tasks
340340
return None
341-
341+
342342
except KeyError as e:
343343
# Silent error handling for invalid request IDs
344344
logger.debug(f"Request ID not found: {e} - terminating process silently")
345345
return None
346-
346+
347347
except asyncio.CancelledError:
348348
# Handle task cancellation gracefully
349349
logger.debug(f"Clarification request {request_id} was cancelled")
350350
orchestration_config.cleanup_clarification(request_id)
351351
return None
352-
352+
353353
except Exception as e:
354354
# Silent error handling for unexpected errors
355355
logger.debug(f"Unexpected error waiting for clarification: {e} - terminating process silently")
@@ -358,12 +358,10 @@ async def _wait_for_user_clarification(
358358
finally:
359359
# Ensure cleanup happens for any incomplete requests
360360
# This provides an additional safety net for resource cleanup
361-
if (request_id in orchestration_config.clarifications and
362-
orchestration_config.clarifications[request_id] is None):
361+
if (request_id in orchestration_config.clarifications and orchestration_config.clarifications[request_id] is None):
363362
logger.debug(f"Final cleanup for pending clarification request {request_id}")
364363
orchestration_config.cleanup_clarification(request_id)
365364

366-
367365
async def get_response(self, chat_history, **kwargs):
368366
"""Get response from the agent - required by Agent base class."""
369367
# Extract the latest user message

src/backend/v3/orchestration/human_approval_manager.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import asyncio
77
import logging
8-
import time
98
from typing import Any, Optional
109

1110
import v3.models.messages as messages
@@ -219,37 +218,37 @@ async def _wait_for_user_approval(
219218
# )
220219
"""
221220
Wait for user approval response using event-driven pattern with timeout handling.
222-
221+
223222
Args:
224223
m_plan_id: The plan ID to wait for approval
225-
224+
226225
Returns:
227226
PlanApprovalResponse: Approval result with approved status and plan ID
228-
227+
229228
Raises:
230229
asyncio.TimeoutError: If timeout is exceeded (300 seconds default)
231230
"""
232231
logger.info(f"Waiting for user approval for plan: {m_plan_id}")
233-
232+
234233
if not m_plan_id:
235234
logger.error("No plan ID provided for approval")
236235
return messages.PlanApprovalResponse(approved=False, m_plan_id=m_plan_id)
237-
236+
238237
# Initialize approval as pending using the new event-driven method
239238
orchestration_config.set_approval_pending(m_plan_id)
240-
239+
241240
try:
242241
# Wait for approval with timeout using the new event-driven method
243242
approved = await orchestration_config.wait_for_approval(m_plan_id)
244-
243+
245244
logger.info(f"Approval received for plan {m_plan_id}: {approved}")
246245
return messages.PlanApprovalResponse(
247246
approved=approved, m_plan_id=m_plan_id
248247
)
249248
except asyncio.TimeoutError:
250249
# Enhanced timeout handling - notify user via WebSocket and cleanup
251250
logger.debug(f"Approval timeout for plan {m_plan_id} - notifying user and terminating process")
252-
251+
253252
# Create timeout notification message
254253
timeout_message = messages.TimeoutNotification(
255254
timeout_type="approval",
@@ -258,7 +257,7 @@ async def _wait_for_user_approval(
258257
timestamp=asyncio.get_event_loop().time(),
259258
timeout_duration=orchestration_config.default_timeout
260259
)
261-
260+
262261
# Send timeout notification to user via WebSocket
263262
try:
264263
await connection_config.send_status_update_async(
@@ -269,25 +268,25 @@ async def _wait_for_user_approval(
269268
logger.info(f"Timeout notification sent to user {self.current_user_id} for plan {m_plan_id}")
270269
except Exception as e:
271270
logger.error(f"Failed to send timeout notification: {e}")
272-
271+
273272
# Clean up this specific request
274273
orchestration_config.cleanup_approval(m_plan_id)
275-
274+
276275
# Return None to indicate silent termination
277276
# The timeout naturally stops this specific wait operation without affecting other tasks
278277
return None
279-
278+
280279
except KeyError as e:
281280
# Silent error handling for invalid plan IDs
282281
logger.debug(f"Plan ID not found: {e} - terminating process silently")
283282
return None
284-
283+
285284
except asyncio.CancelledError:
286285
# Handle task cancellation gracefully
287286
logger.debug(f"Approval request {m_plan_id} was cancelled")
288287
orchestration_config.cleanup_approval(m_plan_id)
289288
return None
290-
289+
291290
except Exception as e:
292291
# Silent error handling for unexpected errors
293292
logger.debug(f"Unexpected error waiting for approval: {e} - terminating process silently")
@@ -296,8 +295,7 @@ async def _wait_for_user_approval(
296295
finally:
297296
# Ensure cleanup happens for any incomplete requests
298297
# This provides an additional safety net for resource cleanup
299-
if (m_plan_id in orchestration_config.approvals and
300-
orchestration_config.approvals[m_plan_id] is None):
298+
if (m_plan_id in orchestration_config.approvals and orchestration_config.approvals[m_plan_id] is None):
301299
logger.debug(f"Final cleanup for pending approval plan {m_plan_id}")
302300
orchestration_config.cleanup_approval(m_plan_id)
303301

src/backend/v3/orchestration/orchestration_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def run_orchestration(self, user_id, input_task) -> None:
119119
"""Run the orchestration with user input loop."""
120120

121121
job_id = str(uuid.uuid4())
122-
#orchestration_config.approvals[job_id] = None
122+
# orchestration_config.approvals[job_id] = None
123123

124124
# Use the new event-driven method to set approval as pending
125125
orchestration_config.set_approval_pending(job_id)

0 commit comments

Comments
 (0)