Skip to content

bug: Paid chat endpoint uses 120s timeout causing failures for complex queries #80

@vybe

Description

@vybe

Summary

The paid chat endpoint (/api/paid/{agent}/chat) calls task_service.execute_task() without specifying a timeout_seconds parameter, so it defaults to 120 seconds. Complex agent queries (e.g., real estate underwriting with market analysis) regularly exceed this, causing task timeouts. The payment verification succeeds but the execution fails, resulting in verify-only payment logs with no settlement — the caller sees a 500 error.

Component

Backend / Paid Chat Router

Priority

P2

Error

[TaskExecService] Failed to execute task on [agent]: Task execution timed out after 120 seconds

Payment log shows repeated verify (OK) followed by no settle, because the execution times out before producing a response.

Location

  • File: src/backend/routers/paid.py
  • Line: ~167
  • Function: paid_chat()

Root Cause

The execute_task() call in the paid router doesn't pass timeout_seconds, defaulting to 120s:

exec_result = await task_service.execute_task(
    agent_name=agent_name,
    message=request_body.message,
    triggered_by="paid",
    resume_session_id=request_body.session_id,
)

The regular chat endpoint (/api/agents/{name}/chat) works fine because it uses the async background task pattern (no synchronous timeout). But the paid endpoint must wait synchronously for the result to settle the payment.

Reproduction Steps

  1. Configure Nevermined payments on an agent
  2. Send a complex query via the paid endpoint that takes >120s to process
  3. Payment verifies successfully
  4. Task execution times out at 120 seconds
  5. No settlement occurs — caller gets 500 error
  6. Payment log shows verify (OK) but no corresponding settle

Suggested Fix

Add an explicit timeout_seconds parameter to the execute_task() call. 600 seconds (10 minutes) is a reasonable default for paid queries that involve tool use and research:

exec_result = await task_service.execute_task(
    agent_name=agent_name,
    message=request_body.message,
    triggered_by="paid",
    timeout_seconds=600,
    resume_session_id=request_body.session_id,
)

Optionally, make this configurable per-agent via nevermined_agent_config.timeout_seconds.

Environment

  • Trinity version: f1dfd7d
  • Component: routers/paid.py, services/task_execution_service.py

Related

  • src/backend/services/task_execution_service.py — defines timeout_seconds=120 default
  • src/backend/routers/paid.py — paid chat endpoint
  • src/backend/services/nevermined_payment_service.py — payment flow

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions