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

`RunnableRetry` Does Not Fire `On_retry` Callback

When using `with_retry` on a Runnable, the `on_retry` callback of `BaseCallbackHandler` is never invoked, preventing observability into retry attempts and error frequencies.

highConfidence 90%LangchainVector StoresChainsAffected V1.2.7

Origin Analysis

The `RunnableRetry` implementation uses tenacity for retries but does not wire tenacity's retry events (such as `before_sleep`) to LangChain's callback manager. As a result, the callback system is bypassed, and `on_retry` is never triggered.
Define a `BaseCallbackHandler` with an `on_retry` method. Create a `RunnableLambda` that fails twice and then succeeds. Apply `.with_retry()` with appropriate retry settings. Invoke the runnable with the callback handler in config. Observe that the `on_retry` method never prints.

Fixing Code Block

Edge Case Audit

This change may affect retry timing if `on_retry` callbacks have side effects or are slow. In multi-threaded environments, the callback manager may not be thread-safe; ensure proper isolation. The fix must be replicated for async paths (`_ainvoke`) and other variants. Test across tenacity versions (e.g., 8.x vs 9.x) because `RetryCallState` attributes may differ. Rollback advice: if issues arise, revert to the previous behavior without callback invocation, or make callback invocation conditional on presence of handlers.

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