fix(tui): correct session details for selected periods - #219
Conversation
Skip recommended plugin metadata when choosing the session title so the first real user prompt remains visible in TUI details. Signed-off-by: jimyag <git@jimyag.com>
Track per-day session activity and usage so period drill-down includes continued and archived sessions while showing only usage from the selected period. Signed-off-by: jimyag <git@jimyag.com>
|
Warning Review limit reached
Next review available in: 5 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds daily session aggregates for messages, statistics, and models. Contribution-cache operations merge and reverse daily data. TUI period filtering uses daily aggregates. Codex title selection ignores ChangesDaily Session Activity
Codex Session Title Filtering
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/tui.rs (1)
251-287: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid cloning the full
dailymap when it is discarded immediately.
sessions_for_periodclones the whole session, includingdaily: BTreeMap<CompactDate, SessionPeriodAggregate>, then overwritesfiltered.stats/filtered.models(lines 268-270) and never readsfiltered.dailyagain.draw_session_stats_table(lines 2131-2137) calls this function on every render, so this clones history-proportional data for every visible session on every draw.Build
filteredfield-by-field instead of cloning the whole struct, skippingdailyentirely, since it is not consumed by the caller.⚡ Proposed fix
- let mut filtered = session.clone(); - filtered.stats = TuiStats::default(); - filtered.models = ModelCounts::new(); + let mut filtered = SessionAggregate { + session_id: session.session_id.clone(), + first_timestamp: session.first_timestamp, + analyzer_name: Arc::clone(&session.analyzer_name), + stats: TuiStats::default(), + models: ModelCounts::new(), + session_name: session.session_name.clone(), + date: session.date, + daily: BTreeMap::new(), + };Also applies to: 2131-2137
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tui.rs` around lines 251 - 287, Update sessions_for_period to construct each filtered SessionAggregate field-by-field instead of cloning the full session, preserving the required non-daily fields while initializing filtered.stats and filtered.models as currently done. Omit the daily map entirely because draw_session_stats_table only consumes the aggregated result; retain the existing empty-daily and has_activity filtering behavior.src/contribution_cache/mod.rs (1)
307-317: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract a shared helper for the daily-activity merge/reverse loop.
The daily-merge loop at lines 307-317 repeats at lines 352-367, 396-407, and 454-469. All four blocks update
message_count,ai_message_count,stats, andmodelson aBTreeMap<CompactDate, SessionPeriodAggregate>, differing only insaturating_add/saturating_subandincrement/decrement. Extract two helper functions (merge_daily_addandmerge_daily_subtract) to remove this duplication. This also reduces the risk of one copy drifting from the others when a new field is added toSessionPeriodAggregate.♻️ Proposed helper extraction
fn merge_daily_add( dst: &mut BTreeMap<CompactDate, SessionPeriodAggregate>, src: &BTreeMap<CompactDate, SessionPeriodAggregate>, ) { for (date, activity) in src { let daily = dst.entry(*date).or_default(); daily.message_count = daily.message_count.saturating_add(activity.message_count); daily.ai_message_count = daily .ai_message_count .saturating_add(activity.ai_message_count); daily.stats += activity.stats; for &(model, count) in activity.models.iter() { daily.models.increment(model, count); } } } fn merge_daily_subtract( dst: &mut BTreeMap<CompactDate, SessionPeriodAggregate>, src: &BTreeMap<CompactDate, SessionPeriodAggregate>, ) { for (date, activity) in src { if let Some(daily) = dst.get_mut(date) { daily.message_count = daily.message_count.saturating_sub(activity.message_count); daily.ai_message_count = daily .ai_message_count .saturating_sub(activity.ai_message_count); daily.stats -= activity.stats; for &(model, count) in activity.models.iter() { daily.models.decrement(model, count); } } } dst.retain(|_, activity| activity.message_count > 0); }Then each call site becomes a single line, e.g.
merge_daily_add(&mut existing.daily, &contrib.daily);.Also applies to: 352-367, 396-407, 454-469
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/contribution_cache/mod.rs` around lines 307 - 317, Extract the repeated daily-activity loops into shared merge_daily_add and merge_daily_subtract helpers operating on the BTreeMap<CompactDate, SessionPeriodAggregate>. Preserve the existing saturating add/subtract, stats, model increment/decrement, and subtraction cleanup behavior, then replace the four duplicated blocks in the surrounding merge/reverse flows with calls to the appropriate helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/analyzer.rs`:
- Around line 316-321: In the session reset logic that initializes
`session.daily` activities, also reset each activity’s `message_count` and
`ai_message_count` to zero alongside `activity.stats` and `activity.models`.
Keep the existing session-level resets unchanged so the skeleton does not retain
message counters before incremental contributions are applied.
---
Nitpick comments:
In `@src/contribution_cache/mod.rs`:
- Around line 307-317: Extract the repeated daily-activity loops into shared
merge_daily_add and merge_daily_subtract helpers operating on the
BTreeMap<CompactDate, SessionPeriodAggregate>. Preserve the existing saturating
add/subtract, stats, model increment/decrement, and subtraction cleanup
behavior, then replace the four duplicated blocks in the surrounding
merge/reverse flows with calls to the appropriate helper.
In `@src/tui.rs`:
- Around line 251-287: Update sessions_for_period to construct each filtered
SessionAggregate field-by-field instead of cloning the full session, preserving
the required non-daily fields while initializing filtered.stats and
filtered.models as currently done. Omit the daily map entirely because
draw_session_stats_table only consumes the aggregated result; retain the
existing empty-daily and has_activity filtering behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9d523b55-dda8-4741-b01b-e92842d9c751
📒 Files selected for processing (12)
src/analyzer.rssrc/analyzers/codex_cli.rssrc/analyzers/tests/codex_cli.rssrc/contribution_cache/mod.rssrc/contribution_cache/single_session.rssrc/contribution_cache/tests/basic_operations.rssrc/contribution_cache/tests/mod.rssrc/contribution_cache/tests/single_session.rssrc/tui.rssrc/tui/logic.rssrc/tui/tests.rssrc/types.rs
Reset daily counters before applying new contributions, centralize daily merge logic, and avoid cloning session history during period rendering. Signed-off-by: jimyag <git@jimyag.com>
mike1858
left a comment
There was a problem hiding this comment.
Ha, good catch. I guess our Codex analyzer has a lot of issues.
Summary
Fix session drill-down so it reflects activity in the selected period rather than only sessions that started in that period. Also prevent Codex injected plugin metadata from becoming the displayed session title.
Key changes
<recommended_plugins>context when choosing Codex session names.Validation
cargo build --quietcargo test --quiet(402 passed)cargo clippy --quiet -- -D warningscargo doc --quietcargo fmt --all --quietNotes
No data migration is required; per-period session aggregates are rebuilt from the existing analyzer messages at startup.
Summary by CodeRabbit
<recommended_plugins>context and using the relevant user message.