Skip to content

feat: add per-session task timing breakdown to session stats - #380

Open
thy950523 wants to merge 1 commit into
agegr:mainfrom
thy950523:feat/task-timing-comparison
Open

feat: add per-session task timing breakdown to session stats#380
thy950523 wants to merge 1 commit into
agegr:mainfrom
thy950523:feat/task-timing-comparison

Conversation

@thy950523

@thy950523 thy950523 commented Aug 4, 2026

Copy link
Copy Markdown

Summary

When comparing several models on the same task locally, I wanted to compare their total runtime and how each one handled its tool calls. But open any session and the UI only shows token counts and cost — there is no timing information at all. You can't see how long the model kept you waiting, how long the tools ran, or how long the whole task actually took. Without those numbers, comparing models comes down to timing it by hand with a stopwatch.

This PR adds a set of timing stats to the Session info panel so that model wait, tool execution, and total active time are visible at a glance.

Changes

New:

  • lib/session-timing.tscomputeSessionTiming(messages): walks the session's messages in order and buckets each gap between two messages; gaps that land right before a user message are treated as human idle and dropped.
  • lib/session-timing.test.mjs — 9 focused unit tests.

Edited:

  • lib/pi-types.ts — new SessionTiming type and a timing field on SessionStatsInfo.
  • lib/session-reader.ts — attach a timestamp to every plain message (previously only compaction/branch messages carried one; regular messages did not).
  • hooks/useAgentSession.ts — timing is always computed from the current session's own messages and merged into the stats, so it switches with the session and never leaks across sessions.
  • components/AppShell.tsx — a compact timing line at the bottom of the Session info panel.
  • lib/i18n/messages/{en,zh-CN}.ts — 4 new strings.

Net: 8 files, +198 / −4.

What each time measures

The panel shows three numbers:

  • Model wait — the time from "the previous step finished" to "the model finished its full reply"; in other words, the time you spend waiting for the model to answer.
    model wait = network transfer + model generation (accumulated once per model reply; a single task usually has many replies, since the model replies again after every tool call)

  • Tool execution — the time a tool actually runs when the model calls one (running a bash command, reading/writing files, etc.).
    tool exec = tool runtime (accumulated once per tool call, from when the model issues the call to when the tool returns)

  • Total active — all the time the agent was actually working.
    total active = model wait + tool exec + other housekeeping ("other housekeeping" is usually 0 and only appears for things like context compaction)

One important detail: total active excludes the time you spend reading a reply, thinking, and typing your next message — that is human idle and is dropped. That keeps different models on the same yardstick when running the same task, so the comparison is fair.

Testing

  • npx tsc --noEmit — clean.
  • npm run lint — clean.
  • node --test lib/session-timing.test.mjs — 9/9 pass.
  • Verified end-to-end against a real 221-message session: all 221 messages carried timestamps, and the three numbers are self-consistent (model wait 28m20s + tool exec 12m38s = total active 40m58s).

ScreenShot

image

Adds a compact timing footer to the Session info panel that decomposes a
session's active time into model-wait, tool-execution, and a total —
excluding gaps where the user was idle, so the total reflects only time the
agent was actually working. Derived from existing per-entry timestamps, so
it works for both historical and live sessions without changes to pi.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@thy950523
thy950523 marked this pull request as ready for review August 4, 2026 08:01
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.

1 participant