Skip to content

GRAPH_REPORT.md counts more communities as "shown" than it renders #3548

Closed

Description

@hriocdn

GRAPH_REPORT.md reports more communities as "shown" than it actually renders

Version: graphifyy 0.9.48
File: graphify/report.py

Summary

The Summary line claims more ### Community sections than the report actually
contains. In my graph it said 69 shown when only 54 sections existed; the gap is
exactly the number of communities whose nodes are all file nodes.

- 84 nodes ... 84 communities (69 shown, 15 thin omitted)
## Communities (84 total, 15 thin omitted)

Actual ### Community sections in that file: 54, not 69. And 30 communities
were omitted, not 15.

Cause

thin_count_summary (report.py ~L144) counts only communities that have at
least one
non-file node:

thin_count_summary = sum(
    1 for nodes in communities.values()
    if 0 < sum(1 for n in nodes if not _ifn(G, n)) < min_community_size
)
shown_count = len(communities) - thin_count_summary

The 0 < guard excludes communities whose non-file-node count is zero. But the
rendering loop (~L248) skips those too:

real_nodes = [n for n in nodes if not _ifn(G, n)]
if not real_nodes:
    continue                       # skipped, but NOT counted as thin
if len(real_nodes) < min_community_size:
    continue                       # skipped, and counted as thin

So an all-file-node community is never rendered yet still counted in
shown_count. shown_count overstates by exactly the number of such
communities.

Reproduced on my graph: 84 communities, 54 renderable, 15 thin, 15 all-file-node.
69 - 54 == 15.

Second, smaller issue

thin_communities in the Knowledge Gaps section (~L287) hardcodes < 3:

if 0 < sum(1 for n in nodes if not _is_file_node(G, n)) < 3

but the message it feeds interpolates min_community_size:

f"- **{len(thin_communities)} thin communities (<{min_community_size} nodes) omitted ...")

Any caller passing a min_community_size other than 3 gets a label that
disagrees with the set it describes. Same 0 < undercount applies here.

Patch

Both hunks just drop the 0 < guard so the count matches what the loop skips,
and make the second site use the parameter it advertises.

--- a/graphify/report.py
+++ b/graphify/report.py
@@ -144,7 +144,7 @@
     thin_count_summary = sum(
         1 for nodes in communities.values()
-        if 0 < sum(1 for n in nodes if not _ifn(G, n)) < min_community_size
+        if sum(1 for n in nodes if not _ifn(G, n)) < min_community_size
     )
     shown_count = len(communities) - thin_count_summary
@@ -287,7 +287,7 @@
     thin_communities = {
         cid: nodes for cid, nodes in communities.items()
-        if 0 < sum(1 for n in nodes if not _is_file_node(G, n)) < 3
+        if sum(1 for n in nodes if not _is_file_node(G, n)) < min_community_size
     }

After the patch

Same graph, regenerated:

- 84 nodes ... 84 communities (54 shown, 30 thin omitted)
## Communities (84 total, 30 thin omitted)

shown == number of rendered sections (54) and shown + omitted == total
(54 + 30 == 84). Both invariants now hold.

Suggested regression check

These two invariants are cheap to assert against a generated report and would
have caught this:

rendered = len(re.findall(r"^### Community \d+ - ", report, re.M))
assert shown_count == rendered
assert shown_count + thin_count_summary == len(communities)

Note on wording (not part of the patch)

The Knowledge Gaps line reads:

- **278 isolated node(s):** ...
  These have <=1 connection - possible missing edges or undocumented components.

The count is correct for its filter, but the filter also drops file nodes,
concept nodes and file_type == "rationale". In my graph 415 nodes have degree
<= 1, so the prose "these have <=1 connection" reads as a count of all such
nodes when it is a filtered subset. Wording only; I left it alone.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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