Skip to content

discover: the example command shown for a bucket changes between runs on the same history #4313

Open

Description

@KuSh

rtk discover prints one example command per bucket in its report. On the same unchanged ~/.claude/projects/ tree, the example for one bucket flips between runs of the same binary while the count and the estimate stay the same.

Observed on develop c529013e (Linux, LC_ALL=C, stdin from /dev/null) against a 6-project history tree with two git commands in one bucket, five runs each of rtk discover --all and rtk discover -p "":

< git status                   2    rtk git            existing      ~168 tokens
> git log                      2    rtk git            existing      ~168 tokens

The label came back status, log, log, log, status on --all and log, status, log, status, status on -p ""; count 2 and ~168 tokens never changed. Exit code 0 every time.

Where to look: the bucket keeps the first command it sees as its example (src/discover/mod.rs, the or_insert_with on the bucket maps around lines 478-492), and the order commands arrive in depends on fs::read_dir order in src/discover/provider.rs::discover_sessions_in_projects_dir and on HashMap iteration in src/discover/mod.rs. Neither is sorted before the example is chosen. Whichever one it is, a deterministic pick (sort the session paths, or keep the most frequent spelling) would make two runs of rtk discover on the same history produce the same report, which also matters for anyone diffing its --format json output.

Found while reviewing #2931; unrelated to that change (both the merge-base and the PR binaries show it).

Activity

  1. added
    bug
    good first issue
    on Sep 27, 2026
  2. rtk-wshm-sync-bot commented on Sep 27, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟢 Priority low
    🎯 Confidence 90%

    Summary

    discover's per-bucket example command is chosen non-deterministically from unsorted dir/HashMap iteration, making repeated runs on the same history produce different (though still correct) reports.

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

    📁 Relevant files
    • src/discover/mod.rs
    • src/discover/provider.rs

    Suggested Actions

    1. Sort session paths before iterating in discover_sessions_in_projects_dir (src/discover/provider.rs)
    2. Make the or_insert_with example pick deterministic in src/discover/mod.rs (lines ~478-492), e.g. lexicographic or most-…
    3. Add a regression test running discover twice on a fixed fixture tree and diffing --format json output

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

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:clibuggood first issuepriority:low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions