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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
use crate::algebra::{ResourceVector, WideResourceVector};
use crate::wire::{BindingEpoch, ConversationId, DeliverySeq, ParticipantId, ParticipantIndex};

use super::{
    ActiveBinding, CommittedDiedTerminal, ObserverProgressProjection,
    claim_frontier::{ValidatedMarkerCandidate, ValidatedMarkerRecord},
};

/// Nonzero componentwise closure debt.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ClosureDebt(WideResourceVector);

impl ClosureDebt {
    /// Creates debt only when at least one component is nonzero.
    #[must_use]
    pub const fn new(value: WideResourceVector) -> Option<Self> {
        if value.is_zero() {
            None
        } else {
            Some(Self(value))
        }
    }

    /// Returns exact entry/byte debt.
    #[must_use]
    pub const fn value(self) -> WideResourceVector {
        self.0
    }
}

/// Observer-projection witness.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ObserverProjection {
    through_seq: DeliverySeq,
}

impl ObserverProjection {
    /// Creates an exact observer-projection witness.
    #[must_use]
    pub const fn new(through_seq: DeliverySeq) -> Self {
        Self { through_seq }
    }

    /// Returns the exact projection boundary.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }
}

/// Physical-compaction range witness.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PhysicalCompaction {
    from_floor: DeliverySeq,
    through_seq: DeliverySeq,
}

impl PhysicalCompaction {
    /// Creates a nonempty, ordered compaction range.
    #[must_use]
    pub const fn new(from_floor: DeliverySeq, through_seq: DeliverySeq) -> Option<Self> {
        if from_floor <= through_seq {
            Some(Self {
                from_floor,
                through_seq,
            })
        } else {
            None
        }
    }

    /// Returns the exact first sequence in the compaction range.
    #[must_use]
    pub const fn from_floor(self) -> DeliverySeq {
        self.from_floor
    }

    /// Returns the exact inclusive compaction boundary.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }
}

/// Exact marker-delivery witness.
///
/// This witness has no public constructor. Fresh delivery is produced only by
/// the claim frontier's consuming marker-drain transition; cold restoration
/// requires its sealed retained-marker-record authority. Raw participant,
/// binding, and sequence values therefore cannot create recovery authority.
///
/// ```compile_fail
/// use liminal_protocol::{
///     lifecycle::MarkerDelivery,
///     wire::{BindingEpoch, ConnectionIncarnation, Generation},
/// };
///
/// let epoch = BindingEpoch::new(
///     ConnectionIncarnation::new(1, 1),
///     Generation::ONE,
/// );
/// let _ = MarkerDelivery::new(7, epoch, 11);
/// ```
// The frozen tag spells this required field `marker_delivery_seq`.
#[allow(clippy::struct_field_names)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct MarkerDelivery {
    conversation_id: ConversationId,
    participant_id: ParticipantId,
    binding_epoch: BindingEpoch,
    marker_delivery_seq: DeliverySeq,
}

impl MarkerDelivery {
    /// Creates the exact post-append marker successor only from one
    /// frontier-consumed marker candidate.
    ///
    /// A candidate whose target epoch is still bound selects live delivery. A
    /// candidate whose target epoch has already died selects the undelivered
    /// detached release directly, so no transient live-delivery authority is
    /// fabricated for a detached participant.
    #[must_use]
    pub(super) const fn successor_from_validated_candidate(
        candidate: ValidatedMarkerCandidate,
    ) -> StoredEdge {
        let conversation_id = candidate.conversation_id();
        let participant_id = candidate.participant_id();
        let marker_delivery_seq = candidate.delivery_seq();
        let successor = match candidate.target_binding() {
            super::FrontierBinding::Bound(binding_epoch) => StoredEdge::MarkerDelivery(Self {
                conversation_id,
                participant_id,
                binding_epoch,
                marker_delivery_seq,
            }),
            super::FrontierBinding::Detached(last_dead_binding_epoch) => {
                StoredEdge::DetachedMarkerRelease(DetachedMarkerRelease {
                    participant_id,
                    marker_delivery_seq,
                    last_dead_binding_epoch,
                })
            }
        };
        candidate.consume();
        successor
    }

    /// Rebuilds delivery only from one frontier-validated retained marker.
    #[must_use]
    pub(super) const fn from_validated_record(record: &ValidatedMarkerRecord) -> Self {
        Self {
            conversation_id: record.conversation_id(),
            participant_id: record.participant_id(),
            binding_epoch: record.binding_epoch(),
            marker_delivery_seq: record.delivery_seq(),
        }
    }

    /// Returns the conversation whose frontier authority minted this delivery.
    #[must_use]
    pub const fn conversation_id(self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the marker owner.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the exact delivery epoch.
    #[must_use]
    pub const fn binding_epoch(self) -> BindingEpoch {
        self.binding_epoch
    }

    /// Returns the exact marker sequence.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> DeliverySeq {
        self.marker_delivery_seq
    }
}

#[cfg(test)]
#[allow(clippy::expect_used, clippy::too_many_lines)]
pub fn validated_marker_record_for_test(
    conversation_id: crate::wire::ConversationId,
    participant_id: ParticipantId,
    target_binding: super::claim_frontier::FrontierBinding,
    marker_delivery_seq: DeliverySeq,
    cursor: DeliverySeq,
) -> ValidatedMarkerRecord {
    use alloc::{vec, vec::Vec};

    use crate::outcome::CandidatePhase;

    use super::{
        AdmissionOrder, OrderClaims, OrderHigh, OrderLedger, RecoverySequenceReserve,
        SequenceClaims, SequenceLedger,
        claim_frontier::{
            BindingTerminalOwner, ClaimFrontiers, ClaimFrontiersRestore, FrontierBinding,
            FrontierParticipant, ImmutableSequenceCandidate, MarkerProvenance, MarkerRecordRequest,
            MovableOrderClaim, MovableSequenceClaim, OrderClaimFrontierRestore, OrderDirectOwner,
            RetainedCausalRecord, RetainedCausalRecordKind, SequenceClaimFrontierRestore,
            SequenceDirectOwner, SequenceProductRangesRestore, TerminalProductRangeRestore,
        },
    };

    let identity_slot_limit = participant_id
        .checked_add(1)
        .expect("test participant must fit a half-open identity domain");
    let exit_seq = marker_delivery_seq
        .checked_add(1)
        .expect("test marker must leave an exit-claim suffix");
    let binding_epoch = match target_binding {
        FrontierBinding::Bound(epoch) | FrontierBinding::Detached(epoch) => epoch,
    };
    let terminal_owner = BindingTerminalOwner {
        participant_index: participant_id,
        binding_epoch,
    };
    let (sequence_claims, sequence_movable, products, order_claims, order_movable) =
        match target_binding {
            FrontierBinding::Bound(_) => {
                let terminal_seq = exit_seq
                    .checked_add(1)
                    .expect("test marker must leave a terminal-claim suffix");
                let product_seq = terminal_seq
                    .checked_add(1)
                    .expect("test marker must leave a terminal-product suffix");
                (
                    SequenceClaims::new(1, 1, 0, RecoverySequenceReserve::None),
                    vec![
                        MovableSequenceClaim {
                            delivery_seq: exit_seq,
                            owner: SequenceDirectOwner::MembershipExit {
                                participant_index: participant_id,
                            },
                        },
                        MovableSequenceClaim {
                            delivery_seq: terminal_seq,
                            owner: SequenceDirectOwner::BindingTerminal(terminal_owner),
                        },
                    ],
                    SequenceProductRangesRestore {
                        live_times_terminal: vec![TerminalProductRangeRestore {
                            start: product_seq,
                            length: 1,
                            terminal: terminal_owner,
                        }],
                        live_times_replacement_terminal: None,
                        other_live_times_exit: vec![],
                    },
                    OrderClaims::new(1, 1, false, false)
                        .expect("bound test claims have no torn recovery pair"),
                    vec![
                        MovableOrderClaim {
                            transaction_order: 1,
                            owner: OrderDirectOwner::ActiveBindingTerminal(terminal_owner),
                        },
                        MovableOrderClaim {
                            transaction_order: 2,
                            owner: OrderDirectOwner::MembershipExit {
                                participant_index: participant_id,
                            },
                        },
                    ],
                )
            }
            FrontierBinding::Detached(_) => (
                SequenceClaims::new(1, 0, 0, RecoverySequenceReserve::None),
                vec![MovableSequenceClaim {
                    delivery_seq: exit_seq,
                    owner: SequenceDirectOwner::MembershipExit {
                        participant_index: participant_id,
                    },
                }],
                SequenceProductRangesRestore::default(),
                OrderClaims::new(0, 1, false, false)
                    .expect("detached test claims have no torn recovery pair"),
                vec![MovableOrderClaim {
                    transaction_order: 1,
                    owner: OrderDirectOwner::MembershipExit {
                        participant_index: participant_id,
                    },
                }],
            ),
        };
    let sequence_ledger = SequenceLedger::try_new(marker_delivery_seq, sequence_claims)
        .expect("test sequence frontier is within the numeric suffix");
    let order_ledger = OrderLedger::try_new(OrderHigh::Allocated(0), order_claims)
        .expect("test order frontier is within the numeric suffix");
    let admission_order = AdmissionOrder::new(0, CandidatePhase::CompactionMarker, participant_id);
    let mut prevalidated = ClaimFrontiers::prevalidate(
        ClaimFrontiersRestore {
            conversation_id,
            active_identities: vec![FrontierParticipant::new(
                participant_id,
                cursor,
                target_binding,
            )],
            identity_slot_limit,
            retained_floor: u128::from(marker_delivery_seq),
            retained_record_limit: 1,
            retained_records: vec![RetainedCausalRecord {
                delivery_seq: marker_delivery_seq,
                admission_order,
                kind: RetainedCausalRecordKind::CompactionMarker {
                    participant_index: participant_id,
                    provenance: MarkerProvenance::NonProductM,
                },
            }],
            active_marker_anchors: vec![marker_delivery_seq],
            historical_marker_deliveries: vec![],
            historical_causal_facts: vec![],
            sequence: SequenceClaimFrontierRestore {
                movable_claims: sequence_movable,
                immutable_candidates: Vec::<ImmutableSequenceCandidate>::new(),
                products,
                recovery: None,
            },
            order: OrderClaimFrontierRestore {
                movable_claims: order_movable,
                immutable_candidates: vec![],
                recovery: None,
            },
            recovery_marker_delivery_seq: None,
        },
        sequence_ledger,
        order_ledger,
    )
    .expect("complete test claim frontier must prevalidate");
    let record = prevalidated
        .take_marker_record(MarkerRecordRequest::planned(
            participant_id,
            marker_delivery_seq,
            target_binding,
        ))
        .expect("prevalidated test frontier retains its exact marker");
    if cursor >= marker_delivery_seq {
        record.delivered_for_test()
    } else {
        record
    }
}

#[cfg(test)]
pub fn marker_delivery_for_test(
    participant_id: ParticipantId,
    binding_epoch: BindingEpoch,
    marker_delivery_seq: DeliverySeq,
) -> Result<MarkerDelivery, super::storage::StorageRestoreError> {
    let record = validated_marker_record_for_test(
        1,
        participant_id,
        super::claim_frontier::FrontierBinding::Bound(binding_epoch),
        marker_delivery_seq,
        marker_delivery_seq.saturating_sub(1),
    );
    super::storage::MarkerDeliveryRestore {
        participant_id,
        binding_epoch,
        marker_delivery_seq,
    }
    .restore_bound(1, record)
}

/// Continuous cursor-progress witness with no delivered marker.
///
/// This witness deliberately has no public constructor. A caller outside this
/// crate cannot turn raw participant/epoch values into executable binding-fate
/// authority; recovered-epoch fate must instead originate from
/// [`FencedAttachCommit::recovered_binding_fate`].
///
/// ```compile_fail
/// use liminal_protocol::{
///     lifecycle::CursorProgressContinuous,
///     wire::BindingEpoch,
/// };
///
/// fn fabricate(epoch: BindingEpoch) {
///     let _ = CursorProgressContinuous::new(7, epoch, 11);
/// }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CursorProgressContinuous {
    participant_id: ParticipantId,
    binding_epoch: BindingEpoch,
    through_seq: DeliverySeq,
}

impl CursorProgressContinuous {
    /// Creates an exact current-epoch continuous-cursor witness internally.
    #[cfg(test)]
    #[must_use]
    pub(crate) const fn new(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        through_seq: DeliverySeq,
    ) -> Self {
        Self {
            participant_id,
            binding_epoch,
            through_seq,
        }
    }

    /// Returns the participant whose cursor is required.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the exact binding epoch.
    #[must_use]
    pub const fn binding_epoch(self) -> BindingEpoch {
        self.binding_epoch
    }

    /// Returns the required cumulative boundary.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }
}

/// Marker-backed cursor-progress witness.
///
/// This value has no public constructor. It is produced only by consuming an
/// exact [`MarkerDelivery`] with its matching [`Event::marker_delivered`]. That
/// makes the durable exact-epoch delivery fact required by the frozen contract
/// a type-level precondition for detached credential recovery.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CursorProgressMarker {
    conversation_id: ConversationId,
    participant_id: ParticipantId,
    binding_epoch: BindingEpoch,
    through_seq: DeliverySeq,
    marker_delivery_seq: DeliverySeq,
}

impl CursorProgressMarker {
    /// Returns the conversation inherited from the exact marker delivery.
    #[must_use]
    pub const fn conversation_id(self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the participant whose marker must be accepted.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the exact epoch that received the marker.
    #[must_use]
    pub const fn binding_epoch(self) -> BindingEpoch {
        self.binding_epoch
    }

    /// Returns the required cumulative boundary.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }

    /// Returns the exact delivered marker.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> DeliverySeq {
        self.marker_delivery_seq
    }
}

/// Cursor progress split into typestates rather than an optional marker bag.
///
/// Continuous construction is crate-private so matching raw participant and
/// epoch values cannot fabricate `DetachedCursorRelease` authority.
///
/// ```compile_fail
/// use liminal_protocol::{
///     lifecycle::ParticipantCursorProgress,
///     wire::BindingEpoch,
/// };
///
/// fn fabricate(epoch: BindingEpoch) {
///     let _ = ParticipantCursorProgress::continuous(7, epoch, 11);
/// }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ParticipantCursorProgress {
    /// Continuous cursor witness.
    Continuous(CursorProgressContinuous),
    /// Exact marker acknowledgement witness, derivable only from delivery.
    Marker(CursorProgressMarker),
}

impl ParticipantCursorProgress {
    /// Creates a continuous, no-marker cursor witness internally.
    #[cfg(test)]
    #[must_use]
    pub(crate) const fn continuous(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        through_seq: DeliverySeq,
    ) -> Self {
        Self::Continuous(CursorProgressContinuous::new(
            participant_id,
            binding_epoch,
            through_seq,
        ))
    }

    pub(super) fn restore_continuous(
        authority: OrdinaryBindingAuthority,
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        through_seq: DeliverySeq,
    ) -> Option<Self> {
        if authority.binding.participant_id != participant_id
            || authority.binding.binding_epoch != binding_epoch
            || authority.through_seq != through_seq
        {
            return None;
        }
        Some(Self::Continuous(CursorProgressContinuous {
            participant_id,
            binding_epoch,
            through_seq,
        }))
    }

    /// Returns the participant whose cursor is required.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        match self {
            Self::Continuous(value) => value.participant_id,
            Self::Marker(value) => value.participant_id,
        }
    }

    /// Returns the exact binding epoch.
    #[must_use]
    pub const fn binding_epoch(self) -> BindingEpoch {
        match self {
            Self::Continuous(value) => value.binding_epoch,
            Self::Marker(value) => value.binding_epoch,
        }
    }

    /// Returns the required cumulative boundary.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        match self {
            Self::Continuous(value) => value.through_seq,
            Self::Marker(value) => value.through_seq,
        }
    }

    /// Returns the exact delivered marker when this is marker-backed.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> Option<DeliverySeq> {
        match self {
            Self::Continuous(_) => None,
            Self::Marker(value) => Some(value.marker_delivery_seq),
        }
    }
}

/// Detached fenced credential-recovery witness.
///
/// This state is produced only by the exact binding fate of a marker-backed
/// cursor witness; callers cannot fabricate a durable delivery fact.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DetachedCredentialRecovery {
    conversation_id: ConversationId,
    participant_id: ParticipantId,
    marker_delivery_seq: DeliverySeq,
    prior_binding_epoch: BindingEpoch,
}

impl DetachedCredentialRecovery {
    /// Returns the conversation inherited from the marker-backed cursor witness.
    #[must_use]
    pub const fn conversation_id(self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the detached participant.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the delivered recovery marker.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> DeliverySeq {
        self.marker_delivery_seq
    }

    /// Returns the prior authoritative epoch.
    #[must_use]
    pub const fn prior_binding_epoch(self) -> BindingEpoch {
        self.prior_binding_epoch
    }
}

/// Leave-only undelivered-marker release witness.
///
/// This state is produced only when exact binding fate consumes a marker that
/// has not reached [`CursorProgressMarker`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DetachedMarkerRelease {
    participant_id: ParticipantId,
    marker_delivery_seq: DeliverySeq,
    last_dead_binding_epoch: BindingEpoch,
}

impl DetachedMarkerRelease {
    /// Returns the detached participant.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the undelivered marker.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> DeliverySeq {
        self.marker_delivery_seq
    }

    /// Returns the dead binding epoch.
    #[must_use]
    pub const fn last_dead_binding_epoch(self) -> BindingEpoch {
        self.last_dead_binding_epoch
    }
}

/// Leave-only detached-cursor release witness.
///
/// This state is produced only when exact binding fate consumes a continuous
/// cursor witness with no marker.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DetachedCursorRelease {
    participant_id: ParticipantId,
    last_dead_binding_epoch: BindingEpoch,
}

impl DetachedCursorRelease {
    /// Returns the detached participant.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the dead binding epoch.
    #[must_use]
    pub const fn last_dead_binding_epoch(self) -> BindingEpoch {
        self.last_dead_binding_epoch
    }
}

/// Exact seven non-clear stored edge kinds.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StoredEdge {
    /// Observer projection.
    ObserverProjection(ObserverProjection),
    /// Physical compaction.
    PhysicalCompaction(PhysicalCompaction),
    /// Marker delivery.
    MarkerDelivery(MarkerDelivery),
    /// Participant cursor progress.
    ParticipantCursorProgress(ParticipantCursorProgress),
    /// Detached credential recovery.
    DetachedCredentialRecovery(DetachedCredentialRecovery),
    /// Detached marker release.
    DetachedMarkerRelease(DetachedMarkerRelease),
    /// Detached cursor release.
    DetachedCursorRelease(DetachedCursorRelease),
}

/// Closure state makes a clear edge with nonzero debt unconstructible.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ClosureState {
    /// No edge and zero debt.
    Clear,
    /// Nonzero debt paired with one exact stored witness.
    Owed {
        /// Exact nonzero debt.
        debt: ClosureDebt,
        /// Current repayment witness.
        edge: StoredEdge,
    },
}

/// Opaque proof that ordinary detached attach entered from a legal closure state.
///
/// Only [`ClosureState::ordinary_detached_attach_admission`] constructs this
/// value. Recovery-fenced DCR, DMR, and `DCursor` states therefore cannot enter
/// the ordinary detached-attach path.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OrdinaryDetachedAttachAdmission {
    _private: (),
}

impl ClosureState {
    /// Admits ordinary detached attach only from clear closure state.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state for every stored edge, including DCR,
    /// DMR, and `DCursor`.
    pub const fn ordinary_detached_attach_admission(
        self,
    ) -> Result<OrdinaryDetachedAttachAdmission, Self> {
        match self {
            Self::Clear => Ok(OrdinaryDetachedAttachAdmission { _private: () }),
            Self::Owed { .. } => Err(self),
        }
    }
}

/// Validated completion restricted to clear, observer projection, or physical
/// compaction.
///
/// Fields are private so DCR, marker delivery, PCP, DMR, and `DCursor` cannot be
/// smuggled through a detached attach or Leave completion.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DebtCompletion(ClosureState);

impl DebtCompletion {
    /// Selects the only legal edge-free state.
    #[must_use]
    pub const fn clear() -> Self {
        Self(ClosureState::Clear)
    }

    /// Selects an independent observer-projection successor under nonzero debt.
    #[must_use]
    pub const fn observer_projection(debt: ClosureDebt, edge: ObserverProjection) -> Self {
        Self(ClosureState::Owed {
            debt,
            edge: StoredEdge::ObserverProjection(edge),
        })
    }

    /// Selects an independent physical-compaction successor under nonzero debt.
    #[must_use]
    pub const fn physical_compaction(debt: ClosureDebt, edge: PhysicalCompaction) -> Self {
        Self(ClosureState::Owed {
            debt,
            edge: StoredEdge::PhysicalCompaction(edge),
        })
    }

    /// Returns the validated closure state.
    #[must_use]
    pub const fn into_state(self) -> ClosureState {
        self.0
    }
}

/// Opaque authority for the current epoch produced by an ordinary attach.
///
/// Only a successful non-fenced attach commit can construct this value. It is
/// therefore disjoint from [`FencedAttachCommit`]: a recovered binding cannot
/// use the ordinary no-marker fate path.
///
/// ```compile_fail
/// use liminal_protocol::lifecycle::{ActiveBinding, OrdinaryBindingAuthority};
///
/// fn fabricate(binding: ActiveBinding) {
///     let _ = OrdinaryBindingAuthority::new(binding, 11);
/// }
/// ```
///
/// An ordinary-attach fork also cannot extract authority through the public
/// surface. Only the protocol-owned aggregate/replay path may consume it:
///
/// ```compile_fail
/// use liminal_protocol::lifecycle::AttachCommit;
///
/// fn splice<F, V>(commit: &AttachCommit<F, V>) {
///     let _ = commit.ordinary_binding_authority();
/// }
/// ```
///
/// Even code handed the opaque type cannot execute its fate transition:
///
/// ```compile_fail
/// use liminal_protocol::lifecycle::{CommittedDiedTerminal, OrdinaryBindingAuthority};
///
/// fn execute(authority: OrdinaryBindingAuthority, terminal: CommittedDiedTerminal) {
///     let _ = authority.binding_fate(terminal, 11);
/// }
/// ```
///
/// ```compile_fail
/// use liminal_protocol::lifecycle::{Event, OrdinaryBindingAuthority};
///
/// fn advance(authority: OrdinaryBindingAuthority, event: Event) {
///     let _ = authority.cursor_progressed(event);
/// }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OrdinaryBindingAuthority {
    binding: ActiveBinding,
    through_seq: DeliverySeq,
}

impl OrdinaryBindingAuthority {
    pub(crate) const fn new(binding: ActiveBinding, through_seq: DeliverySeq) -> Self {
        Self {
            binding,
            through_seq,
        }
    }

    /// Returns the exact authoritative binding committed by ordinary attach.
    #[must_use]
    pub const fn binding(self) -> ActiveBinding {
        self.binding
    }

    /// Returns the durable no-marker cursor carried through ordinary attach.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }

    /// Advances this ordinary binding's cursor through one exact normal ack.
    ///
    /// The returned authority preserves its attach provenance while replacing
    /// the cursor only when participant, epoch, and previous boundary all match.
    ///
    /// # Errors
    ///
    /// Returns this authority unchanged for another event class, participant,
    /// epoch, or previous cursor.
    #[allow(
        dead_code,
        reason = "the crate-owned participant-ack operation advances this sealed authority"
    )]
    pub(crate) fn cursor_progressed(self, event: Event) -> Result<Self, Self> {
        let EventKind::CursorProgressed {
            participant_id,
            binding_epoch,
            progress:
                CursorProgressEvent::Normal {
                    previous_cursor,
                    through_seq,
                },
            ..
        } = event.0
        else {
            return Err(self);
        };
        if participant_id != self.binding.participant_id
            || binding_epoch != self.binding.binding_epoch
            || previous_cursor != self.through_seq
        {
            return Err(self);
        }
        Ok(Self {
            through_seq,
            ..self
        })
    }

    /// Consumes the exact durable death of this ordinary binding.
    ///
    /// # Errors
    ///
    /// Returns this authority unchanged unless the terminal names the same
    /// participant, conversation, and binding epoch.
    pub(crate) fn binding_fate(
        self,
        terminal: CommittedDiedTerminal,
        resulting_floor: DeliverySeq,
    ) -> Result<OrdinaryBindingFate, Self> {
        if terminal.participant_id() != self.binding.participant_id
            || terminal.conversation_id() != self.binding.conversation_id
            || terminal.binding_epoch() != self.binding.binding_epoch
        {
            return Err(self);
        }
        Ok(OrdinaryBindingFate {
            conversation_id: self.binding.conversation_id,
            through_seq: self.through_seq,
            resulting_floor,
            release: DetachedCursorRelease {
                participant_id: self.binding.participant_id,
                last_dead_binding_epoch: self.binding.binding_epoch,
            },
        })
    }
}

/// Exact no-marker fate derived from an ordinary attach and its durable death.
///
/// Fields are private and the only public producer consumes an
/// [`AttachCommit`](crate::lifecycle::AttachCommit) carrying ordinary
/// provenance. A fenced attach cannot produce this type, so
/// executing it cannot bypass [`FencedAttachCommit::recovered_binding_fate`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OrdinaryBindingFate {
    conversation_id: ConversationId,
    through_seq: DeliverySeq,
    resulting_floor: DeliverySeq,
    release: DetachedCursorRelease,
}

impl OrdinaryBindingFate {
    /// Returns the conversation validated against the committed `Died` terminal.
    #[must_use]
    pub const fn conversation_id(self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the durable cursor preceding the ordinary binding's death.
    #[must_use]
    pub const fn through_seq(self) -> DeliverySeq {
        self.through_seq
    }

    /// Returns the participant whose ordinary binding died.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.release.participant_id
    }

    /// Returns the exact dead binding epoch whose fate was observed.
    #[must_use]
    pub const fn last_dead_binding_epoch(self) -> BindingEpoch {
        self.release.last_dead_binding_epoch
    }

    /// Returns the measured floor from the binding-fate transaction.
    #[must_use]
    pub const fn resulting_floor(self) -> DeliverySeq {
        self.resulting_floor
    }
    /// Projects the exact floor measured by this binding fate.
    #[must_use]
    pub const fn observer_progress_projection(&self) -> ObserverProgressProjection {
        ObserverProgressProjection::new(self.conversation_id, self.resulting_floor)
    }

    /// Selects direct `DetachedCursorRelease` when no storage edge precedes it.
    #[must_use]
    pub const fn into_direct_state(self, debt: ClosureDebt) -> ClosureState {
        owed(debt, StoredEdge::DetachedCursorRelease(self.release))
    }
}

/// Opaque proof that an exact marker-fenced attach committed.
///
/// Only [`DetachedCredentialRecovery::fenced_attach`] constructs this value.
/// Ordinary attach therefore cannot fabricate marker acceptance or advance a
/// cursor merely by presenting a marker sequence.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FencedAttachCommit {
    conversation_id: ConversationId,
    participant_id: ParticipantId,
    marker_delivery_seq: DeliverySeq,
    prior_binding_epoch: BindingEpoch,
    new_binding_epoch: BindingEpoch,
    next_state: ClosureState,
}

impl FencedAttachCommit {
    /// Returns the conversation inherited from the consumed recovery edge.
    #[must_use]
    pub const fn conversation_id(self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the participant whose fenced recovery committed.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the exact delivered marker accepted by the commit.
    #[must_use]
    pub const fn marker_delivery_seq(self) -> DeliverySeq {
        self.marker_delivery_seq
    }

    /// Returns the exact dead binding epoch that durably received the marker.
    #[must_use]
    pub const fn prior_binding_epoch(self) -> BindingEpoch {
        self.prior_binding_epoch
    }

    /// Returns the exact newly committed authoritative binding epoch.
    #[must_use]
    pub const fn new_binding_epoch(self) -> BindingEpoch {
        self.new_binding_epoch
    }

    /// Returns the measured clear, observer-projection, or compaction successor.
    #[must_use]
    pub const fn next_state(self) -> ClosureState {
        self.next_state
    }

    /// Validates the exact fate of this commit's recovered binding epoch.
    ///
    /// The returned authority retains both the fenced-attach provenance and its
    /// exact nonzero-debt OP/PC successor. It must be consumed by that stored
    /// edge's recovered-fate transition, so a fate that precedes storage
    /// completion cannot lose the required `DetachedCursorRelease` suffix.
    ///
    /// # Errors
    ///
    /// Returns the unchanged post-attach state unless the event names this
    /// participant and the exact newly committed binding epoch, or when the
    /// fenced attach had already cleared debt.
    pub fn recovered_binding_fate(
        self,
        event: Event,
    ) -> Result<RecoveredBindingFate, ClosureState> {
        let EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            resulting_floor,
        } = event.0
        else {
            return Err(self.next_state);
        };
        if participant_id != self.participant_id || binding_epoch != self.new_binding_epoch {
            return Err(self.next_state);
        }
        let ClosureState::Owed { debt, edge } = self.next_state else {
            return Err(self.next_state);
        };
        let predecessor = match edge {
            StoredEdge::ObserverProjection(value) => {
                RecoveredStorageEdge::ObserverProjection(value)
            }
            StoredEdge::PhysicalCompaction(value) => {
                RecoveredStorageEdge::PhysicalCompaction(value)
            }
            _ => return Err(self.next_state),
        };
        Ok(RecoveredBindingFate {
            conversation_id: self.conversation_id,
            predecessor_debt: debt,
            predecessor,
            resulting_floor,
            release: DetachedCursorRelease {
                participant_id,
                last_dead_binding_epoch: binding_epoch,
            },
        })
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum RecoveredStorageEdge {
    ObserverProjection(ObserverProjection),
    PhysicalCompaction(PhysicalCompaction),
}

impl RecoveredStorageEdge {
    const fn into_stored_edge(self) -> StoredEdge {
        match self {
            Self::ObserverProjection(value) => StoredEdge::ObserverProjection(value),
            Self::PhysicalCompaction(value) => StoredEdge::PhysicalCompaction(value),
        }
    }
}

/// Exact recovered-binding fate authority derived from a fenced attach.
///
/// Fields are private: only [`FencedAttachCommit::recovered_binding_fate`] can
/// bind a no-marker cursor release to the newly recovered epoch and the exact
/// OP/PC state installed by that attach.
#[derive(Debug, PartialEq, Eq)]
pub struct RecoveredBindingFate {
    conversation_id: ConversationId,
    predecessor_debt: ClosureDebt,
    predecessor: RecoveredStorageEdge,
    resulting_floor: DeliverySeq,
    release: DetachedCursorRelease,
}

impl RecoveredBindingFate {
    /// Returns the conversation inherited from the fenced-attach provenance.
    #[must_use]
    pub const fn conversation_id(&self) -> ConversationId {
        self.conversation_id
    }

    /// Returns the exact post-attach state to which this authority is bound.
    #[must_use]
    pub const fn predecessor_state(&self) -> ClosureState {
        owed(self.predecessor_debt, self.predecessor.into_stored_edge())
    }

    /// Returns the participant whose recovered binding died.
    #[must_use]
    pub const fn participant_id(&self) -> ParticipantId {
        self.release.participant_id
    }

    /// Returns the exact recovered epoch whose fate was observed.
    #[must_use]
    pub const fn last_dead_binding_epoch(&self) -> BindingEpoch {
        self.release.last_dead_binding_epoch
    }

    /// Returns the floor measured in the binding-fate transaction.
    #[must_use]
    pub const fn resulting_floor(&self) -> DeliverySeq {
        self.resulting_floor
    }
    /// Projects the exact floor measured by this recovered binding fate.
    #[must_use]
    pub const fn observer_progress_projection(&self) -> ObserverProgressProjection {
        ObserverProgressProjection::new(self.conversation_id, self.resulting_floor)
    }
}

/// Latent cursor-release suffix while an earlier OP/PC witness remains stored.
///
/// This opaque value must survive alongside the preserved storage edge. Exact
/// completion of that edge consumes it and installs `DetachedCursorRelease`, or
/// clears it only when closure debt reaches zero. Both ordinary binding fate
/// and fenced recovered fate produce this common post-provenance state.
#[derive(Debug, PartialEq, Eq)]
pub struct PendingRecoveredCursorRelease {
    debt: ClosureDebt,
    predecessor: RecoveredStorageEdge,
    release: DetachedCursorRelease,
}

impl PendingRecoveredCursorRelease {
    /// Returns the exact OP/PC state that remains current before completion.
    #[must_use]
    pub const fn current_state(&self) -> ClosureState {
        owed(self.debt, self.predecessor.into_stored_edge())
    }

    /// Returns the participant whose cursor release is pending.
    #[must_use]
    pub const fn participant_id(&self) -> ParticipantId {
        self.release.participant_id
    }

    /// Returns the exact recovered epoch whose cursor release is pending.
    #[must_use]
    pub const fn last_dead_binding_epoch(&self) -> BindingEpoch {
        self.release.last_dead_binding_epoch
    }
}

/// Exact released state when binding fate covers storage immediately.
#[derive(Debug, PartialEq, Eq)]
pub struct RecoveredCursorRelease {
    debt: ClosureDebt,
    release: DetachedCursorRelease,
}

impl RecoveredCursorRelease {
    /// Returns the nonzero debt carried by the cursor-release edge.
    #[must_use]
    pub const fn debt(&self) -> ClosureDebt {
        self.debt
    }

    /// Returns the exact derived cursor-release witness.
    #[must_use]
    pub const fn edge(&self) -> DetachedCursorRelease {
        self.release
    }

    /// Installs the exact derived cursor-release state.
    #[must_use]
    pub const fn into_state(self) -> ClosureState {
        owed(self.debt, StoredEdge::DetachedCursorRelease(self.release))
    }
}

/// Preserve-or-cover result for cursor-releasing binding fate against OP/PC.
#[derive(Debug, PartialEq, Eq)]
pub enum RecoveredBindingFateTransition {
    /// Storage remains current and carries a latent cursor-release suffix.
    PendingStorage(PendingRecoveredCursorRelease),
    /// The fate floor covered storage and selected cursor release immediately.
    DetachedCursorRelease(RecoveredCursorRelease),
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum SuccessorUse {
    ObserverCompletion,
    ObserverMarkerAppend,
    ObserverLeave,
    PhysicalCompletion,
    PhysicalCover,
    CursorGreaterAck,
}

/// Strict/later successor authority for OP, PC, and greater cumulative ack.
///
/// The predecessor, consumed event, and validated resulting state are private.
/// A value can be obtained only from the exact predecessor edge's builder, so a
/// caller cannot substitute an earlier edge or direct DCR at application time.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ProjectionCompactionSuccessor {
    predecessor: StoredEdge,
    event: Event,
    use_kind: SuccessorUse,
    state: ClosureState,
}

/// Closed cursor-fate result taxonomy retained for API compatibility.
///
/// [`ParticipantCursorProgress::binding_fate`] produces only the marker-backed
/// recovery arm. Executable cursor release is instead installed through
/// [`OrdinaryBindingFate`] or [`RecoveredBindingFate`], both of which carry the
/// required predecessor authority.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CursorFateSuccessor {
    /// Marker-backed state becomes fenced detached recovery.
    DetachedCredentialRecovery(DetachedCredentialRecovery),
    /// Reserved cursor-release taxonomy arm; raw continuous fate cannot produce it.
    DetachedCursorRelease(DetachedCursorRelease),
}

impl CursorFateSuccessor {
    /// Converts the derived fate into its stored edge.
    #[must_use]
    pub const fn into_stored_edge(self) -> StoredEdge {
        match self {
            Self::DetachedCredentialRecovery(value) => {
                StoredEdge::DetachedCredentialRecovery(value)
            }
            Self::DetachedCursorRelease(value) => StoredEdge::DetachedCursorRelease(value),
        }
    }
}

/// Exact refusal selected by a detached edge or charged retarget check.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DetachedAttachRefusal {
    /// Ordinary attach violates the recovery fence.
    RecoveryFence,
    /// Presented marker was never delivered.
    MarkerNotDelivered,
    /// Edge owns no matching marker.
    MarkerMismatch,
    /// Marker-backed PCP must be acknowledged before supersession.
    DeliveredMarkerAwaitingAck,
    /// The proposed positive churn delta exceeds the episode limit.
    EpisodeChurnLimit,
    /// The proposed binding epoch does not immediately supersede this epoch.
    StaleAuthority,
    /// Binding-required work cannot run for a detached edge owner.
    NoBinding,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum DetachedClaimTarget {
    CredentialRecovery {
        marker_delivery_seq: DeliverySeq,
        binding_epoch: BindingEpoch,
    },
    MarkerRelease {
        marker_delivery_seq: DeliverySeq,
        binding_epoch: BindingEpoch,
    },
    CursorRelease {
        binding_epoch: BindingEpoch,
    },
}

/// Validated evidence for an exact-current K-backed detached Leave.
///
/// There is no public constructor. Each detached edge validates participant,
/// exact edge target, positive actual record charge, remaining K, and the
/// available exit claim before producing this edge-bound value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct KClaimBackedDetachedLeave {
    participant_id: ParticipantId,
    target: DetachedClaimTarget,
    actual_charge: ResourceVector,
}

impl KClaimBackedDetachedLeave {
    /// Returns the exact detached participant.
    #[must_use]
    pub const fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    /// Returns the exact charge already checked against remaining K.
    #[must_use]
    pub const fn actual_charge(self) -> ResourceVector {
        self.actual_charge
    }
}

/// Opaque typed completion event.
///
/// Constructors validate each event's local scalar shape. Edge transitions then
/// consume the event and match its participant, binding, marker, range, and
/// boundary against the exact stored predecessor. The private kind set is the
/// frozen eight-kind register: marker and normal acknowledgements share
/// `CursorProgressed`, while live and detached alternatives share
/// `LeaveCommitted`; the convenience constructors do not invent occurrences.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Event(EventKind);

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum EventKind {
    ProjectionCompleted {
        through_seq: DeliverySeq,
    },
    CompactionCompleted {
        from_floor: DeliverySeq,
        through_seq: DeliverySeq,
        resulting_floor: DeliverySeq,
    },
    MarkerAppended {
        marker_delivery_seq: DeliverySeq,
        resulting_projection_through: DeliverySeq,
    },
    MarkerDelivered {
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        marker_delivery_seq: DeliverySeq,
    },
    CursorProgressed {
        participant_index: ParticipantIndex,
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        progress: CursorProgressEvent,
        resulting_floor: DeliverySeq,
    },
    BindingFateObserved {
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        resulting_floor: DeliverySeq,
    },
    LeaveCommitted {
        participant_id: ParticipantId,
        authority: LeaveAuthority,
        resulting_floor: DeliverySeq,
    },
    FencedRecoveryCommitted {
        participant_id: ParticipantId,
        marker_delivery_seq: DeliverySeq,
        prior_binding_epoch: BindingEpoch,
        new_binding_epoch: BindingEpoch,
        resulting_floor: DeliverySeq,
    },
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CursorProgressEvent {
    Normal {
        previous_cursor: DeliverySeq,
        through_seq: DeliverySeq,
    },
    Marker {
        marker_delivery_seq: DeliverySeq,
    },
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum LeaveAuthority {
    Live(BindingEpoch),
    Detached,
}

impl Event {
    /// Records observer projection through an exact sequence.
    #[must_use]
    pub const fn projection_completed(through_seq: DeliverySeq) -> Self {
        Self(EventKind::ProjectionCompleted { through_seq })
    }

    /// Records exact physical compaction and its resulting floor.
    #[must_use]
    pub const fn compaction_completed(
        from_floor: DeliverySeq,
        through_seq: DeliverySeq,
        resulting_floor: DeliverySeq,
    ) -> Option<Self> {
        if from_floor <= through_seq && resulting_floor > through_seq {
            Some(Self(EventKind::CompactionCompleted {
                from_floor,
                through_seq,
                resulting_floor,
            }))
        } else {
            None
        }
    }

    /// Records a preclaimed marker append that extends an OP suffix.
    #[must_use]
    pub const fn marker_appended(
        marker_delivery_seq: DeliverySeq,
        resulting_projection_through: DeliverySeq,
    ) -> Self {
        Self(EventKind::MarkerAppended {
            marker_delivery_seq,
            resulting_projection_through,
        })
    }

    /// Records final-emitter delivery of an exact marker to an exact epoch.
    #[must_use]
    pub const fn marker_delivered(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        marker_delivery_seq: DeliverySeq,
    ) -> Self {
        Self(EventKind::MarkerDelivered {
            participant_id,
            binding_epoch,
            marker_delivery_seq,
        })
    }

    /// Records a strictly advancing cumulative normal ack.
    ///
    /// V1's permanent participant id is the participant index, so the stored
    /// occurrence key is derived from `participant_id` rather than accepted as
    /// an independently forgeable value.
    #[must_use]
    pub const fn cursor_progressed(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        previous_cursor: DeliverySeq,
        through_seq: DeliverySeq,
        resulting_floor: DeliverySeq,
    ) -> Option<Self> {
        if through_seq > previous_cursor {
            Some(Self(EventKind::CursorProgressed {
                participant_index: participant_id,
                participant_id,
                binding_epoch,
                progress: CursorProgressEvent::Normal {
                    previous_cursor,
                    through_seq,
                },
                resulting_floor,
            }))
        } else {
            None
        }
    }

    /// Records acceptance of one exact delivered marker, deriving its
    /// participant-index occurrence key from the permanent participant id.
    #[must_use]
    pub const fn marker_acknowledged(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        marker_delivery_seq: DeliverySeq,
        resulting_floor: DeliverySeq,
    ) -> Self {
        Self(EventKind::CursorProgressed {
            participant_index: participant_id,
            participant_id,
            binding_epoch,
            progress: CursorProgressEvent::Marker {
                marker_delivery_seq,
            },
            resulting_floor,
        })
    }

    /// Records exact binding fate and its measured floor effect.
    #[must_use]
    pub const fn binding_fate_observed(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        resulting_floor: DeliverySeq,
    ) -> Self {
        Self(EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            resulting_floor,
        })
    }

    /// Records a live-bound Leave and its measured floor effect.
    #[must_use]
    pub const fn live_leave_committed(
        participant_id: ParticipantId,
        binding_epoch: BindingEpoch,
        resulting_floor: DeliverySeq,
    ) -> Self {
        Self(EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Live(binding_epoch),
            resulting_floor,
        })
    }

    /// Records a detached Leave and its measured floor effect.
    #[must_use]
    pub const fn detached_leave_committed(
        participant_id: ParticipantId,
        resulting_floor: DeliverySeq,
    ) -> Self {
        Self(EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Detached,
            resulting_floor,
        })
    }

    /// Records exact fenced recovery into a new binding epoch.
    #[must_use]
    pub const fn fenced_recovery_committed(
        participant_id: ParticipantId,
        marker_delivery_seq: DeliverySeq,
        prior_binding_epoch: BindingEpoch,
        new_binding_epoch: BindingEpoch,
        resulting_floor: DeliverySeq,
    ) -> Self {
        Self(EventKind::FencedRecoveryCommitted {
            participant_id,
            marker_delivery_seq,
            prior_binding_epoch,
            new_binding_epoch,
            resulting_floor,
        })
    }
}

impl ObserverProjection {
    /// Applies ordinary no-marker binding fate while this OP remains current.
    ///
    /// The opaque fate carries ordinary-attach and exact-terminal provenance;
    /// projection completion must retain its cursor-release suffix while debt
    /// remains.
    #[must_use]
    #[allow(
        dead_code,
        reason = "the crate-owned binding-fate operation invokes this sealed OP transition"
    )]
    pub const fn apply_ordinary_binding_fate(
        self,
        resulting_debt: ClosureDebt,
        authority: OrdinaryBindingFate,
    ) -> PendingRecoveredCursorRelease {
        PendingRecoveredCursorRelease {
            debt: resulting_debt,
            predecessor: RecoveredStorageEdge::ObserverProjection(self),
            release: authority.release,
        }
    }

    /// Applies recovered binding fate while this exact OP remains incomplete.
    ///
    /// OP is independent of binding fate, so nonzero debt preserves it and the
    /// returned opaque value retains the exact `DetachedCursorRelease` suffix
    /// until projection completion.
    ///
    /// # Errors
    ///
    /// Returns the unconsumed authority unless it was derived for this exact OP
    /// and its exact post-attach debt.
    pub fn apply_recovered_binding_fate(
        self,
        debt: ClosureDebt,
        resulting_debt: ClosureDebt,
        authority: RecoveredBindingFate,
    ) -> Result<RecoveredBindingFateTransition, RecoveredBindingFate> {
        if authority.predecessor != RecoveredStorageEdge::ObserverProjection(self)
            || authority.predecessor_debt != debt
        {
            return Err(authority);
        }
        Ok(RecoveredBindingFateTransition::PendingStorage(
            PendingRecoveredCursorRelease {
                debt: resulting_debt,
                predecessor: RecoveredStorageEdge::ObserverProjection(self),
                release: authority.release,
            },
        ))
    }

    /// Consumes a latent recovered cursor suffix on exact OP completion.
    ///
    /// # Errors
    ///
    /// Returns the pending authority intact unless it belongs to this exact OP
    /// and the completion event reaches its exact boundary.
    pub fn complete_after_recovered_binding_fate(
        self,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
        pending: PendingRecoveredCursorRelease,
    ) -> Result<ClosureState, PendingRecoveredCursorRelease> {
        self.complete_after_binding_fate(event, resulting_debt, pending)
    }

    /// Consumes a latent ordinary cursor suffix on exact OP completion.
    ///
    /// # Errors
    ///
    /// Returns the pending authority intact unless it belongs to this exact OP
    /// and the completion event reaches the stored projection boundary.
    pub fn complete_after_ordinary_binding_fate(
        self,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
        pending: PendingRecoveredCursorRelease,
    ) -> Result<ClosureState, PendingRecoveredCursorRelease> {
        self.complete_after_binding_fate(event, resulting_debt, pending)
    }

    /// Consumes a latent cursor-release suffix on exact OP completion.
    ///
    /// # Errors
    ///
    /// Returns the pending authority intact unless it belongs to this exact OP
    /// and the completion event reaches its exact boundary.
    pub(crate) fn complete_after_binding_fate(
        self,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
        pending: PendingRecoveredCursorRelease,
    ) -> Result<ClosureState, PendingRecoveredCursorRelease> {
        if pending.predecessor != RecoveredStorageEdge::ObserverProjection(self)
            || projection_completion_boundary(self, event).is_none()
        {
            return Err(pending);
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::DetachedCursorRelease(pending.release),
        ))
    }

    /// Validates clear selection after this exact projection completes.
    #[must_use]
    pub const fn clear_after_completion(
        &self,
        event: &Event,
    ) -> Option<ProjectionCompactionSuccessor> {
        if projection_completion_boundary(*self, *event).is_some() {
            Some(ProjectionCompactionSuccessor {
                predecessor: StoredEdge::ObserverProjection(*self),
                event: *event,
                use_kind: SuccessorUse::ObserverCompletion,
                state: ClosureState::Clear,
            })
        } else {
            None
        }
    }

    /// Validates a non-DCR strict suffix after this exact projection completes.
    #[must_use]
    pub const fn strict_after_completion(
        &self,
        event: &Event,
        debt: ClosureDebt,
        edge: StoredEdge,
        successor_boundary: DeliverySeq,
    ) -> Option<ProjectionCompactionSuccessor> {
        let Some(completed_through) = projection_completion_boundary(*self, *event) else {
            return None;
        };
        if successor_boundary <= completed_through
            || !strict_edge_matches_boundary(edge, successor_boundary)
        {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::ObserverProjection(*self),
            event: *event,
            use_kind: SuccessorUse::ObserverCompletion,
            state: ClosureState::Owed { debt, edge },
        })
    }

    /// Consumes exact projection completion and its predecessor-bound successor.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the event or successor authority
    /// was not built for this exact projection.
    pub fn complete(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ObserverProjection(self));
        if successor.predecessor == StoredEdge::ObserverProjection(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::ObserverCompletion
            && projection_completion_boundary(self, event).is_some()
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// Validates the exact later OP selected by a preclaimed marker append.
    #[must_use]
    pub const fn later_projection_after_marker(
        &self,
        event: &Event,
        debt: ClosureDebt,
        successor: Self,
    ) -> Option<ProjectionCompactionSuccessor> {
        let EventKind::MarkerAppended {
            marker_delivery_seq,
            resulting_projection_through,
        } = event.0
        else {
            return None;
        };
        if marker_delivery_seq <= self.through_seq
            || resulting_projection_through < marker_delivery_seq
            || successor.through_seq != resulting_projection_through
        {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::ObserverProjection(*self),
            event: *event,
            use_kind: SuccessorUse::ObserverMarkerAppend,
            state: owed(debt, StoredEdge::ObserverProjection(successor)),
        })
    }

    /// Consumes the marker occurrence and atomically installs its exact later OP.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the event-bound successor was
    /// built for another projection or occurrence.
    pub fn marker_appended(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ObserverProjection(self));
        if successor.predecessor == StoredEdge::ObserverProjection(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::ObserverMarkerAppend
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// Validates the exact later OP selected atomically by a live or detached Leave.
    #[must_use]
    pub const fn later_projection_after_leave(
        &self,
        event: &Event,
        debt: ClosureDebt,
        successor: Self,
    ) -> Option<ProjectionCompactionSuccessor> {
        let EventKind::LeaveCommitted {
            resulting_floor, ..
        } = event.0
        else {
            return None;
        };
        if successor.through_seq <= self.through_seq || successor.through_seq < resulting_floor {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::ObserverProjection(*self),
            event: *event,
            use_kind: SuccessorUse::ObserverLeave,
            state: owed(debt, StoredEdge::ObserverProjection(successor)),
        })
    }

    /// Consumes exact Leave and atomically installs its predecessor-bound later OP.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the successor was built for
    /// this exact OP and Leave occurrence.
    pub fn leave_with_later_projection(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ObserverProjection(self));
        if successor.predecessor == StoredEdge::ObserverProjection(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::ObserverLeave
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// Consumes an independently valid cursor, marker, fate, or Leave event and
    /// preserves this exact OP while debt remains, or clears it with debt.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state for an event outside those independent
    /// invalidator classes.
    pub const fn independent_event(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ObserverProjection(self));
        if !matches!(
            event.0,
            EventKind::CursorProgressed { .. }
                | EventKind::BindingFateObserved { .. }
                | EventKind::LeaveCommitted { .. }
        ) {
            return Err(original);
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::ObserverProjection(self),
        ))
    }

    /// Applies a binding change only after a positive charged churn preflight.
    ///
    /// # Errors
    ///
    /// Returns the unchanged state and `EpisodeChurnLimit` when the delta is
    /// zero or would exceed the episode limit.
    pub const fn charged_binding_change(
        self,
        debt: ClosureDebt,
        episode_churn_used: u64,
        delta_cycles: u64,
        episode_churn_limit: u64,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, (ClosureState, DetachedAttachRefusal)> {
        let original = owed(debt, StoredEdge::ObserverProjection(self));
        if !charged_churn_fits(episode_churn_used, delta_cycles, episode_churn_limit) {
            return Err((original, DetachedAttachRefusal::EpisodeChurnLimit));
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::ObserverProjection(self),
        ))
    }
}

impl PhysicalCompaction {
    /// Applies ordinary no-marker binding fate by preserving or covering PC.
    #[must_use]
    #[allow(
        dead_code,
        reason = "the crate-owned binding-fate replay boundary invokes this sealed PC transition"
    )]
    pub(crate) const fn apply_ordinary_binding_fate(
        self,
        resulting_debt: ClosureDebt,
        authority: OrdinaryBindingFate,
    ) -> RecoveredBindingFateTransition {
        if authority.resulting_floor > self.through_seq {
            RecoveredBindingFateTransition::DetachedCursorRelease(RecoveredCursorRelease {
                debt: resulting_debt,
                release: authority.release,
            })
        } else {
            RecoveredBindingFateTransition::PendingStorage(PendingRecoveredCursorRelease {
                debt: resulting_debt,
                predecessor: RecoveredStorageEdge::PhysicalCompaction(self),
                release: authority.release,
            })
        }
    }

    /// Applies recovered binding fate by preserving or covering this exact PC.
    ///
    /// A fate floor at or below `through_seq` preserves PC and returns a latent
    /// cursor-release suffix. A greater floor covers PC immediately and selects
    /// the exact cursor release derived from the fenced attach.
    ///
    /// # Errors
    ///
    /// Returns the unconsumed authority unless it was derived for this exact PC
    /// and its exact post-attach debt.
    pub fn apply_recovered_binding_fate(
        self,
        debt: ClosureDebt,
        resulting_debt: ClosureDebt,
        authority: RecoveredBindingFate,
    ) -> Result<RecoveredBindingFateTransition, RecoveredBindingFate> {
        if authority.predecessor != RecoveredStorageEdge::PhysicalCompaction(self)
            || authority.predecessor_debt != debt
        {
            return Err(authority);
        }
        if authority.resulting_floor > self.through_seq {
            Ok(RecoveredBindingFateTransition::DetachedCursorRelease(
                RecoveredCursorRelease {
                    debt: resulting_debt,
                    release: authority.release,
                },
            ))
        } else {
            Ok(RecoveredBindingFateTransition::PendingStorage(
                PendingRecoveredCursorRelease {
                    debt: resulting_debt,
                    predecessor: RecoveredStorageEdge::PhysicalCompaction(self),
                    release: authority.release,
                },
            ))
        }
    }

    /// Consumes a latent recovered cursor suffix on exact PC completion.
    ///
    /// # Errors
    ///
    /// Returns the pending authority intact unless it belongs to this exact PC
    /// and the completion event covers its exact stored range.
    pub fn complete_after_recovered_binding_fate(
        self,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
        pending: PendingRecoveredCursorRelease,
    ) -> Result<ClosureState, PendingRecoveredCursorRelease> {
        self.complete_after_binding_fate(event, resulting_debt, pending)
    }

    /// Consumes a latent cursor-release suffix on exact PC completion.
    ///
    /// # Errors
    ///
    /// Returns the pending authority intact unless it belongs to this exact PC
    /// and the completion event covers its exact stored range.
    pub(crate) fn complete_after_binding_fate(
        self,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
        pending: PendingRecoveredCursorRelease,
    ) -> Result<ClosureState, PendingRecoveredCursorRelease> {
        if pending.predecessor != RecoveredStorageEdge::PhysicalCompaction(self)
            || physical_completion_floor(self, event).is_none()
        {
            return Err(pending);
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::DetachedCursorRelease(pending.release),
        ))
    }

    /// Validates clear selection after exact PC completion.
    #[must_use]
    pub const fn clear_after_completion(
        &self,
        event: &Event,
    ) -> Option<ProjectionCompactionSuccessor> {
        if physical_completion_floor(*self, *event).is_some() {
            Some(ProjectionCompactionSuccessor {
                predecessor: StoredEdge::PhysicalCompaction(*self),
                event: *event,
                use_kind: SuccessorUse::PhysicalCompletion,
                state: ClosureState::Clear,
            })
        } else {
            None
        }
    }

    /// Validates a non-DCR strict suffix after exact PC completion.
    #[must_use]
    pub const fn strict_after_completion(
        &self,
        event: &Event,
        debt: ClosureDebt,
        edge: StoredEdge,
        successor_boundary: DeliverySeq,
    ) -> Option<ProjectionCompactionSuccessor> {
        let Some(resulting_floor) = physical_completion_floor(*self, *event) else {
            return None;
        };
        if successor_boundary < resulting_floor
            || !strict_edge_matches_boundary(edge, successor_boundary)
        {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::PhysicalCompaction(*self),
            event: *event,
            use_kind: SuccessorUse::PhysicalCompletion,
            state: ClosureState::Owed { debt, edge },
        })
    }

    /// Consumes exact PC completion.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the event or successor authority
    /// does not belong to this exact compaction range.
    pub fn complete(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        if successor.predecessor == StoredEdge::PhysicalCompaction(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::PhysicalCompletion
            && physical_completion_floor(self, event).is_some()
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// Records a later marker append while preserving this exact active range.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the appended marker lies
    /// strictly after the physical-compaction range and its projection target
    /// covers that marker.
    pub const fn marker_appended(
        self,
        debt: ClosureDebt,
        event: Event,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        let EventKind::MarkerAppended {
            marker_delivery_seq,
            resulting_projection_through,
        } = event.0
        else {
            return Err(original);
        };
        if marker_delivery_seq <= self.through_seq
            || resulting_projection_through < marker_delivery_seq
        {
            return Err(original);
        }
        Ok(original)
    }

    /// Applies an advancing ack, fate, or Leave whose resulting floor does not
    /// cover this PC, preserving the exact range while debt remains.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the event is not a progress class
    /// or its resulting floor covers the stored range.
    pub const fn preserve_progress(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: ClosureDebt,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        let Some(resulting_floor) = progress_event_floor(event) else {
            return Err(original);
        };
        if resulting_floor > self.through_seq {
            return Err(original);
        }
        Ok(owed(resulting_debt, StoredEdge::PhysicalCompaction(self)))
    }

    /// Validates clear selection when an ack, fate, or Leave covers this PC.
    #[must_use]
    pub const fn clear_after_progress(
        &self,
        event: &Event,
    ) -> Option<ProjectionCompactionSuccessor> {
        let Some(resulting_floor) = progress_event_floor(*event) else {
            return None;
        };
        if resulting_floor <= self.through_seq {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::PhysicalCompaction(*self),
            event: *event,
            use_kind: SuccessorUse::PhysicalCover,
            state: ClosureState::Clear,
        })
    }

    /// Validates a strict non-DCR suffix when an ack, fate, or Leave covers PC.
    #[must_use]
    pub const fn strict_after_progress(
        &self,
        event: &Event,
        debt: ClosureDebt,
        edge: StoredEdge,
        successor_boundary: DeliverySeq,
    ) -> Option<ProjectionCompactionSuccessor> {
        let Some(resulting_floor) = progress_event_floor(*event) else {
            return None;
        };
        if resulting_floor <= self.through_seq
            || successor_boundary < resulting_floor
            || !strict_edge_matches_boundary(edge, successor_boundary)
        {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::PhysicalCompaction(*self),
            event: *event,
            use_kind: SuccessorUse::PhysicalCover,
            state: ClosureState::Owed { debt, edge },
        })
    }

    /// Consumes the covering ack/fate/Leave event and its validated suffix.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the successor authority is not
    /// bound to this range and event.
    pub fn covered_by_progress(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        if successor.predecessor == StoredEdge::PhysicalCompaction(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::PhysicalCover
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// No-op and refused acknowledgements consume no event and preserve exact PC.
    #[must_use]
    pub const fn unchanged(self, debt: ClosureDebt) -> ClosureState {
        owed(debt, StoredEdge::PhysicalCompaction(self))
    }

    /// Applies a charged binding change that leaves this PC range uncovered.
    ///
    /// # Errors
    ///
    /// Returns the unchanged state with the precise churn or stale-selection
    /// refusal when charging fails or the measured floor covers the range.
    pub const fn charged_binding_change_preserving(
        self,
        debt: ClosureDebt,
        episode_churn_used: u64,
        delta_cycles: u64,
        episode_churn_limit: u64,
        resulting_floor: DeliverySeq,
        resulting_debt: ClosureDebt,
    ) -> Result<ClosureState, (ClosureState, DetachedAttachRefusal)> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        if !charged_churn_fits(episode_churn_used, delta_cycles, episode_churn_limit) {
            return Err((original, DetachedAttachRefusal::EpisodeChurnLimit));
        }
        if resulting_floor > self.through_seq {
            return Err((original, DetachedAttachRefusal::StaleAuthority));
        }
        Ok(owed(resulting_debt, StoredEdge::PhysicalCompaction(self)))
    }

    /// Applies a charged binding change whose measured floor covers this PC.
    ///
    /// # Errors
    ///
    /// Returns the unchanged state with the precise churn or stale-selection
    /// refusal when charging fails or the proposed strict suffix is invalid.
    #[allow(clippy::too_many_arguments)]
    pub const fn charged_binding_change_covering(
        self,
        debt: ClosureDebt,
        episode_churn_used: u64,
        delta_cycles: u64,
        episode_churn_limit: u64,
        resulting_floor: DeliverySeq,
        resulting_debt: ClosureDebt,
        edge: StoredEdge,
        successor_boundary: DeliverySeq,
    ) -> Result<ClosureState, (ClosureState, DetachedAttachRefusal)> {
        let original = owed(debt, StoredEdge::PhysicalCompaction(self));
        if !charged_churn_fits(episode_churn_used, delta_cycles, episode_churn_limit) {
            return Err((original, DetachedAttachRefusal::EpisodeChurnLimit));
        }
        if resulting_floor <= self.through_seq
            || successor_boundary < resulting_floor
            || !strict_edge_matches_boundary(edge, successor_boundary)
        {
            return Err((original, DetachedAttachRefusal::StaleAuthority));
        }
        Ok(owed(resulting_debt, edge))
    }
}

impl MarkerDelivery {
    /// Consumes sealed marker-delivery authority and derives its exact cursor
    /// progress witness after validating the delivered event.
    ///
    /// This debt-independent projection is for owners that persist the marker
    /// successor separately from later closure-accounting evolution. Callers
    /// cannot mint `MarkerDelivery`; only a validated marker drain or restore
    /// can supply this authority.
    ///
    /// # Errors
    ///
    /// Returns the unchanged sealed delivery unless participant, epoch, and
    /// marker sequence exactly match.
    pub fn delivered_progress(self, event: Event) -> Result<ParticipantCursorProgress, Self> {
        let EventKind::MarkerDelivered {
            participant_id,
            binding_epoch,
            marker_delivery_seq,
        } = event.0
        else {
            return Err(self);
        };
        if participant_id != self.participant_id
            || binding_epoch != self.binding_epoch
            || marker_delivery_seq != self.marker_delivery_seq
        {
            return Err(self);
        }
        Ok(ParticipantCursorProgress::Marker(CursorProgressMarker {
            conversation_id: self.conversation_id,
            participant_id,
            binding_epoch,
            through_seq: marker_delivery_seq,
            marker_delivery_seq,
        }))
    }

    /// Consumes exact final-emitter delivery and derives marker-backed PCP.
    ///
    /// The PCP boundary is the delivered marker itself; callers cannot supply a
    /// different cursor witness.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless participant, epoch, and marker
    /// exactly match this delivery witness.
    pub fn delivered(self, debt: ClosureDebt, event: Event) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::MarkerDelivery(self));
        let Ok(progress) = self.delivered_progress(event) else {
            return Err(original);
        };
        Ok(owed(debt, StoredEdge::ParticipantCursorProgress(progress)))
    }

    /// Applies a lower normal ack, projection, or compaction below the anchor,
    /// preserving exact delivery while debt remains or clearing it with debt.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state when the event is not a permitted lower
    /// progress event or reaches the marker anchor.
    pub const fn lower_progress(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::MarkerDelivery(self));
        let is_lower = match event.0 {
            EventKind::CursorProgressed {
                progress: CursorProgressEvent::Normal { through_seq, .. },
                ..
            }
            | EventKind::ProjectionCompleted { through_seq } => {
                through_seq < self.marker_delivery_seq
            }
            EventKind::CompactionCompleted {
                through_seq,
                resulting_floor,
                ..
            } => {
                through_seq < self.marker_delivery_seq
                    && resulting_floor <= self.marker_delivery_seq
            }
            _ => false,
        };
        if !is_lower {
            return Err(original);
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::MarkerDelivery(self),
        ))
    }

    /// Consumes exact pre-delivery binding fate and derives Leave-only DMR.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless fate names the exact participant
    /// and binding epoch targeted by this undelivered marker.
    pub fn binding_fate(
        self,
        debt: ClosureDebt,
        event: Event,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::MarkerDelivery(self));
        let EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != self.participant_id || binding_epoch != self.binding_epoch {
            return Err(original);
        }
        Ok(owed(
            debt,
            StoredEdge::DetachedMarkerRelease(DetachedMarkerRelease {
                participant_id,
                marker_delivery_seq: self.marker_delivery_seq,
                last_dead_binding_epoch: binding_epoch,
            }),
        ))
    }

    /// Retargets undelivered marker delivery after exact charged supersession.
    ///
    /// # Errors
    ///
    /// Returns the unchanged delivery with `EpisodeChurnLimit` or
    /// `StaleAuthority` when charged churn or the next-generation check fails.
    pub const fn retarget(
        self,
        new_binding_epoch: BindingEpoch,
        episode_churn_used: u64,
        delta_cycles: u64,
        episode_churn_limit: u64,
    ) -> Result<Self, (Self, DetachedAttachRefusal)> {
        if !charged_churn_fits(episode_churn_used, delta_cycles, episode_churn_limit) {
            return Err((self, DetachedAttachRefusal::EpisodeChurnLimit));
        }
        if !is_next_generation(self.binding_epoch, new_binding_epoch) {
            return Err((self, DetachedAttachRefusal::StaleAuthority));
        }
        Ok(Self {
            binding_epoch: new_binding_epoch,
            ..self
        })
    }

    /// Consumes exact live Leave and installs only clear/OP/PC.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless Leave names the exact live
    /// participant and binding epoch.
    pub fn leave(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::MarkerDelivery(self));
        let EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Live(binding_epoch),
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != self.participant_id || binding_epoch != self.binding_epoch {
            return Err(original);
        }
        Ok(successor.into_state())
    }
}

impl ParticipantCursorProgress {
    /// Consumes an equal normal ack or exact marker ack and selects only
    /// clear/OP/PC.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the ack kind, participant,
    /// epoch, and boundary exactly satisfy this cursor witness.
    pub fn complete_ack(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        let exact = match (self, event.0) {
            (
                Self::Continuous(value),
                EventKind::CursorProgressed {
                    participant_id,
                    binding_epoch,
                    progress: CursorProgressEvent::Normal { through_seq, .. },
                    ..
                },
            ) => {
                participant_id == value.participant_id
                    && binding_epoch == value.binding_epoch
                    && through_seq == value.through_seq
            }
            (
                Self::Marker(value),
                EventKind::CursorProgressed {
                    participant_id,
                    binding_epoch,
                    progress: CursorProgressEvent::Normal { through_seq, .. },
                    ..
                },
            ) => {
                participant_id == value.participant_id
                    && binding_epoch == value.binding_epoch
                    && through_seq == value.through_seq
            }
            (
                Self::Marker(value),
                EventKind::CursorProgressed {
                    participant_id,
                    binding_epoch,
                    progress:
                        CursorProgressEvent::Marker {
                            marker_delivery_seq,
                        },
                    ..
                },
            ) => {
                participant_id == value.participant_id
                    && binding_epoch == value.binding_epoch
                    && marker_delivery_seq == value.marker_delivery_seq
            }
            _ => false,
        };
        if exact {
            Ok(successor.into_state())
        } else {
            Err(original)
        }
    }

    /// Consumes a lesser advancing normal ack and preserves this exact PCP.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the event is a matching current-
    /// epoch normal ack strictly below the stored boundary.
    pub fn lesser_ack(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: ClosureDebt,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        let EventKind::CursorProgressed {
            participant_id,
            binding_epoch,
            progress: CursorProgressEvent::Normal { through_seq, .. },
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != self.participant_id()
            || binding_epoch != self.binding_epoch()
            || through_seq >= self.through_seq()
        {
            return Err(original);
        }
        Ok(owed(
            resulting_debt,
            StoredEdge::ParticipantCursorProgress(self),
        ))
    }

    /// Validates clear selection for one greater cumulative normal ack.
    #[must_use]
    pub fn clear_after_greater_ack(&self, event: &Event) -> Option<ProjectionCompactionSuccessor> {
        if !greater_ack_matches(*self, *event) {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::ParticipantCursorProgress(*self),
            event: *event,
            use_kind: SuccessorUse::CursorGreaterAck,
            state: ClosureState::Clear,
        })
    }

    /// Validates a strict non-DCR suffix for one greater cumulative normal ack.
    #[must_use]
    pub fn strict_after_greater_ack(
        &self,
        event: &Event,
        debt: ClosureDebt,
        edge: StoredEdge,
        successor_boundary: DeliverySeq,
    ) -> Option<ProjectionCompactionSuccessor> {
        if !greater_ack_matches(*self, *event)
            || successor_boundary <= cursor_event_boundary(*event)
            || !strict_edge_matches_boundary(edge, successor_boundary)
        {
            return None;
        }
        Some(ProjectionCompactionSuccessor {
            predecessor: StoredEdge::ParticipantCursorProgress(*self),
            event: *event,
            use_kind: SuccessorUse::CursorGreaterAck,
            state: ClosureState::Owed { debt, edge },
        })
    }

    /// Consumes a greater cumulative normal ack and its predecessor-bound suffix.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the advancing event and strict
    /// successor authority are both bound to this cursor witness.
    pub fn greater_ack(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: ProjectionCompactionSuccessor,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        if successor.predecessor == StoredEdge::ParticipantCursorProgress(self)
            && successor.event == event
            && successor.use_kind == SuccessorUse::CursorGreaterAck
            && greater_ack_matches(self, event)
        {
            Ok(successor.state)
        } else {
            Err(original)
        }
    }

    /// No-op, `AckGap`, and `AckRegression` consume no event and preserve exact PCP.
    #[must_use]
    pub const fn unchanged(self, debt: ClosureDebt) -> ClosureState {
        owed(debt, StoredEdge::ParticipantCursorProgress(self))
    }

    /// Consumes independent projection/compaction completion and preserves PCP
    /// while debt remains, or clears it. Compaction cannot cross an unaccepted
    /// marker anchor.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state for another event class or for a
    /// compaction that reaches an unaccepted marker.
    pub const fn storage_progress(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        let valid = match event.0 {
            EventKind::ProjectionCompleted { .. } => true,
            EventKind::CompactionCompleted {
                through_seq,
                resulting_floor,
                ..
            } => match self.marker_delivery_seq() {
                None => true,
                Some(marker) => through_seq < marker && resulting_floor <= marker,
            },
            _ => false,
        };
        if !valid {
            return Err(original);
        }
        Ok(preserve_or_clear(
            resulting_debt,
            StoredEdge::ParticipantCursorProgress(self),
        ))
    }

    /// Consumes exact binding fate and derives DCR only from marker-backed PCP.
    ///
    /// Continuous PCP never accepts this raw-event transition. Ordinary
    /// no-marker fate requires [`OrdinaryBindingAuthority`], while the fate of
    /// an epoch committed by fenced attach requires
    /// [`FencedAttachCommit::recovered_binding_fate`].
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless fate names the exact participant
    /// and binding epoch carried by this cursor witness.
    pub fn binding_fate(
        self,
        debt: ClosureDebt,
        event: Event,
    ) -> Result<CursorFateSuccessor, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        let Self::Marker(value) = self else {
            return Err(original);
        };
        let EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != value.participant_id || binding_epoch != value.binding_epoch {
            return Err(original);
        }
        Ok(CursorFateSuccessor::DetachedCredentialRecovery(
            DetachedCredentialRecovery {
                conversation_id: value.conversation_id,
                participant_id: value.participant_id,
                marker_delivery_seq: value.marker_delivery_seq,
                prior_binding_epoch: value.binding_epoch,
            },
        ))
    }

    /// Retargets only continuous PCP after exact charged supersession.
    ///
    /// # Errors
    ///
    /// Returns the unchanged cursor and the exact delivered-marker, churn, or
    /// stale-authority refusal when retargeting is forbidden.
    pub const fn retarget(
        self,
        new_binding_epoch: BindingEpoch,
        episode_churn_used: u64,
        delta_cycles: u64,
        episode_churn_limit: u64,
    ) -> Result<Self, (Self, DetachedAttachRefusal)> {
        let Self::Continuous(value) = self else {
            return Err((self, DetachedAttachRefusal::DeliveredMarkerAwaitingAck));
        };
        if !charged_churn_fits(episode_churn_used, delta_cycles, episode_churn_limit) {
            return Err((self, DetachedAttachRefusal::EpisodeChurnLimit));
        }
        if !is_next_generation(value.binding_epoch, new_binding_epoch) {
            return Err((self, DetachedAttachRefusal::StaleAuthority));
        }
        Ok(Self::Continuous(CursorProgressContinuous {
            binding_epoch: new_binding_epoch,
            ..value
        }))
    }

    /// Consumes exact live Leave and installs its measured clear/OP/PC result.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless Leave names the exact live
    /// participant and binding epoch.
    pub fn leave(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::ParticipantCursorProgress(self));
        let EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Live(binding_epoch),
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != self.participant_id() || binding_epoch != self.binding_epoch() {
            return Err(original);
        }
        Ok(successor.into_state())
    }
}

impl DetachedCredentialRecovery {
    /// Validates exact-current K and exit claims for detached Leave.
    #[must_use]
    pub const fn validate_leave_claim(
        &self,
        participant_id: ParticipantId,
        actual_charge: ResourceVector,
        remaining_k: ResourceVector,
        exit_claims: u64,
    ) -> Option<KClaimBackedDetachedLeave> {
        validate_detached_claim(
            self.participant_id,
            DetachedClaimTarget::CredentialRecovery {
                marker_delivery_seq: self.marker_delivery_seq,
                binding_epoch: self.prior_binding_epoch,
            },
            participant_id,
            actual_charge,
            remaining_k,
            exit_claims,
        )
    }

    /// Consumes exact fenced recovery and installs only clear/OP/PC.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the event names the exact marker,
    /// prior epoch, participant, and immediate next generation.
    pub fn fenced_attach(
        self,
        debt: ClosureDebt,
        event: Event,
        successor: DebtCompletion,
    ) -> Result<FencedAttachCommit, ClosureState> {
        let original = owed(debt, StoredEdge::DetachedCredentialRecovery(self));
        let EventKind::FencedRecoveryCommitted {
            participant_id,
            marker_delivery_seq,
            prior_binding_epoch,
            new_binding_epoch,
            ..
        } = event.0
        else {
            return Err(original);
        };
        if participant_id != self.participant_id
            || marker_delivery_seq != self.marker_delivery_seq
            || prior_binding_epoch != self.prior_binding_epoch
            || !is_next_generation(prior_binding_epoch, new_binding_epoch)
        {
            return Err(original);
        }
        Ok(FencedAttachCommit {
            conversation_id: self.conversation_id,
            participant_id,
            marker_delivery_seq,
            prior_binding_epoch,
            new_binding_epoch,
            next_state: successor.into_state(),
        })
    }

    /// Consumes exact K-backed detached Leave and installs only clear/OP/PC.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the Leave and private claim
    /// authority are bound to this exact recovery edge.
    pub fn detached_leave(
        self,
        debt: ClosureDebt,
        event: Event,
        evidence: KClaimBackedDetachedLeave,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::DetachedCredentialRecovery(self));
        let EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Detached,
            ..
        } = event.0
        else {
            return Err(original);
        };
        let target = DetachedClaimTarget::CredentialRecovery {
            marker_delivery_seq: self.marker_delivery_seq,
            binding_epoch: self.prior_binding_epoch,
        };
        if participant_id != self.participant_id
            || evidence.participant_id != self.participant_id
            || evidence.target != target
        {
            return Err(original);
        }
        Ok(successor.into_state())
    }

    /// Ordinary non-fenced attach is refused without mutation.
    #[must_use]
    pub const fn ordinary_attach_refusal(self) -> DetachedAttachRefusal {
        let _ = self;
        DetachedAttachRefusal::RecoveryFence
    }

    /// An explicit marker is eligible only when it is the exact recovery marker.
    #[must_use]
    pub const fn marker_attach_refusal(
        self,
        presented_marker: DeliverySeq,
    ) -> Option<DetachedAttachRefusal> {
        if presented_marker == self.marker_delivery_seq {
            None
        } else {
            Some(DetachedAttachRefusal::MarkerMismatch)
        }
    }

    /// Authority supersession before commit preserves DCR and is stale.
    #[must_use]
    pub const fn authority_superseded(self) -> (Self, DetachedAttachRefusal) {
        (self, DetachedAttachRefusal::StaleAuthority)
    }

    /// Applies only an unrelated participant event, preserving this edge while
    /// debt remains or clearing it with debt.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state for a non-participant event or an event
    /// owned by this detached participant.
    pub const fn unrelated_event(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        unrelated_detached_event(
            StoredEdge::DetachedCredentialRecovery(self),
            self.participant_id,
            debt,
            event,
            resulting_debt,
        )
    }
}

mod sealed {
    pub trait Sealed {}
}

/// Sealed intended-dead-end contract for DMR and `DCursor`.
pub trait LeaveOnlyEdge: sealed::Sealed + Sized + Copy {
    /// Returns the exact owner of this Leave-only edge.
    fn participant_id(self) -> ParticipantId;

    /// Validates participant, exact target, actual charge, remaining K, and the
    /// available exit claim before creating private Leave authority.
    fn validate_leave_claim(
        &self,
        participant_id: ParticipantId,
        actual_charge: ResourceVector,
        remaining_k: ResourceVector,
        exit_claims: u64,
    ) -> Option<KClaimBackedDetachedLeave>;

    /// Sole successful owner transition: exact-current K-backed detached Leave.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state unless the Leave and private claim
    /// authority both name this exact Leave-only edge.
    fn leave(
        self,
        debt: ClosureDebt,
        event: Event,
        evidence: KClaimBackedDetachedLeave,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState>;

    /// Repeat exact fate is an event-consuming no-op.
    ///
    /// # Errors
    ///
    /// Returns the unchanged edge when the event is not fate for its exact owner
    /// and last dead binding epoch.
    fn repeat_fate(self, event: Event) -> Result<Self, Self>;

    /// Supersession is stale and preserves the exact edge.
    fn authority_superseded(self) -> (Self, DetachedAttachRefusal) {
        (self, DetachedAttachRefusal::StaleAuthority)
    }

    /// Normal/marker ack and ordinary admission have no binding authority.
    fn binding_required_refusal(self) -> DetachedAttachRefusal {
        let _ = self;
        DetachedAttachRefusal::NoBinding
    }

    /// Applies an unrelated participant event, preserving this edge while debt
    /// remains or clearing it with debt.
    ///
    /// # Errors
    ///
    /// Returns the unchanged owed state for a non-participant event or an event
    /// owned by this detached participant.
    fn unrelated_event(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState>;
}

impl sealed::Sealed for DetachedMarkerRelease {}
impl sealed::Sealed for DetachedCursorRelease {}

impl LeaveOnlyEdge for DetachedMarkerRelease {
    fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    fn validate_leave_claim(
        &self,
        participant_id: ParticipantId,
        actual_charge: ResourceVector,
        remaining_k: ResourceVector,
        exit_claims: u64,
    ) -> Option<KClaimBackedDetachedLeave> {
        validate_detached_claim(
            self.participant_id,
            DetachedClaimTarget::MarkerRelease {
                marker_delivery_seq: self.marker_delivery_seq,
                binding_epoch: self.last_dead_binding_epoch,
            },
            participant_id,
            actual_charge,
            remaining_k,
            exit_claims,
        )
    }

    fn leave(
        self,
        debt: ClosureDebt,
        event: Event,
        evidence: KClaimBackedDetachedLeave,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::DetachedMarkerRelease(self));
        let EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Detached,
            ..
        } = event.0
        else {
            return Err(original);
        };
        let target = DetachedClaimTarget::MarkerRelease {
            marker_delivery_seq: self.marker_delivery_seq,
            binding_epoch: self.last_dead_binding_epoch,
        };
        if participant_id != self.participant_id
            || evidence.participant_id != self.participant_id
            || evidence.target != target
        {
            return Err(original);
        }
        Ok(successor.into_state())
    }

    fn repeat_fate(self, event: Event) -> Result<Self, Self> {
        let EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            ..
        } = event.0
        else {
            return Err(self);
        };
        if participant_id == self.participant_id && binding_epoch == self.last_dead_binding_epoch {
            Ok(self)
        } else {
            Err(self)
        }
    }

    fn unrelated_event(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        unrelated_detached_event(
            StoredEdge::DetachedMarkerRelease(self),
            self.participant_id,
            debt,
            event,
            resulting_debt,
        )
    }
}

impl DetachedMarkerRelease {
    /// Ordinary attach cannot cross this Leave-only edge.
    #[must_use]
    pub const fn ordinary_attach_refusal(self) -> DetachedAttachRefusal {
        let _ = self;
        DetachedAttachRefusal::RecoveryFence
    }

    /// The exact undelivered marker selects `MarkerNotDelivered`; another marker
    /// selects `MarkerMismatch` without fabricating an expected delivery fact.
    #[must_use]
    pub const fn marker_attach_refusal(
        self,
        presented_marker: DeliverySeq,
    ) -> DetachedAttachRefusal {
        if presented_marker == self.marker_delivery_seq {
            DetachedAttachRefusal::MarkerNotDelivered
        } else {
            DetachedAttachRefusal::MarkerMismatch
        }
    }
}

impl LeaveOnlyEdge for DetachedCursorRelease {
    fn participant_id(self) -> ParticipantId {
        self.participant_id
    }

    fn validate_leave_claim(
        &self,
        participant_id: ParticipantId,
        actual_charge: ResourceVector,
        remaining_k: ResourceVector,
        exit_claims: u64,
    ) -> Option<KClaimBackedDetachedLeave> {
        validate_detached_claim(
            self.participant_id,
            DetachedClaimTarget::CursorRelease {
                binding_epoch: self.last_dead_binding_epoch,
            },
            participant_id,
            actual_charge,
            remaining_k,
            exit_claims,
        )
    }

    fn leave(
        self,
        debt: ClosureDebt,
        event: Event,
        evidence: KClaimBackedDetachedLeave,
        successor: DebtCompletion,
    ) -> Result<ClosureState, ClosureState> {
        let original = owed(debt, StoredEdge::DetachedCursorRelease(self));
        let EventKind::LeaveCommitted {
            participant_id,
            authority: LeaveAuthority::Detached,
            ..
        } = event.0
        else {
            return Err(original);
        };
        let target = DetachedClaimTarget::CursorRelease {
            binding_epoch: self.last_dead_binding_epoch,
        };
        if participant_id != self.participant_id
            || evidence.participant_id != self.participant_id
            || evidence.target != target
        {
            return Err(original);
        }
        Ok(successor.into_state())
    }

    fn repeat_fate(self, event: Event) -> Result<Self, Self> {
        let EventKind::BindingFateObserved {
            participant_id,
            binding_epoch,
            ..
        } = event.0
        else {
            return Err(self);
        };
        if participant_id == self.participant_id && binding_epoch == self.last_dead_binding_epoch {
            Ok(self)
        } else {
            Err(self)
        }
    }

    fn unrelated_event(
        self,
        debt: ClosureDebt,
        event: Event,
        resulting_debt: Option<ClosureDebt>,
    ) -> Result<ClosureState, ClosureState> {
        unrelated_detached_event(
            StoredEdge::DetachedCursorRelease(self),
            self.participant_id,
            debt,
            event,
            resulting_debt,
        )
    }
}

impl DetachedCursorRelease {
    /// Attach without a marker cannot cross this Leave-only edge.
    #[must_use]
    pub const fn ordinary_attach_refusal(self) -> DetachedAttachRefusal {
        let _ = self;
        DetachedAttachRefusal::RecoveryFence
    }

    /// Presenting any marker mismatches a cursor-only edge.
    #[must_use]
    pub const fn marker_attach_refusal(self) -> DetachedAttachRefusal {
        let _ = self;
        DetachedAttachRefusal::MarkerMismatch
    }
}

const fn owed(debt: ClosureDebt, edge: StoredEdge) -> ClosureState {
    ClosureState::Owed { debt, edge }
}

const fn preserve_or_clear(resulting_debt: Option<ClosureDebt>, edge: StoredEdge) -> ClosureState {
    match resulting_debt {
        Some(debt) => owed(debt, edge),
        None => ClosureState::Clear,
    }
}

const fn projection_completion_boundary(
    edge: ObserverProjection,
    event: Event,
) -> Option<DeliverySeq> {
    let EventKind::ProjectionCompleted { through_seq } = event.0 else {
        return None;
    };
    if through_seq == edge.through_seq {
        Some(through_seq)
    } else {
        None
    }
}

const fn physical_completion_floor(edge: PhysicalCompaction, event: Event) -> Option<DeliverySeq> {
    match event.0 {
        EventKind::CompactionCompleted {
            from_floor,
            through_seq,
            resulting_floor,
        } if from_floor == edge.from_floor
            && through_seq == edge.through_seq
            && resulting_floor > edge.through_seq =>
        {
            Some(resulting_floor)
        }
        _ => None,
    }
}

const fn progress_event_floor(event: Event) -> Option<DeliverySeq> {
    match event.0 {
        EventKind::CursorProgressed {
            resulting_floor, ..
        }
        | EventKind::BindingFateObserved {
            resulting_floor, ..
        }
        | EventKind::LeaveCommitted {
            resulting_floor, ..
        } => Some(resulting_floor),
        _ => None,
    }
}

const fn cursor_event_boundary(event: Event) -> DeliverySeq {
    match event.0 {
        EventKind::CursorProgressed {
            progress: CursorProgressEvent::Normal { through_seq, .. },
            ..
        } => through_seq,
        _ => 0,
    }
}

fn greater_ack_matches(edge: ParticipantCursorProgress, event: Event) -> bool {
    let EventKind::CursorProgressed {
        participant_id,
        binding_epoch,
        progress:
            CursorProgressEvent::Normal {
                previous_cursor,
                through_seq,
            },
        ..
    } = event.0
    else {
        return false;
    };
    participant_id == edge.participant_id()
        && binding_epoch == edge.binding_epoch()
        && previous_cursor < edge.through_seq()
        && through_seq > edge.through_seq()
}

const fn strict_edge_matches_boundary(edge: StoredEdge, boundary: DeliverySeq) -> bool {
    match edge {
        StoredEdge::ObserverProjection(value) => value.through_seq == boundary,
        StoredEdge::PhysicalCompaction(value) => value.through_seq == boundary,
        StoredEdge::MarkerDelivery(value) => value.marker_delivery_seq == boundary,
        StoredEdge::ParticipantCursorProgress(value) => value.through_seq() == boundary,
        StoredEdge::DetachedCredentialRecovery(_) => false,
        StoredEdge::DetachedMarkerRelease(value) => value.marker_delivery_seq == boundary,
        // DCursor has no sequence field in the frozen tag. The explicit boundary
        // supplied to the predecessor-bound successor is its typed causal-order
        // witness under LP-EXTRACTION-GOAL.md Fix 2.
        StoredEdge::DetachedCursorRelease(_) => true,
    }
}

const fn charged_churn_fits(used: u64, delta: u64, limit: u64) -> bool {
    delta > 0 && widen_u64(used) + widen_u64(delta) <= widen_u64(limit)
}

#[allow(clippy::cast_lossless)]
const fn widen_u64(value: u64) -> u128 {
    value as u128
}

const fn is_next_generation(old: BindingEpoch, new: BindingEpoch) -> bool {
    match old.capability_generation.get().checked_add(1) {
        Some(expected) => new.capability_generation.get() == expected,
        None => false,
    }
}

const fn validate_detached_claim(
    owner: ParticipantId,
    target: DetachedClaimTarget,
    participant_id: ParticipantId,
    actual_charge: ResourceVector,
    remaining_k: ResourceVector,
    exit_claims: u64,
) -> Option<KClaimBackedDetachedLeave> {
    if participant_id != owner
        || actual_charge.entries == 0
        || actual_charge.bytes == 0
        || actual_charge.entries > remaining_k.entries
        || actual_charge.bytes > remaining_k.bytes
        || exit_claims == 0
    {
        return None;
    }
    Some(KClaimBackedDetachedLeave {
        participant_id,
        target,
        actual_charge,
    })
}

const fn event_participant(event: Event) -> Option<ParticipantId> {
    match event.0 {
        EventKind::MarkerDelivered { participant_id, .. }
        | EventKind::CursorProgressed { participant_id, .. }
        | EventKind::BindingFateObserved { participant_id, .. }
        | EventKind::LeaveCommitted { participant_id, .. }
        | EventKind::FencedRecoveryCommitted { participant_id, .. } => Some(participant_id),
        EventKind::ProjectionCompleted { .. }
        | EventKind::CompactionCompleted { .. }
        | EventKind::MarkerAppended { .. } => None,
    }
}

const fn unrelated_detached_event(
    edge: StoredEdge,
    owner: ParticipantId,
    debt: ClosureDebt,
    event: Event,
    resulting_debt: Option<ClosureDebt>,
) -> Result<ClosureState, ClosureState> {
    let original = owed(debt, edge);
    let Some(participant_id) = event_participant(event) else {
        return Err(original);
    };
    if participant_id == owner {
        return Err(original);
    }
    Ok(preserve_or_clear(resulting_debt, edge))
}