polyc-state-connect 2026.10.2

State plane transport adapter: capability-specific Connect clients and server-trait glue mapping the generated wire types onto the polyc-state kernel — typed outcomes, per-call admission, and the conformance surface the authenticated shell proves itself against (docs/proposals/separated-planes.md).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
//! Server adapter for the narrow projection catalog.

use std::{
    future::Future,
    sync::{
        Arc,
        atomic::{AtomicBool, Ordering},
    },
};

use connectrpc::{ConnectError, RequestContext, Response, Router, ServiceRequest, ServiceResult};
use polyc_proto::proto::polychrome::state::v1::{
    BeginCollectionReply, BeginCollectionRequest, CompleteCollectionReply,
    CompleteCollectionRequest, GetCollectionStateReply, GetCollectionStateRequest,
    GetManifestByGenerationReply, GetManifestByGenerationRequest, GetProjectionReceiptReply,
    GetProjectionReceiptRequest, OpenCollectionState, PublishProjectionManifestReply,
    PublishProjectionManifestRequest, RecordProjectionManifestReply,
    RecordProjectionManifestRequest, RegisterProjectionPublisherReply,
    RegisterProjectionPublisherRequest, ResolveProjectionManifestReply,
    ResolveProjectionManifestRequest, RetireGenerationsReply, RetireGenerationsRequest,
    StateProjectionCatalogService, StateProjectionCatalogServiceExt,
};
use polyc_state::{
    context::CallContext,
    error::StateError,
    feed::ProjectionSource,
    id::{CommandId, OwnerId},
    projection::{
        self, ProjectionCatalog, ProjectionGeneration, ProjectionHead, ProjectionKey,
        ProjectionManifest, PublishManifest, PublisherFence, PublisherId, ReadCollectionState,
        ReadManifestByGeneration, ReadProjectionReceipt, RecordCollectionIntent,
        RecordCollectionReceipt, RecordManifest, RegisterPublisher, ResolveManifest,
        RetireGenerations, artifact::ExactObjectRef,
    },
};

use crate::{
    admission::{
        AudienceBinding, PeerIdentity, check_audience_binding, check_call_context_version,
        check_not_draining, check_transport_deadline, slot_wait, state_audience,
    },
    blocking,
    error::to_connect_error as state_to_connect_error,
    projection::error::to_connect_error,
    trace::adopt_caller_trace,
    wire::{DeclaredCall, Kernel, declared_call},
};

/// State's narrow projection catalog service.
///
/// Every handler runs its whole catalog call inside one `blocking` closure
/// on Tokio's blocking pool, in the shared journal-gate slot share — the
/// catalog writes through the journal's mutation mutex, so it draws from the
/// same bounded capacity the journal itself does.
pub struct ProjectionCatalogSvc {
    catalog: Arc<dyn ProjectionCatalog>,
    draining: Arc<AtomicBool>,
    binding: Arc<AudienceBinding>,
}

impl ProjectionCatalogSvc {
    /// Builds the service.
    #[must_use]
    pub const fn new(
        catalog: Arc<dyn ProjectionCatalog>,
        draining: Arc<AtomicBool>,
        binding: Arc<AudienceBinding>,
    ) -> Self {
        Self {
            catalog,
            draining,
            binding,
        }
    }

    /// Registers the capability-specific service.
    #[must_use]
    pub fn register_on(self, router: Router) -> Router {
        Arc::new(self).register(router)
    }

    fn peer(ctx: &RequestContext) -> PeerIdentity {
        PeerIdentity::from_verified_leaf(
            ctx.peer_certs().and_then(<[_]>::first).map(|leaf| &**leaf),
        )
    }

    fn admit(
        &self,
        ctx: &RequestContext,
        context: impl Into<Option<polyc_proto::proto::polychrome::state::v1::CallContext>>,
        method: &'static str,
    ) -> Result<(CallContext, tracing::Span, std::time::Duration), ConnectError> {
        check_not_draining(self.draining.load(Ordering::Relaxed))?;
        let declared: DeclaredCall =
            declared_call(context).map_err(|error| state_to_connect_error(&error))?;
        let family = projection::family();
        check_call_context_version(declared.version)
            .map_err(|error| state_to_connect_error(&error))?;
        check_audience_binding(
            &Self::peer(ctx),
            &declared.audience,
            &state_audience(),
            &self.binding,
            &family,
        )
        .map_err(|error| state_to_connect_error(&error))?;
        check_transport_deadline(ctx.time_remaining(), &family)
            .map_err(|error| state_to_connect_error(&error))?;
        Ok((
            declared.origin_relative_context(),
            adopt_caller_trace(ctx.headers(), method),
            slot_wait(ctx.time_remaining(), &declared),
        ))
    }
}

fn required<T: Default, P: buffa::ProtoBox<T>>(
    field: &str,
    reason: &str,
    value: buffa::MessageField<T, P>,
) -> Result<T, ConnectError> {
    value.into_option().ok_or_else(|| {
        to_connect_error(
            &StateError::Malformed {
                field: field.to_owned(),
                reason: reason.to_owned(),
            }
            .into(),
        )
    })
}

#[allow(refining_impl_trait)]
impl StateProjectionCatalogService for ProjectionCatalogSvc {
    fn register_publisher(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, RegisterProjectionPublisherRequest>,
    ) -> impl Future<Output = ServiceResult<RegisterProjectionPublisherReply>> {
        let RegisterProjectionPublisherRequest {
            context,
            metadata,
            key,
            source_authority,
            publisher,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "RegisterProjectionPublisher")?;
            let command = RegisterPublisher::new(
                Kernel::try_from(required(
                    "metadata",
                    "a registration carries metadata",
                    metadata,
                )?)
                .map_err(|error: StateError| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a registration names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a registration names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                PublisherId::new(publisher),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let (fence, receipt) =
                blocking::mutation(span, projection::family(), wait, move || {
                    catalog.register(command, &context)
                })
                .await?;
            Response::ok(RegisterProjectionPublisherReply {
                fence: buffa::MessageField::some(Kernel(&fence).into()),
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn record_manifest(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, RecordProjectionManifestRequest>,
    ) -> impl Future<Output = ServiceResult<RecordProjectionManifestReply>> {
        let RecordProjectionManifestRequest {
            context,
            metadata,
            manifest,
            caller,
            signed_artifact,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "RecordProjectionManifest")?;
            let command = RecordManifest::new(
                Kernel::try_from(required("metadata", "a record carries metadata", metadata)?)
                    .map_err(|error: StateError| to_connect_error(&error.into()))?
                    .into_inner(),
                Kernel::<ProjectionManifest>::try_from(required(
                    "manifest",
                    "a record carries one manifest",
                    manifest,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                signed_artifact,
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::mutation(span, projection::family(), wait, move || {
                catalog.record(command, &context)
            })
            .await?;
            Response::ok(RecordProjectionManifestReply {
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn publish_manifest(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, PublishProjectionManifestRequest>,
    ) -> impl Future<Output = ServiceResult<PublishProjectionManifestReply>> {
        let PublishProjectionManifestRequest {
            context,
            metadata,
            key,
            source_authority,
            expected,
            publish,
            publisher,
            fence,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "PublishProjectionManifest")?;
            let command = PublishManifest::new(
                Kernel::try_from(required(
                    "metadata",
                    "a publication carries metadata",
                    metadata,
                )?)
                .map_err(|error: StateError| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a publication names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a publication names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                ProjectionGeneration::new(expected),
                ProjectionGeneration::new(publish),
                PublisherId::new(publisher),
                Kernel::<PublisherFence>::try_from(required(
                    "fence",
                    "a publication carries authority",
                    fence,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::mutation(span, projection::family(), wait, move || {
                catalog.publish(command, &context)
            })
            .await?;
            Response::ok(PublishProjectionManifestReply {
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn resolve_manifest(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, ResolveProjectionManifestRequest>,
    ) -> impl Future<Output = ServiceResult<ResolveProjectionManifestReply>> {
        let ResolveProjectionManifestRequest {
            context,
            key,
            source_authority,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "ResolveProjectionManifest")?;
            let query = ResolveManifest::new(
                Kernel::<ProjectionKey>::try_from(required("key", "a resolve names one key", key)?)
                    .map_err(|error| to_connect_error(&error.into()))?
                    .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a resolve names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let resolution = blocking::read(span, projection::family(), wait, move || {
                catalog.resolve(query, &context)
            })
            .await?;
            // Every arm named. A superseded head sends its generation and its
            // lineage and withholds the manifest, so a reader on the other side
            // cannot receive rows for a journal that no longer exists.
            let (head, pending, highest_recorded) = resolution.into_parts();
            let (manifest, superseded_generation, superseded_source_authority) = match &head {
                ProjectionHead::Absent => (
                    buffa::MessageField::default(),
                    None,
                    buffa::MessageField::default(),
                ),
                ProjectionHead::Current(manifest) => (
                    buffa::MessageField::some(Kernel(manifest.as_ref()).into()),
                    None,
                    buffa::MessageField::default(),
                ),
                ProjectionHead::Superseded { generation, source } => (
                    buffa::MessageField::default(),
                    Some(generation.get()),
                    buffa::MessageField::some(Kernel(source.as_ref()).into()),
                ),
            };
            Response::ok(ResolveProjectionManifestReply {
                manifest,
                superseded_generation,
                superseded_source_authority,
                pending_manifest: pending
                    .as_deref()
                    .map_or_else(buffa::MessageField::default, |manifest| {
                        buffa::MessageField::some(Kernel(manifest).into())
                    }),
                highest_recorded_generation: highest_recorded.get(),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn get_receipt(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, GetProjectionReceiptRequest>,
    ) -> impl Future<Output = ServiceResult<GetProjectionReceiptReply>> {
        let GetProjectionReceiptRequest {
            context,
            key,
            source_authority,
            command_id,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "GetProjectionReceipt")?;
            let query = ReadProjectionReceipt::new(
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a receipt read names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a receipt read names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                CommandId::new(command_id),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::read(span, projection::family(), wait, move || {
                catalog.receipt(query, &context)
            })
            .await?;
            Response::ok(GetProjectionReceiptReply {
                receipt: receipt
                    .as_ref()
                    .map_or_else(buffa::MessageField::default, |receipt| {
                        buffa::MessageField::some(Kernel(receipt).into())
                    }),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn retire(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, RetireGenerationsRequest>,
    ) -> impl Future<Output = ServiceResult<RetireGenerationsReply>> {
        let RetireGenerationsRequest {
            context,
            metadata,
            key,
            source_authority,
            expected,
            floor,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "RetireGenerations")?;
            let command = RetireGenerations::new(
                Kernel::try_from(required("metadata", "a retire carries metadata", metadata)?)
                    .map_err(|error: StateError| to_connect_error(&error.into()))?
                    .into_inner(),
                Kernel::<ProjectionKey>::try_from(required("key", "a retire names one key", key)?)
                    .map_err(|error| to_connect_error(&error.into()))?
                    .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a retire names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                ProjectionGeneration::new(expected),
                ProjectionGeneration::new(floor),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::mutation(span, projection::family(), wait, move || {
                catalog.retire(command, &context)
            })
            .await?;
            Response::ok(RetireGenerationsReply {
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn begin_collection(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, BeginCollectionRequest>,
    ) -> impl Future<Output = ServiceResult<BeginCollectionReply>> {
        let BeginCollectionRequest {
            context,
            metadata,
            key,
            source_authority,
            generation,
            objects,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "BeginCollection")?;
            let objects: Vec<ExactObjectRef> = objects
                .into_iter()
                .map(|object| {
                    Kernel::<ExactObjectRef>::try_from(object)
                        .map(Kernel::into_inner)
                        .map_err(|error: StateError| to_connect_error(&error.into()))
                })
                .collect::<Result<_, _>>()?;
            let command = RecordCollectionIntent::try_new(
                Kernel::try_from(required(
                    "metadata",
                    "a begin-collection carries metadata",
                    metadata,
                )?)
                .map_err(|error: StateError| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a begin-collection names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a begin-collection names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                ProjectionGeneration::new(generation),
                objects,
                OwnerId::new(caller),
            )
            .map_err(|error: StateError| to_connect_error(&error.into()))?;
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::mutation(span, projection::family(), wait, move || {
                catalog.begin_collection(command, &context)
            })
            .await?;
            Response::ok(BeginCollectionReply {
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn complete_collection(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, CompleteCollectionRequest>,
    ) -> impl Future<Output = ServiceResult<CompleteCollectionReply>> {
        let CompleteCollectionRequest {
            context,
            metadata,
            key,
            source_authority,
            generation,
            intent_command_id,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "CompleteCollection")?;
            let command = RecordCollectionReceipt::new(
                Kernel::try_from(required(
                    "metadata",
                    "a complete-collection carries metadata",
                    metadata,
                )?)
                .map_err(|error: StateError| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a complete-collection names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a complete-collection names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                ProjectionGeneration::new(generation),
                CommandId::new(intent_command_id),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let receipt = blocking::mutation(span, projection::family(), wait, move || {
                catalog.complete_collection(command, &context)
            })
            .await?;
            Response::ok(CompleteCollectionReply {
                receipt: buffa::MessageField::some(Kernel(&receipt).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn get_collection_state(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, GetCollectionStateRequest>,
    ) -> impl Future<Output = ServiceResult<GetCollectionStateReply>> {
        let GetCollectionStateRequest {
            context,
            key,
            source_authority,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "GetCollectionState")?;
            let query = ReadCollectionState::new(
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a collection-state read names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a collection-state read names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let state = blocking::read(span, projection::family(), wait, move || {
                catalog.collection_state(query, &context)
            })
            .await?;
            let open = state.open().map(|open| OpenCollectionState {
                generation: open.generation().get(),
                objects: open
                    .objects()
                    .iter()
                    .map(|object| Kernel(object).into())
                    .collect(),
                intent_command_id: open.intent().as_str().to_owned(),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            });
            Response::ok(GetCollectionStateReply {
                retired_floor: state.retired_floor().get(),
                retired_at_nanos: state
                    .retired_at()
                    .map(polyc_state::deadline::MonotonicInstant::as_nanos),
                open: open.map_or_else(buffa::MessageField::default, buffa::MessageField::some),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }

    fn get_manifest_by_generation(
        &self,
        ctx: RequestContext,
        request: ServiceRequest<'_, GetManifestByGenerationRequest>,
    ) -> impl Future<Output = ServiceResult<GetManifestByGenerationReply>> {
        let GetManifestByGenerationRequest {
            context,
            key,
            source_authority,
            generation,
            caller,
            __buffa_unknown_fields: _,
        } = request.to_owned_message();
        async move {
            let (context, span, wait) = self.admit(&ctx, context, "GetManifestByGeneration")?;
            let query = ReadManifestByGeneration::new(
                Kernel::<ProjectionKey>::try_from(required(
                    "key",
                    "a manifest read names one key",
                    key,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                Kernel::<ProjectionSource>::try_from(required(
                    "source_authority",
                    "a manifest read names one source",
                    source_authority,
                )?)
                .map_err(|error| to_connect_error(&error.into()))?
                .into_inner(),
                ProjectionGeneration::new(generation),
                OwnerId::new(caller),
            );
            let catalog = Arc::clone(&self.catalog);
            let manifest = blocking::read(span, projection::family(), wait, move || {
                catalog.manifest_by_generation(query, &context)
            })
            .await?;
            Response::ok(GetManifestByGenerationReply {
                manifest: buffa::MessageField::some(Kernel(&manifest).into()),
                __buffa_unknown_fields: buffa::UnknownFields::default(),
            })
        }
    }
}