fix(anthropic): cover retry stream recreation#1588
fix(anthropic): cover retry stream recreation#1588rosetta-livekit-bot[bot] wants to merge 12 commits into
Conversation
🦋 Changeset detectedLatest commit: 9f8f651 The changes in this PR will be included in the next version bump. This PR includes changesets to release 32 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
| if (this.#ignoringCoT) { | ||
| continue; | ||
| } | ||
|
|
||
| this.queue.put({ | ||
| id: this.#requestId, | ||
| delta: { role: 'assistant', content: text }, | ||
| }); | ||
| retryable = false; |
There was a problem hiding this comment.
🟡 Empty text emitted and retryable set to false after thinking block is completely stripped
When a text delta consists entirely of a <thinking>...</thinking> block (or when the </thinking> tag appears at the very end of a delta leaving nothing after it), the remaining text after filtering is "". The code falls through to emit this empty string as a content chunk and sets retryable = false on line 367. This has two consequences: (1) an empty content delta is needlessly queued to the consumer, and (2) the stream becomes non-retryable despite no meaningful content being delivered, so subsequent API errors will not trigger a retry.
Trace for text delta containing only a thinking block
For text = "<thinking>hidden</thinking>":
thinkingStart= 0,preThinking=""(not emitted because of theif (preThinking)guard)text="hidden</thinking>"after slicing past<thinking>#ignoringCoT= truethinkingEnd= 6,text=""after slicing past</thinking>#ignoringCoT= false- Falls through to line 363, emits
{ content: "" }and setsretryable = false
| if (this.#ignoringCoT) { | |
| continue; | |
| } | |
| this.queue.put({ | |
| id: this.#requestId, | |
| delta: { role: 'assistant', content: text }, | |
| }); | |
| retryable = false; | |
| if (this.#ignoringCoT) { | |
| continue; | |
| } | |
| if (!text) { | |
| continue; | |
| } | |
| this.queue.put({ | |
| id: this.#requestId, | |
| delta: { role: 'assistant', content: text }, | |
| }); | |
| retryable = false; |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Fixes #5805.
Tests
uv run pytest tests\test_plugin_anthropic.py -quv run ruff check livekit-plugins\livekit-plugins-anthropic\livekit\plugins\anthropic\llm.py tests\test_plugin_anthropic.pypython -m py_compile livekit-plugins\livekit-plugins-anthropic\livekit\plugins\anthropic\llm.py tests\test_plugin_anthropic.pygit diff --check