Skip to content

Exit-code inversions: a binary-file match becomes exit 1 (not found), a missing search root becomes exit 0 (success), and files under hidden directories are invisible to rtk find #3432

Open

Description

@HetCreep

Three differences from the real tools where rtk's answer is not merely shorter — it is the opposite verdict.

Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). All three run side by side against the real GNU tools on this machine; outputs verbatim.

1. A binary-file match is reported as "not found"

$ printf 'AKIA_SECRET\x00binary\n' > creds.bin

$ grep -rn AKIA creds.bin ; echo "exit=$?"
Binary file creds.bin matches
exit=0

$ rtk grep -rn AKIA creds.bin ; echo "exit=$?"
exit=1

src/cmds/system/search.rs:291 injects -I (--binary-files=without-match), which the user did not ask for. That suppresses the match — and because grep's exit 1 is the canonical "pattern not found", rtk asserts the opposite of the truth.

This matters most for the case people actually use grep's exit code for: if rtk grep -q AKIA . ; then now takes the wrong branch. A secret sitting in a .bin, a compiled artefact, or any file with a stray NUL is reported as absent, with a success-shaped exit.

-rl and -rc are unaffected (they still list creds.bin), so the mode that inverts is the plain search. Passing -a explicitly does restore the match.

2. A search root that does not exist returns exit 0

$ find /nope/nothere ; echo "exit=$?"
find: '/nope/nothere': No such file or directory
exit=1

$ rtk find /nope/nothere ; echo "exit=$?"
exit=0

Empty stdout, empty stderr, success. src/cmds/system/find_cmd.rs:232-235 does Err(_) => continue on walk errors, so "this path does not exist" and "this path exists and contains nothing" become the same answer — and the exit code affirms the search worked.

A typo'd path, a directory removed between steps, or a wrong assumption about the tree all read as "searched successfully, nothing there".

3. Files under hidden directories are invisible

$ find . -name '*.yml'
./.github/workflows/ci.yml

$ rtk find . -name '*.yml'
(nothing, exit 0)

find_cmd.rs:216-223 sets .hidden(!pattern.starts_with('.')), so any path component beginning with . is skipped unless the pattern itself starts with a dot. .github/, .circleci/, .config/, .vscode/ and their contents are unreachable.

Correcting something in my own reporting: I initially believed gitignored files were also invisible, because that walker sets .git_ignore(true) as well. They are not — in the same repository, with .gitignore containing *.log and secrets.txt, both rtk find . -name '*.log' → app.log and rtk find . -name 'secrets.txt' → secrets.txt returned their files normally. Only the hidden-path filter is live. I am flagging the correction because I nearly filed the wider claim.

Why these three together

All three share a shape: rtk answers a question with a confident negative that the underlying tool would have answered positively, and the exit code backs the wrong answer up. An agent has no way to distinguish "rtk searched and found nothing" from "rtk declined to look".

Suggested directions (untested — no programmer has reviewed these)

  1. Do not inject -I. If binary output is genuinely unwanted in the summary, keep grep's own Binary file … matches line and its exit status — that line is one token and carries the whole answer.
  2. Surface walk errors: report the failing root and exit non-zero, rather than continue. Distinguishing "not found" from "could not look" is the entire value of the exit code here.
  3. Either honour hidden paths by default (real find does) or state the exclusion in the output, the way the +N more marker does for the result cap. --hidden is currently rejected as an unknown flag, so there is no way to ask for them.

Two smaller ones from the same comparison

  • rtk find drops the trailing newline on its last line. With a final result of ไฟล์ไทย.txt, output ends ไฟล์ไทย.txt with no \n, so it concatenates with whatever prints next. Any $(rtk find …) piped into while read loses or corrupts the last entry.
  • Error messages name a binary that does not exist. rtk grep -rn X /nope reports /usr/bin/grep: C:/Program Files/Git/nope: No such file or directory — the path in the message is not the path passed, and /usr/bin/grep is not a path on this machine. Exit code 2 is correct; the diagnostic sends the reader to the wrong file.

Activity

  1. pszymkowiak commented on Aug 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 94%

    Summary

    rtk grep injects unrequested -I causing binary matches to report exit 1 (not found); rtk find swallows missing-root walk errors as exit 0 and hides all paths under dot-directories by default — fix search.rs:291 and find_cmd.rs:216-235 to preserve correct exit codes and hidden-path visibility.

    📁 Relevant files
    • src/cmds/system/search.rs
    • src/cmds/system/find_cmd.rs

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

  2. HetCreep commented on Aug 30, 2026

    @HetCreep
    Author

    Re-verified at develop @ 0de9610, with runs rather than reading. Two of the bullets in my original report were wrong and I am retracting them. The three claims in the issue title are still live.

    Provenance: AI-assisted source audit, human-directed, at develop @ 0de9610. All five sub-claims were executed against a binary built from this commit.

    Retracted — these were never rtk defects

    1. "error messages name a binary that does not exist." Running real grep with the identical argv (grep -n -H -I --null -e X -- /nope) emits the byte-identical /usr/bin/grep: …: No such file or directory. That is Git-for-Windows / MSYS2 path translation plus grep's own argv[0]; rtk forwards it verbatim. My report attributed it to rtk. It should not have been in the issue.
    2. The exploitation illustration if rtk grep -q AKIA . does not reproduce. -q is classified as a format flag (search.rs:779) and routed to passthrough without the injected -I, so it correctly returns exit 0. The exit-code inversion is real but confined to the plain and -rn search modes — my example picked the one mode where it does not happen.

    Fixed since the report

    The trailing-newline concatenation is repaired; output now goes through println! and a { rtk find …; echo NEXTLINE; }} marker test shows no concatenation.

    Still live

    • The injected -I still inverts the verdict on a binary match: rtk grep -rn AKIA creds.bin exits 1 where grep -rn AKIA creds.bin prints Binary file creds.bin matches and exits 0.
    • rtk find /nope/nothere still exits 0 with no output. The exists() guard added at find_cmd.rs:416 is inert for this input, because dispatch treats a first token that is not an existing directory as the pattern, so paths ends up empty and the search root defaults to ".", which exists. Confirmed for /nope/nothere, /nope/nothere -name '*.yml', and nosuchdir -name '*.yml'.
    • Hidden files are still unreachable — rtk find . -name '*.yml' returns nothing where real find returns ./.github/workflows/ci.yml, and no --hidden flag exists.

    One thing my report understated: the silent-success case is broader than the missing-path example. Err(_) => continue in the walk plus a hardcoded 0 exit also swallows mid-walk errors such as permission-denied or a subtree vanishing, even when the exists() precheck does fire.

  3. HetCreep commented on Sep 16, 2026

    @HetCreep
    Author

    Re-checked this against develop @ 5e0f92c, verified by reading the code at this commit (not by building or running it this pass). Status below, item by item. Short version: 2 and 4 are fixed, 5 is an environment artifact rather than an rtk bug, but 1 and 3 are both still open — please don't close this issue.

    1. grep on a binary match reports "not found" — still open, unchanged.
    search.rs:406-411 still returns -I unconditionally for Engine::Grep:

    fn parse_flags(self) -> &'static [&'static str] {
        match self {
            Engine::Grep => &["-n", "-H", "-I", "--null"],
            Engine::Rg => &["-n", "--with-filename", "--null"],
        }
    }

    applied at search.rs:434 (cmd.args(engine.parse_flags());) before any user-supplied flags at :435-437. Diffed this exact block against the 0de9610 state cited in the original report — no change at all. -I is grep's own --binary-files=without-match, so a match that lives inside a binary file is still silently skipped: rtk grep prints nothing and exits 1, where real grep prints Binary file <name> matches and exits 0.

    2. find on a missing search root reports "success" — fixed, fine to close this part.
    find_cmd.rs:415-418 now checks the path explicitly before walking:

    if !Path::new(path).exists() {
        eprintln!("find: '{}': No such file or directory", path);
        return Ok(1);
    }

    and it's actually reachable now, because find_cmd.rs:81-83's looks_like_path routes any slash-bearing token into the path branch regardless of whether it exists (previously a nonexistent path with a separator got read as an RTK -name pattern, silently defaulting the search root to .). This landed in 765b270 and 68dc719 — both commit-tagged "Fixes #3851", a different issue about the same missing-path symptom — so it reads as an independent fix rather than a response to this report. Crediting the actual commits, not claiming it, but thank you either way — this half is closed.

    3. find hides files under hidden/gitignored directories — improved, but please don't close.
    The gate itself hasn't moved: find_cmd.rs:459 (let search_hidden = pattern.starts_with('.');) and :463 (.hidden(!search_hidden)) are unchanged. What's new is disclose_filtered (find_cmd.rs:558-599, also added by 765b270/refined by 68dc719 — so this mitigation traces to the same #3851 work, not to this issue either), which now surfaces a "results were filtered" note instead of dropping them with no trace — a real improvement. But it only enumerates the immediate children of directories the ignore-walker itself visited, and a hidden directory is never visited, so nothing underneath it, at any depth, is named this way — only a trailing-slash marker for the hidden directory itself. So, e.g., a match at .github/workflows/ci.yml still can't be surfaced through rtk find in any form: the walker never visits .github/, so the disclosure can say .github/ at most, never the file inside it. This is confirmed as intended design, not an oversight — the project's own test at find_cmd.rs:1372-1410 (hidden_and_ignored_matches_are_collected_for_disclosure) builds a fixture with .hidden/h.txt and asserts:

    assert_eq!(filtered, vec![".hidden/".to_string(), "build/".to_string(), "secret.txt".to_string()]);

    h.txt is asserted to never appear, at any nesting depth, not just the shallow case in the original report. There's also no opt-out — --hidden/show_hidden don't appear anywhere in find_cmd.rs. Please leave this open: the actual matching file is still never nameable.

    4. find drops the trailing newline — fixed, fine to close this part.
    The final print for find output goes through emit_guarded (find_cmd.rs:739 → runner.rs:22), and runner.rs:22's println!("{}", shown) is unconditional — Rust's println! always appends a newline — so the trailing newline is present regardless of the internal trim/repush dance at find_cmd.rs:389/:729. Matches real find now.

    5. grep error names the wrong binary/path — unchanged, but not an rtk defect.
    search.rs still relays the child process's stderr verbatim (eprint!("{}", result.stderr) at three call sites, e.g. :575-576), so whatever the wrapped grep binary itself reports — its own MSYS name and Git-for-Windows path translation — is what shows through. That's the wrapped binary's own environment behavior, not something rtk generates. Same as originally reported; not something we think needs an rtk-side fix.

    Net: this stays a (C) correctness/conformance issue — an agent or script trusting rtk's exit code or output shape, not an exploitable path — same framing as the original report. But 1 and 3 are both still live, so please keep this open.

  4. HetCreep commented on Oct 14, 2026

    @HetCreep
    Author

    Re-checked on v1.0.0 (stable, 2026-10-13): the official release binary plus the v1.0.0 source. Provenance: AI-assisted check, human-directed. "ran" = executed against rtk 1.0.0 with a control; "read" = verified from source only.

    Fixed (ran): a missing find root. rtk find /nope/nothere now exits 1 with find: '/nope/nothere': No such file or directory. Hidden files are no longer fully invisible: rtk find . -name '*.yml' prints ... (1 filtered) and [+1 hidden: rtk recall X]. Thanks.

    Still live (ran vs /usr/bin controls):

    • Binary-match inversion: grep -rn AKIA creds.bin -> GNU exit 0 Binary file creds.bin matches; rtk grep -rn AKIA creds.bin -> exit 1, empty (-q, -c and -rl do find it, so only the plain mode inverts).
    • A sibling of the fixed case: rtk find nope -name x exits 0 silently; GNU find exits 1 No such file or directory.
    • A match inside a hidden directory is reachable only through rtk recall as the directory name (.github/), not as a path; --hidden is still rejected.

    Not re-checked: the trailing-newline claim and the error-path message.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions