Skip to content

bug: agent-to-agent chat chains have no depth guard — a runaway A→B→A bounce is bounded only by capacity parks and hop timeouts #2806

Closed

Description

@webmixgamer

Summary

chat_with_agent — and the /chat and /task routes it dispatches to — carries no hop or depth marker, so two agents that are permitted to call each other can bounce a call back and forth with nothing that recognises the chain as a chain. What bounds it today is incidental: each hop's execution_timeout_seconds, the per-agent max_parallel_tasks capacity (overflow goes to the durable backlog rather than being refused), and the backend agent-call limiter, whose own header says agent-to-agent chains "can deadlock" and that a finite queue timeout "surfaces such a deadlock as a 503 within an hour" (src/backend/services/agent_call_limiter.py). Rooms already have a chain cap (ROOM_MAX_CHAIN_DEPTH = 8 in src/backend/shared_sessions/service.py); chat has none.

Context

Found while building the J10 journey harness (#2349). J10's "loop guards stop runaway inter-agent recursion" criterion is carried by the harness as a strict=True xfail (tests/journeys/test_j10_agent_calls_agent_journey.py) until a guard exists. parent_execution_id (already threaded from the MCP client to the child row on the task path) means an ancestry depth is derivable without inventing a new header.

Acceptance Criteria

  • A call whose ancestry depth exceeds a configured maximum is refused with a named error (e.g. inter_agent_depth_exceeded) before any model work starts, on every agent-to-agent path: chat_with_agent sequential and parallel, fan_out, and the pull-routed sequential path
  • The maximum has a sensible default and is operator-configurable (system_settings → env → default)
  • The refusal is visible to the caller and recorded on the platform (execution row or activity), never a silent drop
  • Flip condition for the J10 xfail: test_two_agents_cannot_bounce_a_call_between_each_other_forever is rewritten to drive a real A→B→A chain past the maximum on a keyed stack and assert the named refusal; the xfail marker is removed in the same PR
  • An invariant entry for the guard is added to docs/testing/orchestration-invariant-catalog.md (the IA- family covers attribution, fan-out bounds and the stopped callee, not chain depth) and cited by J10's catalog record

Technical Notes

Spans src/mcp-server/src/tools/chat.ts (runAgentChat), src/backend/services/chat_execution_service.py and src/backend/services/agent_call_limiter.py.

Activity

  1. added
    priority-p2
    type-bug
    theme-reliability
    complexity-medium
    status-ready
    on Sep 15, 2026
  2. removed
    status-ready
    on Sep 15, 2026
  3. self-assigned this
    on Sep 15, 2026
  4. added
    status-in-progress
    on Sep 15, 2026
  5. removed their assignment
    on Sep 15, 2026
  6. added
    status-ready
    and removed
    status-in-progress
    on Sep 15, 2026
  7. AndriiPasternak31 commented on Sep 22, 2026

    @AndriiPasternak31
    Contributor

    /claim

  8. 1 remaining item

  9. removed
    status-ready
    on Sep 22, 2026
  10. github-actions commented on Sep 22, 2026

    @github-actions

    Claimed by @AndriiPasternak31. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2806-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2806
  11. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 27, 2026
  12. removed
    status-in-dev
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

complexity-mediumpriority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions