Skip to content

fix(gain): exclude zero-input rows from exec time totals - #4070

Merged
KuSh merged 1 commit into
rtk-ai:developfrom
Raymondriter:fix/gain-interactive-exec-time
Oct 19, 2026
Merged

KuSh merged 1 commit into
rtk-ai:developfrom
Raymondriter:fix/gain-interactive-exec-time

Conversation

@Raymondriter

Copy link
Copy Markdown
Contributor

Summary

  • rtk gain summed exec_time_ms over every row. Passthrough and fallback rows (input_tokens = 0) record the wrapped process's whole lifetime, for example an interactive rtk claude TUI session, so they dominated Total exec time. In gain: interactive TUI sessions inflate Total exec time 865x — 131 rows are 99.7% of the reported total #4003 that was 99.7% of the total and made the average 865x too high.
  • Only rows with captured input now count toward the exec-time total and average. That covers the default summary, --daily/--weekly/--monthly/--all (including the TOTAL row), and the JSON and CSV exports.
  • Command counts, token totals and savings percentages are unchanged. The JSON/CSV schemas are unchanged too: the new timed_commands helper field isn't serialized.
  • Documented the rule in 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

  • New tests test_summary_exec_time_excludes_zero_input_rows, test_period_exec_time_excludes_zero_input_rows (tracking.rs) and test_total_avg_time_ignores_untimed_commands (display_helpers.rs). They fail on develop (39600600 vs 600 ms; 120 vs 150 ms) and pass now.
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test passes (3,784 passed, 0 failed, 0 clippy warnings)
  • Manual check against an isolated RTK_DB_PATH with 4 filtered commands, a real rtk sleep 3 fallback and an 11 h rtk fallback: claude row: Total exec time goes from 660m3s (avg 110m0s) to 262ms (avg 65ms). Tokens, savings and command counts are identical; the daily, JSON and CSV views agree.

🤖 Generated with Claude Code

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added analytics bug Something isn't working tracking labels Sep 14, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes 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

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4003


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

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --all passes (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).

@Raymondriter
Raymondriter force-pushed the fix/gain-interactive-exec-time branch from 9f9131f to ae27a87 Compare October 5, 2026 17:59
@Raymondriter

Copy link
Copy Markdown
Contributor Author

Rebased on develop and ran cargo fmt --all, so the display_helpers.rs import order is fixed. Locally, fmt and clippy are clean and cargo test --all passes (4164). Could you approve the workflow run so CI can go? Leaving the per-command table averaging for a follow-up unless you want it in this PR.

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 660m0s on the rtk fallback: claude row under a 600ms total.
  • input_tokens > 0 also drops real filtered runs that produced no output (e.g. rtk grep with no match: 3.3k rows in my own history). Keying on passthrough/fallback rows would be more precise.

@pszymkowiak
pszymkowiak requested a review from aeppling October 12, 2026 18:25
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics bug Something isn't working tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gain: interactive TUI sessions inflate Total exec time 865x — 131 rows are 99.7% of the reported total

3 participants