Skip to content

[refactor] Stats.RelationCount double-counts pending relations #231

Description

@radimsem

Summary

Stats.RelationCount is computed as relTotal + PendingRelationCount, and the formatter then renders PendingRelationCount again as a child branch under that total. Pending relations are counted once in the headline number and re-listed beneath it — every consumer of MemoryStats and remindb inspect reads an inflated count.

Location

  • pkg/inspect/inspect.go:78RelationCount: relTotal + core.PendingRelationCount
  • pkg/inspect/format.go:79,82-84 — headline Relations: <RelationCount> followed by a pending: <PendingRelationCount> sub-branch

Category

refactor (display/aggregation bug, not a data-corruption bug — the DB stores correct values; only the reported total is wrong)

Impact

High. Anyone scripting against MemoryStats.relations or grepping inspect output for the relations count gets a wrong number. The pending: sub-line implies it's a breakdown of the total, but the total already includes it.

Rationale

// pkg/inspect/inspect.go:78
RelationCount:        relTotal + core.PendingRelationCount,
// pkg/inspect/format.go:78-86
func writeRelations(b *strings.Builder, s *Stats) {
    row(b, "Relations:", fmt.Sprintf("%d", s.RelationCount))

    branches := mapBranches(s.RelationsByOrigin)
    if s.PendingRelationCount > 0 {
        branches = append(branches, branch{key: "pending:", value: fmt.Sprintf("%d", s.PendingRelationCount)})
    }
    writeBranches(b, branches)
}

relTotal already counts every resolved edge; PendingRelationCount counts unresolved wiki-link forwards. Summing them and then showing the pending count as a sub-row creates the inconsistency.

Suggested change direction

Make RelationCount the resolved total only:

RelationCount: relTotal,

Leave the pending: sub-branch in writeRelations as-is. The header now reads honestly ("N resolved relations") and the sub-row legitimately reports "M pending" alongside it. The MCP MemoryStats envelope keeps the same field names; only the value changes meaning.

Filed by the nightly enhancement-scanner routine at commit f11c9f1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-reviewFiled by the nightly enhancement-scanner routinerefactorCode refactoring / architecture cleanup

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions