-
Notifications
You must be signed in to change notification settings - Fork 74
Add an ordering extension to a Vec<Envelope> #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This PR is part of a stack of 11 bookmarks:
Created with jj-stack |
|
Claude finished @insipx's task —— View job Code Review - PR #2771Review Date: November 13, 2025, 22:28 UTC Critical Issues1. Infinite Loop Risk in The // Current code has no way to detect:
// - resolver returns empty vec repeatedly
// - resolver returns envelopes that don't resolve the missing dependencies
// - resolver returns the same envelopes we already haveRecommendation: Track progress between iterations (e.g., count of missing envelopes, hash of missing set) and break/error if no progress is made after resolution attempt. High Priority Issues2. Missing Thread Safety Bounds (xmtp_api_d14n/src/protocol/traits/envelopes.rs:17, 39) As noted by @tylerhawkes, the
But Medium Priority Issues3. Silently Dropping Envelopes on Resolution Failure (order.rs:60-61) When
4. Error Handling Ambiguity (order.rs:56-64) The resolver returns 5. Test Coverage (order.rs:76) The TODO comment at line 76 indicates missing tests for the critical Low Priority / Style6. Splice Performance (order.rs:68-69) Using // Current approach requires shifting elements twice
envelopes.splice(0..0, missing.into_iter());
envelopes.splice(0..0, resolved.into_iter());
// Consider: reserve + rotate or single splice with chain7. Documentation Clarity (order.rs:66-67) The comment "apply missing before resolved" is backwards relative to the code execution order (resolved is actually inserted first at index 0, then missing is inserted before it). SummaryThe implementation provides a solid foundation for envelope ordering with dependency resolution, but needs:
The causal sorting logic itself (in
|
4ff01fb to
56b9cb7
Compare
1ca5869 to
11f190a
Compare
56b9cb7 to
9fc52ab
Compare
bd2576d to
087a21b
Compare
9e14cc2 to
6db2e33
Compare
53dc0ca to
c9aa03a
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2771 +/- ##
==========================================
- Coverage 77.30% 77.27% -0.03%
==========================================
Files 375 376 +1
Lines 53692 53719 +27
==========================================
+ Hits 41504 41512 +8
- Misses 12188 12207 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6db2e33 to
211ce1c
Compare
c9aa03a to
4797452
Compare
| topic_cursor, | ||
| } = self; | ||
| sort::timestamp(envelopes).sort()?; | ||
| while let Some(missing) = sort::causal(envelopes, topic_cursor).sort()? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible infinite loop: while let Some(missing) = sort::causal(...).sort()? can stay Some if resolver.resolve(...) returns no new/related envelopes. Consider detecting no progress (e.g., empty resolved, already-present items, or unchanged missing) and break or return an error.
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
211ce1c to
157a5d8
Compare
d2d3986 to
4401db3
Compare
157a5d8 to
20f196a
Compare
4401db3 to
4e13b77
Compare
20f196a to
33eaaea
Compare
4e13b77 to
cfaca01
Compare
33eaaea to
d93572e
Compare
Add asynchronous ordering for
|
d93572e to
0999e8f
Compare
585234a to
f0eef63
Compare
0999e8f to
e00397f
Compare
f0eef63 to
f908274
Compare
9385776 to
96d5df8
Compare
f908274 to
e787b05
Compare
96d5df8 to
de38fb0
Compare
e787b05 to
86404a0
Compare
86404a0 to
3aa9b6e
Compare
3aa9b6e to
21889f8
Compare
| envelopes.splice(0..0, missing.into_iter()); | ||
| envelopes.splice(0..0, resolved.into_iter()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A VecDeque would be more efficient than calling splice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a VecDeque would be better here. there's also a possibility of using reserve+rotate to keep the Vec. I just gave it a shot, but b/c i coupled the implementation of all the sorts to a Vec it required a bit more re-arranging than I would like
I'm going to be opening PRs for testing each these parts, so I'll revisit the VecDeque in those. I'm also anxious to change to the alternative reserve + rotate w/o good unit tests here as well.
Try to order envelopes by their dependencies and resolve any that are missing. if resolution fails, drop the missing envelopes and continue with the query.
the ordering extension is modified again in #2775 to remove envelopes from
missing. i may backport those changes to this pr for consistency