Skip to content

Conversation

@insipx
Copy link
Contributor

@insipx insipx commented Nov 17, 2025

@insipx
Copy link
Contributor Author

insipx commented Nov 17, 2025

@insipx insipx changed the title proptest ordering implementation proptest ordering test Nov 17, 2025
@claude
Copy link

claude bot commented Nov 17, 2025

Claude finished @insipx's task —— View job


Code Review Complete

Review Date: November 19, 2025, 00:52 UTC


Summary

This PR adds comprehensive property-based tests for ordering with dependency resolution, renames Resolved.envelopesresolved consistently across the codebase, and improves test utilities. The implementation is solid overall with well-structured proptests.

Issues Found

1. Logic Bug in order.rs:84 (Critical) ⚠️

The filter logic appears inverted in xmtp_api_d14n/src/protocol/order.rs:84. You're checking if unresolved contains m.cursor(), but this compares the envelope's own cursor against the set of dependency cursors that couldn't be resolved. This would incorrectly filter out envelopes whose own cursor appears in the unresolved set, rather than filtering out envelopes that depend on unresolved cursors.

The logic should check if any of the envelope's dependencies (from m.depends_on()) are in the unresolved set, not the envelope's own cursor. Macroscopeapp flagged similar logic at line 84, and this needs addressing.

2. Missing Coverage for Edge Case in ExponentialBackoff::builder() (Medium)

In common/src/retry.rs:189-196, the ExponentialBackoffBuilder::build() method doesn't set individual_wait_max, which means it defaults to the struct's field initialization. However, there's no field default for individual_wait_max in the builder. This could cause issues if the field isn't initialized properly. Consider adding individual_wait_max as a builder parameter or documenting why it's hardcoded to 30 seconds.

3. Proptest Edge Case (Low)

In order.rs:221, the test skips envelopes that have_dependency_on_any(&unavailable) but doesn't verify that these skipped envelopes are not in the result. This could hide bugs where unavailable-dependent envelopes incorrectly appear in results. Consider adding an assertion that such envelopes are absent from the final result.

Positive Observations

  • Excellent use of prop_compose! to generate complex test scenarios with resolvable/unresolvable dependencies
  • The TestEnvelope::timestamp() implementation with deterministic timestamps (order.rs:44-50) is clever and enables consistent timestamp-based sorting in tests
  • The proptest regression file captures real failure cases - good practice
  • Field rename from envelopesresolved is consistent and improves clarity
  • Test harness with MockResolver is well-designed and reusable

Recommendation: Address the critical logic bug in order.rs:84 before merging. The other issues are lower priority but worth considering.


@insipx insipx changed the title proptest ordering test ordering proptests Nov 17, 2025
@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Nov 17, 2025

Align protocol ordering proptests and rename Resolved to use resolved while updating Ordered.order to splice resolved and re-sort by timestamp

Refactor dependency resolution by renaming Resolved.envelopes to Resolved.resolved across protocol and tests, adjust Ordered.order to consume the new field and maintain timestamp order, and add property tests with regression seeds for ordering when dependencies are unresolved. Also set default backoff caps in retry.ExponentialBackoffBuilder.build (120s total, 30s individual) and add debugging tools to the Nix dev shell.

📍Where to Start

Start with the Resolved struct change in dependency_resolution.rs, then review its consumption in Ordered.order in order.rs.


Macroscope summarized 9f5e2f8.

@insipx insipx force-pushed the insipx/test-resolution branch from b9af3fe to 3ae81ca Compare November 17, 2025 23:45
@insipx insipx force-pushed the insipx/test-ordering branch from ef324fa to 77ac644 Compare November 17, 2025 23:45
@insipx insipx force-pushed the insipx/test-resolution branch from 3ae81ca to 917b543 Compare November 17, 2025 23:47
@insipx insipx force-pushed the insipx/test-ordering branch from 77ac644 to afeb8c3 Compare November 17, 2025 23:47
let mut to_remove = HashSet::new();
for (i, m) in missing.iter().enumerate() {
if unresolved.contains(&m.cursor()?) {
if !unresolved.contains(&m.cursor()?) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Filter is inverted and uses the wrong cursor. unresolved contains dependency cursors, but we compare each envelope’s cursor(), which retains unresolved entries. Suggest: compare unresolved to each envelope’s missing dependency cursors and drop only envelopes still unresolved; keep those with deps fully resolved.

Suggested change
if !unresolved.contains(&m.cursor()?) {
if unresolved.contains(&m.cursor()?) {

🚀 Reply to ask Macroscope to explain or update this suggestion.

👍 Helpful? React to give us feedback.

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.62%. Comparing base (a1a270f) to head (9f5e2f8).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
xmtp_api_d14n/src/protocol/order.rs 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2802      +/-   ##
==========================================
+ Coverage   74.52%   74.62%   +0.09%     
==========================================
  Files         383      384       +1     
  Lines       49299    49592     +293     
==========================================
+ Hits        36740    37007     +267     
- Misses      12559    12585      +26     

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@insipx insipx force-pushed the insipx/test-ordering branch from afeb8c3 to 6f0b52c Compare November 18, 2025 16:51
@insipx insipx force-pushed the insipx/test-resolution branch 2 times, most recently from 2f6885e to b293d24 Compare November 18, 2025 16:57
@insipx insipx force-pushed the insipx/test-ordering branch from 6f0b52c to 9c1f2f3 Compare November 18, 2025 16:57
@insipx insipx force-pushed the insipx/test-ordering branch from 9c1f2f3 to caab442 Compare November 18, 2025 18:39
Base automatically changed from insipx/test-resolution to main November 18, 2025 21:37
@insipx insipx force-pushed the insipx/test-ordering branch from caab442 to 41d2537 Compare November 19, 2025 00:47
@insipx insipx force-pushed the insipx/test-ordering branch from 41d2537 to 9f5e2f8 Compare November 19, 2025 00:50
@insipx insipx enabled auto-merge (squash) November 19, 2025 00:51
@insipx insipx merged commit 1c958b7 into main Nov 19, 2025
17 checks passed
@insipx insipx deleted the insipx/test-ordering branch November 19, 2025 01:01
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.

3 participants