Skip to content

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

Closed

Description

@dezren39

Problem

mcpx stats grouped opencode statistics always report messages: 0, even for sessions that have messages.

This is the same defect as dezren39/darwin-nix#393 (fixed there by dezren39/nix PR #394), present in this repo's pkgs/mcpx copy and not fixed here. Verified on main (54c223c): this repo's pkgs/mcpx/internal/opencode/opencode.go is byte-identical to the pre-fix version in dezren39/nix.

Evidence

  • pkgs/mcpx/internal/opencode/opencode.go:175-182 — Group declares Messages int64 \json:"messages"``.
  • pkgs/mcpx/internal/opencode/opencode.go:214 — ByModel merges groups with m.Messages += g.Messages, so the field is expected to be populated.
  • pkgs/mcpx/internal/opencode/opencode.go:259-287 — group() (used by ByAgent, ByModel, ByProject) builds SELECT %s AS k, count(*), %s, %s, %s FROM session ... (key, session count, cost, tokens in, tokens out — no message count) and scans only &g.Key, &g.Sessions, &g.Cost, &g.TokensIn, &g.TokensOut. Group.Messages is therefore never populated and always serializes as 0.
  • There is no test file at all in pkgs/mcpx/internal/opencode/ in this repo, so nothing catches it.
  • Contrast: Busiest in the same file does count messages per session with a correlated subquery on message.session_id, which is the pattern the fix should reuse.

Why it matters

Anyone reading grouped stats (by agent / model / project) from this repo's mcpx gets a permanently-zero message count — a silently wrong number, not a missing field — while totals and per-session views report real counts, so the outputs contradict each other.

Acceptance criteria

  • group() populates Group.Messages as the sum, over the group's sessions, of messages per session (correlated subquery on message.session_id, as Busiest uses).
  • A schema whose message table has no session_id column degrades to messages: 0 instead of failing the statistic (guard with the existing has("message", "session_id") helper).
  • New tests in pkgs/mcpx/internal/opencode/ (first test file for the package) cover: grouped counts by agent, ByModel merging summing messages across sessions sharing a model, and the missing-session_id degradation case.
  • Reference implementation and tests: dezren39/nix PR ci: goreleaser and both Jules daily workflows pin checkout/setup-go three majors behind the repo (v4 vs v7) #394 (commit d308cf5) — the fix should mirror it, since the two copies of this file were identical before that fix.

Activity

  1. added a commit that references this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions