Skip to content

fix: rename god_nodes 'edges' field to 'degree'#375

Open
yangmeilly wants to merge 2 commits intosafishamsi:v4from
yangmeilly:fix/god-nodes-degree-field
Open

fix: rename god_nodes 'edges' field to 'degree'#375
yangmeilly wants to merge 2 commits intosafishamsi:v4from
yangmeilly:fix/god-nodes-degree-field

Conversation

@yangmeilly
Copy link
Copy Markdown

@yangmeilly yangmeilly commented Apr 15, 2026

god_nodes() returned a dict with key 'edges' for the degree count, but all consumers (report, serve, wiki, skill scripts) referenced it as 'degree', causing KeyError at runtime.

detail info

$ $(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path

analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text())

# 只显示 GOD 节点和问题
print('=== GOD NODES ===')
for node in analysis['gods'][:10]:  # 前10个
    print(f\"  {node['label']} (degree={node['degree']})\")

print('\n=== SUGGESTED QUESTIONS ===')
for q in analysis['questions'][:5]:  # 前5个
    print(f\"  {q}\")

print('\n=== COMMUNITY COUNT ===')
print(f\"  Total communities: {len(analysis['communities'])}\")

# 查看前几个社区的规模
print('\n=== TOP COMMUNITIES BY SIZE ===')
sorted_comms = sorted(analysis['communities'].items(), key=lambda x: len(x[1]), reverse=True)[:10]
for cid, nodes in sorted_comms:
    print(f\"  Community {cid}: {len(nodes)} nodes\")
"
=== GOD NODES ===
Traceback (most recent call last):
  File "<string>", line 10, in <module>
KeyError: 'degree'

fix policy

god_nodes() in analyze.py:51-55 returns nodes with the field named "edges", not "degree":

 result.append({
     "id": node_id,
     "label": G.nodes[node_id].get("label", node_id),
     "edges": deg,   # <-- field is "edges", not "degree"
 })

 The "degree" field at export.py:385 belongs to the vis.js node payload and is unrelated to the gods array written to .graphify_analysis.json.

 Fix options:
 1. Rename "edges" → "degree" in analyze.py:54 (preferred — degree is the standard graph theory term)
 2. Update consuming code to use node['edges'] instead of node['degree']

god_nodes() returned a dict with key 'edges' for the degree count,
but all consumers (report, serve, wiki, skill scripts) referenced it
as 'degree', causing KeyError at runtime.

Rename the field to 'degree' for consistency and update all callers:
- graphify/analyze.py: field definition
- graphify/report.py: GRAPH_REPORT.md rendering
- graphify/serve.py: MCP tool response
- graphify/wiki.py: wiki index rendering
- tests/test_analyze.py: field-key assertions
test_pipeline.py, test_wiki.py and test_hypergraph.py contained
mock god-node dicts and field-key assertions still using the old
'edges' key. Update all three files to 'degree' to match the
renamed field in analyze.py.

All 433 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant