crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] FileStream rejects streams with integer file-descriptor names

Open emme1t opened this issue 2 months ago • 3 comments

This is an AI-generated issue. I requested the required llm-generated label during creation and retried adding it, but GitHub rejected AddLabelsToLabelable because my account lacks permission. Please apply the label so the contribution can follow the project policy.

Description

FileStream rejects a valid binary stream opened from a file descriptor when filename is omitted. Such streams expose an integer name; filename inference passes that integer to Path and raises TypeError before the file can be supplied to an agent.

Steps to Reproduce

Open a temporary binary file, reopen its descriptor as a binary stream, and construct FileStream with its default optional filename.

Screenshots/Code snippets

from tempfile import TemporaryFile
from crewai_files import FileStream

with TemporaryFile() as original:
    original.write(b"A file supplied to an agent.")
    original.seek(0)
    with open(original.fileno(), "rb", closefd=False) as stream:
        source = FileStream(stream=stream)
        assert source.read() == b"A file supplied to an agent."

Expected behavior

The stream should remain usable with its optional filename unset. An explicitly supplied filename and filename inference from ordinary named files should keep working.

Evidence

Current main (3831e8b6c86f78cb3cde18ebf7be0d197b958f0e) raises:

File "crewai_files/core/sources.py", in _initialize
    self.filename = Path(name).name
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int'

Operating System

Windows.

Python Version

3.13.13.

crewAI Version

Standalone crewai-files 1.15.22 at the main commit above, with Pydantic 2.13.5. The crewai package is not needed for this reproduction.

crewAI Tools Version

Not used by this standalone file-handling reproduction.

Virtual Environment

Venv, created with uv.

Possible Solution

Infer the filename when the stream's name is a string or path-like value. Preserve the optional filename for descriptor-backed streams.

Additional context

The failure requires no model API or remote tool provider.

This issue was prepared with Codex collaboration as part of an Astra Ultra-based automated PR project contributing to the open-source community.

emme1t avatar Sep 19 '26 10:09 emme1t

I'll take this one. FileStream._initialize is passing an integer file-descriptor name into Path() and raising TypeError. I'll infer the filename only when the stream name is a string or path-like value, and leave the optional filename unset for descriptor-backed streams.

leilei3167 avatar Sep 19 '26 13:09 leilei3167

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 20 '26 12:10 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 26 '26 13:10 github-actions[bot]