-
Notifications
You must be signed in to change notification settings - Fork 74
queries to find a dependency of an intent #2819
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 ReviewReview Date: November 21, 2025, 00:18 UTC This PR adds SQL query functionality to find dependencies of intents, which is part of a larger stack implementing dependency resolution. Overall, the implementation is well-structured with good test coverage, but there are a few concerns to address. Critical Issues1. Complex SQL Join Logic May Have Edge Cases (xmtp_db/src/encrypted_store/group_intent.rs:515-585)The .inner_join(
group_messages::table.on(group_messages::group_id
.eq(dsl::group_id)
.and(group_messages::kind.eq(GroupMessageKind::MembershipChange))
.and(group_messages::published_in_epoch.eq(dsl::published_in_epoch - 1))),
)Issues:
Recommendation: Add validation to ensure 2. Error Handling Logic Allows Silent Success (xmtp_db/src/encrypted_store/group_intent.rs:388-401)In if rows_changed == 0 {
let already_published = self.raw_query_read(|conn| {
dsl::group_intents
.filter(dsl::id.eq(intent_id))
.first::<StoredGroupIntent>(conn)
});
if already_published.is_ok() {
return Ok(());
} else {
return Err(NotFound::IntentForToPublish(intent_id).into());
}
}Issue: This treats any existing intent as "already published" even if it's in the wrong state (e.g., Recommendation: Check the actual state of the intent and only return Performance Concerns3. Potential N+1 Query Pattern (xmtp_db/src/encrypted_store/refresh_state.rs:377-418)
for missing_state in &missing_states {
missing_state.store_or_ignore(self)?;
}Issue: This could result in multiple individual INSERT statements if many originators are missing. Recommendation: Use a batch insert with 4. Inefficient Chunking Strategy (xmtp_db/src/encrypted_store/refresh_state.rs:436-464)The .map(|partial_maps| {
partial_maps
.into_iter()
.flat_map(|partial_map| partial_map.into_iter())
.collect()
})Issue: This allocates intermediate Recommendation: Consider using an iterator chain without intermediate collections, or use a more efficient merge strategy. Code Quality Issues5. Unclear Error Message (xmtp_db/src/encrypted_store/group_intent/error.rs:9-13)#[error(
"intent {} for group {group_id} has invalid dependencies={}. one message cannot have more than 1 dependency in same epoch",
hex::encode(payload_hash),
cursors
)]
MoreThanTwoDependencies {Issue: The error name is Recommendation: Rename to 6. Inconsistent NULL Handling (xmtp_db/src/encrypted_store/group_intent.rs:527).filter(dsl::published_in_epoch.is_not_null())The query filters for non-NULL dsl::published_in_epoch.assume_not_null(),Issue: While the assumption is valid given the filter, it's fragile. If the filter logic changes, this could panic. Recommendation: Add a comment explaining why Minor Issues7. Proptest Regression Files (xmtp_db/proptest-regressions/encrypted_store/group_intent.txt)The proptest regression file shows several failure cases have been encountered, including cases with no dependencies and cases with multiple dependencies in the same epoch. Recommendation: Ensure these regression cases are well-understood and that the fixes are correctly implemented. Consider adding explicit test cases for these scenarios in addition to the proptest coverage. 8. Magic Number: CHUNK Size (xmtp_db/src/encrypted_store/refresh_state.rs:435)const CHUNK: usize = 900;Issue: The comment says "comfortably under SQLite's default 999-bind limit," but 900 is quite close to 999. If the query structure changes (e.g., adding more bind parameters per item), this could break. Recommendation: Either document why 900 is safe (e.g., "each item uses exactly 1 bind parameter"), or use a more conservative value like 500. Positive Observations
SummaryThe PR implements complex dependency resolution logic with good test coverage. The main concerns are around edge cases in the SQL join logic (epoch 0, missing dependencies) and some performance optimizations for batch operations. The error handling could be more precise in a few places. Recommended actions:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## insipx/add-published-in-epoch #2819 +/- ##
================================================================
Coverage ? 74.65%
================================================================
Files ? 389
Lines ? 50309
Branches ? 0
================================================================
Hits ? 37560
Misses ? 12749
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| published_in_epoch, | ||
| } | ||
| .store(conn) | ||
| .unwrap() |
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.
store(conn).unwrap() will panic on any failure. Consider returning a Result and using ? so errors propagate (and are logged/reported) instead of crashing.
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
one commit adds a query for TopicCursor
another commit adds a query for finding a dependency based off a stored group intent