feat: add per-session task timing breakdown to session stats - #380
Open
thy950523 wants to merge 1 commit into
Open
feat: add per-session task timing breakdown to session stats#380thy950523 wants to merge 1 commit into
thy950523 wants to merge 1 commit into
Conversation
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
marked this pull request as ready for review
August 4, 2026 08:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ts—computeSessionTiming(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— newSessionTimingtype and atimingfield onSessionStatsInfo.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.ScreenShot