Repository navigation
fix(anthropic): stream tag duplication, 529 mapping, image fetch hardening - #3907
Merged
crazywoola merged 1 commit intoSep 24, 2026
Conversation
…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. - Add URL-based image input-path tests: a direct URL image is fetched and reaches the request as base64; a redirecting URL fails fast at the input path with a clear user-visible error. Rebased onto main (4a9e83b); version 0.3.33 (main carries 0.3.32 via langgenius#3887); verified with Anthropic SDK 1.4.0 (langgenius#3850).
7 of 15 tasks
crazywoola
approved these changes
Sep 24, 2026
crazywoola
enabled auto-merge (squash)
September 24, 2026 03:01
This was referenced Sep 29, 2026
Closed
This branch was successfully deployed
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.4.0 via #3850 and the full suite was re-verified with SDK 1.4.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.32 → 0.3.33 (0.3.32 is on main via fix: fix anthropic structure output failed #3887; 0.3.31/0.3.32 are proposed by fix(anthropic): send anthropic-workspace-id for identity-linked API keys #3788/chore(anthropic): log hygiene, drop obsolete pdfs beta header, remove dead stream branches #3725)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 125 passed, 15 skipped on the rebased head (d2975895, main4a9e83b6, SDK 1.4.0) — 20 tests intest_stream_and_hardening.py, including two new URL-based image input-path tests:test_image_url_input_reaches_request_content(a direct URL image is fetched and reaches the request as base64) andtest_image_url_that_previously_redirected_rejected_at_input_path(a redirecting URL fails fast at the input path with a clear error). 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.4.0 (chore(plugins): refresh verified icons and dependencies, fix CI #3850) those classes exist, so a 503/504 would be surfaced as a client error until explicitly mapped — out of scope here.