canic-core 0.100.61

Canic — a canister orchestration and management toolkit for the Internet Computer
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
//! Module: dto::component_registry
//!
//! Responsibility: carry root-local Component Registry preparation and allocation evidence.
//! Does not own: admission policy, stable mutation, artifact resolution, or lifecycle effects.
//! Boundary: callers name intent and Spec while the root allocates identity under verified authority.

use crate::{
    cdk::types::Cycles,
    config::schema::ComponentChildKind,
    dto::{
        fleet_registry::{FleetDirectorySnapshot, FleetRegistryVersion},
        root_store::RootStoreBootstrapRequest,
    },
    ids::{
        CanisterRole, ComponentBinding, ComponentChildBinding, ComponentInstanceId,
        ComponentSpecId, ComponentTopologyDigest, FleetSubnetRootReleaseSet,
        ManagedCanisterBinding,
    },
};
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};

///
/// RootComponentRegistryPreparationRequest
///
/// Exact authority required before an empty root-local Component Registry may be prepared.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentRegistryPreparationRequest {
    pub store_bootstrap: RootStoreBootstrapRequest,
    pub expected_fleet_registry: FleetRegistryVersion,
}

///
/// RootComponentInitialInventoryStatus
///
/// Durable initial Component inventory sealed for one Fleet Subnet Root activation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentInitialInventoryStatus {
    pub fleet_activation_operation_id: [u8; 32],
    pub component_count: u32,
    pub inventory_hash: [u8; 32],
    pub sealed_at_ns: u64,
    pub directories_converged: bool,
    pub root_runtime_activated: bool,
}

///
/// RootComponentRegistryStatusResponse
///
/// Compact durable Component Registry authority and current allocation counters.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentRegistryStatusResponse {
    pub fleet_subnet_root: Principal,
    pub prepared_against_registry: FleetRegistryVersion,
    pub release_set: FleetSubnetRootReleaseSet,
    pub component_topology_digest: ComponentTopologyDigest,
    pub next_allocation_sequence: u64,
    pub reserved_component_instances: u32,
    pub committed_component_instances: u32,
    pub managed_descendants: u32,
    pub known_created_component_canisters: u32,
    pub encoded_bytes: u64,
    pub initial_inventory: Option<RootComponentInitialInventoryStatus>,
}

///
/// RootComponentAllocationRequest
///
/// Controller command naming one idempotent top-level Component reservation intent.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentAllocationRequest {
    pub operation_id: [u8; 32],
    pub component_spec: ComponentSpecId,
}

///
/// RootComponentAllocationStatusRequest
///
/// Read-only lookup key for one durable top-level Component allocation operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentAllocationStatusRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentChildAllocationRequest
///
/// Parent command naming one idempotent direct-child reservation intent.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildAllocationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_registry: ComponentRegistryHead,
    pub child_role: CanisterRole,
}

///
/// RootComponentChildAllocationStatusRequest
///
/// Parent lookup key for one durable direct-child reservation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildAllocationStatusRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentSubtreeRemovalRequest
///
/// Controller command durably fencing one registered child subtree.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub target_canister_id: Principal,
    pub expected_registry: ComponentRegistryHead,
}

///
/// RootComponentSubtreeRemovalAdvanceRequest
///
/// Controller command advancing bounded traversal from one observed durable step.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalAdvanceRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
}

///
/// RootComponentSubtreeRemovalStopPreparationRequest
///
/// Controller command freezing the exact selected leaf and root stop authority.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalStopPreparationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalStopRequest
///
/// Controller command reconciling and stopping one exactly prepared leaf.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalStopRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalDeletePreparationRequest
///
/// Controller command freezing exact deletion authority from one stopped receipt.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDeletePreparationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalDeleteRequest
///
/// Controller command reconciling and deleting one exactly prepared leaf.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDeleteRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalMembershipRemovalRequest
///
/// Controller command removing one independently deleted leaf from Registry membership.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalMembershipRemovalRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalDirectorySynchronizationRequest
///
/// Controller command converging the post-removal Directory on surviving members.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDirectorySynchronizationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalLeafFinalizationRequest
///
/// Controller command archiving one completed leaf and resuming its retained parent.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalLeafFinalizationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_traversal_steps: u32,
    pub expected_leaf_canister_id: Principal,
    pub expected_leaf_parent_canister_id: Principal,
}

///
/// RootComponentSubtreeRemovalStatusRequest
///
/// Controller lookup key for one durable child-subtree removal operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalStatusRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentDrainingRequest
///
/// Controller command fencing one exact active Component against new mutation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_registry: ComponentRegistryHead,
}

///
/// RootComponentDrainingStatusRequest
///
/// Read-only lookup key for one durable Component-draining operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingStatusRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentQuiescenceRequest
///
/// Controller command converging and stopping one exact draining Component.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentQuiescenceRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_registry: ComponentRegistryHead,
}

///
/// RootComponentQuiescenceStatusRequest
///
/// Read-only lookup key for one draining Component's quiescence progress.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentQuiescenceStatusRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentDrainingAdvanceRequest
///
/// Controller command advancing at most one deterministic draining-removal phase.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingAdvanceRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentFinalInventoryRequest
///
/// Controller command freezing one exact empty draining Component inventory.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentFinalInventoryRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub expected_registry: ComponentRegistryHead,
}

///
/// RootComponentChildCreationRequest
///
/// Parent command continuing one already reserved direct-child operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildCreationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentChildInstallRequest
///
/// Parent command installing and verifying one already created direct-child operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildInstallRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentChildCommitRequest
///
/// Parent command committing one already verified direct-child operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildCommitRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentChildDirectoryPreparationRequest
///
/// Parent command distributing one committed child's Directory and converging its affected members.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildDirectoryPreparationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentChildRuntimeActivationRequest
///
/// Parent command activating one Directory-prepared direct-child runtime.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildRuntimeActivationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentChildMembershipActivationRequest
///
/// Parent command activating one runtime-active direct child's Registry membership.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildMembershipActivationRequest {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
}

///
/// RootComponentCreationRequest
///
/// Controller command continuing one already reserved top-level Component operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentCreationRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentInstallRequest
///
/// Controller command continuing one already created top-level Component operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentInstallRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentCommitRequest
///
/// Controller command committing one already verified top-level Component operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentCommitRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentDirectoryPreparationRequest
///
/// Controller command distributing exact Directories to one committed top-level Component.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDirectoryPreparationRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentRuntimeActivationRequest
///
/// Controller command activating one Directory-prepared top-level Component runtime.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentRuntimeActivationRequest {
    pub operation_id: [u8; 32],
}

///
/// RootComponentMembershipActivationRequest
///
/// Controller command activating one runtime-active Component's Registry membership.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentMembershipActivationRequest {
    pub operation_id: [u8; 32],
}

///
/// ComponentProvisioningOrigin
///
/// Authenticated causal authority retained with one top-level Component allocation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ComponentProvisioningOrigin {
    FleetAdministrator { caller: Principal },
}

///
/// RootComponentAllocationPhase
///
/// Durable root-local progress of one top-level Component allocation operation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum RootComponentAllocationPhase {
    Reserved,
    CreationIntent,
    Created,
    InstallIntent,
    Installed,
    Verified,
    Committed,
}

///
/// RootComponentSubtreeRemovalPhase
///
/// Durable root-local progress of one child-subtree removal operation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[expect(
    clippy::large_enum_variant,
    reason = "wire phases retain complete inline receipts for deterministic Candid responses"
)]
pub enum RootComponentSubtreeRemovalPhase {
    Fenced,
    Traversing(RootComponentSubtreeRemovalNode),
    LeafSelected(RootComponentSubtreeRemovalNode),
    StopIntent(RootComponentSubtreeRemovalStopIntent),
    Stopped(RootComponentSubtreeRemovalStoppedReceipt),
    DeleteIntent(RootComponentSubtreeRemovalDeleteIntent),
    Deleted(RootComponentSubtreeRemovalDeletedReceipt),
    MembershipRemoved(RootComponentSubtreeRemovalMembershipRemovedReceipt),
    DirectorySynchronized(RootComponentSubtreeRemovalDirectorySynchronizedReceipt),
    Completed(RootComponentSubtreeRemovalCompletedReceipt),
}

///
/// RootComponentSubtreeRemovalNode
///
/// Exact registered child selected as a traversal cursor or removable leaf.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalNode {
    pub canister_id: Principal,
    pub parent_canister_id: Principal,
    pub role: CanisterRole,
    pub kind: ComponentChildKind,
    pub installed_artifact_hash: [u8; 32],
    pub status: ComponentLifecycleStatus,
}

///
/// RootComponentSubtreeRemovalStopIntent
///
/// Exact registered leaf and sole root controller frozen before a stop call.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalStopIntent {
    pub leaf: RootComponentSubtreeRemovalNode,
    pub controller: Principal,
}

///
/// RootComponentSubtreeRemovalStoppedReceipt
///
/// Frozen stop authority plus the independently observed installed module.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalStoppedReceipt {
    pub stop: RootComponentSubtreeRemovalStopIntent,
    pub observed_module_hash: [u8; 32],
}

///
/// RootComponentSubtreeRemovalDeleteIntent
///
/// Exact stopped receipt frozen before the destructive management call.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDeleteIntent {
    pub stopped: RootComponentSubtreeRemovalStoppedReceipt,
}

///
/// RootComponentSubtreeRemovalDeletedReceipt
///
/// Frozen deletion authority committed only after independently observed absence.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDeletedReceipt {
    pub deletion: RootComponentSubtreeRemovalDeleteIntent,
}

///
/// RootComponentSubtreeRemovalMembershipRemovedReceipt
///
/// Exact Registry transition retained after the independently deleted leaf is unregistered.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalMembershipRemovedReceipt {
    pub deleted: RootComponentSubtreeRemovalDeletedReceipt,
    pub removed_from_registry: ComponentRegistryHead,
    pub previous_descendant_content_hash: [u8; 32],
    pub previous_committed_descendants: u32,
    pub registry: ComponentRegistryHead,
    pub descendant_content_hash: [u8; 32],
    pub registry_encoded_bytes: u64,
    pub reserved_descendants: u32,
    pub committed_descendants: u32,
    pub directory_synchronized_at_ns: u64,
    pub directory_authority_hash: [u8; 32],
    pub parent_role_instances: u32,
    pub root_managed_descendants: u32,
    pub root_known_created_component_canisters: u32,
}

///
/// RootComponentSubtreeRemovalDirectoryConvergenceEvidence
///
/// Compact durable proof that one surviving member covered the required Directory.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDirectoryConvergenceEvidence {
    pub operation_id: [u8; 32],
    pub canister_id: Principal,
    pub activation: ComponentRuntimeActivationEvidence,
}

///
/// RootComponentSubtreeRemovalDirectorySynchronizedReceipt
///
/// Membership removal plus independently verified surviving-member convergence.
///
/// The owner is absent only when its top-level Component is durably quiescent.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalDirectorySynchronizedReceipt {
    pub membership_removed: RootComponentSubtreeRemovalMembershipRemovedReceipt,
    pub covered_fleet_registry_revision: u64,
    pub covered_fleet_registry_content_hash: [u8; 32],
    pub covered_component_registry: ComponentRegistryHead,
    pub covered_authority_hash: [u8; 32],
    pub owning_component: Option<RootComponentSubtreeRemovalDirectoryConvergenceEvidence>,
    pub parent: Option<RootComponentSubtreeRemovalDirectoryConvergenceEvidence>,
}

///
/// RootComponentSubtreeRemovalCompletedReceipt
///
/// Terminal Registry and Directory authority after the fenced target is finalized.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalCompletedReceipt {
    pub registry: ComponentRegistryHead,
    pub directory_authority_hash: [u8; 32],
}

///
/// ComponentLifecycleStatus
///
/// Root-owned runtime lifecycle state of one committed Component Registry member.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ComponentLifecycleStatus {
    Prepared,
    Active,
    Draining,
    Removed,
}

///
/// ComponentRegistryHead
///
/// Exact independently versioned authority of one Component Registry partition.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRegistryHead {
    pub component: ComponentInstanceId,
    pub revision: u64,
    pub content_hash: [u8; 32],
}

///
/// ComponentRegistryPartitionRequest
///
/// Read-only lookup key for one committed Component Registry partition.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRegistryPartitionRequest {
    pub component: ComponentInstanceId,
}

///
/// ComponentRegistryPartitionResponse
///
/// Protected top-level row and independent head of one Component Registry partition.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRegistryPartitionResponse {
    pub head: ComponentRegistryHead,
    pub binding: ComponentBinding,
    pub provisioning_origin: ComponentProvisioningOrigin,
    pub release_set: FleetSubnetRootReleaseSet,
    pub status: ComponentLifecycleStatus,
    pub reserved_descendants: u32,
    pub committed_descendants: u32,
    pub encoded_bytes: u64,
}

///
/// ComponentDirectoryProvenance
///
/// Exact Component Registry authority from which one Component Directory is derived.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryProvenance {
    pub component: ComponentBinding,
    pub source_fleet_subnet_root: Principal,
    pub component_registry_revision: u64,
    pub component_registry_content_hash: [u8; 32],
    pub synchronized_at_ns: u64,
}

///
/// ComponentDirectoryHead
///
/// Compact independently versioned discovery projection for one Component tree.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryHead {
    pub provenance: ComponentDirectoryProvenance,
    pub descendant_count: u32,
}

///
/// ComponentDirectoryHeadRequest
///
/// Read-only lookup key for one committed Component Directory head.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryHeadRequest {
    pub component: ComponentInstanceId,
}

///
/// ComponentDirectoryPageCursor
///
/// Opaque revision- and filter-bound continuation for one bounded Directory page.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryPageCursor(pub Vec<u8>);

///
/// ComponentDirectoryPageRequest
///
/// Bounded member query against one exact current Component Directory authority.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryPageRequest {
    pub directory: ComponentDirectoryHead,
    pub parent_canister_id: Option<Principal>,
    pub role: Option<CanisterRole>,
    pub status: Option<ComponentLifecycleStatus>,
    pub cursor: Option<ComponentDirectoryPageCursor>,
    pub limit: u16,
}

///
/// ComponentDirectoryChildEntry
///
/// One authoritative normalized child projected with its complete protected binding.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryChildEntry {
    pub binding: ComponentChildBinding,
    pub kind: ComponentChildKind,
    pub installed_artifact_hash: [u8; 32],
    pub status: ComponentLifecycleStatus,
}

///
/// ComponentDirectoryPageResponse
///
/// One bounded caller-scoped page under the exact requested Directory head.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentDirectoryPageResponse {
    pub directory: ComponentDirectoryHead,
    pub entries: Vec<ComponentDirectoryChildEntry>,
    pub next_cursor: Option<ComponentDirectoryPageCursor>,
}

///
/// ComponentRuntimeDirectoryAuthority
///
/// Exact Fleet and Component discovery authority retained by one managed Component-tree node.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeDirectoryAuthority {
    pub fleet: FleetDirectorySnapshot,
    pub component: ComponentDirectoryHead,
}

///
/// ComponentRuntimeDirectoryPreparationRequest
///
/// Root-issued exact Directory preparation command for one managed Component-tree node.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeDirectoryPreparationRequest {
    pub operation_id: [u8; 32],
    pub authority: ComponentRuntimeDirectoryAuthority,
}

///
/// ComponentRuntimeDirectorySynchronizationRequest
///
/// Root-issued replacement of one active managed Component node's current Directory authority.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeDirectorySynchronizationRequest {
    pub operation_id: [u8; 32],
    pub authority: ComponentRuntimeDirectoryAuthority,
}

///
/// ComponentRuntimePhase
///
/// Target-local progress from installation through Component runtime activation.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ComponentRuntimePhase {
    AwaitingDirectory,
    DirectoryPrepared,
    Active,
}

///
/// ComponentRuntimeActivationEvidence
///
/// Exact retained Directory authority under which one Component runtime became Active.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeActivationEvidence {
    pub directory_authority_hash: [u8; 32],
    pub activated_at_ns: u64,
}

///
/// ComponentRuntimeActivationRequest
///
/// Root-issued exact activation command for one Directory-prepared managed Component node.
///

#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeActivationRequest {
    pub operation_id: [u8; 32],
    pub directory_authority_hash: [u8; 32],
}

///
/// ComponentRuntimeStatusResponse
///
/// Independently observable target-local binding and exact retained Directory authority.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeStatusResponse {
    pub operation_id: [u8; 32],
    pub binding: ManagedCanisterBinding,
    pub phase: ComponentRuntimePhase,
    pub authority: Option<ComponentRuntimeDirectoryAuthority>,
    pub authority_hash: Option<[u8; 32]>,
    pub activation: Option<ComponentRuntimeActivationEvidence>,
}

///
/// ComponentRuntimeDirectoryConvergenceEvidence
///
/// Stable root evidence that one active member covered at least the required Directory authority.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ComponentRuntimeDirectoryConvergenceEvidence {
    pub operation_id: [u8; 32],
    pub binding: ManagedCanisterBinding,
    pub covered_authority: ComponentRuntimeDirectoryAuthority,
    pub covered_authority_hash: [u8; 32],
    pub activation: ComponentRuntimeActivationEvidence,
}

///
/// RootComponentCreationEvidence
///
/// Exact Store artifact and root-owned creation settings frozen before the paid effect.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentCreationEvidence {
    pub wasm_store: Principal,
    pub payload_hash: [u8; 32],
    pub payload_size_bytes: u64,
    pub initial_cycles: Cycles,
    pub controller: Principal,
    pub canister: Option<Principal>,
}

///
/// RootComponentInstallEvidence
///
/// Exact raw artifact, chunk source and immutable target binding frozen before installation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentInstallEvidence {
    pub raw_module_hash: [u8; 32],
    pub chunk_hashes: Vec<Vec<u8>>,
    pub binding: ComponentBinding,
}

///
/// RootComponentChildInstallEvidence
///
/// Exact child module and immutable retained binding frozen before installation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildInstallEvidence {
    pub raw_module_hash: [u8; 32],
    pub chunk_hashes: Vec<Vec<u8>>,
    pub binding: ComponentChildBinding,
}

///
/// RootComponentAllocationResponse
///
/// Durable identity reservation returned identically for exact operation retry.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentAllocationResponse {
    pub operation_id: [u8; 32],
    pub allocation_sequence: u64,
    pub component: ComponentInstanceId,
    pub component_spec: ComponentSpecId,
    pub spec_hash: [u8; 32],
    pub role: CanisterRole,
    pub provisioning_origin: ComponentProvisioningOrigin,
    pub release_set: FleetSubnetRootReleaseSet,
    pub phase: RootComponentAllocationPhase,
    pub creation: Option<RootComponentCreationEvidence>,
    pub installation: Option<RootComponentInstallEvidence>,
}

///
/// RootComponentChildAllocationResponse
///
/// Durable direct-child lifecycle progress returned identically for exact parent retry.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildAllocationResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub parent_canister_id: Principal,
    pub parent_role: CanisterRole,
    pub child_role: CanisterRole,
    pub child_kind: ComponentChildKind,
    pub maximum_instances_per_parent: u32,
    pub maximum_descendants: u32,
    pub maximum_registry_bytes: u64,
    pub reserved_against_registry: ComponentRegistryHead,
    pub release_set: FleetSubnetRootReleaseSet,
    pub phase: RootComponentAllocationPhase,
    pub creation: Option<RootComponentCreationEvidence>,
    pub installation: Option<RootComponentChildInstallEvidence>,
}

///
/// RootComponentSubtreeRemovalResponse
///
/// Current durable snapshot of one monotonic subtree-removal operation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentSubtreeRemovalResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub target_canister_id: Principal,
    pub target_parent_canister_id: Principal,
    pub target_role: CanisterRole,
    pub target_status: ComponentLifecycleStatus,
    pub reserved_against_registry: ComponentRegistryHead,
    pub maximum_completed_leaves: u32,
    pub completed_leaves: u32,
    pub traversal_steps: u32,
    pub phase: RootComponentSubtreeRemovalPhase,
}

///
/// RootComponentDrainingResponse
///
/// Exact Registry and Directory authority produced by the durable draining fence.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub previous_registry: ComponentRegistryHead,
    pub registry: ComponentRegistryHead,
    pub descendant_count: u32,
    pub descendant_content_hash: [u8; 32],
    pub directory_authority_hash: [u8; 32],
    pub started_at_ns: u64,
}

///
/// RootComponentQuiescenceStopIntent
///
/// Exact runtime, Directory, module and controller authority frozen before stopping.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentQuiescenceStopIntent {
    pub registry: ComponentRegistryHead,
    pub descendant_count: u32,
    pub descendant_content_hash: [u8; 32],
    pub canister_id: Principal,
    pub controller: Principal,
    pub expected_module_hash: [u8; 32],
    pub covered_fleet_registry_revision: u64,
    pub covered_fleet_registry_content_hash: [u8; 32],
    pub covered_authority_hash: [u8; 32],
    pub runtime_operation_id: [u8; 32],
    pub activation: ComponentRuntimeActivationEvidence,
    pub prepared_at_ns: u64,
}

///
/// RootComponentQuiescentReceipt
///
/// Durable evidence that the exact prepared Component was independently observed stopped.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentQuiescentReceipt {
    pub stop: RootComponentQuiescenceStopIntent,
    pub observed_module_hash: [u8; 32],
    pub quiesced_at_ns: u64,
}

///
/// RootComponentQuiescencePhase
///
/// Monotonic progress from pre-effect stop authority to observed quiescence.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum RootComponentQuiescencePhase {
    StopIntent(RootComponentQuiescenceStopIntent),
    Quiescent(RootComponentQuiescentReceipt),
}

///
/// RootComponentQuiescenceResponse
///
/// Current durable quiescence progress for one draining Component.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentQuiescenceResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub phase: RootComponentQuiescencePhase,
}

///
/// RootComponentDrainingDescendantsEmpty
///
/// Exact current Registry proof that one draining Component has no descendants.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingDescendantsEmpty {
    pub registry: ComponentRegistryHead,
    pub descendant_content_hash: [u8; 32],
}

///
/// RootComponentDrainingAdvancePhase
///
/// One bounded driver result: current subtree progress or exact empty inventory.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[expect(
    clippy::large_enum_variant,
    reason = "wire result embeds the current durable subtree snapshot without a Rust-only indirection"
)]
pub enum RootComponentDrainingAdvancePhase {
    DescendantRemoval(RootComponentSubtreeRemovalResponse),
    DescendantsEmpty(RootComponentDrainingDescendantsEmpty),
}

///
/// RootComponentDrainingAdvanceResponse
///
/// Current bounded progress of one terminally quiescent Component drain.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDrainingAdvanceResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub phase: RootComponentDrainingAdvancePhase,
}

///
/// RootComponentFinalInventory
///
/// Exact empty Component Registry and current Fleet Directory authority frozen before deletion.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentFinalInventory {
    pub registry: ComponentRegistryHead,
    pub descendant_content_hash: [u8; 32],
    pub registry_encoded_bytes: u64,
    pub directory_synchronized_at_ns: u64,
    pub covered_fleet_registry_revision: u64,
    pub covered_fleet_registry_content_hash: [u8; 32],
    pub directory_authority_hash: [u8; 32],
    pub inventory_hash: [u8; 32],
    pub finalized_at_ns: u64,
}

///
/// RootComponentFinalInventoryResponse
///
/// Response-idempotent receipt for one finalized empty Component inventory.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentFinalInventoryResponse {
    pub operation_id: [u8; 32],
    pub component: ComponentInstanceId,
    pub inventory: RootComponentFinalInventory,
}

///
/// RootComponentChildCommitResponse
///
/// Exact committed child operation, authoritative Component Registry and next Directory head.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildCommitResponse {
    pub allocation: RootComponentChildAllocationResponse,
    pub registry: ComponentRegistryPartitionResponse,
    pub directory: ComponentDirectoryHead,
}

///
/// RootComponentChildDirectoryPreparationResponse
///
/// Exact child preparation plus stable bounded active-member Directory coverage.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildDirectoryPreparationResponse {
    pub committed: RootComponentChildCommitResponse,
    pub child: ComponentRuntimeStatusResponse,
    pub owning_component: ComponentRuntimeDirectoryConvergenceEvidence,
    pub parent: Option<ComponentRuntimeDirectoryConvergenceEvidence>,
}

///
/// RootComponentChildRuntimeActivationResponse
///
/// Exact child commitment plus independently observed Directory-bound runtime activation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildRuntimeActivationResponse {
    pub committed: RootComponentChildCommitResponse,
    pub child: ComponentRuntimeStatusResponse,
}

///
/// RootComponentChildMembershipActivationResponse
///
/// Original child commitment plus active Registry, Directory and target convergence evidence.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentChildMembershipActivationResponse {
    pub committed: RootComponentChildCommitResponse,
    pub registry: ComponentRegistryPartitionResponse,
    pub directory: ComponentDirectoryHead,
    pub child: ComponentRuntimeStatusResponse,
}

///
/// RootComponentCommitResponse
///
/// Exact committed allocation, authoritative Registry row and derived Directory head.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentCommitResponse {
    pub allocation: RootComponentAllocationResponse,
    pub registry: ComponentRegistryPartitionResponse,
    pub directory: ComponentDirectoryHead,
}

///
/// RootComponentDirectoryPreparationResponse
///
/// Exact root authority plus independently observed target-local Directory preparation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentDirectoryPreparationResponse {
    pub committed: RootComponentCommitResponse,
    pub target: ComponentRuntimeStatusResponse,
}

///
/// RootComponentRuntimeActivationResponse
///
/// Exact root authority plus independently observed target-local runtime activation.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentRuntimeActivationResponse {
    pub committed: RootComponentCommitResponse,
    pub target: ComponentRuntimeStatusResponse,
}

///
/// RootComponentMembershipActivationResponse
///
/// Exact active Registry authority plus independently observed current target Directory.
///

#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct RootComponentMembershipActivationResponse {
    pub allocation: RootComponentAllocationResponse,
    pub registry: ComponentRegistryPartitionResponse,
    pub directory: ComponentDirectoryHead,
    pub target: ComponentRuntimeStatusResponse,
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        dto::root_store::RootStoreBootstrapRequest,
        ids::{
            AppId, CanonicalNetworkId, FleetCoordinatorBinding, FleetId, FleetKey,
            FleetRegistryAuthority, ReleaseBuildId, ReleaseBuildNonce, ReleaseSetDigest, SubnetId,
        },
    };

    #[test]
    fn component_registry_contracts_round_trip_through_candid() {
        let request = RootComponentRegistryPreparationRequest {
            store_bootstrap: RootStoreBootstrapRequest {
                manifest_payload_size_bytes: 128,
            },
            expected_fleet_registry: FleetRegistryVersion {
                authority: fleet_registry_authority(),
                revision: 4,
                content_hash: [5; 32],
            },
        };
        let response = RootComponentRegistryStatusResponse {
            fleet_subnet_root: Principal::from_slice(&[6; 29]),
            prepared_against_registry: request.expected_fleet_registry.clone(),
            release_set: FleetSubnetRootReleaseSet {
                release_build_id: ReleaseBuildId::from_nonce(ReleaseBuildNonce::from_random_bytes(
                    [7; 32],
                )),
                manifest_digest: ReleaseSetDigest::from_bytes([8; 32]),
            },
            component_topology_digest: ComponentTopologyDigest::from_bytes([9; 32]),
            next_allocation_sequence: 1,
            reserved_component_instances: 0,
            committed_component_instances: 0,
            managed_descendants: 0,
            known_created_component_canisters: 0,
            encoded_bytes: 0,
            initial_inventory: Some(RootComponentInitialInventoryStatus {
                fleet_activation_operation_id: [10; 32],
                component_count: 0,
                inventory_hash: [11; 32],
                sealed_at_ns: 12,
                directories_converged: true,
                root_runtime_activated: true,
            }),
        };
        let allocation = RootComponentAllocationResponse {
            operation_id: [10; 32],
            allocation_sequence: 1,
            component: ComponentInstanceId::from_generated_bytes([11; 32]),
            component_spec: "projects".parse().expect("Component Spec ID"),
            spec_hash: [12; 32],
            role: CanisterRole::new("project_hub"),
            provisioning_origin: ComponentProvisioningOrigin::FleetAdministrator {
                caller: Principal::from_slice(&[13; 29]),
            },
            release_set: response.release_set,
            phase: RootComponentAllocationPhase::Reserved,
            creation: None,
            installation: None,
        };
        let created = RootComponentAllocationResponse {
            phase: RootComponentAllocationPhase::Created,
            creation: Some(RootComponentCreationEvidence {
                wasm_store: Principal::from_slice(&[14; 29]),
                payload_hash: [15; 32],
                payload_size_bytes: 4_096,
                initial_cycles: Cycles::new(5_000_000_000_000),
                controller: Principal::from_slice(&[6; 29]),
                canister: Some(Principal::from_slice(&[16; 29])),
            }),
            installation: None,
            ..allocation.clone()
        };
        let request_bytes = candid::encode_one(&request).expect("encode request");
        let response_bytes = candid::encode_one(&response).expect("encode response");
        let allocation_bytes = candid::encode_one(&allocation).expect("encode allocation");
        let created_bytes = candid::encode_one(&created).expect("encode created allocation");

        assert_eq!(
            candid::decode_one::<RootComponentRegistryPreparationRequest>(&request_bytes)
                .expect("decode request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentRegistryStatusResponse>(&response_bytes)
                .expect("decode response"),
            response
        );
        assert_eq!(
            candid::decode_one::<RootComponentAllocationResponse>(&allocation_bytes)
                .expect("decode allocation"),
            allocation
        );
        assert_eq!(
            candid::decode_one::<RootComponentAllocationResponse>(&created_bytes)
                .expect("decode created allocation"),
            created
        );
    }

    #[test]
    fn component_commit_response_round_trips_through_candid() {
        let root = Principal::from_slice(&[6; 29]);
        let component = ComponentInstanceId::from_generated_bytes([11; 32]);
        let component_spec: ComponentSpecId = "projects".parse().expect("Component Spec ID");
        let release_set = FleetSubnetRootReleaseSet {
            release_build_id: ReleaseBuildId::from_nonce(ReleaseBuildNonce::from_random_bytes(
                [7; 32],
            )),
            manifest_digest: ReleaseSetDigest::from_bytes([8; 32]),
        };
        let provisioning_origin = ComponentProvisioningOrigin::FleetAdministrator {
            caller: Principal::from_slice(&[13; 29]),
        };
        let binding = ComponentBinding {
            authority: fleet_registry_authority(),
            component,
            component_spec: component_spec.clone(),
            spec_hash: [12; 32],
            role: CanisterRole::new("project_hub"),
            placement_subnet: SubnetId::from_principal(Principal::from_slice(&[17; 29])),
            fleet_subnet_root: root,
            canister_id: Principal::from_slice(&[16; 29]),
        };
        let head = ComponentRegistryHead {
            component,
            revision: 1,
            content_hash: [18; 32],
        };
        let committed = RootComponentCommitResponse {
            allocation: RootComponentAllocationResponse {
                operation_id: [10; 32],
                allocation_sequence: 1,
                component,
                component_spec,
                spec_hash: binding.spec_hash,
                role: binding.role.clone(),
                provisioning_origin: provisioning_origin.clone(),
                release_set,
                phase: RootComponentAllocationPhase::Committed,
                creation: Some(RootComponentCreationEvidence {
                    wasm_store: Principal::from_slice(&[14; 29]),
                    payload_hash: [15; 32],
                    payload_size_bytes: 4_096,
                    initial_cycles: Cycles::new(5_000_000_000_000),
                    controller: root,
                    canister: Some(binding.canister_id),
                }),
                installation: Some(RootComponentInstallEvidence {
                    raw_module_hash: [20; 32],
                    chunk_hashes: vec![vec![21; 32]],
                    binding: binding.clone(),
                }),
            },
            registry: ComponentRegistryPartitionResponse {
                head: head.clone(),
                binding: binding.clone(),
                provisioning_origin,
                release_set,
                status: ComponentLifecycleStatus::Prepared,
                reserved_descendants: 0,
                committed_descendants: 0,
                encoded_bytes: 2_048,
            },
            directory: ComponentDirectoryHead {
                provenance: ComponentDirectoryProvenance {
                    component: binding,
                    source_fleet_subnet_root: root,
                    component_registry_revision: head.revision,
                    component_registry_content_hash: head.content_hash,
                    synchronized_at_ns: 19,
                },
                descendant_count: 0,
            },
        };
        let committed_bytes = candid::encode_one(&committed).expect("encode committed allocation");

        assert_eq!(
            candid::decode_one::<RootComponentCommitResponse>(&committed_bytes)
                .expect("decode committed allocation"),
            committed
        );
    }

    #[test]
    fn component_directory_page_contracts_round_trip_through_candid() {
        let root = Principal::from_slice(&[6; 29]);
        let component = ComponentInstanceId::from_generated_bytes([11; 32]);
        let binding = ComponentBinding {
            authority: fleet_registry_authority(),
            component,
            component_spec: "projects".parse().expect("Component Spec ID"),
            spec_hash: [12; 32],
            role: CanisterRole::new("project_hub"),
            placement_subnet: SubnetId::from_principal(Principal::from_slice(&[17; 29])),
            fleet_subnet_root: root,
            canister_id: Principal::from_slice(&[16; 29]),
        };
        let directory = ComponentDirectoryHead {
            provenance: ComponentDirectoryProvenance {
                component: binding.clone(),
                source_fleet_subnet_root: root,
                component_registry_revision: 3,
                component_registry_content_hash: [18; 32],
                synchronized_at_ns: 19,
            },
            descendant_count: 1,
        };
        let request = ComponentDirectoryPageRequest {
            directory: directory.clone(),
            parent_canister_id: Some(binding.canister_id),
            role: Some(CanisterRole::new("project_instance")),
            status: Some(ComponentLifecycleStatus::Active),
            cursor: Some(ComponentDirectoryPageCursor(vec![20; 64])),
            limit: 50,
        };
        let response = ComponentDirectoryPageResponse {
            directory,
            entries: vec![ComponentDirectoryChildEntry {
                binding: ComponentChildBinding {
                    component: binding.clone(),
                    parent_canister_id: binding.canister_id,
                    role: CanisterRole::new("project_instance"),
                    canister_id: Principal::from_slice(&[21; 29]),
                },
                kind: ComponentChildKind::Instance,
                installed_artifact_hash: [22; 32],
                status: ComponentLifecycleStatus::Active,
            }],
            next_cursor: Some(ComponentDirectoryPageCursor(vec![23; 64])),
        };
        let request_bytes = candid::encode_one(&request).expect("encode Directory page request");
        let response_bytes = candid::encode_one(&response).expect("encode Directory page response");

        assert_eq!(
            candid::decode_one::<ComponentDirectoryPageRequest>(&request_bytes)
                .expect("decode Directory page request"),
            request
        );
        assert_eq!(
            candid::decode_one::<ComponentDirectoryPageResponse>(&response_bytes)
                .expect("decode Directory page response"),
            response
        );
    }

    fn fleet_registry_authority() -> FleetRegistryAuthority {
        FleetRegistryAuthority {
            binding: FleetCoordinatorBinding {
                fleet: crate::ids::FleetBinding {
                    fleet: FleetKey {
                        canonical_network_id: CanonicalNetworkId::ic_mainnet(),
                        fleet_id: FleetId::from_generated_bytes([1; 32]),
                    },
                    app: AppId::from("toko"),
                },
                coordinator_subnet: SubnetId::from_principal(Principal::from_slice(&[2; 29])),
                coordinator: Principal::from_slice(&[3; 29]),
            },
            epoch: 1,
        }
    }

    #[test]
    fn component_creation_request_round_trips_through_candid() {
        let request = RootComponentCreationRequest {
            operation_id: [10; 32],
        };
        let bytes = candid::encode_one(request).expect("encode creation request");

        assert_eq!(
            candid::decode_one::<RootComponentCreationRequest>(&bytes)
                .expect("decode creation request"),
            request
        );
    }

    #[test]
    #[expect(
        clippy::too_many_lines,
        reason = "one Candid contract test covers every subtree-removal phase receipt"
    )]
    fn component_subtree_removal_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([41; 32]);
        let registry = ComponentRegistryHead {
            component,
            revision: 7,
            content_hash: [42; 32],
        };
        let request = RootComponentSubtreeRemovalRequest {
            operation_id: [43; 32],
            component,
            target_canister_id: Principal::from_slice(&[44; 29]),
            expected_registry: registry.clone(),
        };
        let status_request = RootComponentSubtreeRemovalStatusRequest {
            operation_id: request.operation_id,
            component,
        };
        let advance_request = RootComponentSubtreeRemovalAdvanceRequest {
            operation_id: request.operation_id,
            component,
            expected_traversal_steps: 1,
        };
        let stop_request = RootComponentSubtreeRemovalStopPreparationRequest {
            operation_id: request.operation_id,
            component,
            expected_traversal_steps: 2,
            expected_leaf_canister_id: Principal::from_slice(&[46; 29]),
            expected_leaf_parent_canister_id: request.target_canister_id,
        };
        let stopped = RootComponentSubtreeRemovalStoppedReceipt {
            observed_module_hash: [49; 32],
            stop: RootComponentSubtreeRemovalStopIntent {
                controller: Principal::from_slice(&[48; 29]),
                leaf: RootComponentSubtreeRemovalNode {
                    canister_id: Principal::from_slice(&[46; 29]),
                    parent_canister_id: request.target_canister_id,
                    role: CanisterRole::new("project_ledger"),
                    kind: ComponentChildKind::Singleton,
                    installed_artifact_hash: [47; 32],
                    status: ComponentLifecycleStatus::Active,
                },
            },
        };
        let response = RootComponentSubtreeRemovalResponse {
            operation_id: request.operation_id,
            component,
            target_canister_id: request.target_canister_id,
            target_parent_canister_id: Principal::from_slice(&[45; 29]),
            target_role: CanisterRole::new("project_instance"),
            target_status: ComponentLifecycleStatus::Active,
            reserved_against_registry: registry,
            maximum_completed_leaves: 4,
            completed_leaves: 1,
            traversal_steps: 2,
            phase: RootComponentSubtreeRemovalPhase::DirectorySynchronized(
                RootComponentSubtreeRemovalDirectorySynchronizedReceipt {
                    membership_removed: RootComponentSubtreeRemovalMembershipRemovedReceipt {
                        deleted: RootComponentSubtreeRemovalDeletedReceipt {
                            deletion: RootComponentSubtreeRemovalDeleteIntent { stopped },
                        },
                        removed_from_registry: ComponentRegistryHead {
                            component,
                            revision: 8,
                            content_hash: [50; 32],
                        },
                        previous_descendant_content_hash: [51; 32],
                        previous_committed_descendants: 4,
                        registry: ComponentRegistryHead {
                            component,
                            revision: 9,
                            content_hash: [52; 32],
                        },
                        descendant_content_hash: [53; 32],
                        registry_encoded_bytes: 4_096,
                        reserved_descendants: 1,
                        committed_descendants: 3,
                        directory_synchronized_at_ns: 54,
                        directory_authority_hash: [55; 32],
                        parent_role_instances: 0,
                        root_managed_descendants: 4,
                        root_known_created_component_canisters: 4,
                    },
                    covered_fleet_registry_revision: 6,
                    covered_fleet_registry_content_hash: [56; 32],
                    covered_component_registry: ComponentRegistryHead {
                        component,
                        revision: 9,
                        content_hash: [52; 32],
                    },
                    covered_authority_hash: [55; 32],
                    owning_component: Some(
                        RootComponentSubtreeRemovalDirectoryConvergenceEvidence {
                            operation_id: [57; 32],
                            canister_id: Principal::from_slice(&[58; 29]),
                            activation: ComponentRuntimeActivationEvidence {
                                directory_authority_hash: [59; 32],
                                activated_at_ns: 60,
                            },
                        },
                    ),
                    parent: Some(RootComponentSubtreeRemovalDirectoryConvergenceEvidence {
                        operation_id: [61; 32],
                        canister_id: request.target_canister_id,
                        activation: ComponentRuntimeActivationEvidence {
                            directory_authority_hash: [62; 32],
                            activated_at_ns: 63,
                        },
                    }),
                },
            ),
        };

        let request_bytes = candid::encode_one(&request).expect("encode subtree removal request");
        let advance_bytes =
            candid::encode_one(advance_request).expect("encode subtree removal advance request");
        let stop_bytes =
            candid::encode_one(stop_request).expect("encode subtree removal stop request");
        let status_bytes =
            candid::encode_one(status_request).expect("encode subtree removal status request");
        let response_bytes =
            candid::encode_one(&response).expect("encode subtree removal response");

        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalRequest>(&request_bytes)
                .expect("decode subtree removal request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalAdvanceRequest>(&advance_bytes)
                .expect("decode subtree removal advance request"),
            advance_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalStopPreparationRequest>(&stop_bytes)
                .expect("decode subtree removal stop request"),
            stop_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalStatusRequest>(&status_bytes)
                .expect("decode subtree removal status request"),
            status_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalResponse>(&response_bytes)
                .expect("decode subtree removal response"),
            response
        );

        let mut quiescent_owner_response = response;
        let RootComponentSubtreeRemovalPhase::DirectorySynchronized(receipt) =
            &mut quiescent_owner_response.phase
        else {
            panic!("Directory-synchronized response");
        };
        receipt.owning_component = None;
        let quiescent_owner_bytes = candid::encode_one(&quiescent_owner_response)
            .expect("encode quiescent-owner subtree response");
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalResponse>(&quiescent_owner_bytes)
                .expect("decode quiescent-owner subtree response"),
            quiescent_owner_response
        );
    }

    #[test]
    fn component_draining_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([60; 32]);
        let previous_registry = ComponentRegistryHead {
            component,
            revision: 7,
            content_hash: [61; 32],
        };
        let request = RootComponentDrainingRequest {
            operation_id: [62; 32],
            component,
            expected_registry: previous_registry.clone(),
        };
        let status_request = RootComponentDrainingStatusRequest {
            operation_id: request.operation_id,
            component,
        };
        let response = RootComponentDrainingResponse {
            operation_id: request.operation_id,
            component,
            previous_registry,
            registry: ComponentRegistryHead {
                component,
                revision: 8,
                content_hash: [63; 32],
            },
            descendant_count: 20_000,
            descendant_content_hash: [64; 32],
            directory_authority_hash: [65; 32],
            started_at_ns: 66,
        };

        let request_bytes =
            candid::encode_one(&request).expect("encode Component draining request");
        let status_bytes =
            candid::encode_one(status_request).expect("encode Component draining status request");
        let response_bytes =
            candid::encode_one(&response).expect("encode Component draining response");

        assert_eq!(
            candid::decode_one::<RootComponentDrainingRequest>(&request_bytes)
                .expect("decode Component draining request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentDrainingStatusRequest>(&status_bytes)
                .expect("decode Component draining status request"),
            status_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentDrainingResponse>(&response_bytes)
                .expect("decode Component draining response"),
            response
        );
    }

    #[test]
    fn component_quiescence_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([67; 32]);
        let registry = ComponentRegistryHead {
            component,
            revision: 9,
            content_hash: [68; 32],
        };
        let request = RootComponentQuiescenceRequest {
            operation_id: [69; 32],
            component,
            expected_registry: registry.clone(),
        };
        let status_request = RootComponentQuiescenceStatusRequest {
            operation_id: request.operation_id,
            component,
        };
        let stop = RootComponentQuiescenceStopIntent {
            registry,
            descendant_count: 20_000,
            descendant_content_hash: [70; 32],
            canister_id: Principal::from_slice(&[71; 29]),
            controller: Principal::from_slice(&[72; 29]),
            expected_module_hash: [73; 32],
            covered_fleet_registry_revision: 10,
            covered_fleet_registry_content_hash: [74; 32],
            covered_authority_hash: [75; 32],
            runtime_operation_id: [76; 32],
            activation: ComponentRuntimeActivationEvidence {
                directory_authority_hash: [77; 32],
                activated_at_ns: 78,
            },
            prepared_at_ns: 79,
        };
        let response = RootComponentQuiescenceResponse {
            operation_id: request.operation_id,
            component,
            phase: RootComponentQuiescencePhase::Quiescent(RootComponentQuiescentReceipt {
                stop,
                observed_module_hash: [73; 32],
                quiesced_at_ns: 80,
            }),
        };

        let request_bytes = candid::encode_one(&request).expect("encode quiescence request");
        let status_bytes =
            candid::encode_one(status_request).expect("encode quiescence status request");
        let response_bytes = candid::encode_one(&response).expect("encode quiescence response");
        assert_eq!(
            candid::decode_one::<RootComponentQuiescenceRequest>(&request_bytes)
                .expect("decode quiescence request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentQuiescenceStatusRequest>(&status_bytes)
                .expect("decode quiescence status request"),
            status_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentQuiescenceResponse>(&response_bytes)
                .expect("decode quiescence response"),
            response
        );
    }

    #[test]
    fn component_draining_advance_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([81; 32]);
        let registry = ComponentRegistryHead {
            component,
            revision: 12,
            content_hash: [82; 32],
        };
        let request = RootComponentDrainingAdvanceRequest {
            operation_id: [83; 32],
            component,
        };
        let descendant_removal = RootComponentDrainingAdvanceResponse {
            operation_id: request.operation_id,
            component,
            phase: RootComponentDrainingAdvancePhase::DescendantRemoval(
                RootComponentSubtreeRemovalResponse {
                    operation_id: [84; 32],
                    component,
                    target_canister_id: Principal::from_slice(&[85; 29]),
                    target_parent_canister_id: Principal::from_slice(&[86; 29]),
                    target_role: CanisterRole::new("project_instance"),
                    target_status: ComponentLifecycleStatus::Active,
                    reserved_against_registry: registry.clone(),
                    maximum_completed_leaves: 20_000,
                    completed_leaves: 0,
                    traversal_steps: 0,
                    phase: RootComponentSubtreeRemovalPhase::Fenced,
                },
            ),
        };
        let descendants_empty = RootComponentDrainingAdvanceResponse {
            operation_id: request.operation_id,
            component,
            phase: RootComponentDrainingAdvancePhase::DescendantsEmpty(
                RootComponentDrainingDescendantsEmpty {
                    registry,
                    descendant_content_hash: [87; 32],
                },
            ),
        };

        let request_bytes =
            candid::encode_one(request).expect("encode Component draining advance request");
        let removal_bytes = candid::encode_one(&descendant_removal)
            .expect("encode Component draining removal response");
        let empty_bytes = candid::encode_one(&descendants_empty)
            .expect("encode Component draining empty response");

        assert_eq!(
            candid::decode_one::<RootComponentDrainingAdvanceRequest>(&request_bytes)
                .expect("decode Component draining advance request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentDrainingAdvanceResponse>(&removal_bytes)
                .expect("decode Component draining removal response"),
            descendant_removal
        );
        assert_eq!(
            candid::decode_one::<RootComponentDrainingAdvanceResponse>(&empty_bytes)
                .expect("decode Component draining empty response"),
            descendants_empty
        );
    }

    #[test]
    fn component_final_inventory_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([88; 32]);
        let registry = ComponentRegistryHead {
            component,
            revision: 21,
            content_hash: [89; 32],
        };
        let request = RootComponentFinalInventoryRequest {
            operation_id: [90; 32],
            component,
            expected_registry: registry.clone(),
        };
        let response = RootComponentFinalInventoryResponse {
            operation_id: request.operation_id,
            component,
            inventory: RootComponentFinalInventory {
                registry,
                descendant_content_hash: [91; 32],
                registry_encoded_bytes: 4_096,
                directory_synchronized_at_ns: 92,
                covered_fleet_registry_revision: 93,
                covered_fleet_registry_content_hash: [94; 32],
                directory_authority_hash: [95; 32],
                inventory_hash: [96; 32],
                finalized_at_ns: 97,
            },
        };

        let request_bytes =
            candid::encode_one(&request).expect("encode Component final inventory request");
        let response_bytes =
            candid::encode_one(&response).expect("encode Component final inventory response");
        assert_eq!(
            candid::decode_one::<RootComponentFinalInventoryRequest>(&request_bytes)
                .expect("decode Component final inventory request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentFinalInventoryResponse>(&response_bytes)
                .expect("decode Component final inventory response"),
            response
        );
    }

    #[test]
    fn component_subtree_removal_deletion_requests_round_trip_through_candid() {
        let prepare = RootComponentSubtreeRemovalDeletePreparationRequest {
            operation_id: [50; 32],
            component: ComponentInstanceId::from_generated_bytes([51; 32]),
            expected_traversal_steps: 3,
            expected_leaf_canister_id: Principal::from_slice(&[52; 29]),
            expected_leaf_parent_canister_id: Principal::from_slice(&[53; 29]),
        };
        let request = RootComponentSubtreeRemovalDeleteRequest {
            operation_id: prepare.operation_id,
            component: prepare.component,
            expected_traversal_steps: prepare.expected_traversal_steps,
            expected_leaf_canister_id: prepare.expected_leaf_canister_id,
            expected_leaf_parent_canister_id: prepare.expected_leaf_parent_canister_id,
        };
        let membership_request = RootComponentSubtreeRemovalMembershipRemovalRequest {
            operation_id: prepare.operation_id,
            component: prepare.component,
            expected_traversal_steps: prepare.expected_traversal_steps,
            expected_leaf_canister_id: prepare.expected_leaf_canister_id,
            expected_leaf_parent_canister_id: prepare.expected_leaf_parent_canister_id,
        };
        let directory_request = RootComponentSubtreeRemovalDirectorySynchronizationRequest {
            operation_id: prepare.operation_id,
            component: prepare.component,
            expected_traversal_steps: prepare.expected_traversal_steps,
            expected_leaf_canister_id: prepare.expected_leaf_canister_id,
            expected_leaf_parent_canister_id: prepare.expected_leaf_parent_canister_id,
        };
        let finalization_request = RootComponentSubtreeRemovalLeafFinalizationRequest {
            operation_id: prepare.operation_id,
            component: prepare.component,
            expected_traversal_steps: prepare.expected_traversal_steps,
            expected_leaf_canister_id: prepare.expected_leaf_canister_id,
            expected_leaf_parent_canister_id: prepare.expected_leaf_parent_canister_id,
        };
        let prepare_bytes = candid::encode_one(prepare)
            .expect("encode subtree removal deletion preparation request");
        let request_bytes =
            candid::encode_one(request).expect("encode subtree removal deletion request");
        let membership_request_bytes = candid::encode_one(membership_request)
            .expect("encode subtree removal membership-removal request");
        let directory_request_bytes = candid::encode_one(directory_request)
            .expect("encode subtree removal Directory synchronization request");
        let finalization_request_bytes = candid::encode_one(finalization_request)
            .expect("encode subtree removal leaf-finalization request");

        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalDeletePreparationRequest>(
                &prepare_bytes
            )
            .expect("decode subtree removal deletion preparation request"),
            prepare
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalDeleteRequest>(&request_bytes)
                .expect("decode subtree removal deletion request"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalMembershipRemovalRequest>(
                &membership_request_bytes
            )
            .expect("decode subtree removal membership-removal request"),
            membership_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalDirectorySynchronizationRequest>(
                &directory_request_bytes
            )
            .expect("decode subtree removal Directory synchronization request"),
            directory_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalLeafFinalizationRequest>(
                &finalization_request_bytes
            )
            .expect("decode subtree removal leaf-finalization request"),
            finalization_request
        );
    }

    #[test]
    fn component_subtree_removal_stop_request_round_trips_through_candid() {
        let request = RootComponentSubtreeRemovalStopRequest {
            operation_id: [50; 32],
            component: ComponentInstanceId::from_generated_bytes([51; 32]),
            expected_traversal_steps: 3,
            expected_leaf_canister_id: Principal::from_slice(&[52; 29]),
            expected_leaf_parent_canister_id: Principal::from_slice(&[53; 29]),
        };
        let bytes =
            candid::encode_one(request).expect("encode subtree removal stop execution request");

        assert_eq!(
            candid::decode_one::<RootComponentSubtreeRemovalStopRequest>(&bytes)
                .expect("decode subtree removal stop execution request"),
            request
        );
    }

    #[test]
    #[expect(
        clippy::too_many_lines,
        reason = "one round-trip test keeps the complete child lifecycle boundary coherent"
    )]
    fn component_child_lifecycle_contracts_round_trip_through_candid() {
        let component = ComponentInstanceId::from_generated_bytes([11; 32]);
        let registry = ComponentRegistryHead {
            component,
            revision: 2,
            content_hash: [12; 32],
        };
        let request = RootComponentChildAllocationRequest {
            operation_id: [13; 32],
            component,
            expected_registry: registry.clone(),
            child_role: CanisterRole::new("project_instance"),
        };
        let status_request = RootComponentChildAllocationStatusRequest {
            operation_id: request.operation_id,
            component,
        };
        let creation_request = RootComponentChildCreationRequest {
            operation_id: request.operation_id,
            component,
        };
        let install_request = RootComponentChildInstallRequest {
            operation_id: request.operation_id,
            component,
        };
        let commit_request = RootComponentChildCommitRequest {
            operation_id: request.operation_id,
            component,
        };
        let directory_request = RootComponentChildDirectoryPreparationRequest {
            operation_id: request.operation_id,
            component,
        };
        let activation_request = RootComponentChildRuntimeActivationRequest {
            operation_id: request.operation_id,
            component,
        };
        let membership_request = RootComponentChildMembershipActivationRequest {
            operation_id: request.operation_id,
            component,
        };
        let root = Principal::from_slice(&[17; 29]);
        let parent = Principal::from_slice(&[14; 29]);
        let child = Principal::from_slice(&[18; 29]);
        let child_binding = ComponentChildBinding {
            component: ComponentBinding {
                authority: fleet_registry_authority(),
                component,
                component_spec: "projects".parse().expect("Component Spec"),
                spec_hash: [19; 32],
                role: CanisterRole::new("project_hub"),
                placement_subnet: SubnetId::from_principal(Principal::from_slice(&[20; 29])),
                fleet_subnet_root: root,
                canister_id: parent,
            },
            parent_canister_id: parent,
            role: request.child_role.clone(),
            canister_id: child,
        };
        let response = RootComponentChildAllocationResponse {
            operation_id: request.operation_id,
            component,
            parent_canister_id: parent,
            parent_role: CanisterRole::new("project_hub"),
            child_role: request.child_role.clone(),
            child_kind: ComponentChildKind::Instance,
            maximum_instances_per_parent: 10_000,
            maximum_descendants: 20_000,
            maximum_registry_bytes: 16_777_216,
            reserved_against_registry: registry,
            release_set: FleetSubnetRootReleaseSet {
                release_build_id: ReleaseBuildId::from_nonce(ReleaseBuildNonce::from_random_bytes(
                    [15; 32],
                )),
                manifest_digest: ReleaseSetDigest::from_bytes([16; 32]),
            },
            phase: RootComponentAllocationPhase::Verified,
            creation: Some(RootComponentCreationEvidence {
                wasm_store: Principal::from_slice(&[21; 29]),
                payload_hash: [22; 32],
                payload_size_bytes: 4_096,
                initial_cycles: Cycles::new(5_000_000_000_000),
                controller: root,
                canister: Some(child),
            }),
            installation: Some(RootComponentChildInstallEvidence {
                raw_module_hash: [23; 32],
                chunk_hashes: vec![vec![24; 32]],
                binding: child_binding.clone(),
            }),
        };
        let commit_response = RootComponentChildCommitResponse {
            allocation: response.clone(),
            registry: ComponentRegistryPartitionResponse {
                head: ComponentRegistryHead {
                    component,
                    revision: 3,
                    content_hash: [25; 32],
                },
                binding: child_binding.component.clone(),
                provisioning_origin: ComponentProvisioningOrigin::FleetAdministrator {
                    caller: Principal::from_slice(&[26; 29]),
                },
                release_set: response.release_set,
                status: ComponentLifecycleStatus::Active,
                reserved_descendants: 0,
                committed_descendants: 1,
                encoded_bytes: 8_192,
            },
            directory: ComponentDirectoryHead {
                provenance: ComponentDirectoryProvenance {
                    component: child_binding.component.clone(),
                    source_fleet_subnet_root: root,
                    component_registry_revision: 3,
                    component_registry_content_hash: [25; 32],
                    synchronized_at_ns: 27,
                },
                descendant_count: 1,
            },
        };
        let runtime_authority = ComponentRuntimeDirectoryAuthority {
            fleet: FleetDirectorySnapshot {
                provenance: crate::dto::fleet_registry::FleetDirectoryProvenance {
                    registry: FleetRegistryVersion {
                        authority: fleet_registry_authority(),
                        revision: 4,
                        content_hash: [28; 32],
                    },
                    source_fleet_subnet_root: root,
                },
                fleet_subnet_roots: vec![
                    crate::dto::fleet_registry::FleetSubnetRootDirectoryEntry {
                        placement_subnet: commit_response.registry.binding.placement_subnet,
                        fleet_subnet_root: root,
                        status: crate::dto::fleet_registry::FleetSubnetRootStatus::Active,
                    },
                ],
            },
            component: commit_response.directory.clone(),
        };
        let activation = ComponentRuntimeActivationEvidence {
            directory_authority_hash: [29; 32],
            activated_at_ns: 30,
        };
        let directory_response = RootComponentChildDirectoryPreparationResponse {
            committed: commit_response.clone(),
            child: ComponentRuntimeStatusResponse {
                operation_id: request.operation_id,
                binding: ManagedCanisterBinding::ComponentChild(child_binding.clone()),
                phase: ComponentRuntimePhase::DirectoryPrepared,
                authority: Some(runtime_authority.clone()),
                authority_hash: Some([31; 32]),
                activation: None,
            },
            owning_component: ComponentRuntimeDirectoryConvergenceEvidence {
                operation_id: [32; 32],
                binding: ManagedCanisterBinding::Component(child_binding.component.clone()),
                covered_authority: runtime_authority.clone(),
                covered_authority_hash: [31; 32],
                activation,
            },
            parent: None,
        };
        let activation_response = RootComponentChildRuntimeActivationResponse {
            committed: commit_response.clone(),
            child: ComponentRuntimeStatusResponse {
                operation_id: request.operation_id,
                binding: ManagedCanisterBinding::ComponentChild(child_binding.clone()),
                phase: ComponentRuntimePhase::Active,
                authority: Some(runtime_authority.clone()),
                authority_hash: Some([31; 32]),
                activation: Some(ComponentRuntimeActivationEvidence {
                    directory_authority_hash: [31; 32],
                    activated_at_ns: 33,
                }),
            },
        };
        let active_directory = ComponentDirectoryHead {
            provenance: ComponentDirectoryProvenance {
                component: child_binding.component.clone(),
                source_fleet_subnet_root: root,
                component_registry_revision: 4,
                component_registry_content_hash: [34; 32],
                synchronized_at_ns: 35,
            },
            descendant_count: 1,
        };
        let active_authority = ComponentRuntimeDirectoryAuthority {
            fleet: runtime_authority.fleet,
            component: active_directory.clone(),
        };
        let membership_response = RootComponentChildMembershipActivationResponse {
            committed: commit_response.clone(),
            registry: ComponentRegistryPartitionResponse {
                head: ComponentRegistryHead {
                    component,
                    revision: 4,
                    content_hash: [34; 32],
                },
                binding: child_binding.component.clone(),
                provisioning_origin: commit_response.registry.provisioning_origin.clone(),
                release_set: commit_response.registry.release_set,
                status: ComponentLifecycleStatus::Active,
                reserved_descendants: 0,
                committed_descendants: 1,
                encoded_bytes: 8_256,
            },
            directory: active_directory,
            child: ComponentRuntimeStatusResponse {
                operation_id: request.operation_id,
                binding: ManagedCanisterBinding::ComponentChild(child_binding),
                phase: ComponentRuntimePhase::Active,
                authority: Some(active_authority),
                authority_hash: Some([36; 32]),
                activation: Some(ComponentRuntimeActivationEvidence {
                    directory_authority_hash: [31; 32],
                    activated_at_ns: 33,
                }),
            },
        };

        let request_bytes = candid::encode_one(&request).expect("encode child reservation");
        let status_bytes =
            candid::encode_one(status_request).expect("encode child reservation status");
        let creation_bytes =
            candid::encode_one(creation_request).expect("encode child creation request");
        let install_bytes =
            candid::encode_one(install_request).expect("encode child install request");
        let response_bytes = candid::encode_one(&response).expect("encode child response");
        let commit_request_bytes =
            candid::encode_one(commit_request).expect("encode child commit request");
        let directory_request_bytes =
            candid::encode_one(directory_request).expect("encode child Directory request");
        let activation_request_bytes =
            candid::encode_one(activation_request).expect("encode child activation request");
        let membership_request_bytes =
            candid::encode_one(membership_request).expect("encode child membership request");
        let commit_response_bytes =
            candid::encode_one(&commit_response).expect("encode child commit response");
        let directory_response_bytes =
            candid::encode_one(&directory_response).expect("encode child Directory response");
        let activation_response_bytes =
            candid::encode_one(&activation_response).expect("encode child activation response");
        let membership_response_bytes =
            candid::encode_one(&membership_response).expect("encode child membership response");

        assert_eq!(
            candid::decode_one::<RootComponentChildAllocationRequest>(&request_bytes)
                .expect("decode child reservation"),
            request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildAllocationStatusRequest>(&status_bytes)
                .expect("decode child reservation status"),
            status_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildCreationRequest>(&creation_bytes)
                .expect("decode child creation request"),
            creation_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildInstallRequest>(&install_bytes)
                .expect("decode child install request"),
            install_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildAllocationResponse>(&response_bytes)
                .expect("decode child response"),
            response
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildCommitRequest>(&commit_request_bytes)
                .expect("decode child commit request"),
            commit_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildDirectoryPreparationRequest>(
                &directory_request_bytes
            )
            .expect("decode child Directory request"),
            directory_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildCommitResponse>(&commit_response_bytes)
                .expect("decode child commit response"),
            commit_response
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildDirectoryPreparationResponse>(
                &directory_response_bytes
            )
            .expect("decode child Directory response"),
            directory_response
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildRuntimeActivationRequest>(
                &activation_request_bytes
            )
            .expect("decode child activation request"),
            activation_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildRuntimeActivationResponse>(
                &activation_response_bytes
            )
            .expect("decode child activation response"),
            activation_response
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildMembershipActivationRequest>(
                &membership_request_bytes
            )
            .expect("decode child membership request"),
            membership_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentChildMembershipActivationResponse>(
                &membership_response_bytes
            )
            .expect("decode child membership response"),
            membership_response
        );
    }

    #[test]
    fn component_install_request_round_trips_through_candid() {
        let request = RootComponentInstallRequest {
            operation_id: [10; 32],
        };
        let bytes = candid::encode_one(request).expect("encode install request");

        assert_eq!(
            candid::decode_one::<RootComponentInstallRequest>(&bytes)
                .expect("decode install request"),
            request
        );
    }

    #[test]
    fn component_commit_request_round_trips_through_candid() {
        let request = RootComponentCommitRequest {
            operation_id: [10; 32],
        };
        let bytes = candid::encode_one(request).expect("encode commit request");

        assert_eq!(
            candid::decode_one::<RootComponentCommitRequest>(&bytes)
                .expect("decode commit request"),
            request
        );
    }

    #[test]
    fn component_runtime_activation_requests_round_trip_through_candid() {
        let root_request = RootComponentRuntimeActivationRequest {
            operation_id: [22; 32],
        };
        let target_request = ComponentRuntimeActivationRequest {
            operation_id: root_request.operation_id,
            directory_authority_hash: [23; 32],
        };
        let membership_request = RootComponentMembershipActivationRequest {
            operation_id: root_request.operation_id,
        };
        let root_bytes = candid::encode_one(root_request).expect("encode root activation request");
        let target_bytes =
            candid::encode_one(target_request).expect("encode target activation request");
        let membership_bytes =
            candid::encode_one(membership_request).expect("encode membership activation request");

        assert_eq!(
            candid::decode_one::<RootComponentRuntimeActivationRequest>(&root_bytes)
                .expect("decode root activation request"),
            root_request
        );
        assert_eq!(
            candid::decode_one::<ComponentRuntimeActivationRequest>(&target_bytes)
                .expect("decode target activation request"),
            target_request
        );
        assert_eq!(
            candid::decode_one::<RootComponentMembershipActivationRequest>(&membership_bytes)
                .expect("decode membership activation request"),
            membership_request
        );
    }
}