liminal-protocol 0.2.1

Shared participant-lifecycle protocol types for liminal
Documentation
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
//! Fail-first evidence and closure tests for the `LP-CLIENT-GOAL` r2
//! lost-authority testimony amendment (2026-07-18).
//!
//! The first four tests were authored RED against round-4 tip `40244d6` and
//! their pre-fix failures are recorded in the commit that introduced them:
//!
//! - [`same_envelope_re_record_over_terminal_replay_refuses`] — round-4 door
//!   (b): the retained-envelope admission arm revived expected-detach authority
//!   over an inactive replay.
//! - [`tokenless_abandonment_survives_encode_without_take`] — the typed
//!   `TokenlessAfterCrash` abandonment was process-local and silently dropped
//!   by encode-without-take.
//! - [`restored_issued_permit_rejects_prior_process_permit`] — a cold-restored
//!   issued permit could still be redeemed by the dead process's permit value
//!   while the loss went unrecorded.
//! - [`restored_issued_operation_rejects_prior_process_correlation`] — a
//!   cold-restored issued operation could still be resolved by the dead
//!   process's correlation while the loss went unrecorded.

use super::*;
use crate::wire::{
    AttachSecret, BindingEpoch, ClientRequest, ConnectionIncarnation, DetachAttemptToken,
    DetachRequest, EnrollmentRequest, EnrollmentResponse, EnrollmentToken, Generation,
};
use alloc::vec;

type TestResult<T = ()> = Result<T, &'static str>;

fn generation(value: u64) -> TestResult<Generation> {
    Generation::new(value).ok_or("generation must be nonzero")
}

fn tokenless_request() -> ClientRequest {
    ClientRequest::ObserverRecovery(crate::wire::ObserverRecoveryHandshake {
        observer_refusals: vec![],
    })
}

fn epoch(value: u64) -> TestResult<BindingEpoch> {
    Ok(BindingEpoch::new(
        ConnectionIncarnation::new(161, 162),
        generation(value)?,
    ))
}

fn bound() -> TestResult<ClientParticipantAggregate> {
    let mut aggregate = ClientParticipantAggregate::new();
    aggregate.binding = ClientBindingState::Bound {
        conversation_id: 161,
        participant_id: 162,
        generation: generation(7)?,
        attach_secret: AttachSecret::new([163; 32]),
        binding_epoch: epoch(7)?,
    };
    Ok(aggregate)
}

fn detach_request() -> TestResult<ClientRequest> {
    Ok(ClientRequest::Detach(DetachRequest {
        conversation_id: 161,
        participant_id: 162,
        capability_generation: generation(7)?,
        detach_attempt_token: DetachAttemptToken::new([164; 16]),
    }))
}

#[test]
fn same_envelope_re_record_over_terminal_replay_refuses() -> TestResult {
    let ClientOperationRecordDecision::Pending(pending) =
        record_operation(bound()?, detach_request()?)
    else {
        return Err("bound detach must enter the durability barrier");
    };
    let (aggregate, operation) = pending.commit().into_parts();
    let (_, correlation) = operation.into_request();
    let committed = crate::wire::DetachCommitted::new(
        161,
        162,
        DetachAttemptToken::new([164; 16]),
        epoch(7)?,
        0,
    );
    let ApplyDetachOutcomeDecision::Terminal(applied) = apply_detach_outcome(
        aggregate,
        DetachReplayOutcome::DetachCommitted(committed),
        correlation,
    ) else {
        return Err("exact detach outcome must terminalize replay");
    };
    let ClientOperationRecordDecision::Refused(refusal) =
        record_operation(applied.into_aggregate(), detach_request()?)
    else {
        return Err("same-envelope re-record over terminal replay must refuse");
    };
    let (aggregate, _) = refusal.into_parts();
    assert!(!aggregate.has_expected_operation());
    Ok(())
}

#[test]
fn tokenless_abandonment_survives_encode_without_take() -> TestResult {
    let mut aggregate = bound()?;
    let request = tokenless_request();
    aggregate.expected = Some(ExpectedOperationState {
        request: request.clone(),
        issued: true,
        authorization: 1,
        lost: None,
    });
    aggregate.next_operation_authorization = 1;
    let restored = aggregate
        .resume_record()
        .map_err(|_| "tokenless fixture must encode")?
        .restore()
        .map_err(|_| "tokenless fixture must restore")?;
    let mut second = restored
        .resume_record()
        .map_err(|_| "pending abandonment must encode")?
        .restore()
        .map_err(|_| "re-encoded abandonment must restore")?;
    let abandonment = second
        .take_restored_operation_abandonment()
        .ok_or("encode-without-take must not lose the abandonment")?;
    assert_eq!(abandonment.into_request(), request);
    Ok(())
}

#[test]
fn restored_issued_permit_rejects_prior_process_permit() -> TestResult {
    let ReconnectPermitDecision::Permitted {
        aggregate, permit, ..
    } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    )
    else {
        return Err("fresh action must issue permit");
    };
    let restored = aggregate
        .resume_record()
        .map_err(|_| "issued permit must encode")?
        .restore()
        .map_err(|_| "issued permit must restore")?;
    assert!(matches!(
        redeem_attempt(restored, permit),
        ReconnectAttemptDecision::Refused { .. }
    ));
    Ok(())
}

#[test]
fn restored_issued_operation_rejects_prior_process_correlation() -> TestResult {
    let token = EnrollmentToken::new([21; 16]);
    let request = ClientRequest::Enrollment(EnrollmentRequest {
        conversation_id: 2,
        enrollment_token: token,
    });
    let ClientOperationRecordDecision::Pending(pending) =
        record_operation(ClientParticipantAggregate::new(), request)
    else {
        return Err("enrollment must enter the durability barrier");
    };
    let (aggregate, operation) = pending.commit().into_parts();
    let (_, correlation) = operation.into_request();
    let restored = aggregate
        .resume_record()
        .map_err(|_| "issued operation must encode")?
        .restore()
        .map_err(|_| "issued operation must restore")?;
    let exact = EnrollmentResponse::connection_conversation_capacity_exceeded(
        crate::wire::EnrollmentEnvelope {
            conversation_id: 2,
            enrollment_token: token,
        },
        10,
    )
    .into_server_value();
    assert!(matches!(
        decide_correlated_inbound(restored, exact, correlation),
        ClientCorrelatedInboundDecision::Refused(_)
    ));
    Ok(())
}

fn detach_envelope() -> TestResult<crate::wire::DetachEnvelope> {
    Ok(crate::wire::DetachEnvelope {
        conversation_id: 161,
        participant_id: 162,
        capability_generation: generation(7)?,
        detach_attempt_token: DetachAttemptToken::new([164; 16]),
    })
}

fn round_trip(aggregate: &ClientParticipantAggregate) -> TestResult<ClientParticipantAggregate> {
    let bytes = aggregate
        .resume_record()
        .map_err(|_| "aggregate must encode")?
        .encode_canonical();
    ClientResumeRecord::decode_canonical(&bytes)
        .map_err(|_| "canonical record must decode")?
        .restore()
        .map_err(|_| "canonical record must restore")
}

fn restored_issued(request: ClientRequest) -> TestResult<ClientParticipantAggregate> {
    let start = if matches!(request, ClientRequest::Enrollment(_)) {
        ClientParticipantAggregate::new()
    } else {
        bound()?
    };
    let ClientOperationRecordDecision::Pending(pending) = record_operation(start, request) else {
        return Err("token-bearing request must enter the durability barrier");
    };
    let (aggregate, operation) = pending.commit().into_parts();
    let (_, _correlation) = operation.into_request();
    round_trip(&aggregate)
}

#[test]
fn testimony_round_trips_distinctly_for_every_kind() -> TestResult {
    let restored = restored_issued(detach_request()?)?;
    assert_eq!(
        restored
            .lost_operation_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::DetachTransportAttempt)
    );
    let again = round_trip(&restored)?;
    assert_eq!(
        again
            .lost_operation_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::DetachTransportAttempt),
        "encode-without-take must carry the detach testimony exactly once"
    );

    let attach = ClientRequest::CredentialAttach(crate::wire::CredentialAttachRequest {
        conversation_id: 161,
        participant_id: 162,
        capability_generation: generation(7)?,
        attach_secret: AttachSecret::new([163; 32]),
        attach_attempt_token: crate::wire::AttachAttemptToken::new([165; 16]),
        accept_marker_delivery_seq: None,
    });
    let restored = restored_issued(attach)?;
    assert_eq!(
        restored
            .lost_operation_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::IssuedOperationCorrelation)
    );
    let again = round_trip(&restored)?;
    assert_eq!(
        again
            .lost_operation_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::IssuedOperationCorrelation),
        "encode-without-take must carry the correlation testimony exactly once"
    );

    let ReconnectPermitDecision::Permitted { aggregate, .. } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    ) else {
        return Err("fresh action must issue permit");
    };
    let restored = round_trip(&aggregate)?;
    assert_eq!(
        restored
            .lost_reconnect_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::ReconnectPermit)
    );
    let again = round_trip(&restored)?;
    assert_eq!(
        again
            .lost_reconnect_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::ReconnectPermit)
    );

    let ReconnectPermitDecision::Permitted {
        aggregate, permit, ..
    } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    )
    else {
        return Err("fresh action must issue permit");
    };
    let ReconnectAttemptDecision::Started { aggregate, .. } = redeem_attempt(aggregate, permit)
    else {
        return Err("permit must start attempt");
    };
    let restored = round_trip(&aggregate)?;
    assert_eq!(
        restored
            .lost_reconnect_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::ReconnectAttempt)
    );
    let again = round_trip(&restored)?;
    assert_eq!(
        again
            .lost_reconnect_testimony()
            .map(LostAuthorityTestimony::kind),
        Some(LostAuthorityKind::ReconnectAttempt)
    );
    Ok(())
}

#[test]
fn detach_loss_resolves_to_parked_and_reissues_exactly_once() -> TestResult {
    let restored = restored_issued(detach_request()?)?;
    let LostOperationAuthorityDecision::DetachParked {
        aggregate,
        request,
        testimony,
    } = resolve_lost_operation_authority(restored)
    else {
        return Err("lost detach attempt must park through its testimony");
    };
    assert_eq!(testimony.kind(), LostAuthorityKind::DetachTransportAttempt);
    assert_eq!(request, detach_request()?);
    assert!(matches!(
        aggregate.detach_replay().status(),
        Some(DetachReplayStatus::Parked)
    ));
    let LostOperationAuthorityDecision::Refused {
        aggregate,
        reason: LostAuthorityResolutionRefusalReason::NoPendingTestimony,
    } = resolve_lost_operation_authority(aggregate)
    else {
        return Err("second resolution must refuse without a pending testimony");
    };
    let DetachTransportAttemptDecision::Started { aggregate, .. } =
        transport_attempt_started(aggregate)
    else {
        return Err("parked exact detach must release one replacement send");
    };
    assert!(matches!(
        transport_attempt_started(aggregate),
        DetachTransportAttemptDecision::Refused(_)
    ));
    Ok(())
}

#[test]
fn restore_refuses_testimony_and_abandonment_coupling_mismatches() -> TestResult {
    let mut unissued = bound()?;
    unissued.expected = Some(ExpectedOperationState {
        request: ClientRequest::CredentialAttach(crate::wire::CredentialAttachRequest {
            conversation_id: 161,
            participant_id: 162,
            capability_generation: generation(7)?,
            attach_secret: AttachSecret::new([163; 32]),
            attach_attempt_token: crate::wire::AttachAttemptToken::new([166; 16]),
            accept_marker_delivery_seq: None,
        }),
        issued: false,
        authorization: 1,
        lost: Some(LostAuthorityTestimony::mint(
            LostAuthorityKind::IssuedOperationCorrelation,
        )),
    });
    unissued.next_operation_authorization = 1;
    assert_eq!(
        unissued
            .resume_record()
            .map_err(|_| "mismatch fixture must encode")?
            .restore(),
        Err(ClientResumeRestoreError::LostAuthorityTestimonyMismatch)
    );

    let mut wrong_kind = bound()?;
    wrong_kind.expected = Some(ExpectedOperationState {
        request: detach_request()?,
        issued: true,
        authorization: 1,
        lost: Some(LostAuthorityTestimony::mint(
            LostAuthorityKind::IssuedOperationCorrelation,
        )),
    });
    wrong_kind.next_operation_authorization = 1;
    wrong_kind.detach_replay.state = super::replay::DetachReplayState::Recorded {
        request: detach_envelope()?,
        status: DetachReplayStatus::InFlight,
    };
    assert_eq!(
        wrong_kind
            .resume_record()
            .map_err(|_| "wrong-kind fixture must encode")?
            .restore(),
        Err(ClientResumeRestoreError::LostAuthorityTestimonyMismatch)
    );

    let mut parked = ClientParticipantAggregate::new();
    parked.reconnect.lost = Some(LostAuthorityTestimony::mint(
        LostAuthorityKind::ReconnectPermit,
    ));
    assert_eq!(
        parked
            .resume_record()
            .map_err(|_| "parked fixture must encode")?
            .restore(),
        Err(ClientResumeRestoreError::LostAuthorityTestimonyMismatch)
    );

    let ReconnectPermitDecision::Permitted { mut aggregate, .. } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    ) else {
        return Err("fresh action must issue permit");
    };
    aggregate.reconnect.lost = Some(LostAuthorityTestimony::mint(
        LostAuthorityKind::ReconnectAttempt,
    ));
    assert_eq!(
        aggregate
            .resume_record()
            .map_err(|_| "wrong reconnect kind must encode")?
            .restore(),
        Err(ClientResumeRestoreError::LostAuthorityTestimonyMismatch)
    );

    Ok(())
}

#[test]
fn restore_refuses_abandonment_beside_tokenless_expected() -> TestResult {
    let mut conflicted = bound()?;
    conflicted.restored_abandonment = Some(RestoredExpectedOperationAbandonment {
        request: tokenless_request(),
        reason: RestoredExpectedOperationAbandonmentReason::TokenlessAfterCrash,
        was_issued: true,
    });
    conflicted.expected = Some(ExpectedOperationState {
        request: tokenless_request(),
        issued: false,
        authorization: 1,
        lost: None,
    });
    conflicted.next_operation_authorization = 1;
    assert_eq!(
        conflicted
            .resume_record()
            .map_err(|_| "conflict fixture must encode")?
            .restore(),
        Err(ClientResumeRestoreError::PendingAbandonmentConflict)
    );
    Ok(())
}

#[test]
fn pending_operation_testimony_gates_every_correlation_path() -> TestResult {
    let restored = restored_issued(ClientRequest::Enrollment(EnrollmentRequest {
        conversation_id: 161,
        enrollment_token: EnrollmentToken::new([167; 16]),
    }))?;
    let exact = EnrollmentResponse::connection_conversation_capacity_exceeded(
        crate::wire::EnrollmentEnvelope {
            conversation_id: 161,
            enrollment_token: EnrollmentToken::new([167; 16]),
        },
        10,
    )
    .into_server_value();
    let correlation = ClientResponseCorrelation { authorization: 1 };
    let ClientCorrelatedInboundDecision::Refused(refusal) =
        decide_correlated_inbound(restored, exact, correlation)
    else {
        return Err("pending testimony must refuse correlated inbound");
    };
    assert_eq!(
        refusal.reason(),
        ClientInboundRefusalReason::LostAuthorityPending
    );
    let (aggregate, _, correlation) = refusal.into_parts();
    let ExpectedOperationFateDecision::Refused { reason, .. } = record_expected_operation_fate(
        aggregate,
        correlation,
        ExpectedOperationTransportFate::ResponseUnavailable,
    ) else {
        return Err("pending testimony must refuse transport fate");
    };
    assert_eq!(
        reason,
        ExpectedOperationFateRefusalReason::LostAuthorityPending
    );

    let restored = restored_issued(detach_request()?)?;
    let correlation = ClientResponseCorrelation { authorization: 1 };
    let DetachTransportFateDecision::Refused(refusal) = transport_fate(
        restored,
        correlation,
        DetachTransportFate::ResponseUnavailable,
    ) else {
        return Err("pending testimony must refuse detach transport fate");
    };
    assert_eq!(
        refusal.reason(),
        DetachReplayRefusalReason::LostAuthorityPending
    );
    let (aggregate, (correlation, _)) = refusal.into_parts();
    let committed = crate::wire::DetachCommitted::new(
        161,
        162,
        DetachAttemptToken::new([164; 16]),
        epoch(7)?,
        0,
    );
    let ApplyDetachOutcomeDecision::Refused(refusal) = apply_detach_outcome(
        aggregate,
        DetachReplayOutcome::DetachCommitted(committed),
        correlation,
    ) else {
        return Err("pending testimony must refuse detach outcome");
    };
    assert_eq!(
        refusal.reason(),
        DetachReplayRefusalReason::LostAuthorityPending
    );
    Ok(())
}

#[test]
fn pending_reconnect_testimony_gates_redemption_and_attempt_fate() -> TestResult {
    let ReconnectPermitDecision::Permitted {
        aggregate, permit, ..
    } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    )
    else {
        return Err("fresh action must issue permit");
    };
    let restored = round_trip(&aggregate)?;
    let ReconnectAttemptDecision::Refused { reason, .. } = redeem_attempt(restored, permit) else {
        return Err("pending testimony must refuse redemption");
    };
    assert_eq!(reason, ReconnectAttemptRefusalReason::LostAuthorityPending);

    let ReconnectPermitDecision::Permitted {
        aggregate, permit, ..
    } = record_explicit_reconnect(
        ClientParticipantAggregate::new(),
        ExplicitReconnectAction::ReconnectNow,
    )
    else {
        return Err("fresh action must issue permit");
    };
    let ReconnectAttemptDecision::Started { aggregate, attempt } =
        redeem_attempt(aggregate, permit)
    else {
        return Err("permit must start attempt");
    };
    let restored = round_trip(&aggregate)?;
    let ReconnectAttemptFateDecision::Refused { reason, .. } =
        record_attempt_fate(restored, attempt, ReconnectAttemptFate::Connected)
    else {
        return Err("pending testimony must refuse attempt fate");
    };
    assert_eq!(
        reason,
        ReconnectAttemptFateRefusalReason::LostAuthorityPending
    );
    Ok(())
}

#[test]
fn pending_abandonment_gates_tokenless_admission_only() -> TestResult {
    let mut aggregate = bound()?;
    let request = tokenless_request();
    aggregate.expected = Some(ExpectedOperationState {
        request: request.clone(),
        issued: true,
        authorization: 1,
        lost: None,
    });
    aggregate.next_operation_authorization = 1;
    let restored = round_trip(&aggregate)?;
    assert!(
        restored
            .restored_operation_abandonment()
            .is_some_and(RestoredExpectedOperationAbandonment::was_issued)
    );
    let ClientOperationRecordDecision::Refused(refusal) = record_operation(restored, request)
    else {
        return Err("tokenless re-record must wait for the pending abandonment");
    };
    assert_eq!(
        refusal.reason(),
        ClientOperationRecordRefusalReason::AbandonmentPending
    );
    let (aggregate, _) = refusal.into_parts();
    assert!(
        aggregate.restored_operation_abandonment().is_some(),
        "refusal must retain the pending abandonment"
    );
    assert!(matches!(
        record_operation(aggregate, detach_request()?),
        ClientOperationRecordDecision::Pending(_)
    ));
    Ok(())
}

#[test]
fn unissued_tokenless_abandonment_take_releases_nothing() -> TestResult {
    let ClientOperationRecordDecision::Pending(pending) =
        record_operation(bound()?, tokenless_request())
    else {
        return Err("record admission must enter the durability barrier");
    };
    let commit = pending.commit();
    let mut restored = commit
        .resume_record()
        .map_err(|_| "commit must encode")?
        .restore()
        .map_err(|_| "commit must restore")?;
    let abandonment = restored
        .take_restored_operation_abandonment()
        .ok_or("unissued tokenless restore must abandon")?;
    assert!(!abandonment.was_issued());
    assert!(restored.take_restored_operation_abandonment().is_none());
    assert!(matches!(
        recover_expected_operation(restored),
        RecoveredExpectedOperationDecision::NotAvailable {
            already_issued: false,
            ..
        }
    ));
    Ok(())
}

#[test]
fn same_envelope_re_record_refuses_every_inactive_status_and_admits_parked() -> TestResult {
    let inactive = [
        DetachReplayStatus::Superseded,
        DetachReplayStatus::LeaveSuperseded,
        DetachReplayStatus::Terminal(DetachReplayTerminal::DetachCommitted(
            crate::wire::DetachCommitted::new(
                161,
                162,
                DetachAttemptToken::new([164; 16]),
                epoch(7)?,
                0,
            ),
        )),
    ];
    for status in inactive {
        let mut aggregate = bound()?;
        aggregate.detach_replay.state = super::replay::DetachReplayState::Recorded {
            request: detach_envelope()?,
            status,
        };
        let ClientOperationRecordDecision::Refused(refusal) =
            record_operation(aggregate, detach_request()?)
        else {
            return Err("inactive same-envelope re-record must refuse");
        };
        assert_eq!(
            refusal.reason(),
            ClientOperationRecordRefusalReason::DetachReplayIncompatible
        );
    }

    let mut parked = bound()?;
    parked.detach_replay.state = super::replay::DetachReplayState::Recorded {
        request: detach_envelope()?,
        status: DetachReplayStatus::Parked,
    };
    assert!(matches!(
        record_operation(parked, detach_request()?),
        ClientOperationRecordDecision::Pending(_)
    ));
    Ok(())
}