Skip to content

fix: ls tracking baseline should compare against ls not ls -la #561

Open

Description

@pszymkowiak

Problem

rtk ls internally runs ls -la to get file metadata for grouping/filtering, then compresses the output. The savings % is tracked against the ls -la output, not plain ls (which is what the agent would have run without RTK).

This inflates the reported savings. Example from user report:

  • ls = 332 tokens
  • ls -la = 4173 tokens
  • rtk ls = 993 tokens
  • Reported: 76.2% savings (vs ls -la)
  • Actual: -199% vs plain ls

Fix

Track against the baseline command the agent would have run (ls), not the internal enriched command (ls -la).

In src/ls.rs line 113-118, change the tracking input from the ls -la raw output to a plain ls capture (or estimate).

Reference

https://www.reddit.com/r/ClaudeAI/comments/1rjkf9r/comment/oa3trnn/

Activity

  1. added
    bug
    effort-small
    filter-quality
    good first issue
    and removed
    bug
    filter-quality
    good first issue
    effort-small
    on Mar 20, 2026
  2. pszymkowiak commented on Mar 20, 2026

    @pszymkowiak
    CollaboratorAuthor

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 96%

    Summary

    ls savings baseline uses ls -la instead of ls, inflating reported savings; fix is localized to src/ls.rs and PR #760 is already in progress.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/ls.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. lntutor commented on Jul 19, 2026

    @lntutor
    Contributor

    I am implementing this against current develop after the inactive PR #760 was closed. I will add an explicit tracking baseline to the shared runner, capture the exact user-facing ls invocation separately, and keep the enriched ls -la output only for filtering and display guards.

  4. randomparity commented on Aug 24, 2026

    @randomparity

    Independent reproduction — still present on master @ b34be37 and in v0.45.0, on macOS arm64.

    I hit this while benchmarking RTK inside a coding harness and arrived at the same root cause before finding this issue. Adding fresh numbers since the report is from March.

    The unconditional -la is at src/cmds/system/ls.rs:53, and the tracked baseline is the synthesised command at ls.rs:87 (&format!("-la {}", target_display)):

    let mut cmd = resolved_command("ls");
    cmd.env("LC_ALL", "C");
    cmd.arg("-la");                     // always, whatever the user asked for

    Note the flag filter below it strips only l, a, and h, so other flags survive and combine with the injected -la. That means the effect is not limited to plain ls — it also applies to ls -R, where the enrichment is much more expensive:

    $ ls -R src        | wc -c      #  6,926   what the agent would have run
    $ ls -la -R src    | wc -c      # 33,692   what RTK runs internally
    $ rtk ls -R src    | wc -c      #  8,956   what RTK returns

    Recorded by RTK for that invocation:

    original_cmd | input_tokens | output_tokens | saved_tokens | savings_pct
    ls -la src   |         8423 |          2239 |         6184 |        73.4
    

    So RTK reports 73.4% saved while returning 29% more than the agent's own command. Two further details worth noting:

    • original_cmd is recorded as ls -la src — the synthesised command, not the ls -R src that was actually issued — so the row cannot be reconciled against the agent's transcript after the fact.
    • The regression is invisible in aggregates regardless, because saved_tokens is computed with saturating_sub on usize and floors to zero. I filed that separately as rtk gain cannot represent a regression: saturating_sub floors negative savings to zero #3702; fixing this issue alone would still not let rtk gain show the negative cases.

    Happy to test a patch against my fixture if that's useful.

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

    area:clibugeffort-smallfilter-qualitygood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions