Skip to content

Native graph engine: cyclic density (SCC) + articulation points in O(V+E) (#3035) - #3046

Merged
squid-protocol merged 5 commits into
mainfrom
fix/3035-scc-articulation-points
Sep 14, 2026
Merged

squid-protocol merged 5 commits into
mainfrom
fix/3035-scc-articulation-points

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3035. Part of #3033 (the native graph engine). Stacked on #3044 (#3037): this branch contains #3044's two commits until it merges, and review should cover only the last commit(s).

What changed

Two O(V+E) algorithms in gitgalaxy/core/graph_engine.py. Both read the shared CSR index and never recurse.

  • nodes_in_cycles(index): iterative Tarjan SCC over the out-runs, using an explicit (node, next-edge) work stack. It gives cyclic density = nodes in SCCs of size > 1, divided by V. Strict parity with sum(len(c) for c in nx.strongly_connected_components(G) if len(c) > 1).
  • articulation_point_count(index): iterative Hopcroft–Tarjan low-link over the undirected view. _undirected_neighbors gives each node's distinct neighbours with direction ignored, which is the adjacency of G.to_undirected(). Strict parity with len(list(nx.articulation_points(G.to_undirected()))). The parent is skipped as a node, not an edge, so a mutually importing pair counts as one undirected edge, as in networkx.

NetworkRiskSensor._cycle_metrics() runs both in both modes, outside the networkx macro block, which drops the nx.strongly_connected_components and nx.articulation_points calls. Both metrics are None for an empty graph, as before. No work budget is needed, since both are linear.

Both are registered in tests/tools/graph_parity.py as strict.

Measured on language-crucible v1.2.0 (V=2,817, E=1,354; warm, best of 10, graph_parity.py --db)

metric parity native networkx
cyclic density strict, max |diff| 0.0 1.12 ms 2.14 ms
articulation points strict, exact (137) 2.28 ms 9.87 ms (includes to_undirected())

Other checks:

  • Seeded random graphs: 0 mismatches on 300 in the prototype, plus the 25 per metric in pytest.
  • A 5,000-node cycle and a 5,000-node chain run without hitting the recursion limit.

Golden masters

I diffed fresh scans of each mode against the committed fixtures with an uncapped golden_diff.deep_compare. The scans used GITGALAXY_DISABLE_GIT_HISTORY=1 and the same flags as test_golden_crucible.py.

  • Full precision: 0 differences. crucible_check.py --update also reported "No drift detected". This is the strict-parity guarantee holding on the real corpus.
  • Zero dependency: 2 differences, both intended. Each is a metric that was None there before and is now native:
    • network_macro/cyclic_density: None → 0.005
    • network_macro/articulation_points: None → 137
  • The full-precision scan reports the same values (0.005, 137), so the two modes now agree.

The zero-dependency fixture is re-blessed in the second commit.

Verification

  • pytest passes on the 9 affected suites (360 passed), run as plain pytest from outside the repo.
  • New tests:
    • the 5,000-node cycle and chain
    • a mutual import counts as one undirected edge
    • the sensor never calls nx.strongly_connected_components or nx.articulation_points, and both modes agree
  • audit_check.py: all clear.
  • Docs updated: zero_dependency_mode.md (table, summary, and an older-snapshots note: zero-dep values were NULL, and the definition is unchanged), the 02-16 wiki, README, CLAUDE.md, the console banner, and the zero-dependency warning.

🤖 Generated with Claude Code

squid-protocol and others added 4 commits September 14, 2026 18:21
…modes (#3037)

- graph_engine.closeness_and_path_length(): one BFS per node over the
  reversed CSR index yields both hop-count metrics.
  - closeness: strict parity with nx.closeness_centrality (Wasserman-Faust)
  - average path length: REDEFINED per #3033's tailoring decisions as the
    mean hops over every directed reachable pair (A transitively imports B)
    across all files, instead of the largest undirected component
  - None when no file imports another
- The V>1500 (closeness) and V>5000 (path length) node-count cutoffs are
  replaced by a deterministic WorkBudget: PATH_METRICS_WORK_BUDGET = 50M
  incoming-edge scans, past which both metrics are None, never 0.0.
- Runs in BOTH modes like PageRank, so zero-dependency mode now gets
  closeness, the "fragile dependency chain" ranking and path length.
- language-crucible (V=2,817): both metrics in 1.7 ms. Before this, closeness
  took 12.9 ms (nx) and was skipped at this size, and the undirected path
  length took about 1.2 s. Path length reads 1.358 (was 7.0723).
- Docs: zero_dependency_mode.md, the 02-16 wiki page, README, CLAUDE.md,
  the console banner and the LLM brief's section 3.5 text.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ragile-chain ranking populated)

Scoped with an uncapped golden_diff over fresh scans of both modes: exactly
two differences per mode -- network_macro/avg_path_length (7.0723 / None ->
1.358) and systemic_bottlenecks/fragile_dependency_chain ([] -> populated,
closeness now computed at the crucible's 2,817 files).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…V+E) (#3035)

- graph_engine.nodes_in_cycles(): iterative Tarjan SCC over the CSR
  out-runs. Strict parity with
  sum(len(c) for c in nx.strongly_connected_components(G) if len(c) > 1).
- graph_engine.articulation_point_count(): iterative Hopcroft-Tarjan over
  the undirected view (_undirected_neighbors = the adjacency of
  G.to_undirected()). Strict parity with nx.articulation_points.
- Neither recurses: a 5,000-node cycle and chain are tested.
- NetworkRiskSensor._cycle_metrics() runs both in BOTH modes, outside the
  networkx macro block, replacing the nx calls. Zero-dependency mode now
  reports cyclic density and articulation points.
- language-crucible: 1.12 ms vs 2.14 ms (SCC); 2.28 ms vs 9.87 ms
  (articulation points, incl. to_undirected). Values are identical.
- Registered as strict in tests/tools/graph_parity.py. Docs updated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…y + articulation points now native)

Uncapped golden_diff scope: full precision 0 differences (crucible_check
--update: no drift); zero dependency exactly 2 -- network_macro/
cyclic_density None -> 0.005 and articulation_points None -> 137, the same
values full precision reports.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol squid-protocol added enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates core-engine Modifications to the central physics and parsing engine labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Comment thread tests/tools/graph_parity.py Fixed
…ality

CodeQL (py/unnecessary-lambda) on #3046: `oracle=lambda graph:
nx.closeness_centrality(graph)` is a bare wrapper -- use the callable
directly. Behaviour-identical (the harness calls oracle(graph)). Other
oracles keep their lambdas: pagerank binds weight=, cyclic_density is a
composed expression, articulation_points calls .to_undirected()/len().

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_014gkhy3FWC4ovUWkMDonGMr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native graph engine: cyclic density (SCC) and articulation points in O(V+E)

2 participants