fix(api): sign tool file URLs generated by ToolFileMessageTransformer#39225
Open
amogh-nagri-11 wants to merge 4 commits into
Open
fix(api): sign tool file URLs generated by ToolFileMessageTransformer#39225amogh-nagri-11 wants to merge 4 commits into
amogh-nagri-11 wants to merge 4 commits into
Conversation
session.add/session.commit for a new segment ran outside the redis_client.lock covering the max-position read, so concurrent create_segment calls on the same document could read the same max_position and commit duplicate segment positions.
hlen() and hset() were two separate, unsynchronized Redis round-trips, letting concurrent requests all read a count under the cap and all get admitted, exceeding max_active_requests. Replaced with a single atomic Lua script that checks-and-sets in one round trip.
…test create_segment takes session as an explicit parameter and never touches the module-level db global, so patching it was unnecessary and appears fragile under CI's parallel (-n auto) test execution, where the patch target intermittently reported "module has no attribute db". Build the mock session directly instead.
amogh-nagri-11
requested review from
JohnJyong,
QuantumGhost and
laipz8200
as code owners
July 19, 2026 06:59
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
ToolFileMessageTransformer.get_tool_file_url()built tool file URLs as a bare/files/tools/<id><ext>path with no signature, and that URL is used directly as the text ofIMAGE_LINK/BINARY_LINK/LINKtool messages, which flow straight into the agent's answer/workflow output with no re-signing step downstream./files/tools/<id>requirestimestamp,nonce, andsignquery params (validated viaToolFileQueryincontrollers/files/tool_files.py), any request to these unsigned URLs returns a 400.get_tool_file_url()through the existingsign_tool_file()helper (core/tools/signature.py), the same signer used elsewhere in the codebase.Note on scope: the issue also flags
base_app_runner.py(MessageFile.urlstored unsigned). That value is only used internally to recovertool_file_id(Message.message_filesinmodels/model.py) and is re-signed fresh viaFile.generate_url()before ever reaching a client, so it isn't part of this bug and wasn't changed here.Fixes #39222
Test plan
uv run --project api python -m pytest api/tests/unit_tests/core/tools/utils/test_message_transformer.py -quv run --project api python -m pytest api/tests/unit_tests/core/tools/test_signature.py -quv run ruff check/ruff format --checkon changed files