Skip to content

ADR-117: Add source-anchored canonical minimum cut implementation#287

Merged
ruvnet merged 3 commits intomainfrom
claude/canonical-mincut-adr-KXL6i
Mar 23, 2026
Merged

ADR-117: Add source-anchored canonical minimum cut implementation#287
ruvnet merged 3 commits intomainfrom
claude/canonical-mincut-adr-KXL6i

Conversation

@ruvnet
Copy link
Copy Markdown
Owner

@ruvnet ruvnet commented Mar 23, 2026

Summary

Implements ADR-117: Pseudo-Deterministic Canonical Minimum Cut, adding a new source-anchored canonical minimum cut API to ruvector-mincut. This provides a unique, deterministic canonical cut suitable for RVF witness generation, proof-gated mutations, and structural identity tracking across the RuVector stack.

Key Changes

  • New canonical module (crates/ruvector-mincut/src/canonical/source_anchored/):

    • SourceAnchoredCut struct: represents the canonical cut with lambda value, first separable vertex, side vertices, and SHA-256 hash
    • SourceAnchoredConfig: configuration for source vertex, vertex ordering, and per-vertex priorities
    • canonical_mincut(): main entry point computing the canonical cut via Stoer-Wagner + s-t cut probing
    • SourceAnchoredMinCut: stateful wrapper for dynamic graph mutations with epoch tracking
    • Embedded SHA-256 implementation for stable cut hashing (FIPS 180-4)
    • Dinic's max-flow algorithm for minimum s-t cut computation
    • Comprehensive test suite (503 lines) covering edge cases, determinism, and custom configurations
  • WASM FFI bindings (crates/ruvector-mincut/src/wasm/canonical.rs):

    • canonical_init(), canonical_add_edge(), canonical_compute() for graph construction
    • canonical_get_result(), canonical_get_hash(), canonical_get_side(), canonical_get_cut_edges() for result retrieval
    • Thread-safe state management via Mutex for testing compatibility
    • Constant-time hash comparison via canonical_hashes_equal()
  • Integration with MCP brain server:

    • partition_canonical_full() method in KnowledgeGraph for deterministic clustering
    • New canonical query parameter in partition endpoint
    • cut_hash field in PartitionResult for witness compatibility
  • Documentation:

    • ADR-117 design document (391 lines) detailing the algorithm, API, and three-tier implementation roadmap
    • Tier 1 (ship now): exact engine using Stoer-Wagner + s-t cut scanning
    • Tier 2 (fast path): tree packing and 2-respecting cuts
    • Tier 3 (dynamic): incremental maintenance for evolving graphs
  • Benchmarks (crates/ruvector-mincut/benches/canonical_bench.rs):

    • Performance measurements for random, cycle, and complete graphs
    • Scalability testing from 10 to 100+ vertices

Algorithm Details

The canonical cut is uniquely determined by the lexicographic tuple:

(λ, first_separable_vertex, |S|, π(S))

Where:

  • λ is the global minimum cut value (computed via Stoer-Wagner)
  • first_separable_vertex is the first vertex in the fixed ordering that can be separated from source by a minimum cut
  • |S| is the cardinality of the source side
  • π(S) is the sum of vertex priorities on the source side

The implementation uses capacity perturbation to enforce lexicographic ordering during max-flow computation, ensuring the chosen side minimizes cardinality and priority sum among all minimum s-t cuts.

Notable Implementation Details

  • Determinism: All computations use fixed-point arithmetic (FixedWeight as 32.32 fixed-point) and stable SHA-256 hashing for receipt generation
  • Correctness: Comprehensive test coverage including NIST SHA-256 vectors, triangle/cycle graphs, complete graphs, and 100-run determinism verification
  • Compatibility: Additive change—existing cactus enumeration API remains unchanged
  • Feature-gated: Behind the existing canonical feature flag in Cargo.toml

https://claude.ai/code/session_01UrVLJpxq8itzVxycy5sjNw

claude added 3 commits March 23, 2026 13:37
Introduces source-anchored canonical min-cut based on Kenneth-Mordoch 2026,
with lexicographic tie-breaking (λ, first_separable_vertex, |S|, π(S)) for
unique reproducible cuts. Three-tier plan: exact engine now, O(m log²n) fast
path, then dynamic maintenance via sparsifiers. Integrates with RVF witness
hashing for cut receipts.

https://claude.ai/code/session_01UrVLJpxq8itzVxycy5sjNw
…-cut

Full Tier 1 implementation of the Kenneth-Mordoch 2026 canonical min-cut
algorithm with lexicographic tie-breaking (λ, first_separable_vertex, |S|, π(S)).

Core implementation (source_anchored/mod.rs):
- AdjSnapshot for deterministic computation on FixedWeight (32.32)
- Stoer-Wagner global min-cut on fixed-point weights
- Dinic's max-flow for exact s-t cuts
- SHA-256 (FIPS 180-4, self-contained, no_std compatible)
- SourceAnchoredMinCut stateful wrapper with cache invalidation
- CanonicalMinCutResult repr(C) struct for FFI

WASM bindings (wasm/canonical.rs):
- Thread-safe Mutex-guarded global state (no static mut)
- 8 extern "C" functions: init, add_edge, compute, get_result,
  get_hash, get_side, get_cut_edges, free, hashes_equal
- Constant-time hash comparison for timing side-channel prevention
- Null pointer validation on all FFI entry points
- Graph size limit (10,000 vertices) to prevent OOM

Tests (40 total):
- 33 source_anchored tests: SHA-256 NIST vectors, determinism (100+1000
  iterations), symmetric graphs (K4, K5, cycles, ladders, barbells),
  custom source/priorities, disconnected rejection, FFI conversion
- 7 WASM tests: init/compute lifecycle, null safety, hash comparison,
  self-loop rejection, size limit enforcement

Benchmarks (canonical_bench.rs):
- Random connected graphs (10-100 vertices)
- Cycle and complete graph families
- Hash stability measurement

Security hardening:
- No static mut (Mutex for thread safety)
- Integer-exact FixedWeight arithmetic (no floats in comparisons)
- Checked capacity perturbation bounds
- Source-side orientation invariant enforced
- NIST-validated SHA-256 for witness hashes

ADR-117 updated to production-quality spec with explicit vertex-splitting
requirement for capacity perturbation, WASM FFI documentation, and
Phase 1 completion status.

https://claude.ai/code/session_01UrVLJpxq8itzVxycy5sjNw
- Enable `canonical` feature on ruvector-mincut dependency
- Add `partition_canonical_full()` to KnowledgeGraph using source-anchored
  canonical min-cut for deterministic, hashable partitions
- Add `canonical` query parameter to `/v1/partition` endpoint
- Add `cut_hash` (hex SHA-256) and `first_separable_vertex` fields to
  PartitionResult and PartitionResultCompact types
- Backward compatible: canonical fields are skip_serializing_if None,
  only populated when `?canonical=true` is passed

https://claude.ai/code/session_01UrVLJpxq8itzVxycy5sjNw
@ruvnet ruvnet merged commit 6b6fb0e into main Mar 23, 2026
6 checks passed
@ruvnet ruvnet deleted the claude/canonical-mincut-adr-KXL6i branch April 21, 2026 20:30
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.

2 participants