Repository navigation
fix(anthropic): stream tag duplication, 529 mapping, image fetch hardening - #3757
Closed
hpiclaranet wants to merge 1 commit into
Closed
hpiclaranet wants to merge 1 commit into
hpiclaranet wants to merge 1 commit into
Conversation
7 of 15 tasks
…ening - Tool-use deltas now mark the block as "tool_use", fixing duplicate closing think tags when a thinking block is followed directly by a tool_use block in streams. - Map anthropic.OverloadedError (HTTP 529) to InvokeServerUnavailableError (retryable), ordered before the generic APIError catch-all. - Harden image URL fetching: (5s, 15s) timeout, 10 MB streamed cap with early Content-Length rejection, http(s)-only schemes, redirects rejected. Rebased onto main (9e1fb9d); version 0.3.30 (main carries 0.3.29 via langgenius#3811).
hpiclaranet
force-pushed
the
fix/anthropic-stream-errors-image-fetch
branch
from
September 5, 2026 00:18
3a5987a to
d639254
Compare
Closed
6 of 15 tasks
Mairuis
reviewed
Sep 7, 2026
Contributor
There was a problem hiding this comment.
Please rebase onto current main and choose a fresh Anthropic manifest version: 0.3.30 is already on main, and #3788/#3725 now propose 0.3.31/0.3.32. The new image fetch path intentionally rejects all redirects and caps downloads at 10 MB; please call out those user-visible restrictions in Release Notes and include image-input verification for URL-based images that previously redirected. The thinking-tag and 529 fixes should remain covered after rebasing.
7 of 15 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three reliability fixes in the Anthropic provider, each confirmed by code-path analysis of the streaming state machine and the installed
anthropicSDK (0.120.0 at analysis time; the plugin now locks 1.3.0 via #3811 and the full suite was re-verified on 1.3.0):thinkingblock was followed directly by atool_useblock, theinput_json_deltaevents matched none of the block-type branches, socurrent_block_typestayed"thinking". The block transition had already emitted the closing tag once, and theMessageStopEventhandler emitted it a second time, corrupting the thought text Dify stores. Tool-use deltas now mark the block as"tool_use".anthropic.OverloadedErroris a direct subclass ofAPIStatusError(notInternalServerError), so it fell through theAPIErrorcatch-all intoInvokeBadRequestError. It is now mapped toInvokeServerUnavailableError(server-side capacity, retryable). The mapping entry is ordered before the catch-all, which is what the SDK's first-match lookup requires.requests.get(data)had no timeout (a hung URL could block the worker indefinitely), no size cap, accepted any URL scheme, and followed redirects. It now uses a(5s connect, 15s read)timeout, streamed reads bounded to a 10 MB cap (early rejection viaContent-Lengthor duringiter_content, so a hostile server cannot push unbounded bytes into the process), http(s)-only URLs (surrounding whitespace tolerated), and no redirect following with explicit 3xx rejection (a 3xx with an image-like body is rejected, not consumed).Release Notes
Change Type
Screenshots / Videos
Not applicable — streaming state machine, error mapping, and fetch hardening, covered by unit tests.
LLM Plugin Checklist
Areas affected by this change (check all that apply)
Version
versioninmanifest.yaml(not the one undermeta) — 0.3.29 → 0.3.30 (0.3.29 is taken by feat(models): add Claude Fable 5.1 and Gemini 3.8 Flash support #3811)dify_plugin>=0.10.2is declared inpyproject.tomland locked inuv.lock(locked at 0.10.2, inherited from feat(models): add Claude Fable 5.1 and Gemini 3.8 Flash support #3811)Testing
uvvenv aligned withmanifest.yaml,pyproject.toml, anduv.lock: full anthropic suite 94 passed, 15 skipped on the rebased head (d639254f, main9e1fb9d5) — 18 new tests built from real SDK stream event objects. The bug-target tests fail against the pre-fix code (verified by checking out the base commit): duplicate-tag, 529 mapping, timeout/no-redirect/stream kwargs, whitespace stripping, 3xx-with-valid-body, Content-Length cap, oversized body.ruff checkshows zero new findings vs baseline.Known limitations (pre-existing, out of scope here):
ServiceUnavailableError/DeadlineExceededErrorare not explicitly mapped in this PR (pre-existing gap; generic 5xx map toInternalServerError, which is already mapped). With the SDK now at 1.3.0 (feat(models): add Claude Fable 5.1 and Gemini 3.8 Flash support #3811) those classes exist, so a 503/504 would be surfaced as a client error until explicitly mapped — out of scope here.