"""Default retry/backoff policy for outbound A2A calls, centralized so no
app team writes its own ad hoc retry loop with inconsistent behavior.

Only retries connection-level failures (connect errors, timeouts, dropped
connections) -- never retries on a response that came back with a body,
since that could double-invoke a non-idempotent remote skill.
"""
from __future__ import annotations

import httpx
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential

from a2a_passport.config import settings

default_retry = retry(
    reraise=True,
    stop=stop_after_attempt(settings.retry_attempts),
    wait=wait_exponential(multiplier=0.2, max=settings.retry_max_wait_seconds),
    retry=retry_if_exception_type(
        (httpx.ConnectError, httpx.ReadTimeout, httpx.RemoteProtocolError)
    ),
)
