Skip to content

Make assignment construction fallible (#137) - #226

Draft
leynos wants to merge 1 commit into
mainfrom
issue-137-make-clusteringresult-assignment-construction-explicitly-fallible
Draft

Make assignment construction fallible (#137)#226
leynos wants to merge 1 commit into
mainfrom
issue-137-make-clusteringresult-assignment-construction-explicitly-fallible

Conversation

@leynos

@leynos leynos commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

This branch makes manual ClusteringResult construction explicitly fallible,
so invalid cluster identifiers produce NonContiguousClusterIds rather than a
public-API panic. The CPU pipeline retains its crate-private convenience
constructor because it establishes contiguous labels by construction.

Closes #137.

Review walkthrough

Validation

  • make check-fmt: passed
  • make lint: passed (Rustdoc, Clippy, and Whitaker)
  • make test: passed (1,087 tests)
  • make markdownlint: passed
  • make nixie: passed
  • cargo test --workspace --doc: passed (5 doctests)
  • coderabbit review --agent: 0 findings

References

Summary by Sourcery

Make manual clustering-result construction explicitly fallible while preserving a CPU-internal convenience path for guaranteed-valid assignments.

New Features:

  • Make manual ClusteringResult construction use a public fallible API that reports invalid cluster identifiers through NonContiguousClusterIds.
  • Retain the panicking assignment constructor as an internal CPU-only convenience for pipelines that guarantee contiguous labels.

Bug Fixes:

  • Prevent invalid manually supplied cluster identifiers from causing panics through the public API.

Enhancements:

  • Update CLI usage, examples, and user-facing design guidance to use and document fallible result construction.

Documentation:

  • Document the fallible construction contract and clarify the internal scope of the panicking convenience constructor.

Tests:

  • Add a compile-fail API-surface test confirming the panicking constructor is not publicly accessible.
  • Expand result-construction regression coverage for invalid cluster identifier cases.

Keep the panicking result constructor inside the CPU pipeline, where
contiguous labels are guaranteed, and expose the typed fallible
constructor for all external callers.

Add public-surface and validation regression coverage, including the
CPU-disabled build, and document the constructor contract.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Warning

Your free Security trial is over. An organization admin can activate billing to continue.


Comment @coderabbitai help to get the list of available commands.

codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quality gates enabled for this code.

@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR changes manual ClusteringResult construction from a public panicking API to the public fallible try_from_assignments, confines the panicking helper to the CPU pipeline, adds API and regression tests, updates documentation and callers, and records unrelated validation investigations.

Sequence diagram for fallible clustering result construction

sequenceDiagram
    participant Caller
    participant ClusteringResult
    participant CpuPipeline

    Caller->>ClusteringResult: try_from_assignments(assignments)
    ClusteringResult-->>Caller: Ok(ClusteringResult)
    ClusteringResult-->>Caller: Err(NonContiguousClusterIds)
    CpuPipeline->>ClusteringResult: from_assignments(assignments)
    ClusteringResult-->>CpuPipeline: ClusteringResult
Loading

File-Level Changes

Change Details Files
Make manual clustering-result construction explicitly fallible while retaining an internal CPU-only fast path.
  • Restrict the panicking constructor to the cpu feature and crate visibility.
  • Update callers and examples to use try_from_assignments and handle validation errors.
  • Document the public fallible construction contract and internal CPU invariant.
chutoro-core/src/result.rs
chutoro-cli/src/cli/commands.rs
chutoro-cli/src/cli/tests.rs
docs/users-guide.md
docs/chutoro-design.md
Add regression coverage for the constructor’s public API boundary and invalid-identifier error behavior.
  • Add a trybuild compile-fail test proving from_assignments is not externally accessible.
  • Update assignment-based tests to exercise the fallible constructor.
  • Document duplicate identifiers alongside missing-zero, gap, and overflow error cases.
chutoro-core/tests/result_api_surface.rs
chutoro-core/tests/trybuild/clustering_result_from_assignments_private.rs
chutoro-core/tests/trybuild/clustering_result_from_assignments_private.stderr
chutoro-core/tests/chutoro.rs
docs/chutoro-design.md
Record investigation plans for unrelated validation blockers encountered during the change.
  • Capture hypotheses and isolation steps for benchmark smoke-test timeouts.
  • Capture CPU-disabled fixture diagnostic drift caused by warnings promoted to errors.
docs/debugging/debugging-plan-2026-08-24T153310+0200.md
docs/debugging/debugging-plan-2026-08-24T155013+0200.md

Assessment against linked issues

Issue Objective Addressed Explanation
#137 Make unchecked or manually constructed ClusteringResult values use an explicitly fallible public constructor, so invalid cluster identifiers return a typed error instead of causing a public API panic.
#137 Remove or restrict the panicking from_assignments constructor so it cannot be used as a public API for invalid input.
#137 Add regression coverage and documentation for invalid, non-contiguous, and overflowing assignment inputs through the public fallible API.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Make ClusteringResult assignment construction explicitly fallible

1 participant