Skip to content

Route async task mode through TaskExecutionService #95

Closed

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

Activity

  1. added
    priority-p1
    on Mar 11, 2026
  2. vybe commented on Mar 30, 2026

    @vybe
    ContributorAuthor

    Actualization (2026-03-30)

    Current state: Still valid. _execute_task_background() in chat.py still has inline slot/activity/error handling that bypasses TaskExecutionService.

    Quick verification:

    • chat.py still contains _execute_task_background() with inline slot_service.acquire_slot(), activity_service.track_activity(), and custom error handling
    • public.py has similar inline logic in _execute_public_chat_background()
    • The sync path correctly uses TaskExecutionService.execute_task()

    Impact remains: Fixes to TaskExecutionService (status values, sanitization, slot logic) don't apply to async mode. Two maintenance surfaces for the same operation.

    Recommendation: Still needs implementation. This is a code quality / reliability issue that will cause divergence bugs over time.

  3. added
    status-in-progress
    on Apr 13, 2026
  4. added 3 commits that reference this issue on Apr 26, 2026
  5. removed
    status-in-progress
    on May 7, 2026
  6. added
    complexity-medium
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions