-
Notifications
You must be signed in to change notification settings - Fork 74
internally resolve envelopes in causal sort #2921
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 12 bookmarks:
Created with jj-stack |
|
Claude finished @insipx's task —— View job Code Review - December 10, 2025, 16:21 UTCOverviewThis PR successfully addresses an important limitation in the causal sort algorithm where deeply nested dependency chains within the same batch couldn't be resolved internally. The implementation is sound and well-tested. ✅ Strengths
🔍 Potential Issues1. Performance consideration (causal.rs:60-62) The current implementation calls if vector_clock.dominates(&last_seen) {
self.topic_cursor.apply(env)?;
let newly_valid = self.recover_newly_valid(&mut missed); // O(|missed|)
i += 1;
self.envelopes.splice(i..i, newly_valid.into_iter()); // O(k) shift
}For deep dependency chains (e.g., 100 envelopes each depending on the previous), this could result in:
Suggested optimization: Consider batching the recovery process. After processing all immediately-valid envelopes in one pass, check for newly-valid ones, then repeat. This would reduce the number of iterations through 2. Unstable API usage (causal.rs:40) .extract_if(.., |m| {
3. Edge case: Iterator invalidation during splice (causal.rs:62) The code splices newly recovered envelopes into the current position while iterating: self.envelopes.splice(i..i, newly_valid.into_iter());While this should work correctly since you increment 📊 Test Coverage Assessment✅ Both property tests are comprehensive:
The test assertions properly verify that:
🔒 Security & CorrectnessNo security concerns identified. The algorithm maintains causal ordering invariants correctly. 💡 Minor Suggestions
SummaryThis is a solid fix that correctly addresses the reported issue. The main consideration is whether the O(n²) behavior in worst-case scenarios (deep dependency chains) is acceptable for your use case. If typical batches are small or dependencies are shallow, the current implementation is perfectly fine. Otherwise, consider the batching optimization mentioned above. Recommendation: ✅ Approve with the performance consideration noted for future optimization if needed. |
417931a to
302503e
Compare
Resolve within-batch causal dependencies inside
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2921 +/- ##
==========================================
- Coverage 73.86% 73.86% -0.01%
==========================================
Files 397 397
Lines 50612 50634 +22
==========================================
+ Hits 37387 37403 +16
- Misses 13225 13231 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
302503e to
3a8a1e7
Compare
if there's an envelope sequence like: ``` D -> C -> B -> A ``` where `->` indicates a dependency relationship, i.e `A -> B` means "A depends on B" a list like: ``` C A B D ``` Would return `C` and `D` as missing without this fix, since the topic cursor did not yet contain necessary dependencies `A` and `B` before processing `C`, which `D` then depends on. I thought this would be a non-issue, but in reality it made ordering deeply nested chains of dependencies much more difficult. in this PR, on every dependency we can resolve, a new functions checks if any of the dependencies in `Missed` can now be processed
if there's an envelope sequence like:
where
->indicates a dependency relationship, i.eA -> Bmeans "A depends on B"a list like:
Would return
CandDas missing without this fix, since the topic cursor did not yet contain necessary dependenciesAandBbefore processingC, whichDthen depends on. I thought this would be a non-issue, but in reality it made ordering deeply nested chains of dependencies much more difficult. in this PR, on every dependency we can resolve, a new functions checks if any of the dependencies inMissedcan now be processed