Skip to content

Bedrock S3 upload path is unreachable: _should_upload checks supports_file_upload before prefer_upload #9623

Closed

Description

@Kiko0301

Description

The Bedrock S3 upload path cannot be reached. _get_resolver_config() turns on prefer_upload for Bedrock when CREWAI_BEDROCK_S3_BUCKET is set:

lib/crewai-files/src/crewai_files/formatting/api.py:293-302

if "bedrock" in provider_lower:
    s3_bucket = os.environ.get("CREWAI_BEDROCK_S3_BUCKET")
    prefer_upload = (
        prefer_upload_override
        if prefer_upload_override is not None
        else bool(s3_bucket)
    )
    return FileResolverConfig(
        prefer_upload=prefer_upload, use_bytes_for_bedrock=True
    )

But FileResolver._should_upload() returns early whenever the provider constraints do not set supports_file_upload:

lib/crewai-files/src/crewai_files/resolution/resolver.py:252-256

if constraints is None or not constraints.supports_file_upload:
    return False

if self.config.prefer_upload:
    return True

BEDROCK_CONSTRAINTS deliberately leaves supports_file_upload=False (its comment documents S3/URL support instead):

lib/crewai-files/src/crewai_files/processing/constraints.py:280-292

BEDROCK_CONSTRAINTS = ProviderConstraints(
    ...
    supports_url_references=True,  # S3 URIs supported
)

So with a bucket configured, prefer_upload is True but _should_upload() returns False before reading it. Files are always resolved inline (InlineBytes), and the FileReference -> s3Location branch in BedrockFormatter plus BedrockFileUploader are dead code. This also affects format_multimodal_content(..., provider="bedrock", prefer_upload=True).

Reproduction

import os

from crewai_files import FileBytes, ImageFile
from crewai_files.formatting.api import _get_resolver_config
from crewai_files.processing.constraints import BEDROCK_CONSTRAINTS
from crewai_files.resolution.resolver import FileResolver

os.environ["CREWAI_BEDROCK_S3_BUCKET"] = "my-bucket"
image = ImageFile(source=FileBytes(data=b"x" * 1024, filename="chart.png"))

config = _get_resolver_config("bedrock")
resolver = FileResolver(config=config)

print(config.prefer_upload)  # True
print(resolver._should_upload(image, "bedrock", BEDROCK_CONSTRAINTS, 1024))  # False

Expected behaviour

An explicit upload preference should win over the provider's default capability flag, so a configured Bedrock bucket produces a FileReference (S3 upload) instead of inline bytes. Providers that leave supports_file_upload=False and do not set prefer_upload must stay inline.

Tests

lib/crewai-files/tests/test_resolver.py adds TestBedrockUploadPreference:

  • test_s3_bucket_enables_upload fails on main with AssertionError: assert False for _should_upload(...) and passes with the fix.
  • test_no_bucket_stays_inline guards the default path.

AI assistance

I used an AI coding agent to investigate, implement, and test this change, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

Activity

  1. abhi478jeetur-rgb commented on Nov 22, 2026

    @abhi478jeetur-rgb

    Confirmed — the S3 path really is unreachable. I reproduced it against the current code:

    _get_resolver_config("bedrock") with CREWAI_BEDROCK_S3_BUCKET set returns FileResolverConfig(prefer_upload=True, use_bytes_for_bedrock=True), but FileResolver._should_upload() then returns False for that same file, because BEDROCK_CONSTRAINTS never sets supports_file_upload (it's False) and the early return at resolver.py:252 fires before prefer_upload is ever looked at. The constraints only set supports_url_references=True with the S3 comment, so the config the formatter builds can never take effect.

    The mismatch is that "upload" means different things here: for most providers it's a direct file upload, for Bedrock it's an S3 URI, which the constraints describe via supports_url_references instead. Two ways to reconcile it:

    • In _should_upload, check self.config.prefer_upload before the supports_file_upload gate when the provider supports URL references, or
    • give Bedrock its own upload flag, e.g. set supports_file_upload=True on BEDROCK_CONSTRAINTS with the understanding that the upload mechanism is S3.

    The first option is the smaller change and keeps the existing meaning of supports_file_upload for providers that do direct uploads. Either way, as it stands, setting the bucket env var changes nothing at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions