Skip to content

Create execution records for /api/chat endpoint (unify with task tracking) #96

Closed

Description

@vybe

Problem

The /api/chat endpoint is the ONLY execution path that does not create records in the execution table (schedule_executions). It only writes to chat_messages. This means:

  • Chat executions don't appear in the Tasks tab history
  • Chat executions can't be queried via the execution API
  • Chat execution costs/metrics aren't tracked in the unified execution log
  • The only exception is MCP-triggered chats (agent-to-agent), which DO create execution records

Current Behavior

Path Creates Execution Record? Creates Activity?
/api/chat (user) NO YES
/api/chat (MCP) YES YES
/api/task YES YES
Public chat YES NO
Paid chat YES NO
Scheduled YES YES

Impact

  • No unified view of ALL work an agent has done
  • Chat costs not aggregated with task costs
  • Can't answer "how many total executions did this agent run today?" without querying two tables
  • Inconsistent data model makes reporting unreliable

Required Changes

  1. Create execution record for every /api/chat call (not just MCP)
  2. Use triggered_by="chat" to distinguish from tasks
  3. Link the execution record to the chat message via existing related_execution_id in activities
  4. Ensure execution queue still works (queue manages concurrency, execution record tracks history)
  5. Update Tasks tab to optionally show/filter chat executions

Considerations

Files to Change

  • src/backend/routers/chat.py — Create execution record in chat_with_agent()
  • src/backend/db/schedules.py — Potentially add execution_type filter
  • src/frontend/src/components/TasksPanel.vue — Add filter for execution type

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