Skip to content

Fix extension-less filenames never getting a .txt default - #1576

Open
Osamaali313 wants to merge 1 commit into
TransformerOptimus:mainfrom
Osamaali313:fix/resource-extension-default
Open

Osamaali313 wants to merge 1 commit into
TransformerOptimus:mainfrom
Osamaali313:fix/resource-extension-default

Conversation

@Osamaali313

Copy link
Copy Markdown

Problem

ResourceHelper.make_written_file_resource (superagi/helper/resource_helper.py) tries to give a .txt extension to a written file that has none:

file_parts = os.path.splitext(file_name)
if len(file_parts) <= 1:
    file_name = file_name + ".txt"
file_extension = os.path.splitext(file_name)[1][1:]

os.path.splitext() always returns a 2-tuple (root, ext), so len(file_parts) is always 2 and len(file_parts) <= 1 is never true. The .txt default is dead code.

The intent is clearly "if the filename has no extension, append .txt" — and the very next line reads the extension from os.path.splitext(file_name)[1], confirming the extension lives in the tuple's [1] slot, not in its length.

Impact

An agent writing an extension-less file (e.g. report) is stored with no .txt suffix, and its file_type classification falls through to application/misc instead of application/txt. make_written_file_resource is the write path used by resource_manager/file_manager.py (write_to_s3 via write_file/write_binary_file/write_csv_file).

Reproduction

file_name = "report"   # no extension
file_name file_type
before (len(file_parts) <= 1) report application/misc
after (not file_parts[1]) report.txt application/txt

Fix

if not file_parts[1]:
    file_name = file_name + ".txt"

`ResourceHelper.make_written_file_resource` tries to append a `.txt`
extension when the written file has none:

    file_parts = os.path.splitext(file_name)
    if len(file_parts) <= 1:
        file_name = file_name + ".txt"

But `os.path.splitext()` always returns a 2-tuple `(root, ext)`, so
`len(file_parts)` is always 2 and the guard is never true — the `.txt`
default is dead code. The very next line reads the extension from
`os.path.splitext(file_name)[1]`, which shows the extension lives in the
tuple's `[1]` slot, not in its length.

As a result, an agent writing an extension-less file (e.g. `report`) is
stored with no extension and its `file_type` falls through to
`application/misc` instead of `application/txt`.

Check the extension component instead of the tuple length.
Copilot AI review requested due to automatic review settings July 16, 2026 21:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants