fix(media): raise ToolError on redirect response missing Location header (#616) - #633
Closed
Tiktokaiagent wants to merge 3 commits into
Closed
fix(media): raise ToolError on redirect response missing Location header (#616)#633Tiktokaiagent wants to merge 3 commits into
Tiktokaiagent wants to merge 3 commits into
Conversation
1 task
Tiktokaiagent
force-pushed
the
fix/616-media-redirect-crash
branch
from
September 1, 2026 01:28
5ecd1e2 to
274f729
Compare
Tiktokaiagent
added a commit
to Tiktokaiagent/agent-os
that referenced
this pull request
Sep 1, 2026
The new test_fetch_image_redirect_missing_location_raises_tool_error and test_fetch_image_too_many_redirects_raises_tool_error use pytest.raises(ToolError) but ToolError was not imported. Added the import from agentos.tools.types.
1 task
When _fetch_image_url encounters a redirect (301, 302, 303, 307, 308) but the response has no Location header, it previously broke out of the redirect loop and tried to process the response as a non-redirect. This caused httpx.StreamClosed errors when it tried to read the body of an already-closed response. Instead, raise a clear ToolError immediately so the caller gets a usable error message instead of a cryptic StreamClosed crash. Fixes use-agent-os#616
The new test_fetch_image_redirect_missing_location_raises_tool_error and test_fetch_image_too_many_redirects_raises_tool_error use pytest.raises(ToolError) but ToolError was not imported. Added the import from agentos.tools.types.
Tiktokaiagent
force-pushed
the
fix/616-media-redirect-crash
branch
from
September 1, 2026 17:30
aa67b64 to
bdf5deb
Compare
Contributor
|
Closing as superseded. Reviewed alongside the other three PRs on issue #616; #773 was picked. Your fix is in the right place. The difference is the message: Thanks for the contribution. |
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
When
_fetch_image_urlencounters a redirect response (301, 302, 303, 307, 308) but the response has noLocationheader, the code previouslybreakout of the redirect loop and continued to process the response as a non-redirect. This causedhttpx.StreamClosederrors when trying to read the body of an already-closed response.Fix
ToolErrorimmediately when a redirect response is missing theLocationheaderStreamClosedcrashChanges
src/agentos/tools/builtin/media.py: 3 lines changedTests
3 new regression tests in
tests/test_tools/test_media_image_download_cap.py:Fixes #616