AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ChatOpenRouter: Max_retries=0 Enables The SDK Default Retry Policy Instead Of Disabling Retries

Setting max_retries=0 in ChatOpenRouter does not disable retries; the omission of retry_config causes OpenRouter SDK to apply its default backoff policy, leading to unexpected repeated requests and potentially long hangs on 5xx responses.

highConfidence 92%LangChainMemoryRetrieverslangchain-coreAffected V<=0.2.8

Origin Analysis

In ChatOpenRouter._build_client, the retry_config parameter is conditionally set only for positive max_retries, otherwise it is left as UNSET. The OpenRouter SDK interprets UNSET as its default retry configuration, not as 'no retries'. Therefore max_retries=0 is silently ignored.
1. Install langchain-openrouter==0.2.8 and openrouter==0.10.0. 2. Instantiate ChatOpenRouter(model='openai/gpt-4o-mini', api_key='unused', max_retries=0). 3. Print model.client.sdk_configuration.retry_config; it shows Unset() instead of None. 4. Send a request to an endpoint that always returns HTTP 500; observe that the client performs multiple retry attempts and continues running, whereas explicit retry_config=None would fail immediately after one request.

Fixing Code Block

Edge Case Audit

This change requires openrouter SDK version that supports retry_config=None to disable retries (verified in 0.10.0). Users who previously (unintentionally) relied on retries when max_retries=0 may now see immediate failures for transient 5xx errors; this is the documented correct behavior. To roll back, restore the original conditional that omitted retry_config for zero. Ensure that max_retries=None (unset) is not accidentally converted to None, as that would also disable the SDK default retry policy.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state