-
Notifications
You must be signed in to change notification settings - Fork 74
simple timestamp sort #2676
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
simple timestamp sort #2676
Conversation
How to use the Graphite Merge QueueAdd the label mergequeue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Claude finished @insipx's task —— View job PR Review CompleteReviewed on: 2025-11-13 21:13 UTC SummaryThe timestamp-based sorting implementation looks solid overall. The key concerns have already been identified by other reviewers. Below are additional observations not yet mentioned: Code Quality & Architecture✅ Well-structured: The visitor pattern implementation is clean and the extractor abstraction is well-designed. ✅ Good test coverage approach: Property-based tests with proptest are appropriate for sorting validation. Issues Found (Not Yet Mentioned)1. Test Coverage Gap - Empty/None Timestamps (xmtp_api_d14n/src/protocol/sort/timestamp.rs:26)The documentation states:
However, the test suite only generates envelopes with
Suggestion: Add test cases like: #[xmtp_common::test]
fn sorts_none_timestamps_consistently() {
let mut envelopes = vec![
TestEnvelope { time: None },
TestEnvelope::new(100),
TestEnvelope { time: None },
];
sort::timestamp(&mut envelopes).sort();
// Assert None values are grouped appropriately
}2. Type Safety Concern - u64 → i64 Cast (xmtp_api_d14n/src/protocol/extractors/timestamp.rs:45,50,54)While Macroscope correctly identified the overflow risk, the issue is more nuanced:
The cast
However, the existing codebase already has this pattern in other extractors (group_messages.rs:59, welcomes.rs:56), suggesting this might be an accepted risk or architectural decision. Recommendation: If this is intentional, document it. Otherwise, align all timestamp handling to use saturating conversion consistently across the codebase. 3. Documentation Accuracy (xmtp_api_d14n/src/protocol/sort/timestamp.rs:27)Line 27 states: "This sort will never return any missing envelopes." This is correct for timestamp sort but contrasts with the Performance✅ The change from Test Quality
fn envelope_all_some()(ns in 0i64..i64::MAX) -> TestEnvelope {
TestEnvelope::new(ns)
}Priority Issues
Task List:
|
73a67a1 to
50231fe
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2676 +/- ##
==========================================
- Coverage 77.41% 77.32% -0.10%
==========================================
Files 365 371 +6
Lines 53312 53461 +149
==========================================
+ Hits 41271 41338 +67
- Misses 12041 12123 +82 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
88d2d1b to
f347bed
Compare
|
This PR is part of a stack of 11 bookmarks:
Created with jj-stack |
f347bed to
d11cf35
Compare
d11cf35 to
f98bdf4
Compare
3cdda8d to
50739cb
Compare
50739cb to
8d9c7b6
Compare
8d9c7b6 to
7822659
Compare
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::protocol::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.
these tests are a bit extra since this sort is exactly one call to sort_by_key on Vec::, but it is consistent with how the causal sort is tested
7822659 to
3519e85
Compare
3519e85 to
7e857bd
Compare
| proptest = { workspace = true, features = [ | ||
| "std", | ||
| "fork", | ||
| "timeout", | ||
| "bit-set", | ||
| ] } |
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.
why can't we proptest in wasm?
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.
proptest exists in wasm, but they dont support the fork feature for wasm so had to turn it off

Add timestamp-based envelope sorting and expose
protocol::traits::Envelope::timestamp()to support simple timestamp sortIntroduce
protocol::sort::timestampwithTimestampSortand atimestamphelper, addTimestampExtractorandCursorExtractor, and extendprotocol::traits::Envelopewithtimestamp()while refactoringprotocol::traits::Sortto a singlesortmethod and renamingCursor::welcomestoCursor::v3_welcomes.📍Where to Start
Start with the
TimestampSortimplementation in xmtp_api_d14n/src/protocol/sort/timestamp.rs, then reviewEnvelope::timestamp()in xmtp_api_d14n/src/protocol/traits/envelopes.rs and theTimestampExtractorin xmtp_api_d14n/src/protocol/extractors/timestamp.rs.Macroscope summarized 7e857bd.