Skip to content

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

Closed

Description

@chadalanlester

Summary

rtk gain reports Total exec time and a derived average. Any long-running
interactive command wrapped by rtk — e.g. launching a TUI as rtk claude —
records its entire session lifetime into exec_time_ms. Those rows filter
nothing (input_tokens = 0), but they completely dominate the time aggregate.

rtk 0.49.0, macOS arm64, 90-day window:

reported:  Total exec time: 92607m0s   (avg 9m5s)

Split by row kind:

kind rows input_tok saved_tok minutes
rtk fallback: … 4,608 0 0 92,499
real (filtered) commands 5,590 21,145,470 11,049,817 107

Within the fallback class, 131 rows of rtk fallback: claude alone account for
92,358 minutes — 99.7% of the reported total
— averaging 11.75 h each, max 75.4 h
(a session left open over a weekend).

Actual filtering work is 107 minutes across 5,590 commands, avg 1.15 s. The
reported avg 9m5s is an 865x overstatement, and Total exec time is really
measuring how long the TUI was open.

Reproduce

-- against a COPY of history.db
SELECT CASE WHEN rtk_cmd LIKE 'rtk fallback%' THEN 'fallback' ELSE 'real' END AS kind,
       COUNT(*)              AS rows_,
       SUM(input_tokens)     AS input_tok,
       SUM(exec_time_ms)/60000 AS minutes
FROM commands GROUP BY kind;

-- the offenders
SELECT rtk_cmd, COUNT(*) n, SUM(exec_time_ms)/60000 minutes, MAX(exec_time_ms)/60000 max_min
FROM commands WHERE rtk_cmd LIKE 'rtk fallback%' GROUP BY rtk_cmd ORDER BY minutes DESC LIMIT 5;

Why this isn't just "don't do that"

Wrapping a TUI is a reasonable thing for a user to try, and rtk accepts it silently:
rtk claude runs, the row is recorded, no warning is emitted. The stats then become
unreadable with no indication why.

Worth noting the hook is not involved — rtk hook check "claude" correctly
returns No rewrite for: claude. This is the direct rtk <cmd> path, and
[hooks] exclude_commands in config.toml has no effect on it.

Suggested fix

Any one of these would be sufficient:

  1. Exclude zero-token rows from the time aggregate. A row with input_tokens = 0
    did no filtering work, so its duration isn't rtk's to report. This also fixes the
    command count, which is inflated 10,198 → 5,590 on this install.
  2. Cap or flag outlier durations. Anything past a threshold (~60 s) is almost
    certainly an interactive or long-running process, not a filter operation.
  3. Report median duration beside the mean, consistent with gain: add median and concentration to the summary — means alone hide what the tool is actually doing #3507.
  4. Optionally, warn when rtk is asked to wrap a known interactive TUI.

Related

Same family of accounting defects, but a different aggregate — none of these cover
the time column:

Activity

  1. rtk-wshm-sync-bot commented on Sep 12, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 86%

    Summary

    gain's Total exec time aggregate is dominated by interactive TUI session durations (zero-token fallback rows); exclude zero-token rows or cap outlier durations in the time aggregate, and report median alongside mean


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

  2. added a commit that references this issue on Oct 5, 2026
    ae27a87
  3. added a commit that references this issue on Oct 18, 2026
    fa4e847
  4. added 2 commits that reference this issue on Nov 2, 2026
    fd68451
    e3dc290
  5. chadalanlester commented on Nov 18, 2026

    @chadalanlester
    Author

    Thank you!

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

    area:clibugpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions