rtk icon indicating copy to clipboard operation
rtk copied to clipboard

rtk session and rtk discover can disagree on RTK adoption for the same transcript

Open KuSh opened this issue 3 months ago • 2 comments

Found by `/code-review max` while iterating on #3206.

`src/analytics/session_cmd.rs::count_rtk_commands` counts any `Classification::Supported` command as adopted RTK usage without checking whether the hook was actually installed or consulting the `hook_decisions` measured log — unlike `discover::run()`'s `hook_coverage`/`estimate_hook_coverage`, added by #3206, which now correctly answers "was this actually routed through RTK" using ground truth where available and a hook-installed-aware estimate otherwise.

Concretely: on a machine/project where RTK's hook was never installed, every `git status`, `grep -n foo`, etc. in a transcript was never actually rewritten — but `rtk session` still counts each one as "RTK" and reports a high adoption percentage, directly contradicting what `rtk discover` reports for the identical transcript data (which correctly shows them as missed savings).

A prior fixup (5b6ed49, per the review) only addressed the separate `rtk proxy`-counted-as-covered gap in this same function, not the hook-installed/measured-coverage gap.

Likely fix: have `count_rtk_commands` reuse the same coverage-determination logic `discover::run()` uses (or a shared extraction of it), rather than a separate simpler heuristic. Scoped as its own issue since it's a different command's counting logic, not part of #3206's stated scope (the `hook_decisions`-logging feature itself).

KuSh avatar Aug 23 '26 23:08 KuSh

wshm · Automated triage by AI

🔍 Automated Triage

🐛 Category bug
🟡 Priority medium
🎯 Confidence 90%

Summary

rtk session's count_rtk_commands treats all Classification::Supported commands as RTK-adopted without checking hook-installed status or hook_decisions log, causing it to disagree with rtk discover's more accurate coverage estimate for the same transcript; should reuse discover::run()'s hook_coverage/estimate_hook_coverage logic.

📁 Relevant files
  • src/analytics/session_cmd.rs
  • src/discover.rs

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

pszymkowiak avatar Aug 23 '26 23:08 pszymkowiak

Independent reproduction of this, with a clean natural experiment — the machine had rtk installed today, so every historical session is guaranteed to contain zero rtk-prefixed commands.

rtk session reported, for a transcript recorded two days before rtk existed on this machine:

Session      Date          Cmds   RTK  Adoption
d12edfdc     Yesterday     1674   588       35%

Ground truth from the same transcript file:

  • Bash tool_use entries: 969 (reported: 1674)
  • Of those, commands starting with rtk: 0 (reported: 588)
  • rtk's own history.db spans only today, 84 rows at the time of check; the Homebrew install receipt confirms the install happened today.
  • rtk discover on the same history says Already using RTK: 2 commands (0.0%), contradicting the 25% average rtk session prints.

So this is reproducible without any subtle state: with the hook installed for a matter of hours, rtk session still attributes ~35% adoption to sessions that predate the install — consistent with the count_rtk_commands / Classification::Supported diagnosis in the issue body.

Minor separate nit spotted alongside it: the Date column labeled that session "Yesterday" while the transcript file's mtime was two days earlier, so the day-bucketing looks off by one as well (possibly a UTC/local boundary issue — this machine runs UTC+8).

NashCC1550 avatar Aug 29 '26 07:08 NashCC1550