Problem
The async mode path in chat.py (_execute_task_background(), lines 376-567) does NOT use TaskExecutionService. It implements its own parallel logic for slot management, activity tracking, error handling, and credential sanitization — inline.
/api/task (async=true) → _execute_task_background() ← INLINE, NOT TaskExecutionService
/api/task (sync) → TaskExecutionService.execute_task() ← Unified path
Impact
- Any fix applied to
TaskExecutionService (status values, sanitization, slot logic) does NOT apply to async mode
- Async mode has its own slot acquire/release that could diverge
- Async mode has its own error handling with potentially different status values
- Async mode may miss credential sanitization steps added to the service
- Two maintenance surfaces for the same logical operation
Current Async Flow (chat.py)
- Create execution record early (
db.create_task_execution())
- Acquire slot inline (
slot_service.acquire_slot())
- Track activity inline (
activity_service.track_activity())
- Spawn
asyncio.create_task(_execute_task_background())
- Background function: call agent, update records, release slot in finally
Required Changes
- Add async support to
TaskExecutionService (e.g., execute_task_async() that spawns background and returns immediately)
- Move all inline logic from
_execute_task_background() into the service
- Chat router's async path should only create execution record + call service
- Ensure identical slot, activity, sanitization, and error handling between sync and async
Files to Change
src/backend/services/task_execution_service.py — Add async execution mode
src/backend/routers/chat.py — Remove _execute_task_background(), delegate to service
src/backend/routers/public.py — Also has _execute_public_chat_background() that should use service
Problem
The async mode path in
chat.py(_execute_task_background(), lines 376-567) does NOT useTaskExecutionService. It implements its own parallel logic for slot management, activity tracking, error handling, and credential sanitization — inline.Impact
TaskExecutionService(status values, sanitization, slot logic) does NOT apply to async modeCurrent Async Flow (chat.py)
db.create_task_execution())slot_service.acquire_slot())activity_service.track_activity())asyncio.create_task(_execute_task_background())Required Changes
TaskExecutionService(e.g.,execute_task_async()that spawns background and returns immediately)_execute_task_background()into the serviceFiles to Change
src/backend/services/task_execution_service.py— Add async execution modesrc/backend/routers/chat.py— Remove_execute_task_background(), delegate to servicesrc/backend/routers/public.py— Also has_execute_public_chat_background()that should use service