Skip to content

[Bug] \ls\ reports a non-empty directory as \(empty directory)\ when \limit\ is 0 or negative #3353

Description

@aniruddhaadak80

💡 English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️

  • I'm on the latest version and searched existing issues (incl. closed) — no duplicate.

Environment

Version: current master (commit 08f64f7)
OS: any — platform-independent
Python: 3.11 / 3.13 (CI matrix)
Install: any
Channel: any (ls is a built-in tool, reachable from every channel)

What happened?

The ls tool reports a non-empty directory as (empty directory) when the model passes a limit of 0 or a negative number. It also fails with a raw TypeError when limit is not a number.

limit is read straight out of the tool arguments and used in the loop guard:

limit = args.get("limit", DEFAULT_LIMIT)
...
for entry in entries:
    if len(results) >= limit:
        entry_limit_reached = True
        break

With limit=0 the guard is already true for the first entry, so the loop breaks with nothing collected. The if not results: branch that follows cannot tell that apart from a genuinely empty directory, and answers (empty directory) — and returns status=success, so nothing looks wrong.

This matters more than a cosmetic slip: the model is told the directory is empty and will conclude the files are not there, then move on or ask the user to check their path. The entry_limit_reached notice is swallowed too, so there is no hint that anything was truncated.

Steps to reproduce

Directory containing alpha.txt, beta.txt, gamma.md:

>>> from agent.tools.ls.ls import Ls
>>> Ls().execute({"path": d, "limit": 0}).result
{'message': '(empty directory)', 'entries': []}
>>> Ls().execute({"path": d, "limit": -1}).result
{'message': '(empty directory)', 'entries': []}
>>> Ls().execute({"path": d, "limit": "10"}).result
"Error listing directory: '>=' not supported between instances of 'int' and 'str'"
>>> Ls().execute({"path": d, "limit": None}).result
"Error listing directory: '>=' not supported between instances of 'int' and 'NoneType'"
>>> Ls().execute({"path": d, "limit": 1.5}).result
{'output': 'alpha.txt\n\n[1.5 entries limit reached. Use limit=3.0 for more]', 'entry_count': 2, ...}

Expected: limit=0 / negative still list something and say the limit was reached; a non-numeric limit falls back to the default (or is rejected with a clear message) instead of raising TypeError.

Actual: as above — an empty directory is reported for a full one, and non-numeric values produce an internal error message rather than a listing.

Why this happens

limit is declared as an integer in the tool's JSON schema, but the schema is a hint to the model, not an enforcement boundary — the value is model output, and null, "20" and 1.5 all show up in practice. The tool never coerces or validates it before using it in a numeric comparison.

Note the last case: limit=1.5 does not raise, it silently truncates to a 2-entry listing and then reports the raw fraction back in the notice ("Use limit=3.0 for more"), which is not a value the model can meaningfully use.

Logs

Not applicable — reproducible directly through Ls().execute(...) as shown above; the empty-directory case returns status=success with no log line.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions