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
- 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)
- Call the
LS tool with {"directory_path": "/path/to/dir"}
- 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
Bug Report
Project: cortex
Description
In
cortex-engine/src/tools/registry/executors/file_ops.rs, theexecute_list_dirfunction iterates over directory entries using:When
dir.next_entry().awaitreturns anErr(e.g., due to a permission error on a specific entry, an I/O error mid-enumeration, or a filesystem issue), thewhile let Ok(Some(...)))pattern does not match, causing the loop to exit silently. The function then returns aToolResult::successwith 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::successwith a partial listing.System Information
Steps to Reproduce
LStool with{"directory_path": "/path/to/dir"}execute_list_dirreturns a success result with only the entries read before the error — the error is silently swallowedExpected Behavior
If
next_entry()returns anErrduring directory enumeration, the function should either:ToolResult::errordescribing the I/O error, orActual Behavior
The
while let Ok(Some(entry)) = dir.next_entry().awaitpattern silently exits the loop on anyErrfromnext_entry(). The partial listing is returned asToolResult::successwith no indication that an error occurred or that entries may be missing.Additional Context
src/cortex-engine/src/tools/registry/executors/file_ops.rs, line 66while let Some(entry) = dir.next_entry().await?(propagating errors) or explicitly match onErrto report itwhile let Ok(Some(x)) = iter.next()silently stops on errors, unlikefor x in iterwhich would surface them