Repository navigation
fix(discover): distinguish zero-session scans - #3374
Conversation
# Conflicts: # src/discover/report.rs
A zero-session scan can come from three scopes: `--all`, `-p <filter>` and the current-directory default. The report carried a two-way flag, so a `-p` miss was described as a current-project miss and pointed at `--all` instead of at the filter. Carry the scope as an enum, print the filter or the encoded directory name and the day window in every message, and keep JSON output unchanged. Tests cover each scope, the agent notes on the zero-session path, and the JSON invariance. Co-Authored-By: Claude Fable 5.1 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — APPROVED, follow-ups filed
Claim: a rtk discover scan that found zero sessions no longer prints "No missed savings found. RTK usage looks good!" and instead says what was scanned and points at --all.
Scope: accept (round 1, frozen). No other open PR touches the zero-session branch; #4143's copy of it was closed as a duplicate of this one.
Ran: rtk discover on the real ~/.claude/projects store (1 355 sessions) and on three empty scopes (cwd with no transcripts, -p with no match, --all under an empty and under a missing ~/.claude), text and -f json, --help, -v, exit codes, on merge-base, head and head-merged-onto-develop binaries (distinct md5s); invariants: every branch of the new decision, split streams (-v stderr), under the hook (rtk rewrite "rtk discover --all" returns it unchanged, exit 3). Savings floor not applicable: discover is a meta command, not a filter. Gates on head and on the merge: fmt clean, clippy 0 warnings, 2 564 / 3 801 tests green. Mutants: unreachable early return fails both new tests; dropping the agent notes on the zero path survived on the head (fixed in the fixup).
Matrix: executed this round.
CI @22ae255a: all green (10 jobs: fmt, clippy, tests on ubuntu/macos/windows, semgrep, security scan, benchmark, doc review, test presence; plus CLA). The original head 2398f8c was never built by CI (its run expired unapproved with 0 jobs) and conflicted with develop.
Blocks merge (0)
Filed as follow-ups
- #2834 —
-p <filter>with no match printed the same all-clear; the fixup's message now names the filter, the matching rule and the window, so the false all-clear half of that issue is covered here and the absolute-path matching half stays open there (comment added). - #4314 —
rtk learnprints "No Claude Code sessions found in the last N days." for all three scopes, so the cwd-default narrowing this PR fixes indiscoveris still silent inlearn— outside this PR's hunks (src/learn/mod.rs), filed as its own issue.
Checked and correct — no need to re-verify
- Ordering against develop's newer
rtk_disabled_count == 0condition: with zero sessions every counter is zero, the zero-session return comes first and the estimate caveat above it prints nothing. - JSON output for a zero-session scan is byte-identical across
--all,-pand the default, and identical to develop's shape; the scope stays out of the schema. - Non-empty scans are unchanged (only live-session drift between runs).
- Exit code stays 0 on zero sessions;
discoveris a report, not a check, and agents that call it under the hook should not see a failure for an empty scan. - Agent notes (Cursor/Hermes/Copilot) still print on the zero-session path.
Your questions
- none asked.
Next
fixup 22ae255 pushed on top of a develop merge (99be1f3): the two-way all_projects flag became a three-way ScanScope (--all / -p <filter> / cwd) so a -p miss no longer says "current project" and no longer points away from the filter; every message names the filter or the encoded directory and the day window; tests per scope, for the agent notes on the zero path and for JSON invariance — approving once CI is green on that head.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
learn defaulted every empty scan to "No Claude Code sessions found in the last N days", even when the miss was a cwd or -p filter. discover already carries ScanScope after rtk-ai#3374; reuse that enum via a shared zero_session_message helper and print the matching hint with `rtk learn --all` for the two narrowed scopes. Fixes rtk-ai#4314
learn defaulted every empty scan to "No Claude Code sessions found in the last N days", even when the miss was a cwd or -p filter. discover already carries ScanScope after rtk-ai#3374; reuse that enum via a shared zero_session_message helper and print the matching hint with `rtk learn --all` for the two narrowed scopes. Fixes rtk-ai#4314
learn defaulted every empty scan to "No Claude Code sessions found in the last N days", even when the miss was a cwd or -p filter. discover already carries ScanScope after rtk-ai#3374; reuse that enum via a shared zero_session_message helper and print the matching hint with `rtk learn --all` for the two narrowed scopes. Fixes rtk-ai#4314
Summary
rtk discover --all--allwhen an all-project scan found no sessions in the selected time rangeAddresses the zero-session reporting defect in #3315. Node and PowerShell filter requests remain out of scope.
Root cause
The empty-report branch only checked whether the supported and unsupported command lists were empty. A scan with no session files produces the same empty lists as a successful scan with no missed savings, so both received the same all-clear message.
The report now carries the scan scope internally and handles
sessions_scanned == 0before the genuine no-missed-savings branch.Validation
cargo test test_zero_sessions_does_not_report_successfailed before the fix and passed afterwardcargo test zero_sessions— 2 passedcargo fmt --all -- --check— passedcargo clippy --all-targets -- -D warnings— passedcargo test --all— 2,564 unit tests passed, 8 ignored; 64 integration tests passedRisk and rollback
Only text output for zero-session scans changes. JSON output remains schema-compatible because the internal scan-scope field is skipped during serialization. Non-empty scans and genuine clean scans keep their existing output. Rollback is limited to reverting this commit.
AI assistance
Prepared with Codex assistance. Candidate duplication, repository policy, the diff, and all reported validation results were reviewed before submission.