Skip to content

feat(graph-algos): extract page_rank and god_nodes to cognicode-graph-algos (PR #2b)#22

Merged
Rubentxu merged 4 commits into
mainfrom
feat/graph-algos-extract-algorithms
Jun 24, 2026
Merged

feat(graph-algos): extract page_rank and god_nodes to cognicode-graph-algos (PR #2b)#22
Rubentxu merged 4 commits into
mainfrom
feat/graph-algos-extract-algorithms

Conversation

@Rubentxu

Copy link
Copy Markdown
Owner

Summary

Extract the inline PageRank and god_nodes algorithm bodies from into , delegating from core to the WASM-compilable algorithm crate.

Changes

Dependencies

  • Added to workspace dependencies
  • Added with feature to

Core Changes

  1. GraphBuilder impl (): Implemented trait for using petgraph visitor traits (, )

  2. Algorithm delegation ():

    • : Uses → calls → maps results back to
    • : Translates → , calls , translates back

Adapter Stub

Updated to document that the actual lives in cognicode-core.

Validation

  • ✅ passes

  • running 17 tests
    test adapters::json_graph::tests::dangling_edge_ignored ... ok
    test adapters::json_graph::tests::three_node_cycle ... ok
    test adapters::json_graph::tests::empty_graph_yields_empty_adjacency ... ok
    test algorithms::god_nodes::tests::percentile_0_returns_all ... ok
    test algorithms::god_nodes::tests::empty_scores_returns_empty ... ok
    test algorithms::god_nodes::tests::percentile_1_returns_top_only ... ok
    test algorithms::god_nodes::tests::percentile_95_returns_top_5 ... ok
    test algorithms::god_nodes::tests::percentile_clamped ... ok
    test algorithms::god_nodes::tests::sort_descending_by_score ... ok
    test algorithms::god_nodes::tests::tie_breaking_by_id_ascending ... ok
    test algorithms::page_rank::tests::cycle_mass_conservation ... ok
    test algorithms::page_rank::tests::disconnected_components ... ok
    test algorithms::page_rank::tests::deterministic_across_runs ... ok
    test algorithms::page_rank::tests::empty_graph_returns_empty_map ... ok
    test algorithms::page_rank::tests::self_loop_only ... ok
    test algorithms::page_rank::tests::single_node_returns_one ... ok
    test algorithms::page_rank::tests::star_center_outranks_leaves ... ok

test result: ok. 17 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

running 1 test
test crates/cognicode-graph-algos/src/graph_builder.rs - graph_builder::GraphBuilder (line 22) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

all doctests ran in 0.29s; merged doctests compilation took 0.29s — 17 tests pass


  • running 16 tests
    test application::services::graph_analytics::tests::god_nodes_empty_graph_returns_empty_vec ... ok
    test application::services::graph_analytics::tests::all_simple_paths_empty_when_symbols_missing ... ok
    test application::services::graph_analytics::tests::condensation_dag_returns_n_singletons ... ok
    test application::services::graph_analytics::tests::condensation_cycle_collapses_into_single_component ... ok
    test application::services::graph_analytics::tests::god_nodes_single_node_returns_that_node ... ok
    test application::services::graph_analytics::tests::all_simple_paths_finds_three_paths_in_diamond ... ok
    test application::services::graph_analytics::tests::page_rank_empty_graph_returns_empty_map ... ok
    test application::services::graph_analytics::tests::page_rank_dag_assigns_higher_score_to_root ... ok
    test application::services::graph_analytics::tests::feedback_arc_set_acyclic_returns_empty ... ok
    test application::services::graph_analytics::tests::all_simple_paths_respects_max_hops ... ok
    test application::services::graph_analytics::tests::feedback_arc_set_cycle_returns_at_least_one_edge ... ok
    test application::services::graph_analytics::tests::feedback_arc_set_three_cycle ... ok
    test application::services::graph_analytics::tests::god_nodes_finds_highly_called_symbol ... ok
    test application::services::graph_analytics::tests::transitive_reduction_cycle_keeps_all_edges ... ok
    test application::services::graph_analytics::tests::transitive_reduction_acyclic_diamond ... ok
    test application::services::graph_analytics::tests::transitive_reduction_dag_drops_implied_edges ... ok

test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 1388 filtered out; finished in 0.00s — 16 tests pass

  • ✅ passes
  • ✅ applied

Public API Preservation

and have byte-identical signatures:

All existing tests pass without modification.

ADR-048 Compliance

Per ADR-048 (WASM graph transforms architecture), is the single source of truth for graph algorithms. cognicode-core delegates without reimplementing. The WASM-compilable crate compiles cleanly to (proven by spike per engram obs-2856).


Parent PRs: #20 (skeleton), #21 (CI removal)
Next: PR #3 — cognicode-graph-wasm bindgen shim

Rubentxu and others added 4 commits June 24, 2026 16:33
Add cognicode-graph-algos to workspace.dependencies in /Cargo.toml and
as a direct dependency in cognicode-core/Cargo.toml with the
petgraph-adapter feature enabled.

This establishes the bridge from cognicode-core (which owns
CallGraphProjection) to cognicode-graph-algos (which provides the
WASM-compilable algorithm implementations).
Replace the stub implementation with documentation explaining that the
actual impl GraphBuilder for CallGraphProjection lives in cognicode-core
(where the type is defined). This module exists only to validate that
the feature flag compiles correctly and to serve as a placeholder for
future PETGRAPH-specific adapters.
Implement the GraphBuilder trait for CallGraphProjection in
cognicode-core (where the type lives). The impl extracts adjacency
structure from the underlying StableGraph using petgraph visitor traits
(NodeIndexable, EdgeRef).

This enables the delegation from GraphAnalytics::page_rank and
GraphAnalytics::god_nodes to the pure algorithm functions in
cognicode-graph-algos.
…lgos

Replace the inline PageRank and god_nodes algorithm bodies in
GraphAnalyticsService with delegation to cognicode-graph-algos.

page_rank:
- Uses CallGraphProjection::build_adjacency() to get (in_neighbors, out_degree)
- Calls cognicode_graph_algos::page_rank() with the raw slices
- Maps usize results back to SymbolId via projection.id_to_index()

god_nodes:
- Reuses the delegated page_rank (unchanged signature)
- Translates SymbolId -> usize for cognicode_graph_algos::god_nodes()
- Translates results back to SymbolId

Public API of both methods is byte-identical (same signatures, same
error behavior). All existing tests pass without modification.

Per ADR-048, cognicode-graph-algos is the single source of truth for
graph algorithms; cognicode-core delegates without reimplementing.
@Rubentxu Rubentxu merged commit e203eff into main Jun 24, 2026
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