Skip to content

export wiki Audit Trail double-counts intra-community edges, systematically understating the AMBIGUOUS share #2633

Open

Description

@rajarshidattapy

Labels: bug, export, wiki, reporting
Version: 0.9.40

Summary

Every community article ends with an "Audit Trail" section reporting the
EXTRACTED / INFERRED / AMBIGUOUS split of that community's edges. The counting loop visits
each edge once per endpoint inside the community, so:

  • an edge with both endpoints in the community is counted twice
  • an edge crossing out of the community is counted once

Since intra-community edges are overwhelmingly the high-confidence EXTRACTED ones (that is
what makes a community a community) and cross-community edges are disproportionately the
uncertain ones, the reported percentages are biased towards confidence in exactly the
direction that matters least for a reviewer.

AMBIGUOUS is documented in ARCHITECTURE.md as "flagged for human review", so this
under-reports the review burden.

Steps to reproduce

import networkx as nx
from graphify.wiki import _community_article

G = nx.Graph()
for n in ['a', 'b', 'c', 'x']:
    G.add_node(n, label=n, source_file='f.py')

G.add_edge('a', 'b', relation='calls', confidence='EXTRACTED')   # intra
G.add_edge('b', 'c', relation='calls', confidence='EXTRACTED')   # intra
G.add_edge('c', 'x', relation='calls', confidence='AMBIGUOUS')   # cross

article = _community_article(
    G, 0, ['a', 'b', 'c'], 'Core', {0: 'Core', 1: 'Other'},
    None, {'a': 0, 'b': 0, 'c': 0, 'x': 1}, {},
)
print(article[article.index('## Audit Trail'):])

Actual behavior

## Audit Trail

- EXTRACTED: 4 (80%)
- INFERRED: 0 (0%)
- AMBIGUOUS: 1 (20%)

There are only 3 edges. EXTRACTED: 4 counts two edges twice.

Expected behavior

- EXTRACTED: 2 (67%)
- INFERRED: 0 (0%)
- AMBIGUOUS: 1 (33%)

Root cause

graphify/wiki.py:77-82:

conf_counts: Counter = Counter()
for nid in nodes:
    for neighbor in G.neighbors(nid):
        ed = edge_data(G, nid, neighbor)
        conf_counts[ed.get("confidence", "EXTRACTED")] += 1
total_edges = sum(conf_counts.values()) or 1

Iterating nodes × neighbors visits the pair (a, b) once as a→b and again as b→a when
both are in nodes. Nothing deduplicates the unordered pair.

Suggested fix

Count each edge once by normalising the endpoint pair:

conf_counts: Counter = Counter()
member = set(nodes)
seen: set[tuple[str, str]] = set()
for nid in nodes:
    for neighbor in G.neighbors(nid):
        key = (nid, neighbor) if nid <= neighbor else (neighbor, nid)
        if key in seen:
            continue
        seen.add(key)
        conf_counts[edge_data(G, nid, neighbor).get("confidence", "EXTRACTED")] += 1
total_edges = sum(conf_counts.values()) or 1

(member is not strictly needed for the fix, but if the intent is "edges belonging to this
community" rather than "edges touching it", the cross-community ones should be excluded too —
worth confirming which is meant, since the section sits under a community heading.)

Note on a nearby counter

_cross_community_links (graphify/wiki.py:51-59) is not affected: a cross-community
edge has only one endpoint in nodes, so it is naturally counted once.

Related

Activity

  1. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by bedf32e0 (fix(wiki): count each incident edge once in the audit trail (#2635)). Could a maintainer confirm and close?

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