Skip to content

[BUG] [v0.0.7] execute_list_dir silently truncates directory listing when next_entry() returns an error mid-enumeration #18539

Description

@echoforge2200

Bug Report

Project: cortex

Description

In cortex-engine/src/tools/registry/executors/file_ops.rs, the execute_list_dir function iterates over directory entries using:

while let Ok(Some(entry)) = dir.next_entry().await {
    // ...
    entries.push(format!("{name}{suffix}"));
}

entries.sort();
Ok(ToolResult::success(entries.join("\n")))

When dir.next_entry().await returns an Err (e.g., due to a permission error on a specific entry, an I/O error mid-enumeration, or a filesystem issue), the while let Ok(Some(...))) pattern does not match, causing the loop to exit silently. The function then returns a ToolResult::success with only the partial list of entries collected before the error — with no indication that the listing is incomplete.

This is a silently-wrong-behavior bug: the caller receives a success result with a truncated directory listing, believing it to be complete.

Error Message

No error is raised. The tool returns ToolResult::success with a partial listing.

System Information

OS: Linux (Ubuntu 22.04)
cortex v0.0.7
File: src/cortex-engine/src/tools/registry/executors/file_ops.rs, line 66

Steps to Reproduce

  1. Create a directory containing entries where some are readable and at least one causes an I/O error during enumeration (e.g., a broken symlink or a filesystem that returns errors mid-read)
  2. Call the LS tool with {"directory_path": "/path/to/dir"}
  3. Observe that execute_list_dir returns a success result with only the entries read before the error — the error is silently swallowed

Expected Behavior

If next_entry() returns an Err during directory enumeration, the function should either:

  • Return a ToolResult::error describing the I/O error, or
  • Include a warning in the output indicating that the listing may be incomplete

Actual Behavior

The while let Ok(Some(entry)) = dir.next_entry().await pattern silently exits the loop on any Err from next_entry(). The partial listing is returned as ToolResult::success with no indication that an error occurred or that entries may be missing.

Additional Context

  • File: src/cortex-engine/src/tools/registry/executors/file_ops.rs, line 66
  • The correct pattern would be to use while let Some(entry) = dir.next_entry().await? (propagating errors) or explicitly match on Err to report it
  • This is a classic Rust pitfall: while let Ok(Some(x)) = iter.next() silently stops on errors, unlike for x in iter which would surface them

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