Skip to content

Fix bug in circularities code - #1537

Merged
tsmbland merged 1 commit into
mainfrom
circularity_bug
Sep 7, 2026
Merged

Fix bug in circularities code#1537
tsmbland merged 1 commit into
mainfrom
circularity_bug

Conversation

@tsmbland

@tsmbland tsmbland commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Description

There was a bug in the circularities code that enabled zero-capacity assets to creep through. This was causing a panic in a later part of the code, which made it quite tricky to track down. I've added a step to remove any zero-capacity assets, and added a panic so that zero-capacity assets can be caught earlier.

This is a bit of a plaster as this part of the code is a mess and needs larger work.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

It needs a release note entry (per AGENTS.md) and a regression unit test for the newly introduced panic path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses a bug in the circularities market-cycle selection logic where assets could end up with zero capacity (zero tranches), leading to a later panic that was hard to diagnose. It filters out zero-tranche assets at the end of cycle selection and adds an earlier assertion to fail fast if a zero-tranche asset is converted to a single tranche.

Changes:

  • Filter out cycle-selected assets whose capacity was reduced to zero (zero tranches) before returning them.
  • Add an assertion in AssetRef::as_single_tranche to panic immediately when called on a zero-tranche asset.
File summaries
File Description
src/simulation/market.rs Filters out zero-tranche assets after dispatch-based capacity adjustment (and adds a clarifying comment).
src/asset.rs Adds an assertion to prevent converting zero-tranche assets into a “single tranche” asset.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/asset.rs
Comment on lines +1027 to +1030
assert!(
self.num_tranches() > 0,
"Cannot convert an asset with zero tranches to a single tranche"
);
Comment thread src/simulation/market.rs
}
}

// Drop any assets who's capacities were dropped to zero
Comment thread src/simulation/market.rs
Comment on lines +370 to +372
// Drop any assets who's capacities were dropped to zero
all_cycle_assets.retain(|asset| asset.num_tranches() > 0);

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.85%. Comparing base (d24583f) to head (deadb4f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1537   +/-   ##
=======================================
  Coverage   90.85%   90.85%           
=======================================
  Files          61       61           
  Lines        9039     9042    +3     
  Branches     9039     9042    +3     
=======================================
+ Hits         8212     8215    +3     
  Misses        508      508           
  Partials      319      319           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsmbland
tsmbland marked this pull request as ready for review September 7, 2026 15:22
@tsmbland
tsmbland merged commit e467309 into main Sep 7, 2026
10 checks passed
@tsmbland
tsmbland deleted the circularity_bug branch September 7, 2026 15:22
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