Skip to content

Conversation

@insipx
Copy link
Contributor

@insipx insipx commented Dec 1, 2025

Add BytesExtractor, OrphanExtractor, and delegate_envelope_visitor! to enable Envelope::bytes() and Envelope::orphan() across protocol and collection types

Introduce new extractors and a delegating macro, extend the Envelope and EnvelopeCollection traits with bytes() and orphans(), and wire orphans() through subscribe types; update DB icebox queries to handle multiple cursors with idempotent inserts.

📍Where to Start

Start with the new trait methods in Envelope and EnvelopeCollection in xmtp_api_d14n/src/protocol/traits/envelopes.rs and xmtp_api_d14n/src/protocol/traits/envelope_collection.rs, then review the extractors in xmtp_api_d14n/src/protocol/extractors/bytes.rs and xmtp_api_d14n/src/protocol/extractors/orphaned_envelope.rs, and finally the delegating macro in xmtp_api_d14n/src/protocol/macros.rs.


Macroscope summarized e05e925.

@insipx
Copy link
Contributor Author

insipx commented Dec 1, 2025

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @insipx's task —— View job


Code Review

Review Date: December 11, 2025, 03:30 UTC

Key Findings

1. Missing group_id in OrphanExtractor (xmtp_api_d14n/src/protocol/extractors/orphaned_envelope.rs:30)

The OrphanExtractor::get() doesn't set group_id on the OrphanedEnvelope builder. The extractor's inner tuple has a GroupMessageExtractor at position 3, but group_id is never extracted from it:

let mut envelope = OrphanedEnvelope::builder();
envelope.cursor(extracted.0.get()?);
envelope.depends_on(extracted.1.get().unwrap_or_default());
envelope.payload(extracted.2.get());
// Missing: envelope.group_id(extracted.3.get()?.group_id);
Ok(envelope.build()?)

This was already noted by macroscopeapp but remains unaddressed.

2. Test implementation incompleteness (xmtp_api_d14n/src/protocol/utils/test/test_envelope.rs:94-96)

The TestEnvelope::orphan() method uses todo!() rather than unreachable!() like other unimplemented methods. This inconsistency suggests incomplete test infrastructure:

fn orphan(&self) -> Result<xmtp_proto::types::OrphanedEnvelope, EnvelopeError> {
    todo!()  // Should be unreachable!() or implemented
}
3. Potential double-encoding in BytesExtractor (xmtp_api_d14n/src/protocol/extractors/bytes.rs:35-38)

The visit_originator method encodes the OriginatorEnvelope, then the visitor pattern calls accept which will encode the nested envelope. This may produce concatenated bytes rather than just the protobuf body. See macroscopeapp's comment - this needs clarification on intended behavior.

4. Coverage concerns

The codecov report shows 45.40% patch coverage with 208 missing lines. Critical paths include:

  • The entire delegate_envelope_visitor! macro (144 lines, 0% coverage)
  • BytesExtractor implementation (18 lines, 0% coverage)
  • OrphanExtractor implementation (8 lines, 0% coverage)

While macro-generated code is hard to test directly, the extractors should have unit tests demonstrating they work correctly across envelope types.

Positive aspects

  • Clean macro design for reducing boilerplate in delegate_envelope_visitor!
  • Consistent trait extension pattern for bytes() and orphans() methods
  • Good use of idempotent inserts (on_conflict_do_nothing) in database layer
  • Well-structured visitor pattern implementation

@insipx insipx changed the title orphan extractor extractors - bytes & OrphanedEnvelope Dec 1, 2025
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

❌ Patch coverage is 45.40682% with 208 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.80%. Comparing base (d704e2f) to head (e05e925).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
xmtp_api_d14n/src/protocol/macros.rs 0.00% 144 Missing ⚠️
xmtp_api_d14n/src/protocol/extractors/bytes.rs 0.00% 18 Missing ⚠️
xmtp_api_d14n/src/protocol/traits/envelopes.rs 0.00% 10 Missing ⚠️
..._api_d14n/src/protocol/impls/protocol_envelopes.rs 0.00% 9 Missing ⚠️
..._d14n/src/protocol/extractors/orphaned_envelope.rs 0.00% 8 Missing ⚠️
xmtp_db/src/encrypted_store/icebox.rs 95.45% 8 Missing ⚠️
xmtp_api_d14n/src/protocol/sort/timestamp.rs 0.00% 4 Missing ⚠️
..._api_d14n/src/protocol/utils/test/test_envelope.rs 0.00% 4 Missing ⚠️
...pi_d14n/src/protocol/traits/envelope_collection.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2868      +/-   ##
==========================================
- Coverage   73.98%   73.80%   -0.19%     
==========================================
  Files         398      401       +3     
  Lines       50905    51274     +369     
==========================================
+ Hits        37661    37841     +180     
- Misses      13244    13433     +189     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@insipx insipx force-pushed the insipx/extractors branch from 71ae3cb to d0c6474 Compare December 2, 2025 14:59
@insipx insipx force-pushed the insipx/icebox-global-cursor branch from 5895dcb to 40377cf Compare December 2, 2025 14:59
@insipx insipx force-pushed the insipx/extractors branch from d0c6474 to 2a525e0 Compare December 2, 2025 15:28
@insipx insipx force-pushed the insipx/icebox-global-cursor branch from 40377cf to 25263b8 Compare December 2, 2025 15:28
@insipx insipx force-pushed the insipx/extractors branch from 2a525e0 to 4aa9e3f Compare December 3, 2025 22:15
@insipx insipx force-pushed the insipx/extractors branch 2 times, most recently from 40bd8fd to 4937bec Compare December 3, 2025 22:38
@insipx insipx force-pushed the insipx/batch-queries branch from f13537d to 5814a9d Compare December 10, 2025 20:38
@insipx insipx force-pushed the insipx/extractors branch 2 times, most recently from 74f8e3d to 411c071 Compare December 10, 2025 20:57
@insipx insipx force-pushed the insipx/batch-queries branch 2 times, most recently from 191eb3a to 9164a3f Compare December 10, 2025 21:02
@insipx insipx force-pushed the insipx/batch-queries branch from 9164a3f to e9ce2c6 Compare December 10, 2025 21:26
@insipx insipx force-pushed the insipx/batch-queries branch from e9ce2c6 to 370f70d Compare December 10, 2025 21:28
@insipx insipx force-pushed the insipx/extractors branch 2 times, most recently from 17e7833 to 058f33b Compare December 10, 2025 21:38
@insipx insipx force-pushed the insipx/batch-queries branch from 370f70d to 6bea462 Compare December 10, 2025 21:38
@insipx insipx force-pushed the insipx/batch-queries branch from 6bea462 to 9521de6 Compare December 10, 2025 21:39
Base automatically changed from insipx/batch-queries to main December 10, 2025 21:51
@insipx insipx merged commit 58fdd7b into main Dec 10, 2025
28 checks passed
@insipx insipx deleted the insipx/extractors branch December 10, 2025 21:58
rygine pushed a commit that referenced this pull request Dec 28, 2025
…2868)

<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible
markers, and the markers themselves will not be visible in the GitHub
rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's
description, Macroscope will post its summary as a comment. -->
### Add `BytesExtractor`, `OrphanExtractor`, and
`delegate_envelope_visitor!` to enable `Envelope::bytes()` and
`Envelope::orphan()` across protocol and collection types
Introduce new extractors and a delegating macro, extend the `Envelope`
and `EnvelopeCollection` traits with `bytes()` and `orphans()`, and wire
`orphans()` through subscribe types; update DB icebox queries to handle
multiple cursors with idempotent inserts.

#### 📍Where to Start
Start with the new trait methods in `Envelope` and `EnvelopeCollection`
in
[xmtp_api_d14n/src/protocol/traits/envelopes.rs](https://github.com/xmtp/libxmtp/pull/2868/files#diff-974a5b6ad5cd0c15ff488b73bf921d7c4b255f5ff3d4f053ab99f1a7bc477ef5)
and
[xmtp_api_d14n/src/protocol/traits/envelope_collection.rs](https://github.com/xmtp/libxmtp/pull/2868/files#diff-0af39c7627e651b4a4f836c6082762ca4cb70e8992b62695adcd4cb2fa8bd512),
then review the extractors in
[xmtp_api_d14n/src/protocol/extractors/bytes.rs](https://github.com/xmtp/libxmtp/pull/2868/files#diff-a6cbfd5d967e5d7345d86635f7f820d05712ea8b41434f1179f1f4ad35e0341d)
and
[xmtp_api_d14n/src/protocol/extractors/orphaned_envelope.rs](https://github.com/xmtp/libxmtp/pull/2868/files#diff-a15a2ff96d5029829ea707ef220be104b97cdc4c2f7a12f085ff7e1d2c5ea3d4),
and finally the delegating macro in
[xmtp_api_d14n/src/protocol/macros.rs](https://github.com/xmtp/libxmtp/pull/2868/files#diff-b253d53f5aff5a0ddee62ddccdeda11f5959d4f1c3f7ed130e4f047fecf0c91a).

----
<!-- Macroscope's review summary starts here -->

<a href="https://app.macroscope.com">Macroscope</a> summarized e05e925.
<!-- Macroscope's review summary ends here -->

<!-- macroscope-ui-refresh -->
<!-- Macroscope's pull request summary ends here -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants