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

RunnableSequence Silently Swallows Exceptions In Async Streaming Path

When a step inside RunnableSequence raises an exception during astream(), the exception is caught internally and the stream closes without surfacing the error to the caller. Sync stream() and async ainvoke() propagate correctly; only the async streaming path is affected.

highConfidence 89%Langchain

Origin Analysis

The async streaming implementation of RunnableSequence (likely in langchain_core/runnables/base.py) contains a try/except block that catches exceptions from intermediate steps and silently returns or breaks instead of re-raising, causing the generator to stop without notifying the consumer.
1. Create a RunnableSequence with at least two steps, where a non-first step raises an exception when invoked. 2. Call chain.astream(input) and iterate over the async generator. 3. Observe that the stream ends silently without raising, while chain.stream(input) and chain.ainvoke(input) both raise the exception.

Fixing Code Block

Edge Case Audit

This change may break callers that have come to rely on the silent behavior, as they might not expect an exception to be raised mid-stream. Users should update their error handling to catch exceptions during astream() iteration. In concurrent scenarios (e.g., multiple streams via asyncio.gather), one stream raising may cancel others; consider using return_exceptions or per-task handling. When rolling back to a previous version, the bug will reappear, so maintain test coverage for exception propagation.

Ecosystem Topology