Skip to content

Route async task mode through TaskExecutionService #95

Description

@vybe

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)

  1. Create execution record early (db.create_task_execution())
  2. Acquire slot inline (slot_service.acquire_slot())
  3. Track activity inline (activity_service.track_activity())
  4. Spawn asyncio.create_task(_execute_task_background())
  5. Background function: call agent, update records, release slot in finally

Required Changes

  1. Add async support to TaskExecutionService (e.g., execute_task_async() that spawns background and returns immediately)
  2. Move all inline logic from _execute_task_background() into the service
  3. Chat router's async path should only create execution record + call service
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions