Skip to content

normalize_input_files silently drops IOBase inputs despite accepting them in its type #9625

Closed

Description

@Kiko0301

Description

normalize_input_files() accepts FileSourceInput, whose public definition includes IOBase:

lib/crewai-files/src/crewai_files/core/types.py:25

FileSourceInput = str | Path | bytes | IOBase | FileSource

The dispatch loop, however, handles only FilePath, FileBytes, FileStream, FileUrl, Path, str, bytes, and memoryview. Everything else, including a BytesIO or an opened binary file, falls into the final else: continue:

lib/crewai-files/src/crewai_files/resolution/utils.py:83-86

elif isinstance(item, (bytes, memoryview)):
    file_source = FileBytes(data=bytes(item))
else:
    continue

The stream is silently absent from the returned dictionary. No warning or error is produced, so a task declared with input_files=[open("report.pdf", "rb")] or a BytesIO ends up with that file missing from its inputs.

Note that File(source=stream) already supports streams through _FileSourceCoercer (types.py:27-46), so the two entry points disagree about the same documented input type.

Reproduction

import io

from crewai_files import normalize_input_files

stream = io.BytesIO(b"streamed content")
stream.name = "streamed.txt"

print(normalize_input_files([stream]))
# {} on main; expected {"streamed.txt": <FileInput>}

Expected behaviour

An IOBase input should be wrapped in FileStream, as File construction does, so the stream appears in the result under its .name (or file_<index> when unnamed).

Tests

lib/crewai/tests/utilities/test_files.py adds test_normalize_file_like_object under TestNormalizeInputFiles. It fails on main with:

AssertionError: assert 'streamed.txt' in {}

and passes with the fix.

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 21, 2026

    @abhi478jeetur-rgb

    Confirmed — a named BytesIO and an unnamed one both come back as {}:

    normalize_input_files([stream])  # {} — stream had name "streamed.txt"
    normalize_input_files([b"abc"])  # {'file_0': ...} — bytes still work

    The dispatch loop really does fall through to else: continue for anything that isn't a path/str/bytes/memoryview, while FileSourceInput advertises IOBase and File(source=stream) coerces streams fine through _FileSourceCoercer. So the two entry points disagree on the same documented input type, and the silent drop is the worst part — nothing tells you the file never made it in. Wrapping IOBase inputs in FileStream here, the way File construction already does, lines them up.

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