Repository navigation
fix(gain): exclude zero-input rows from exec time totals - #4070
Conversation
📊 Automated PR Analysis
SummaryFixes rtk gain's exec time totals, which previously summed exec_time_ms across all rows including zero-input passthrough/fallback commands (like interactive rtk claude TUI sessions) that recorded the wrapped process's whole lifetime, skewing totals and averages. The fix adds a timed_commands field to track only commands with captured input, applying this filtering across the default summary, daily/weekly/monthly/all views (including TOTAL rows), and JSON/CSV exports, while leaving command count… Review Checklist
Linked issues: #4003 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
pszymkowiak
left a comment
There was a problem hiding this comment.
Thanks for this. Tested on current develop (merged locally, macOS): the fix works, but the branch needs a rebase before it can merge.
cargo test --allpasses (4115 tests) and the new tests fail without the fix.- On the same history, total exec time drops from 3.1s to 76ms once the zero-input fallback row is excluded.
To fix before merge: cargo fmt --check fails on the merge. develop is now on edition 2024, so the import in src/core/display_helpers.rs must be reordered. Please rebase on develop and run cargo fmt --all; that will also start CI, which has not run on this PR yet.
Optional: the per-command table still shows the full duration for the excluded row (get_by_command keeps AVG(exec_time_ms) over all rows).
9f9131f to
ae27a87
Compare
|
Rebased on |
pszymkowiak
left a comment
There was a problem hiding this comment.
Thanks for the rebase. Re-tested on current develop (merged locally, no conflicts): cargo fmt --check and cargo clippy --all-targets are clean, cargo test --all passes (4279), and the new tracking tests fail when the filter is reverted. On a seeded DB, rtk gain goes from ~13h to 600ms (avg 200ms), and the daily table and JSON export agree.
Approving; CI run approved too, good to merge once it is green. Two follow-ups, not blocking:
- The per-command table still shows e.g.
660m0son thertk fallback: clauderow under a600mstotal. input_tokens > 0also drops real filtered runs that produced no output (e.g.rtk grepwith no match: 3.3k rows in my own history). Keying on passthrough/fallback rows would be more precise.
`rtk gain` summed `exec_time_ms` over every tracked row. Rows recorded through the passthrough/fallback path carry no input (`input_tokens = 0`) and their duration is the wrapped process's whole lifetime, so a single interactive TUI launched as `rtk claude` adds hours of wall-clock time. On the reporter's install 131 such rows were 99.7% of `Total exec time` and inflated the average 865x (9m5s reported vs 1.15s of real filtering). Only rows with captured input now count toward the exec-time total and its average, in the summary and in the daily/weekly/monthly breakdowns (text, JSON and CSV), including the TOTAL row of the period tables. Command counts, token totals and savings percentages are unchanged. Closes rtk-ai#4003 Signed-off-by: Raymond Riter <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
ae27a87 to
fa4e847
Compare
Summary
rtk gainsummedexec_time_msover every row. Passthrough and fallback rows (input_tokens = 0) record the wrapped process's whole lifetime, for example an interactivertk claudeTUI session, so they dominatedTotal exec time. Ingain: interactive TUI sessions inflateTotal exec time865x — 131 rows are 99.7% of the reported total #4003 that was 99.7% of the total and made the average 865x too high.--daily/--weekly/--monthly/--all(including the TOTAL row), and the JSON and CSV exports.timed_commandshelper field isn't serialized.docs/usage/TRACKING.md.This implements option 1 from the issue. I deliberately left the "Total commands" count and the per-command table unchanged to keep the PR to one fix (the command-count side overlaps with #3522).
Closes #4003
Test plan
test_summary_exec_time_excludes_zero_input_rows,test_period_exec_time_excludes_zero_input_rows(tracking.rs) andtest_total_avg_time_ignores_untimed_commands(display_helpers.rs). They fail ondevelop(39600600 vs 600 ms; 120 vs 150 ms) and pass now.cargo fmt --all --check && cargo clippy --all-targets && cargo testpasses (3,784 passed, 0 failed, 0 clippy warnings)RTK_DB_PATHwith 4 filtered commands, a realrtk sleep 3fallback and an 11 hrtk fallback: clauderow:Total exec timegoes from660m3s (avg 110m0s)to262ms (avg 65ms). Tokens, savings and command counts are identical; the daily, JSON and CSV views agree.🤖 Generated with Claude Code