refactor(xmtp_mls): parse the client's own pkg_version once into LibXMTPVersion#3876
Conversation
|
Claude finished @tylerhawkes's task —— View job Code Review — 2026-07-20SummaryThis PR refactors version parsing in ✅ Strengths1. Critical Safety Fix LibXMTPVersion::parse(own_version).ok()? If the client's own version was unparseable, it returned 2. Performance Improvement 3. Clean Implementation
4. Display Implementation 5. Comprehensive Testing
🔍 Minor Observations1. Panic vs Result in let pkg_semver = LibXMTPVersion::parse(version)
.unwrap_or_else(|_| panic!("client pkg_version {version:?} is not valid semver"));Status: ✅ Appropriate. This is the client's own build identity ( 2. Send-side paths not updated 3. Test coverage for 📊 Code Quality
✅ No Issues Found
ConclusionStrong approval. This PR eliminates a subtle but serious fail-unsafe bug where the pause mechanism could silently break, while simultaneously improving hot-path performance. The implementation is clean, well-tested, and the decision to panic on malformed own-version is the correct safety trade-off. |
ApprovabilityVerdict: Approved Mechanical refactor consolidating repeated semver parsing into a single cached parse at VersionInfo construction. All files owned by the author, no behavioral changes, just performance/code organization improvement. You can customize Macroscope's approvability policy. Learn more. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3876 +/- ##
==========================================
+ Coverage 85.61% 85.64% +0.02%
==========================================
Files 415 415
Lines 67401 67663 +262
==========================================
+ Hits 57704 57948 +244
- Misses 9697 9715 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Follow-up to #3864. The receive-path floor guards took the client's own
pkg_versionas an&strand re-parsed it into aLibXMTPVersionon every message/commit. This parses it once atVersionInfoconstruction and hands the typed value around.Why
pkg_versionis the client's own build identity — in production always the compile-timeCARGO_PKG_VERSION(nothing in the bindings/SDKs constructs a customVersionInfo). Re-parsing it deep in the guards was:committed_floor_exceedingdidLibXMTPVersion::parse(own_version).ok()?— if our own version were unparseable it returnedNone→ "no floor exceeds" → the below-floor pause silently never fires. Parsing once at the boundary turns "our own version is garbage" into a loud construction-time failure instead of a per-group safety hole.What changed
VersionInfonow cachespkg_semver: LibXMTPVersion, parsed once in the constructor and asserted valid (it's our own build/config, not remote data). Newpkg_semver()accessor;pkg_version()(the&str) stays for logging/display.committed_floor_exceeding/_in_extensionsandprocess_message_with_app_datatake&LibXMTPVersioninstead of&str.context.version_info().pkg_semver(): the 3 floor-guard callers (mod.rs,validated_commit.rs,mls_sync.rs), the commit-validation enforce path (validated_commit.rs), the welcome pause (xmtp_welcome.rs), and the paused-group sweep/unpause (welcome_sync.rs,mls_sync.rs).LibXMTPVersiongains aDisplayimpl (theProtocolVersionTooLowerror carries the own version as a string).min_version/ required-version values (remote data) are still parsed at the point of use and stay lenient on garbage.Deliberately out of scope: the send-side setters (
update_group_min_version/enable_proposals) that parse own version for the "min_version above own" footgun guard. Those are cold paths with their ownGroupError::InvalidMinVersionhandling; converting them can be a separate cleanup.Behavior note
The old code was lenient on an unparseable own version (skip the guard). The new design makes that a panic at
VersionInfoconstruction — which is unreachable in production (CARGO_PKG_VERSIONis always valid) and is the safe direction (a garbage own-version disabling the pause is worse than failing loudly at startup). Thecommitted_floor_exceeding_in_extensions("garbage")unit case is removed accordingly; the malformed-floor cases remain.Test
min_versionmonotonicity (enforce path), pause/welcome/unpause receive behaviors: 184 passcargo clippy -p xmtp_mls --all-features --all-targets -Dwarningsclean on this change (see note), fmt clean🤖 Generated with Claude Code
Note
Parse client
pkg_versiononce intoLibXMTPVersionatVersionInfoconstructionpkg_semverfield toVersionInfothat caches the parsedLibXMTPVersionat construction time, eliminating repeated runtime parsing across the sync and welcome processing paths.committed_floor_exceeding,process_message_with_app_data,ValidatedCommit::from_staged_commit, andunstick_paused_groupsto accept or retrieve&LibXMTPVersioninstead of a raw&str.Displayimpl forLibXMTPVersionso the parsed version can be formatted in error messages.VersionInfo::new()now panics if the suppliedpkg_versionstring is not valid semver; previously, invalid versions would silently skip version-floor guards.Macroscope summarized 0e15579.