Skip to content

fix(tui): correct session details for selected periods - #219

Merged
mike1858 merged 3 commits into
Piebald-AI:mainfrom
jimyag:fix/session-daily-details
Jul 31, 2026
Merged

fix(tui): correct session details for selected periods#219
mike1858 merged 3 commits into
Piebald-AI:mainfrom
jimyag:fix/session-daily-details

Conversation

@jimyag

@jimyag jimyag commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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

  • Track per-day stats, models, and activity counts inside session aggregates.
  • Include continued and archived sessions when they have activity in the selected day, week, month, or year.
  • Show only usage from the selected period while preserving the original session start time.
  • Keep incremental contribution-cache updates consistent across date boundaries.
  • Skip <recommended_plugins> context when choosing Codex session names.

Validation

  • cargo build --quiet
  • cargo test --quiet (402 passed)
  • cargo clippy --quiet -- -D warnings
  • cargo doc --quiet
  • cargo fmt --all --quiet
  • Runtime TUI check with local Codex data: July 31 drill-down showed continued sessions and its total matched the daily aggregate.

Notes

No data migration is required; per-period session aggregates are rebuilt from the existing analyzer messages at startup.

Summary by CodeRabbit

  • New Features
    • Added accurate per-day session activity tracking, including message counts, AI activity, statistics, and model usage.
    • Period-based views now show the correct activity for sessions spanning multiple dates.
  • Bug Fixes
    • Improved session titles by ignoring <recommended_plugins> context and using the relevant user message.
    • Corrected daily totals when sessions are added, removed, or filtered.
  • Tests
    • Added coverage for date-boundary activity totals and improved session naming.

jimyag added 2 commits July 31, 2026 16:39
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>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jimyag, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 40986fcc-4c86-47fd-8ea5-bf7613c6443b

📥 Commits

Reviewing files that changed from the base of the PR and between 7681350 and fc33811.

📒 Files selected for processing (3)
  • src/analyzer.rs
  • src/contribution_cache/mod.rs
  • src/tui.rs
📝 Walkthrough

Walkthrough

This 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 <recommended_plugins> metadata.

Changes

Daily Session Activity

Layer / File(s) Summary
Session daily aggregate model
src/types.rs, src/contribution_cache/single_session.rs, src/tui/logic.rs
Adds per-day aggregate types and records daily counts, statistics, and model usage during session aggregation.
Contribution cache daily merging
src/contribution_cache/mod.rs, src/analyzer.rs, src/contribution_cache/tests/*, src/types.rs
Merges and reverses daily session data for message, single-session, and multi-session operations. New sessions reset daily statistics and models.
TUI period-specific sessions
src/tui.rs, src/tui/tests.rs
Filters sessions by daily activity and renders owned sessions with period-specific totals. Tests cover activity across date boundaries.

Codex Session Title Filtering

Layer / File(s) Summary
Recommended plugins title handling
src/analyzers/codex_cli.rs, src/analyzers/tests/codex_cli.rs
Treats <recommended_plugins> content as noise when selecting a Codex session title. A regression test verifies later user-message selection.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: mike1858

Poem

A rabbit tracks each session day,
Counts and models in a tidy array.
Plugins fade from titles bright,
Later words now name them right.
Dates guide the view with care.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: correcting TUI session details for selected periods.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/tui.rs (1)

251-287: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid cloning the full daily map when it is discarded immediately.

sessions_for_period clones the whole session, including daily: BTreeMap<CompactDate, SessionPeriodAggregate>, then overwrites filtered.stats/filtered.models (lines 268-270) and never reads filtered.daily again. 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 filtered field-by-field instead of cloning the whole struct, skipping daily entirely, 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 win

Extract 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, and models on a BTreeMap<CompactDate, SessionPeriodAggregate>, differing only in saturating_add/saturating_sub and increment/decrement. Extract two helper functions (merge_daily_add and merge_daily_subtract) to remove this duplication. This also reduces the risk of one copy drifting from the others when a new field is added to SessionPeriodAggregate.

♻️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9de0187 and 7681350.

📒 Files selected for processing (12)
  • src/analyzer.rs
  • src/analyzers/codex_cli.rs
  • src/analyzers/tests/codex_cli.rs
  • src/contribution_cache/mod.rs
  • src/contribution_cache/single_session.rs
  • src/contribution_cache/tests/basic_operations.rs
  • src/contribution_cache/tests/mod.rs
  • src/contribution_cache/tests/single_session.rs
  • src/tui.rs
  • src/tui/logic.rs
  • src/tui/tests.rs
  • src/types.rs

Comment thread src/analyzer.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 mike1858 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, good catch. I guess our Codex analyzer has a lot of issues.

@mike1858
mike1858 merged commit fd59fa9 into Piebald-AI:main Jul 31, 2026
6 checks passed
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.

2 participants