Skip to content

GRAPH_REPORT.md: community Nodes listing includes rationale/concept nodes, so docstring fragments print as node names #3794

Closed

Description

@BloodyBeard

Summary

GRAPH_REPORT.md's per-community Nodes (N): ... listing includes rationale (docstring-fragment) and concept nodes as if they were real code declarations, so a community's node list can read like raw docstring prose — e.g. on code2flow (a real, small Python project):

### Community 14 - "Community 14"
Cohesion: 0.09
Nodes (13): Node, Check whether this variable is what the call is acting on. For example, if we…, Names exist largely for unit tests and deterministic node sorting :rtype: str, ...

"Names exist largely for unit tests and deterministic node sorting :rtype: str" is the literal docstring of code2flow/model.py's Node.name() method (file_type: "rationale"), not a node name. It's listed as if it were one, and it also inflates the community's reported size (len(real_nodes), which counts it).

Root cause

This is the same bug class as the closed #1768 (suggest_questions() vs report.py's Knowledge Gaps disagreeing over a missing rationale filter) — but a third, still-unfixed spot, inside report.py itself this time.

report.py, the community-rendering loop (~line 284):

# Filter method/function stubs from display - they're structural noise
real_nodes = [n for n in nodes if not _ifn(G, n)]

_ifn is _is_file_node (imported from .analyze) — it excludes file nodes only.

Compare the Knowledge Gaps section, ~30 lines later in the same function:

isolated = [
    n for n in G.nodes()
    if G.degree(n) <= 1
    and not _is_file_node(G, n)
    and not _is_concept_node(G, n)
    and G.nodes[n].get("file_type") != "rationale"
]

This one correctly excludes file, concept, and rationale nodes — the exact exclusion set #1768 established as the right one for report.py. The community-listing loop was never given the same treatment, so rationale (and concept) nodes still leak into Nodes (N): ... even though the codebase already knows how to filter them out, a few lines below.

Minimal reproduction

pip install graphifyy
git clone https://github.com/scottrogowski/code2flow
graphify code2flow --code-only --no-label

Open code2flow/graphify-out/GRAPH_REPORT.md and look at any community whose members include a Node/model-style class with docstrings — several communities list docstring text (including truncated … mid-sentence, and :param/:rtype: Sphinx directives) directly in the Nodes (N): ... line.

Suggested fix

real_nodes = [
    n for n in nodes
    if not _is_file_node(G, n)
    and not _is_concept_node(G, n)
    and G.nodes[n].get("file_type") != "rationale"
]

i.e. reuse the exact filter the Knowledge Gaps section already applies, in the community-rendering loop too.

Related

Environment

  • graphifyy==0.9.65 (PyPI)
  • Windows 11
  • AST-only extraction (--code-only --no-label), no LLM

Activity

  1. BloodyBeard commented on Sep 24, 2026

    @BloodyBeard
    Author

    Patched this locally and found the gap is wider than the one line above: _ifn's rationale/concept exclusion is missing from three sites in the same function, not one, and they're supposed to agree with each other by the report's own design (see the #3148/#3548 comments a few lines above the community loop, which explicitly say the "Communities" header count and the render loop should match):

    • the Nodes (N): ... display (reported above)
    • thin_count_summary/shown_count (drives the ## Communities (X total, Y thin omitted) header)
    • thin_communities in the Knowledge Gaps section (sum(1 for n in nodes if not _is_file_node(G, n)) < min_community_size — same partial filter, independently)

    Fix that resolved all three at once: make the single _ifn alias already used throughout the function apply the full exclusion (file + concept + rationale), instead of adding the check ad hoc at each site:

    from .analyze import _is_file_node, _is_concept_node
    
    def _ifn(G, n) -> bool:
        return (
            _is_file_node(G, n)
            or _is_concept_node(G, n)
            or G.nodes[n].get("file_type") == "rationale"
        )

    Then every site that already called _ifn(G, n) is correct for free, and the two spots that had rolled their own partial version (isolated's inline chain, thin_communities's bare _is_file_node) can just call _ifn too. Verified across 12 real projects post-patch: no docstring/rationale text in any Nodes (N): ... line, and the "X total, Y thin omitted" header now agrees with the Knowledge Gaps "thin communities" count in every case (previously could disagree by the same rationale-inflation amount).

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