Skip to content

fix(speed): count each API call once in token speed widgets - #735

Merged
sirmalloc merged 2 commits into
sirmalloc:mainfrom
effectustasi:fix/speed-streaming-duplicates
Oct 29, 2026
Merged

sirmalloc merged 2 commits into
sirmalloc:mainfrom
effectustasi:fix/speed-streaming-duplicates

Conversation

@effectustasi

Copy link
Copy Markdown
Contributor

The Input, Output and Total Speed widgets count one API call several times when it is written as several transcript entries that share a message.id (the same streaming duplicates #278 handled for token totals). The speed collector added each entry as its own request, so the call's input tokens were counted once per entry and its output was the sum of the growing per-entry counts. In a session with one call written as three entries, Output Speed showed 13.0 t/s instead of 8.0 t/s.

Entries that share the previous request's message.id now update that request instead of adding another: input from the latest entry, the largest output, and the latest end time. Entries without an id are counted as before. A new test in jsonl-metrics.test.ts covers this; it fails on main and passes with the fix.

Claude Code can write one API call as several transcript entries that
share a message.id and repeat its usage. The speed collector added every
entry as its own request, so Input, Output and Total Speed summed the
call's tokens once per entry. Entries sharing the previous request's
message.id now update that request instead.
@eric-engberg

Copy link
Copy Markdown
Contributor

Quick heads-up: the token totals still have the same message.id double-count on main (tracked in #549), and a few other open PRs are working on it. #591, #595 and #622 each cover the speed widgets as well as the token totals, #725 covers the token totals (so it complements this one), and #587 includes its own version of both alongside its cost widgets. Might be worth comparing notes so the speed and token sides can land as one version.

@sirmalloc
sirmalloc merged commit 39ea0d3 into sirmalloc:main Oct 29, 2026
3 checks passed
sirmalloc added a commit to iy88/ccstatusline that referenced this pull request Oct 29, 2026
Preserve maximum-output accounting and context snapshots from sirmalloc#725 and sirmalloc#735 while deduplicating nonconsecutive message IDs. Keep independent timing intervals and subagent collectors, retain both sets of regression tests, and compute speed window bounds once.
pcvelz added a commit to pcvelz/ccstatusline-usage that referenced this pull request Nov 2, 2026
Upstream: weekly limit timers (sirmalloc#768), prompt cache miss widgets (sirmalloc#770), context window size env override (sirmalloc#352, sirmalloc#407), windowed speed fixes (sirmalloc#769, sirmalloc#771), separator/renderer fixes (sirmalloc#773), custom-command styling (sirmalloc#775), clickable cwd links (sirmalloc#744), account email from live credentials (sirmalloc#724), cache timer reported expiry + short toggle (sirmalloc#576, sirmalloc#592), claude-status lock (sirmalloc#635, sirmalloc#772), dedup token metrics (sirmalloc#622, sirmalloc#725, sirmalloc#735).
Not adopted: sirmalloc#765 terminal width from COLUMNS with fixed reserve - the fork keeps flexMode/compactThreshold and tmux pane priority.

Hand edits outside conflicts:
- README.md: kept fork Configure flex separator behavior bullet and older-updates details wrapper; dropped upstream Related Projects additions (claude-eta)
- AGENTS.md: kept fork terminal width wording (sirmalloc#765 not adopted)
- src/types/FlexMode.ts, src/tui/components/TerminalWidthMenu.tsx, src/tui/components/__tests__/TerminalWidthMenu.test.ts, src/tui/components/TerminalOptionsMenu.tsx, src/tui/components/__tests__/TerminalOptionsMenu.test.ts: restored, fork keeps terminal width settings
- src/tui/App.tsx, src/tui/components/index.ts, src/types/index.ts: re-wired terminal width menu and FlexMode export
- src/types/StatusJSON.ts: dropped fork duplicate prompt_cache key, upstream schema is a superset
- src/utils/terminal.ts: COLUMNS source gated on non-tmux so tmux pane width keeps priority
- src/widgets/WeeklyLimitTimer.ts, src/utils/usage-prefetch.ts, src/widgets/__tests__/WeeklyLimitTimer.test.ts: compat fix - fableUsage/fableResetAt -> weeklyFableUsage/weeklyFableResetAt
- src/widgets/ApiUsage.tsx: compat fix - Context Bar honors effective context window (override, clamp, 1.0M format); Weekly renders a valid value despite a session error
- src/widgets/__tests__/ApiUsage.localModelFallback.test.ts: output tokens no longer counted in context (upstream sirmalloc#730)
- src/utils/__tests__/renderer-flex-width.test.ts, src/utils/__tests__/renderer-ansi.test.ts, src/utils/__tests__/gradient.test.ts, src/utils/__tests__/renderer-separator-collapse.test.ts, src/utils/__tests__/config.test.ts, src/tui/__tests__/App.test.ts: fork deviation - fork width model (flexMode, 6-column full reserve, kept settings, Terminal Width menu entry)
- src/utils/__tests__/default-colors.test.ts: fork deviation - accept ansi256:/hex: defaults
- src/utils/__tests__/usage-prefetch.test.ts: fork deviation - weekly usage comes from the API, fork widget imports from ApiUsage
- src/widgets/__tests__/CurrentWorkingDir.test.ts, src/widgets/__tests__/CustomCommand.test.ts: Settings literal gains flexMode/compactThreshold
- src/utils/__tests__/context-window.test.ts, src/utils/__tests__/jsonl-metrics.test.ts: restored fork tests upstream dropped
- docs/test-retirements.md: ledger for the dev-reload snapshot-path and RemoteControlStatus glyph (sirmalloc#605) tests upstream replaced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants