Skip to content

Deduplicate cycle-analysis work and missing-dependency records across output aliases (#979) - #1198

Draft
leynos wants to merge 11 commits into
mainfrom
issue-979-deduplicate-cycle-analysis-work-and-missing-dependency-records-across-output-aliases
Draft

leynos wants to merge 11 commits into
mainfrom
issue-979-deduplicate-cycle-analysis-work-and-missing-dependency-records-across-output-aliases

Conversation

@leynos

@leynos leynos commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #979

Summary

Cycle analysis previously keyed its depth-first traversal by output alias,
so an edge with several aliases was expanded once per alias and every absent
dependency was copied into the report once per alias. Key traversal state by
the canonical EdgeId instead, and retain the entry alias in each stack frame
so witnesses still name real output paths.

  • Each canonical edge is expanded once per analysis pass and its dependency
    lists are scanned once, regardless of how many aliases index it.
  • A back edge requesting alias b of an active edge yields the witness
    [b, later entry aliases…, b]. Exact single-output diagnostics are
    unchanged.
  • Each missing dependency is recorded once per examined entry, under the alias
    that entered the dependent edge. Retained records are bounded by the declared
    dependency entries rather than the alias × dependency product.
  • Kani presence mode still allocates no witness and no missing records.
    order_only_deps remain in traversal per ADR-0068.

Bounds and evidence

  • Before: a four-alias edge with four absent dependencies retained 16 records,
    and a three-alias edge with two entries was scanned six times.
  • After: four records under the entry alias, and exactly d scans for d
    declared entries.
  • The generated-graph property fails on the pre-fix detector with
    5 missing records exceed 3 declared entries and
    7 dependency scans exceed 3 declared entries.
  • Manifest lowering: 64 aliases with 64 external sources lowers to one
    canonical edge. A cyclic variant retains exactly 64 records and a witness
    naming the requested non-first alias.

Tests and gates

  • make check-fmt
  • make markdownlint
  • make doc-coverage
  • make test
  • make lint
  • make test-workflow-contracts
  • make kani-check
  • make kani-full
  • make test-kani-mutations

Toolchain: Rust nightly-2026-11-10, Linux mold linker, pinned Kani 0.67.0.
The mutation gate needs a git checkout, which the worktree provides.

All gates passed on the final head. The first make test-kani-mutations run
timed out its cold prewarm at the configured 900-second allowance under host
load; the warm retry passed the prewarm, the negative control, and every
patched-tree compile. CodeRabbit reported one trivial finding on the
multi-alias control graph, which is fixed; the re-review reports zero
findings.

Notes

  • No public API, error Display text, or users' guide behaviour changes.
  • The coding plan's clause to exclude order_only_deps was not actioned:
    ADR-0068 and the live order_only_two_node_cycle_reports_cycle harness
    require order-only traversal.
  • Regression tests live in src/ir/cycle/alias_regression_tests.rs,
    src/ir/cycle/property_tests/multi_alias_property_tests/, and
    tests/ir_from_manifest_tests/canonical_edge_storage.rs.
  • ExecPlan:
    docs/execplans/issue-979-deduplicate-cycle-analysis-work-and-missing-dependency-records-across-output-aliases.md.

References

🤖 Generated with Claude Code

Summary by Sourcery

Deduplicate cycle detection across output aliases while retaining accurate diagnostics and bounded missing-dependency reporting.

Bug Fixes:

  • Prevent duplicate cycle-analysis work and missing-dependency records when multiple output aliases reference the same build edge.
  • Preserve alias-accurate cycle witnesses, including witnesses closed through non-first explicit or implicit aliases.

Enhancements:

  • Key cycle traversal by canonical edge identity while retaining entry aliases for diagnostics and continue traversing all prerequisite kinds, including order-only dependencies.

Documentation:

  • Document canonical edge traversal, alias-aware witnesses, and bounded missing-dependency reporting in the developer and design guides.
  • Add the completed execution plan for the cycle-analysis deduplication work.

Tests:

  • Add regression, property-based, and manifest-lowering coverage for scan bounds, missing-record limits, canonical edge storage, and multi-alias cycle witnesses.
  • Update verification mutation patches for the revised cycle detector.

leynos and others added 10 commits November 25, 2026 21:32
Record the delivery plan for deduplicating cycle-analysis work and
missing-dependency records across output aliases. The plan traces the
reported allocation finding to alias-keyed traversal, sets out the
edge-keyed remediation, and records that the supplied instruction to
exclude order-only dependencies is not actioned because it contradicts
ADR-0068 and a live Kani proof.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Reproduce the reported amplification before changing traversal. A target
with four output aliases and four absent dependencies retains sixteen
missing-dependency records instead of four, and a three-alias edge with
two dependencies is scanned six times instead of twice. Also pin the
existing exact alias witnesses so the fix cannot silently alter them.

The scan accounting is a test-only thread-local counter reset at the
start of each detection pass; non-test builds compile it as a no-op.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Cycle detection previously keyed visitation by output alias, so an edge
with several aliases was expanded once per alias and every absent
dependency was copied into the report once per alias. Key state by
EdgeId instead, resolve each alias before the state check, and retain
the entry alias in each stack frame so witnesses still name real output
paths.

Missing dependencies are now recorded once per examined entry under the
alias that entered the edge, bounding the report by the declared
dependency entries. Presence mode keeps allocating no records and no
witness, and Kani's bounded map gains plain EdgeId key equality. Order-
only dependencies remain in traversal per ADR-0068.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Add a generated-graph property that requires every edge to declare at
least two aliases and an absent dependency, then asserts that missing
records and dependency scans stay within the declared entries. Each
reported witness must be closed and every consecutive pair must be a
declared dependency of its producer, and cycle presence must agree with
the independent edge-level oracle.

Add manifest-lowering cases for one target with 64 aliases and 64
external sources, and for a cycle closed through the second alias. The
cyclic case proves the report retains one record per external source
under the entry alias and still names the requested alias in its
witness.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Describe the once-per-edge traversal, alias-bearing stack frames, and
missing-record bound in the design and developers' guides. Regenerate
the five mutation patches whose hunk context moved when traversal
became edge-keyed; the seeded faults are unchanged. Record the
implementation progress and decisions in the ExecPlan.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Split the generator and its graph descriptions into a child module so
neither source file exceeds the repository's 400-line limit. No test
behaviour changes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Extract the extra-dependency resolution so the generator closure is no
longer excessively nested, rename the bounded alias ordinal, and give
each representative-graph violation list its own binding. Behaviour is
unchanged.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Point the developers' guide at the directory module produced by the
file-size split, and record the gate results, the Kani prewarm capacity
retry, and the measured bounds in the ExecPlan.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The representative cyclic graph declared no implicit output on its
target edge, so the implicit-output back arc fell back to an explicit
alias and the control did not test what its documentation claimed. Give
that edge an implicit output and require the witness to name it.

Addresses the CodeRabbit review finding on the multi-alias property
module.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Describe VisitState in terms of canonical edges, which is what the
detector now keys on, and record the test-only gate scope in the
ExecPlan.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 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

@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Data structures

Add EdgeId key equality to Kani’s bounded map so traversal state can be keyed by canonical edge identity.

  • src/ir/graph/kani_map.rs L12-13, L92-97

API

Add a crate-private graph lookup that returns the stored alias, canonical edge ID, and producing edge in one probe.

  • src/ir/graph/mod.rs L203-237

Implementation

Change cycle detection to visit each canonical edge once while retaining entry aliases for missing-dependency records and cycle witnesses.

  • src/ir/cycle/detector.rs L212-227, L240-258, L317-333 (+16 small edits)

Update cycle-analysis helpers to resolve aliases to canonical edge IDs and look up visitation state by edge.

  • src/ir/cycle/support.rs L11-20, L105-110

Wire in the scan-accounting helper and test modules for the new cycle-analysis coverage.

  • src/ir/cycle/mod.rs L31-32, L39-44

Add test-only per-thread accounting for dependency entries examined during cycle detection.

  • src/ir/cycle/scan_counter.rs L1-36

Documentation

Document edge-keyed traversal, alias-bearing witnesses, and the bound on missing-dependency records in the design and developer guides.

  • docs/developers-guide.md L9565-9570, L14836-14839, L14880-14901
  • docs/netsuke-design.md L2794-2807, L2813-2819

Record the implementation plan, constraints, decisions, and verification evidence for issue 979.

  • docs/execplans/issue-979-deduplicate-cycle-analysis-work-and-missing-dependency-records-across-output-aliases.md L1-288

Tests

Add focused regressions for bounded missing records, once-per-edge scans, and alias-specific cycle witnesses.

  • src/ir/cycle/alias_regression_tests.rs L1-244

Add generated multi-alias graphs and properties checking scan and record bounds, witness validity, and cycle detection against an independent oracle.

  • src/ir/cycle/property_tests/mod.rs L19-20
  • src/ir/cycle/property_tests/multi_alias_property_tests/graph.rs L1-317
  • src/ir/cycle/property_tests/multi_alias_property_tests/mod.rs L1-163

Share cycle-test graph builders and update existing detector tests to use the revised lookup result.

  • src/ir/cycle/test_fixtures.rs L1-40
  • src/ir/cycle/tests.rs L4-7, L9 (removed lines), L31

Extend manifest-lowering tests to cover one canonical edge with many aliases and bounded missing records in a cycle through a non-first alias.

  • tests/ir_from_manifest_tests/canonical_edge_storage.rs L147-227

Refresh mutation patches so the existing Kani verification faults still apply to the restructured detector.

  • docs/verification/mutations/ir__cycle__verification__canonicalize_four_node_cycle_is_canonical.patch L2-5, L14
  • docs/verification/mutations/ir__cycle__verification__direct_missing_dependency_does_not_report_cycle.patch L2-7
  • docs/verification/mutations/ir__cycle__verification__order_only_two_node_cycle_reports_cycle.patch L2-13
  • docs/verification/mutations/ir__cycle__verification__transitive_missing_dependency_does_not_report_cycle.patch L2-7
  • docs/verification/mutations/ir__graph__property_tests__cycles__cycles_are_rejected_at_larger_n.patch L2-7, L15-25

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

codescene-access[bot]

This comment was marked as outdated.

Record the draft pull request, the final review outcome, and the plan's
completion status.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@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.

Gates Failed
Enforce advisory code health rules (2 files with Code Duplication)

Our agent can fix these. Install it.

Gates Passed
5 Quality Gates Passed

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
alias_regression_tests.rs 1 advisory rule 9.39 Suppress
mod.rs 1 advisory rule 10.00 → 9.39 Suppress

See analysis details in CodeScene

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

This branch has not been deployed

No deployments
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.

Deduplicate cycle-analysis work and missing-dependency records across output aliases

1 participant