[Bug]: FallbackChatGenerator forwards a failed attempt's partial stream, so the streamed answer contains the abandoned prefix
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #13595 của @Wang-Zephyr — đã đóng, không merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 47/100
Hướng nghiên cứu
Read haystack/components/generators/chat/fallback.py and test/components/generators/chat/test_fallback.py; compare how run and run_async forward callbacks across failed attempts. Add coverage for a generator that emits chunks and then raises, followed by a successful generator. Done means both paths exhibit the agreed behavior and streamed output matches the documented contract.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
FallbackChatGenerator passes the caller's streaming_callback straight to every generator in the chain. When a generator fails after it has already streamed something, those chunks are already in the caller's hands, and the next generator's chunks are appended to them. Nothing separates the abandoned attempt from the successful one.
So the streamed answer reads PARTIAL-from-A still-A FULL-answer-from-B, while replies[0].text is just FULL-answer-from-B. The streamed text and the returned message disagree.
Both the sync and the async path behave the same way.
Minimal reproduction
Two duck-typed generators (only .run / .run_async are used), no API key needed:
import asyncio
from haystack.components.generators.chat.fallback import FallbackChatGenerator
from haystack.dataclasses import ChatMessage, StreamingChunk
class FlakyGenerator: # streams, then fails
def run(self, messages=None, generation_kwargs=None, tools=None, streaming_callback=None):
streaming_callback(StreamingChunk(content="PARTIAL-from-A "))
streaming_callback(StreamingChunk(content="still-A "))
raise RuntimeError("provider dropped the connection after two chunks")
async def run_async(self, **kw):
return self.run(**kw)
class BackupGenerator: # succeeds
def run(self, messages=None, generation_kwargs=None, tools=None, streaming_callback=None):
streaming_callback(StreamingChunk(content="FULL-answer-from-B"))
return {"replies": [ChatMessage.from_assistant("FULL-answer-from-B")]}
async def run_async(self, **kw):
return self.run(**kw)
received = []
gen = FallbackChatGenerator([FlakyGenerator(), BackupGenerator()])
out = gen.run(messages=[ChatMessage.from_user("hi")], streaming_callback=received.append)
print("sync user reads:", "".join(c.content for c in received))
print("sync reply :", out["replies"][0].text)
async def main():
received = []
gen = FallbackChatGenerator([FlakyGenerator(), BackupGenerator()])
out = await gen.run_async(messages=[ChatMessage.from_user("hi")], streaming_callback=received.append)
print("async user reads:", "".join(c.content for c in received))
print("async meta :", out["meta"])
asyncio.run(main())
Actual output on main (8ed1ee6):
sync user reads: PARTIAL-from-A still-A FULL-answer-from-B
sync reply : FULL-answer-from-B
async user reads: PARTIAL-from-A still-A FULL-answer-from-B
async meta : {'successful_chat_generator_index': 1, 'successful_chat_generator_class': 'BackupGenerator', 'total_attempts': 2, 'failed_chat_generators': ['FlakyGenerator']}
Why the current tests do not catch it
In test/components/generators/chat/test_fallback.py the failing generator (_DummyFailGen) raises before it emits anything, and the two streaming-forwarding tests use only a successful generator. The "streamed some chunks, then failed" path is not exercised.
docs-website/docs/pipeline-components/generators/fallbackchatgenerator.mdx:80 says the callback "is passed directly to the underlying Generators" — which describes the mechanism, but does not say what a caller should expect when an attempt fails mid-stream.
Options
I did not pick one myself because all three touch the component's contract:
- Buffer until an attempt succeeds, then flush. Streamed and returned text always agree, but the caller sees nothing until the answer is complete — the streaming benefit is gone for the first attempt.
- Do not fall back once an attempt has streamed anything (raise instead), mirroring how a truncated tool call is handled elsewhere. Keeps output correct, but removes failover exactly in the case it matters most.
- Mark the first chunk of every attempt with the existing
StreamingChunk.startflag (start: bool— "whether this chunk marks the start of a content block"). Nothing changes for callers that ignore it; callers that render streamed text can reset on it. It does not fix a UI that ignores the flag.
I lean towards 3 as the smallest change that gives callers a signal without changing failover semantics, but 1 or 2 may match what you intend better.
If one of these works for you, I'm happy to open a PR (with the CLA signed) and add the missing test: a generator that streams two chunks and then raises, asserting the chosen behaviour for both run and run_async.
👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!
- Ngôn ngữ chính
- Python
- Star
- 27.1k
- Fork
- 3.5k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 239
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của deepset-ai/haystack
-
BlockingConfirmationStrategy ignores an empty argument replacementCó thể đã có người làm @Aarkin7 đã nhận 3 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
deepset-ai/haystack#13863 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
deepset-ai/haystack#13830 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DocumentSplitter misplaces repeated literal chunks from an overlapping custom splitterCó thể đã có người làm @davidsbatista đã nhận 7 ngày trước. Đang mởP2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepset-ai/haystack#13806 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CSVToDocument accepts an unsupported conversion_mode and silently converts in row modeCó thể đã có người làm @Lesereingrape đã nhận 54 ngày trước. Đang mởP3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
deepset-ai/haystack#13070 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
InMemoryDocumentStore: count_unique_metadata_by_filter and get_metadata_field_unique_values disagree on int/float/bool valuesCó thể đã có người làm @sjrl đã nhận 14 ngày trước. Đang mởP3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepset-ai/haystack#13040 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của deepset-ai/haystack
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
langgenius/graphon#443 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
docling-project/docling-serve#788 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Mend: dependency security vulnerability untriaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainer thường phản hồi trong vòng 1 ngày