Phase 1: d14n service restructuring#328
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5 tasks
Wrap request fields in OriginatorFilter inner message and response envelopes in a single-item oneof for consistency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
ApprovabilityVerdict: Needs human review This is a significant API restructuring that splits ReplicationApi into multiple focused services (QueryApi, PublishApi, NotificationApi, GatewayApi) and deprecates existing endpoints. While the author owns all files and changes are to proto schemas (not runtime code), the architectural scope of this 'Phase 1' restructuring warrants human review to ensure alignment with the intended service decomposition strategy. You can customize Macroscope's approvability policy. Learn more. |
fbac
approved these changes
Apr 2, 2026
|
🎉 This PR is included in version 3.89.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
neekolas
added a commit
to xmtp/xmtpd
that referenced
this pull request
Apr 7, 2026
…ors (#1917) ## Summary Phase 1 of the d14n service restructuring ([xmtp/proto#327](xmtp/proto#327)). Registers the new gRPC services introduced by [xmtp/proto#328](xmtp/proto#328) on the xmtpd server and implements the only new RPC method, `SubscribeOriginators`. ### New services registered | Service | Server | Backed by | Methods | |---------|--------|-----------|---------| | `QueryApi` | Replication | `message.Service` | `QueryEnvelopes`, `SubscribeTopics`, `GetInboxIds`, `GetNewestEnvelope` | | `PublishApi` | Replication | `message.Service` | `PublishPayerEnvelopes` | | `NotificationApi` | Replication | `message.Service` | `SubscribeAllEnvelopes` | | `GatewayApi` | Gateway | `payer.Service` | `PublishClientEnvelopes`, `GetNodes` | No new structs — the existing service structs satisfy the new interfaces because the proto changes use identical method signatures and request/response types. ### New RPC: `SubscribeOriginators` Added to `ReplicationApi`. Subscribes to envelopes from specific originator nodes with cursor-based catch-up, using the same `subscribeWorker` infrastructure as `SubscribeEnvelopes`. - `LastSeen` cursor is **required** (nil returns `InvalidArgument`) - Responses use the `Envelopes` oneof variant, leaving room for future status signals - Envelope batching accounts for the oneof wrapper overhead to avoid exceeding gRPC payload limits ### Internal type: `subscribeFilter` Replaced internal usage of the deprecated `message_api.EnvelopesQuery` proto with `subscribeFilter`, an unexported type with explicit `catchUpMode` enum: ```go type catchUpMode int const ( catchUpNone catchUpMode = iota // stream new envelopes only catchUpFromStart // catch up from the very beginning catchUpFromCursor // catch up from specified cursor position ) ``` Each subscribe endpoint sets the mode explicitly at its entry point — no implicit nil cursor semantics. ### Shared subscribe helpers Extracted `batchAndSendEnvelopes` and `catchUpWithSendFn` into `subscribe_common.go`, eliminating ~200 lines of duplication between `SubscribeEnvelopes` and `SubscribeOriginators`. Both use callback-based response wrapping so the batching, cursor dedup, and pagination logic is written once. ### Deprecated endpoints All deprecated `ReplicationApi` and `PayerApi` endpoints remain fully functional. SA1019 lint warnings for deprecated type usage are suppressed with a scoped exclusion in `.golangci.yaml` — these will be cleaned up in Phase 2 when deprecated endpoints are removed. ## Test plan - [x] `TestSubscribeOriginators` — filters by originator, catches up from empty cursor, streams live - [x] `TestSubscribeOriginators_NilFilter` — returns `InvalidArgument` - [x] `TestSubscribeOriginators_EmptyOriginatorIds` — returns `InvalidArgument` - [x] `TestSubscribeOriginators_NilLastSeen` — returns `InvalidArgument` (cursor required) - [x] `TestSubscribeOriginators_FromCursor` — catches up past cursor, then streams live - [x] `TestQueryApi_QueryEnvelopes` — new service endpoint returns envelopes - [x] `TestQueryApi_GetInboxIds` — new service endpoint is reachable - [x] `TestPublishApi_PublishPayerEnvelopes` — new service endpoint routes correctly - [x] `TestGatewayApi_GetNodes` — returns same response as deprecated `PayerApi.GetNodes` - [x] All 94 existing + new tests pass - [x] `go build ./...` clean - [x] `dev/lint-fix` clean (0 issues) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- 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 append its summary at the bottom of the description. --> > [!NOTE] > ### Register new d14n gRPC services and implement `SubscribeOriginators` endpoint > - Adds `SubscribeOriginators` to `ReplicationApi` ([subscribe_originators.go](https://github.com/xmtp/xmtpd/pull/1917/files#diff-a77ed6e8a3a598507d3073a7941663293d866e4ca492147442e3deb18f37e4bd)): streams envelopes by originator node ID with catch-up from cursor, periodic keepalives, and oversized-envelope skipping. > - Registers `QueryApi`, `PublishApi`, and `NotificationApi` handlers in both the node API server ([server.go](https://github.com/xmtp/xmtpd/pull/1917/files#diff-104a11712684e520f0affa95e6a053faeb713306a10f69ee99b9729cc9dd1996)) and test infrastructure ([api.go](https://github.com/xmtp/xmtpd/pull/1917/files#diff-9c8d5b82b5a6dd5f551c0a19ec4a8491c0318e4efe142779bb3edad24d9b476c)). > - Registers `GatewayApi` alongside `PayerApi` in the gateway builder ([builder.go](https://github.com/xmtp/xmtpd/pull/1917/files#diff-27a239accb0576c3da95c1fea41bd81227bc4355f38be11a66d7b15135ea8e61)); `payer.Service` now also satisfies `GatewayApiHandler`. > - Refactors internal subscribe/query methods to use a `subscribeFilter` struct instead of proto `EnvelopesQuery`, and extracts shared helpers `batchAndSendEnvelopes` and `catchUpWithSendFn` ([subscribe_common.go](https://github.com/xmtp/xmtpd/pull/1917/files#diff-c9ba1bfc58febac0c4fd7dc8805ba3b94783de3dfd139c36c5526705416d9c25)). > - Updates generated proto, gRPC, Connect-Go, and OpenAPI files to reflect the new service split (QueryApi, PublishApi, NotificationApi, GatewayApi) and the replacement of `SubscribeAllEnvelopes` on `ReplicationApi` with `SubscribeOriginators`. > - Behavioral Change: `SubscribeAllEnvelopes` moves to `NotificationApi`; callers using `ReplicationApi.SubscribeAllEnvelopes` must migrate to `NotificationApiClient`. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 6ae509c.</sup> > <!-- Macroscope's review summary ends here --> > <!-- macroscope-ui-refresh --> <!-- Macroscope's pull request summary ends here --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Restructures the gRPC service definitions in
proto/xmtpv4/to cleanly separate consumer concerns, as outlined in #327. This is Phase 1 — additive changes with deprecation markers. The only breaking change is moving the unusedSubscribeAllEnvelopesRPC to a newNotificationApiservice.New services
QueryApi— Client-to-node queries and subscriptions (QueryEnvelopes,SubscribeTopics,GetInboxIds,GetNewestEnvelope)PublishApi— Gateway-to-node publishing (PublishPayerEnvelopes)NotificationApi— Full envelope stream for push notification servers (SubscribeAllEnvelopes)GatewayApi— Client-to-gateway requests, replacingPayerApi(PublishClientEnvelopes,GetNodes). Reuses message types frompayer_api.ReplicationApi changes
SubscribeOriginatorswith dedicated request/response types for node-to-node subscriptionSubscribeAllEnvelopes(moved toNotificationApi, safe since unused)Other changes
PayerApiservicegoogle/api/annotationsimports and HTTP option blocks from all xmtpv4 protosbuf.yamllint ignores for shared request/response types during transitionVerification
buf buildpassesbuf breakingpasses (no breaking changes detected)google/api/annotationsremain in xmtpv4Closes #327 (Phase 1)
Note
Restructure d14n service protos into dedicated API services
ReplicationApiinto focused services:QueryApi,PublishApi,NotificationApi, and a newGatewayApifor client-facing operations.SubscribeOriginatorsRPC toReplicationApiwith a newSubscribeOriginatorsRequestsupporting per-originator node filters and a cursor; marks several existing RPCs as deprecated.google.api.annotationsbindings fromMisbehaviorApi,MetadataApi, andPayerApi, leaving only gRPC method signatures.PayerApiitself as deprecated; itsPublishClientEnvelopesandGetNodesRPCs are now exposed via the newGatewayApi.SubscribeAllEnvelopesis removed fromReplicationApiand moved to the newNotificationApiservice.Macroscope summarized fcad8b1.