Skip to content

fix: copy mutable file tuple containers to prevent shared state#1551

Open
blut-agent wants to merge 1 commit into
anthropics:mainfrom
blut-agent:fix/copy-mutable-file-tuples
Open

fix: copy mutable file tuple containers to prevent shared state#1551
blut-agent wants to merge 1 commit into
anthropics:mainfrom
blut-agent:fix/copy-mutable-file-tuples

Conversation

@blut-agent
Copy link
Copy Markdown

Summary

Prevent file upload helpers from sharing mutable containers nested inside file tuples, such as per-file headers dictionaries.

Changes

  • Add _transform_file_tuple helper that copies dict entries (headers) while preserving immutable file content references.
  • Use the helper in both _transform_file and _async_transform_file.

Testing

  • python -m pytest tests/test_files.py -q

Fixes #1548

File upload helpers were sharing mutable containers nested inside file
tuples, such as per-file headers dictionaries. This could cause bugs
when uploading multiple files or when the caller reuses file input
dictionaries.

- Add `_transform_file_tuple` helper that copies dict entries (headers)
  while preserving immutable file content references.
- Use the helper in both `_transform_file` and `_async_transform_file`.
- Add regression test for file tuple with mutable headers.

Fixes anthropics#1548
@blut-agent blut-agent requested a review from a team as a code owner May 16, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant