Skip to content

mcpx: populate Group.Messages in grouped opencode statistics (#261) - #262

Merged
dezren39 merged 1 commit into
mainfrom
creator/261-group-messages
Oct 18, 2026
Merged

dezren39 merged 1 commit into
mainfrom
creator/261-group-messages

Conversation

@dezren39

@dezren39 dezren39 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Fixes #261. Mirrors dezren39/nix PR #394 (the fix for dezren39/darwin-nix#393) — this repo's pkgs/mcpx/internal/opencode/opencode.go was byte-identical to the pre-fix version in dezren39/nix.

group() selected no message count, so ByAgent/ByModel/ByProject always reported messages: 0 even though Group.Messages is a declared field and ByModel merges it.

  • Count messages per session with the correlated subquery Busiest already uses, summed over the group, guarded by has(message, session_id) so a moved schema degrades to 0 instead of failing the statistic.
  • First test file for internal/opencode: grouped counts by agent, ByModel merge summing messages across sessions sharing a model, and the missing-session_id degradation case.

Verification:

  • go test ./internal/opencode/ passes with the fix.
  • Ablation: with only opencode.go reverted, TestGroupCountsMessages fails with Messages:0 for every group (build want 5, got 0; plan want 1, got 0; test/m-a want 4, got 0; test/m-b want 2, got 0).
  • gofmt -l clean, go vet ./internal/opencode/ clean.

Summary by CodeRabbit

  • New Features
    • OpenCode usage statistics now include message counts for each agent and model group. Groups show zero messages when session message counts are unavailable.
  • Tests
    • Added coverage for message counts across sessions and for databases without session identifiers.

group() selected no message count, so ByAgent/ByModel/ByProject always reported messages: 0 in JSON output even though Group.Messages is a declared field and ByModel merges it. Count messages per session with the correlated subquery Busiest already uses, summed over the group, guarded by has(message, session_id) so a moved schema degrades to 0 instead of failing the statistic. First test file for internal/opencode. Mirrors dezren39/nix PR #394 (fix for dezren39/darwin-nix#393); the two copies of opencode.go were identical before that fix.
@dezren39
dezren39 requested a review from a team as a code owner October 18, 2026 09:03
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9147735c-a0a0-4508-ac20-3265e4fafb38
📥 Commits

Reviewing files that changed from the base of the PR and between 54c223c and 163f299.

📒 Files selected for processing: 2
  • pkgs/mcpx/internal/opencode/opencode.go
  • pkgs/mcpx/internal/opencode/opencode_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

OpenCode grouped statistics now report message totals for agent and model groups. If the message table lacks a session_id column, the totals are zero. SQLite tests cover both cases.

Changes: OpenCode grouped message counts

Layer / File(s) Summary
Grouped query and validation
pkgs/mcpx/internal/opencode/opencode.go, pkgs/mcpx/internal/opencode/opencode_test.go
DB.group sums per-session message counts when message.session_id exists and scans the result into Group.Messages. SQLite tests check agent and model totals, including merged model groups, and verify zero totals when the column is absent.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 163f2

Grouped OpenCode statistics now report message totals, and report zero when the message table has no session_id column. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: populating Group.Messages for grouped OpenCode statistics.
Linked Issues check Passed Issue #261 requires grouped message totals, schema degradation, and tests. DB.group in pkgs/mcpx/internal/opencode/opencode.go checks has("message", "session_id"), sums a correlated count(*) f…
Out of Scope Changes check Passed The reviewed changes are limited to grouped OpenCode message-count implementation and focused tests in pkgs/mcpx/internal/opencode/. The implementation supports issue #261, and the fixtures directly…
Full details: Linked Issues check

Explanation

Issue #261 requires grouped message totals, schema degradation, and tests. DB.group in pkgs/mcpx/internal/opencode/opencode.go checks has("message", "session_id"), sums a correlated count(*) for each session, selects the result, and scans it into Group.Messages. ByModel already adds m.Messages, and the new tests verify agent totals, model merging, and zero messages when session_id is absent. The supplied verification also reports passing package tests.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to grouped OpenCode message-count implementation and focused tests in pkgs/mcpx/internal/opencode/. The implementation supports issue #261, and the fixtures directly test its required behavior. No unrelated change is shown.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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.

mcpx stats: grouped opencode statistics always report messages: 0 (Group.Messages never populated)

1 participant