Skip to content

bug: inter-agent task timeout hardcoded at 600s ignores per-agent execution_timeout_seconds #418

Closed

Description

@vybe

Summary

TaskExecService (the backend service that handles agent-to-agent task invocations) enforces a hardcoded ~600-second timeout on inter-agent calls that is independent of and shorter than the per-agent execution_timeout_seconds configured via /api/agents/{name}/timeout (default 900s). When a scheduled or fan-out task delegates work from agent A to agent B, agent B's execution is killed at ~610s even when its own timeout is set to 900s or higher. This caused a cascading failure burst of ~150 failed sub-executions across 7 delegate agents in an 80-minute window during a single parent schedule.

Component

Backend / Task Execution Service (logger: services.task_execution_service)

Priority

P1 — major feature broken (agent-to-agent fan-out with long-running sub-tasks), no workaround other than disabling or shortening parent schedules. Reproduces deterministically whenever an agent's sub-task takes >10 min.

Error

[TaskExecService] TIMEOUT on <agent-name> after 610s (limit=600s)
[TaskExecService] Failed to execute task on <agent-name>: Task returned empty response
[TaskExecService] Failed to execute task on <agent-name>: Task execution error: [Errno 32] Broken pipe

Location

  • Logger: services.task_execution_service
  • Likely file: backend/services/task_execution_service.py (location of TaskExecService)
  • Symptom: timeout enforced at ~600s regardless of target agent's execution_timeout_seconds (900s in this case).

Root Cause

The inter-agent invocation path in TaskExecService applies a fixed 600s ceiling and does not read the target agent's execution_timeout_seconds column from agent_ownership. The per-agent timeout configured via the /api/agents/{name}/timeout endpoint only affects scheduled and manual/UI executions, not agent-triggered ones.

Secondary symptoms observed during the same burst (likely downstream effects of the timeout kill):

  • "Task returned empty response" — subprocess/stdout closed when the caller abandons the connection.
  • "[Errno 32] Broken pipe" — write to closed socket after caller timed out.
  • Failed to import credentials into agent X after 3 attempts: All connection attempts failed — connection exhaustion under the resulting retry storm.
  • [FastMCP error] No connection established for request ID: N — MCP server connections dropped while the platform was flooded with retries.

Reproduction Steps

  1. Create agent-A with a schedule that calls agent-B via the MCP chat_with_agent tool (or equivalent agent-triggered path).
  2. Configure agent-B via PUT /api/agents/agent-B/timeout with execution_timeout_seconds: 1800.
  3. Give agent-B a task that takes >10 minutes (large prompt, heavy analysis).
  4. Trigger agent-A's schedule.
  5. Observe: agent-B's execution in /api/agents/agent-B/executions/{id} has duration_ms ≈ 610000, status: "failed", error: "Task returned empty response" (or TIMEOUT after 610s (limit=600s) in backend logs), even though agent-B's configured timeout is 1800s.

Suggested Fix

In TaskExecService, before dispatching an inter-agent task, load the target agent's execution_timeout_seconds and use it as the ceiling:

# Pseudo-code
target_timeout = db.get_agent_execution_timeout(target_agent_name)  # reads agent_ownership.execution_timeout_seconds
effective_timeout = min(target_timeout, platform_max_inter_agent_timeout)  # allow platform-wide upper bound
# dispatch with effective_timeout instead of the current hardcoded 600s

Alternatively, expose the inter-agent timeout as a separate configurable field (e.g., inter_agent_timeout_seconds) on the agent or as an env var with a sane default (e.g., 1800s) so operators can tune it without source changes.

Environment

  • Trinity version: 3b02871 (fix(agent-runtime): reap claude subprocess tree via process groups)
  • Deployment: Docker Compose (prod profile)
  • Workload: 1 orchestrator agent + 7 delegate agents, orchestrator fans out via scheduled task every 6 hours

Related

  • POST /api/agents/{name}/fan-out (FANOUT-001) and MCP chat_with_agent are the main code paths exercising this timeout.
  • PUT /api/agents/{name}/timeout (TIMEOUT-001) — per-agent configuration that is silently ignored on the inter-agent path.
  • schedule_executions table — failed rows during an 80-minute burst all show triggered_by=agent and duration_ms ≈ 610000.

Observed Impact (one 80-minute window)

Delegate agent Failed sub-executions Pattern
delegate-1 21 limit=600s + empty-response
delegate-2 15 same
delegate-3 17 same
delegate-4 15 same
delegate-5 14 same
delegate-6 18 same
delegate-7 17 same

~120 failed executions in ~80 min, all tied to one parent schedule run.

Activity

  1. added
    priority-p1
    type-bug
    status-in-progress
    and removed on Apr 20, 2026
  2. self-assigned this
    on Apr 20, 2026
  3. vybe commented on Apr 20, 2026

    @vybe
    ContributorAuthor

    Post-deploy verification: fix is incomplete

    Deployed 0027b8b (which includes eb4dad9) to production. The 14:30 UTC orchestrator schedule fan-out reproduced the same failures as before:

    [TaskExecService] TIMEOUT on oracle-8-biotech after 610s (limit=600s)
    [TaskExecService] TIMEOUT on oracle-3-ai after 610s (limit=600s)
    [TaskExecService] TIMEOUT on oracle-7-ai-semi after 610s (limit=600s)
    [TaskExecService] TIMEOUT on oracle-4-politics after 610s (limit=600s)
    

    Target agents all have execution_timeout_seconds=900 via /api/agents/{name}/timeout.

    Root cause of incomplete fix

    The PR correctly removed the 600s default from the MCP side, so chat_with_agent and fan_out tools now forward timeout_seconds: undefined to the backend. However, the backend side was not fully updated — src/backend/services/task_execution_service.py still has two 600s fallbacks:

    • Line 89 — agent_post_with_retry(..., timeout: float = 600.0) — default kwarg
    • Line 409 — effective_timeout = float(timeout_seconds or 600) + 10

    When the MCP path now passes None, line 409's timeout_seconds or 600 resolves to 600, so agent_post_with_retry is called with timeout=610. The log line is emitted from this same function:

    [TaskExecService] Calling agent <name> /api/task (timeout=610.0s, ...)
    

    Effectively the MCP→backend hop now forwards the "undefined" signal, but the backend doesn't resolve it to execution_timeout_seconds from agent_ownership as the PR description intended.

    Suggested completion

    At the top of the execute-task code path in TaskExecutionService, when timeout_seconds is None, load it from the target agent's DB row:

    if timeout_seconds is None:
        timeout_seconds = db.get_agent_execution_timeout(agent_name)  # reads agent_ownership.execution_timeout_seconds

    Then float(timeout_seconds or 600) + 10 becomes a safe fallback only when the DB lookup itself fails.

    Secondary observation

    When the 610s timeout fires, the termination path also hangs:

    [TaskExecService] Terminate timed out for execution <id> on agent '<name>' — watchdog will clean up
    

    The cleanup-service watchdog eventually reconciles these, but the agent keeps running the original work for longer than the timeout window, wasting subscription budget and tying up slots. Worth looking at in the same PR.

    Scale of ongoing impact

    The 14:30 UTC fan-out produced ~4 more fresh timeouts per delegate agent in ~30 minutes. Next scheduled fan-out is 20:30 UTC — same burst pattern will recur until the backend fallback is removed.

  4. vybe commented on Apr 20, 2026

    @vybe
    ContributorAuthor

    Correction: backend fix is fine — caller was passing 600 explicitly

    My previous comment was wrong. I missed lines 275-277 of task_execution_service.py:

    # TIMEOUT-001: Use agent's configured timeout if not explicitly provided
    if timeout_seconds is None:
        timeout_seconds = db.get_execution_timeout(agent_name)

    This already resolves None → target agent's configured value before line 409 is reached. The or 600 at line 409 is effectively dead code in normal operation. The deployed backend and MCP-server images both contain the new code — I verified both.

    Actual root cause of the persistent 610s timeouts

    The orchestrator agent's skill was passing timeout_seconds: 600 explicitly to chat_with_agent:

    .claude/skills/assumption-extract/SKILL.md:43:
      Trinity calls MUST use `parallel: true, model: sonnet, timeout_seconds: 600` for extraction calls.
    

    So MCP forwarded 600, backend used 600, log shows limit=600s. The backend never got a chance to resolve from DB because the caller supplied an explicit value. Fixed on our side by updating the skill to omit timeout_seconds (falls back to agent config = 900s).

    Defense-in-depth suggestion (optional, still worth doing)

    The or 600 magic numbers at task_execution_service.py:89 and :409 are misleading — they look like they matter but shouldn't ever fire in normal flow. Either remove them (make None a loud bug) or reassert the DB lookup there. A test for the end-to-end None → DB → HTTP timeout chain would also help — the new test_inter_agent_timeout_unit.py covers fan-out forwarding but not this chain.

    Secondary issue still valid

    The Terminate timed out for execution X on agent Y — watchdog will clean up pattern is orthogonal and I'll file it separately.

    Apologies for the noise — closing the loop on this one.

  5. added a commit that references this issue on May 25, 2026
  6. added 2 commits that reference this issue on May 25, 2026
  7. added
    complexity-low
    on Jun 3, 2026
  8. removed
    status-in-progress
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p1type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions