You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Top Sessions currently ranks by wall-clock duration, computed as the gap between started_at and ended_at. That overstates sessions left idle, a terminal left open overnight dominates the ranking even if actual tool work lasted only a few minutes. The underlying per-turn timing data already exists and powers the per-session timing endpoint, but the analytics aggregation path never uses it.
This change adds an explicit active_duration_min field to the Top Sessions contract, computed from the same tool-turn timing semantics the repo already uses elsewhere, and switches the duration ranking to use that active value across the SQLite, PostgreSQL, and DuckDB analytics backends. The existing duration_min field stays populated so total session time remains visible to users as secondary context, which keeps the “show both” part of the issue intact.
On the frontend, the duration view now reads as active or tool time, uses the active value as the primary metric, keeps total duration available alongside it, and routes the new tooltip text through the existing Paraglide message surface. Focused backend regression tests cover the case where wall-clock duration and active duration disagree, the SQLite DST fallback path, DuckDB parity, PostgreSQL running-session null handling, and the ranking helper, while the Top Sessions frontend test proves the new display contract.
Problem: Active duration is rounded before ranking in the SQLite SQL path, the SQLite Go fallback, and the DuckDB path. Because the duration query orders and limits on that rounded value, sessions that differ by less than 0.05 minutes can be misordered or excluded from the top 10. This also disagrees with the PostgreSQL path, which sorts before rounding.
Fix: Keep active duration as a raw minute value through ordering/sorting and truncation, then round only in rankTopSessions or immediately before returning the response.
Do you want me to hold? I traced both paths and they are different:
current PR code: sums tool-use turn durations
velocity: sums every positive gap between consecutive messages, capped at 5 minutes per gap
That means the current branch can undercount reasoning-heavy, low-tool sessions. I was about to patch top-session duration to reuse the velocity calculation across SQLite, PostgreSQL, DuckDB, and the SQLite fallback and see how the totals net out, but I can switch things up based on your direction.
Even with this change, the top results are still very long sessions, and the new active-duration values stay close to total duration on my data. It does knock out the worst idle outliers, so it is moving in the right direction, but it still is not measuring activity the way the velocity view does. I'm reworking this to reuse the "active minutes" concept from velocity so long idle gaps are capped consistently and the Top Sessions ranking lines up better with actual active work.
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
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.
Top Sessions currently ranks by wall-clock duration, computed as the gap between
started_atandended_at. That overstates sessions left idle, a terminal left open overnight dominates the ranking even if actual tool work lasted only a few minutes. The underlying per-turn timing data already exists and powers the per-session timing endpoint, but the analytics aggregation path never uses it.This change adds an explicit
active_duration_minfield to the Top Sessions contract, computed from the same tool-turn timing semantics the repo already uses elsewhere, and switches the duration ranking to use that active value across the SQLite, PostgreSQL, and DuckDB analytics backends. The existingduration_minfield stays populated so total session time remains visible to users as secondary context, which keeps the “show both” part of the issue intact.On the frontend, the duration view now reads as active or tool time, uses the active value as the primary metric, keeps total duration available alongside it, and routes the new tooltip text through the existing Paraglide message surface. Focused backend regression tests cover the case where wall-clock duration and active duration disagree, the SQLite DST fallback path, DuckDB parity, PostgreSQL running-session null handling, and the ranking helper, while the Top Sessions frontend test proves the new display contract.
Fixes #83