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
//! **Appendix B — "The shell surface (rulings 46, 47, 49, 50)", the part
//! slice 3 can reach.**
//!
//! Appendix B is non-normative but its obligations are written against the
//! *finished* protocol, while `PLAN.md` delivers it in ten slices. That
//! mismatch has a failure mode worth naming: a test file that **looks**
//! like it discharges Appendix B and does not. So the table below is the
//! whole obligation, marked, and the unreached rows name the slice that
//! owes them. `.slices/03-skeleton/PLAN.md` C5 is the same observation for
//! the `closed()` rows specifically.
//!
//! | Appendix B obligation | Here |
//! |---|---|
//! | `closed()` resolves on every death, with no verb in flight | `tests/story_lifecycle.rs` (S27); rows reached and owed are listed there |
//! | `closed()` is latched — concurrent, late, cancel-safe | `tests/story_lifecycle.rs` (S27, T10) |
//! | Dropping a `Connecting` frees the static; the train stops; NONE routing | `tests/story_lifecycle.rs` (S29, T11) |
//! | The peer-side half of ruling 50: a half-open session reaped at `DEAD_TIMEOUT` | **here** — `cancelled_dial_leaves_the_peer_a_silent_half_open_session`, by an equivalent construction; see G10 |
//! | Notification retention and its O(1) bound (ruling 46) | **owed: slice 7.** `Notification`, `notified()` and the slots do not exist yet (§16.2) |
//! | Delivery confirmation / `acked()` (ruling 47) | **owed: slice 5.** `acked()`, streams and messages do not exist yet |
//! | A send failure is traced, never acted on (ruling 49) | **partly here** — the *never acted on* half. See G7 for the *traced* half and G8 for "traffic resumes when the seam heals" |
//! | CLOSE linger: ≤ 1 reply/s, replies to the session address only, none to a forgery (§15.2, T13) | **not reachable from `tests/`.** See G6 |
//!
//! Also pinned here, because they are shell-surface rulings with no other
//! home in slice 3: **ruling 87** (`connect()` is synchronous), **ruling
//! 89** (`session_id()` is hiss's), **§6.2**'s drop-is-a-silent-reject at
//! all three stages, and **§16.3**'s staged-object/`Connecting` asymmetry
//! over `EndpointDropped`.
//!
//! # Authorship (CLAUDE.md working rule 6)
//!
//! Written by **TEST-B** from `SPEC.md` (§6.1–§6.2, §15.2, §16.1–§16.3,
//! §16.10, Appendix B) and `STORIES.md` alone, while IMPL-B wrote the shell
//! concurrently. No file under `src/shell/` and no line of
//! `src/testutil/mod.rs` was read. Names for shell and harness items are
//! **proposals**; the integrator renames *calls*, never assertions.
//!
//! # Gaps found while writing this file (working rule 8)
//!
//! * **G6 — §15.2's linger reply rule is unreachable from an integration
//! test.** T13 asks for three assertions: exactly one reply to ten
//! authenticated inbound packets in a second, the reply sent to the
//! *session's* address rather than the triggering packet's source, and
//! **no** reply to a packet that routes by `receiver_index` but fails the
//! AEAD. All three require minting an authenticated (or
//! deliberately-unauthenticated-but-index-correct) packet at a chosen
//! moment — and after a peer receives a CLOSE it is *draining* and sends
//! nothing (§15.2), so no second slither endpoint can generate the
//! traffic either. The session keys live inside the crate. **This
//! obligation is reachable only from an in-crate test module**, and this
//! file cannot discharge it. Ruling 83 (the opening CLOSE is not a reply,
//! so the 1 Hz clock starts at the first *reply*) is unreachable for the
//! same reason and is **not** depended on by any test in this file.
//! * **G7 — CLOSED by the gap slice (`tests/story_traced.rs`), and its
//! stated cause was wrong.** This entry read "needs a dev-dependency
//! that does not exist" and "adding a dev-dependency is the
//! orchestrator's call". Neither held: `tracing` alone exposes
//! `Subscriber`, `field::Visit` and `subscriber::set_default`, and
//! `testutil::capture` closes the gap in ~150 lines with **no change to
//! the dependency graph**. The original author was right to report
//! rather than work around; the diagnosis just named the wrong missing
//! piece. §16.3's MUST is now asserted per failed send, from both
//! sides, in `story_traced.rs`.
//! * **G8 — "traffic resumes when the seam heals" needs data frames.**
//! Slice 4. Named in `.slices/03-skeleton/PLAN.md` §5.2 already.
//! * **G9 — §16.2's `accept() -> Option<Intro>` says "`None` = endpoint
//! closed" and no verb in this specification closes an endpoint.** The
//! surface has no `Endpoint::close()`, §16.3's only endpoint-lifetime
//! rule is "dropping every handle stops the driver", and `accept(&self)`
//! borrows the `Endpoint` — so the `Endpoint` provably outlives every
//! `accept()` future and the `None` arm has no constructible cause. This
//! is working rule 8's shape exactly: **a stated construction (`None`)
//! with an unstated scope (what closes an endpoint)**. Either a verb is
//! missing from §16.2's list, or `None` is unreachable and the return
//! type should say so. Not invented here; the tests below `.expect()` on
//! the `Some` arm and say why.
//!
//! **Update (post-slice-3b seam review).** There is now one constructible
//! cause: a **failed driver**. The driver's stop path runs on an unwind
//! as well as on the ordinary exit, so a panicking driver drops the
//! parked `accept()` senders while an `Endpoint` handle still lives, and
//! `accept()` resolves `None` —
//! `a_panicking_driver_resolves_every_waiter_instead_of_parking_it`
//! below is the constructive proof. That answers "is `None` reachable"
//! and **not** "is a driver fault what §16.2 meant by *endpoint
//! closed*". `.slices/03-skeleton/FIXES-3b.md` §2a files the remaining
//! wording question as a ruling candidate; no spec text was changed, and
//! the `.expect()`s below stand.
//! * **G10 — Appendix B's "drop the `Connecting` after its msg2 is on the
//! wire" is not separable on a zero-latency fabric.** Stated in full on
//! `cancelled_dial_leaves_the_peer_a_silent_half_open_session`, which
//! reaches the same peer-side state by §16.3's other route rather than
//! inventing a directional-loss knob on `FlakyPolicy`.
//!
//! # Paused clock, never a sleep (§16.10)
//!
//! Every test here is `#[tokio::test(start_paused = true)]` on a
//! `LocalSet`. `tokio::time::timeout` is the observation instrument, not a
//! deadline: `timeout(d, &mut fut).await.is_err()` asserts `fut` was still
//! `Pending` at `now + d`.
//!
//! # Post-slice-3b seam-review regressions (appended, different author)
//!
//! The last three tests in this file are **not** TEST-B's and are not
//! Appendix B obligations. They pin three findings from the chartered seam
//! review of `src/shell/`, and each one needed a fixture the file did not
//! have — which is the common thread worth recording:
//!
//! | Test | Pins |
//! |---|---|
//! | `a_close_sealed_while_the_wire_is_suspended_still_reaches_its_peer` | §16.4's drain contract across a wire that returns `Pending` |
//! | `accept_vs_connect_race_reaches_6_4s_pending_branch` | §6.4's PENDING branch, reached — was the C-B1 mirror regression, rewritten for ruling 90 |
//! | `a_panicking_driver_resolves_every_waiter_instead_of_parking_it` | §16.3: a driver fault resolves every waiter rather than freezing the endpoint |
//!
//! `testutil::FlakyWire` models everything a *network* does — loss, delay,
//! reordering, duplication, `ENETUNREACH` — and nothing a *socket* does:
//! its `send_to` never returns `Pending` and never panics. Two of the three
//! findings lived precisely in that blind spot and were unreachable from
//! all 451 tests **by construction**, which is the shape `PLAN.md`'s target
//! 6 asks reviewers to hunt. `GatedWire` and `PanicWire` below are the two
//! wires that reach it; they are deliberately local to this file rather
//! than added to `testutil`, whose surface ruling 60 attests.
//!
//! See `.slices/03-skeleton/FIXES-3b.md` for the findings and the
//! reasoning.
use Cell;
use Future;
use ;
use pin;
use Rc;
use Poll;
use Duration;
use Config;
use ;
use ;
use ;
use Wire;
use ;
// ══════════════════════════════════════════════════════════════════════
// FIXTURE — proposed names, flagged loudly. Identical in intent to the
// blocks at the top of `tests/story_lifecycle.rs` and `tests/story_dial.rs`;
// duplicated because each file in `tests/` is its own crate and this author
// owns no shared module.
//
// INTEGRATOR: redirect at IMPL-B's `testutil` harness if one fits. Nothing
// below the `── tests ──` line touches these names except through `Node`,
// `establish` and the two tap helpers.
//
// The **single riskiest name in this file** is the send-failure injector:
//
// let policy = FlakyPolicy::perfect();
// let wire = net.wire_with(addr, policy.clone());
// policy.fail_sends(true); // every send_to returns ENETUNREACH
//
// §16.10 ratifies that `FlakyPolicy` exists, that it carries "loss,
// reordering, duplication, and **send failure**", and that "send-failure
// injection is required, not optional" — so the *capability* is contract.
// The toggle above is this author's shape for it, chosen because Appendix
// B describes "a bounded interval, then heals", which a toggle expresses
// without assuming anything about scheduling. Every assertion that uses it
// is written on the connection's behaviour, not on the injector.
// ══════════════════════════════════════════════════════════════════════
type Suite = ReferenceSuite;
type Id = ;
type Pk = ;
type Endpoint = Endpoint;
// See the note on the same alias in `tests/story_lifecycle.rs`: §16.2 writes
// a bare `Connection`, `core::Connection<C: Handshake>` is
// suite-parameterised. One line to change; no test names the type.
type Connection = Connection;
async
/// §3.1: byte 0 is the packet type, and the length gate is **exact** for
/// `HandshakeResp` (107 bytes).
async
// ══════════════════════════════════════════════════════════════════════
// Two wires the shared fixture cannot express.
//
// `FlakyWire` models everything a *network* does — loss, delay, reorder,
// duplication, `ENETUNREACH` — and nothing a *socket* does. Its `send_to`
// never returns `Pending` and never panics, so two whole classes of driver
// behaviour are unreachable from the 451-test suite by construction. Both
// classes turned out to hold a defect (see the module-doc note above).
// ══════════════════════════════════════════════════════════════════════
/// A latch a test opens and closes to suspend [`GatedWire`] mid-send.
/// A [`Wire`] whose `send_to` can be held `Pending`, the way a real socket
/// holds one when its send buffer is full.
///
/// This is not an exotic condition: `tokio::net::UdpSocket::send_to`
/// returns `Pending` whenever the kernel's send buffer is full, which is
/// every congested endpoint. `FlakyWire::send_to` never does — it queues
/// into an in-memory inbox and returns — so **no test in this repository
/// could reach a driver-side yield between the drain and the next
/// `poll_output()`** until this type existed.
/// A [`Wire`] whose `send_to` panics once armed — the smallest way to make
/// the driver task unwind using only the public surface.
///
/// The panic message is deliberately self-describing: the test that arms
/// this **expects** a driver panic, and the harness prints it under
/// `--nocapture` while still reporting `ok`. That is the point of the test,
/// not a failure of it.
// ────────────────────────────── tests ──────────────────────────────────
/// **Ruling 87 — `connect()` is synchronous, and `AlreadyConnected` comes
/// back before any await.**
///
/// §16.3 (4249–4264): "§16.2 declares `pub fn connect(…) -> Result<
/// Connecting, ConnectError>` — **not `async`** — so
/// `ConnectError::AlreadyConnected` is returned before any await, and a
/// oneshot reply cannot be read from it without blocking, which §16.8
/// forbids. … the NONE/PENDING/LIVE test §16.1 requires 'at the instant of
/// the call' is a synchronous read of the same shared cell §16.8 already
/// mandates for the accessors."
///
/// # The mutation this catches — and why there is no `await` in the gap
///
/// The broken version is ruling 53's *original* table, which listed
/// `connect` beside the genuinely-`async` endpoint verbs: a command sent to
/// the driver, with the PENDING bookkeeping done **on the driver task**.
/// Such a build is indistinguishable from the correct one as soon as the
/// test yields — the driver runs, the pending is minted, and the second
/// `connect()` sees PENDING.
///
/// So the second call is made with **no `.await` and no clock advance**
/// after the first. On a paused, current-thread runtime the driver is not
/// scheduled in that gap at all. A driver-side build therefore reads NONE
/// and hands back a second `Connecting` — two concurrent outbound attempts
/// to one static, which §16.1 says "every routing rule keys on" not
/// happening. The synchronous-cell build returns `AlreadyConnected`.
///
/// This is the exact mirror of `s29_cancel_then_immediate_redial`: that one
/// pins the cell being *cleared* synchronously, this one pins it being
/// *written* synchronously. Neither implies the other.
///
/// (The LIVE case — `connect()` to a static that already has a live
/// `Connection` — is **S3a**, which is not slice 3b's story. Only the
/// in-flight-outbound clause is pinned here.)
async
/// **Ruling 89 — `session_id()` is hiss's, derived from the handshake hash,
/// and both peers of a session produce the same value.**
///
/// §16.2: "hiss derives it from the handshake hash, **both peers of a
/// session produce the same value**, and its own documentation states it is
/// a *public* channel-binding value meant for out-of-band comparison —
/// which is precisely what an application logs it for, and what a
/// short-authentication-string check needs."
///
/// # The mutation this catches
///
/// The obvious test is `assert_eq!(ca.session_id(), cb.session_id())`. It
/// passes against **every** degenerate accessor: one that returns
/// `Default::default()`, a zero id, a constant, or the endpoint's own index
/// if both endpoints happen to mint the same one. A constant is exactly
/// what a not-yet-wired accessor looks like.
///
/// The separating assertion is the second one: a **different** session must
/// produce a **different** id. Agreement across peers and difference across
/// sessions together are the only pair that pins a value derived from the
/// handshake hash. A short-authentication-string check is worthless without
/// both.
async
/// **§6.2 — dropping an `Intro` is a silent reject, and the ladder charges
/// 0 DH for it.**
///
/// §6.1/§16.1: "staged objects … drop = silent reject at every stage."
/// §6.2: "Dropping the object at any stage is the application's rejection —
/// the only rejection there is, and slither keeps no record of it (ruling
/// 48, §6.1)."
///
/// # The mutations this catch, and why "nothing transmitted" is not enough
///
/// * **Not silent** — a build that answers the initiation, or emits any
/// packet, on a rejected `Intro`. Caught by the `sent_count` assertion.
/// * **Not free** — a build whose driver eagerly runs `es` when the
/// initiation is queued, so that the "0 DH so far" of §6.1's table is a
/// fiction. Caught by the `DhCounter` assertion; §6.9's whole DoS
/// accounting rests on it.
/// * **Not recoverable** — a build that poisons the peer's static or the
/// stage-0 slot on rejection, so the *next* initiation from the same peer
/// can never be accepted. This is the one a "nothing was transmitted"
/// test cannot see, and it is the difference between a silent reject and
/// a silent blackhole. Caught by driving the very next `accept()` chain to
/// a live connection.
///
/// §5.5 step 2 supplies the next initiation for free: "every retransmit is
/// a completely fresh initiation", one per `RETRANSMIT_BASE`.
async
/// **§6.1/§6.2 — the responder's ladder is 0 / 1 / 2 / 4, and no stage runs
/// ahead of its verb.**
///
/// §6.1's table prices the staged accept: `Intro` 0 DH, `read_identity()`
/// +1 (`es`), `authenticate()` +1 (`ss`), `accept()` +2 (`ee`, `se`).
/// Slice 2a pins this on the core; what is pinned **here** is that the
/// *shell*'s staged handles do not move the work — §16.3: "The endpoint
/// verbs stay round-trips because §6.2 requires the DH costs to land on the
/// driver task."
///
/// # The mutation this catches
///
/// The sharp one is at `Proven`: a driver that computes msg2 during
/// `authenticate()` — a natural optimisation, since `authenticate()` has
/// already done the expensive part and the answer is usually wanted. It
/// costs the responder 4 DH for an initiation the application then rejects,
/// which is §6.9's accounting inverted, and it **transmits msg2 on a
/// `Proven` the application drops**, which §6.2 says is a silent reject.
/// Both consequences are asserted: the count at `Proven` is `2`, exactly,
/// and no `HandshakeResp` has left the responder at that point.
///
/// `assert_eq!` and not `<=` at every step: an upper bound is satisfied by
/// a collapsed ladder that skips `ss`, and `ss` is the DH that proves
/// possession.
async
/// **§6.2 — dropping a `Proven` transmits nothing.**
///
/// The stage-specific companion to the ladder test above: there, the
/// `Proven` is accepted; here it is dropped, which is the case §6.2 calls
/// "the application's rejection".
///
/// # The mutation this catches
///
/// A build that emits msg2 at `Proven` construction rather than at
/// `accept()`. `the_staged_ladder_charges_and_transmits_only_at_its_own_verb`
/// catches it too — but only *while* the chain is walked to `accept()`.
/// This one catches the variant that defers the transmit to the `Proven`'s
/// **drop**, which is the shape a `Drop` impl written for symmetry with
/// "close on drop" would produce, and which no assertion taken before
/// `accept()` can see.
///
/// The dialler's `Connecting` must also still be in flight afterwards: a
/// rejected chain leaves the initiator retransmitting (§5.5), not resolved.
async
/// **§16.3 — a staged object's verb is a round-trip to a driver it does not
/// keep alive.**
///
/// §16.3 (4304–4311): "The consequence is that **`ConnectError` needs no
/// `EndpointDropped`** … The asymmetry with `IntroError`, `AuthError` and
/// `AcceptError` — which all carry `EndpointDropped` — is therefore correct
/// and not an omission: a staged object's verb is a **round-trip to a
/// driver it does not keep alive**, so the driver can stop underneath it;
/// an outbound attempt keeps its own driver running."
///
/// # The mutation this catches
///
/// A shell that counts staged objects as handles — the symmetric-looking
/// choice, and the one ruling 62 explicitly declines. Under it, the driver
/// survives on the strength of an `Intro` the application has forgotten
/// about, and `read_identity()` succeeds here instead of reporting
/// `EndpointDropped`. Nothing else in this file or in
/// `tests/story_lifecycle.rs` distinguishes the two, because the difference
/// is invisible while any real handle lives.
///
/// It is also the constructive proof that `IntroError::EndpointDropped` is
/// reachable at all: §18.1 lists the variant, and a variant no test can
/// reach is a variant nothing pins.
async
/// **Ruling 49 — a send failure is traced, never acted on: the connection
/// survives and the death, when it comes, is the ordinary receive-driven
/// `TimedOut`.**
///
/// Appendix B: "Assert the connection **survives** — no teardown, no verb
/// resolving with an error, no notification … Then hold the failure past
/// `DEAD_TIMEOUT` and assert the death is still the ordinary
/// receive-driven `TimedOut` (§7.4)."
///
/// §16.3's reasoning is the thing being pinned: "A failed send is not
/// authoritative. Liveness in this protocol is **receive-driven by ruling**
/// (§7.4) — a connection dies because nothing authenticated arrived, never
/// because something failed to leave."
///
/// # The mutation this catches, and both sides of it
///
/// * **Acting on the failure** — killing the connection, or resolving a
/// verb with an error, when `send_to` returns `Err`. §16.3 says this
/// "would convert the exact scenario the migration guarantee exists for
/// into a teardown — it would **delete** the guarantee, not implement an
/// error path." Caught by the first assertion: nothing may happen in the
/// first `DEAD_TIMEOUT − 1 s`, which is far longer than any I/O reaction
/// would take.
/// * **Not dying at all** — a build that suppresses the liveness deadline
/// while sends are failing, e.g. by treating a failed send as "we are
/// still trying". Caught by the second.
///
/// The variant assertion is the third side: `TimedOut`, not some new I/O
/// death — §16.3 is explicit that "§18.1's taxonomy stays closed and gains
/// no I/O variant."
///
/// The peer is retired by ruling 88's silent drop so the silence is
/// genuine; see `s26_coincident_last_handle_drop_transmits_nothing` in
/// `tests/story_lifecycle.rs`.
///
/// **G7:** the *traced* half of the obligation — a `slither::io` event per
/// failed send, carrying the destination address — is not assertable from
/// `tests/`; see the module doc.
async
/// **Ruling 49 — a `close()` whose CLOSE cannot leave still reports
/// `LocallyClosed`.**
///
/// §16.2 makes `close()` infallible (`pub async fn close(&self, code: u64,
/// reason: &[u8])` — no `Result`), and §15.2 makes the local surface
/// `LocallyClosed`. §16.3 forbids acting on a send failure. Composed: a
/// `close()` over a broken seam resolves, surfaces `LocallyClosed`, and the
/// peer learns nothing — it waits out `DEAD_TIMEOUT`, which §15.4's rows
/// already accept as the cost of a lost signal.
///
/// # The mutation this catches
///
/// A driver that treats the CLOSE as the one send worth retrying or
/// reporting — plausible, because it is the one packet whose loss has a
/// visible 25 s cost, and §15.2's linger reply rule really is "CLOSE's only
/// reliability mechanism". The temptation is to make `close()` wait for the
/// send, or to surface the I/O error somewhere. Both are forbidden:
/// `close()` "resolves once the CLOSE frame is sealed" (§16.2) — **sealed**,
/// not sent — and §18.1 gains no I/O variant.
///
/// The peer-side assertion is the half that makes it non-vacuous: the peer
/// must **not** report `PeerClosed`, which proves the packet genuinely did
/// not leave and that the local `LocallyClosed` was not merely the happy
/// path in disguise.
async
/// **Ruling 50, the peer-side half — a cancelled dial leaves the peer a
/// silent half-open session that is reaped at `DEAD_TIMEOUT`.**
///
/// Appendix B: "let the peer answer, drop the `Connecting` after its msg2
/// is on the wire, and assert the peer's half-open session **transmits
/// nothing** and dies at `DEAD_TIMEOUT` (25 s) — ruling 39's reap case
/// (§7.4), which is the cost this ruling accepts."
///
/// §16.3 states the mechanism: "§7.4's install pin arms the death deadline
/// at install and sets `last_send` equal to `last_authenticated_recv`, so a
/// session that receives nothing after install **emits nothing at all** and
/// is reaped in silence."
///
/// # The mutations this catches
///
/// * **A session that chatters** — the natural bug is a keepalive beacon
/// armed at install, which turns every abandoned dial into 25 s of
/// traffic toward a peer that is not there. §7.4's install pin exists to
/// forbid exactly that, and only the `sent_count` assertion sees it.
/// * **A session never reaped** — the half-open state leaks for the life
/// of the process. Caught by the `TimedOut` assertion.
/// * **A session reaped on the wrong clock** — `KEEPALIVE_TIMEOUT` (10 s)
/// is the other candidate; caught by the "still alive at
/// `DEAD_TIMEOUT − 1 s`" half.
///
/// # G10 — the literal ordering Appendix B specifies is not separable here
///
/// Appendix B says "drop the `Connecting` **after** its msg2 is on the
/// wire". On the in-memory fabric there is no latency between msg2 leaving
/// the responder and the initiator's driver completing the pending, so by
/// the time a test can observe msg2 in the tap the attempt has already
/// completed — and dropping the `Connecting` then drops a **completed**
/// `Connection`, which §16.2 turns into `close(NO_ERROR, "")` and which
/// would make this test assert the opposite of what it is for. Separating
/// them needs directional loss injection ("lose the next inbound datagram
/// at A"), which is a `FlakyPolicy` capability this author will not invent.
///
/// What is written instead reaches the **identical peer-side state** by
/// §16.3's own other sentence: "A msg2 racing the drop arrives after the
/// pending index is gone: it routes by index to nothing and is inert
/// (§17.3's corollary), so no session is installed on our side and no state
/// is resurrected." The dial is cancelled first, the responder accepts
/// afterwards, and the responder is left holding exactly the half-open
/// session ruling 39 reaps. The tap assertion below pins that msg2 really
/// was emitted, so the case is not the trivially-empty one.
async
// ══════════════════════════════════════════════════════════════════════
// Post-slice-3b seam-review regressions.
//
// Three findings from the chartered review of `src/shell/`. Each is
// written from the side working rule 9 asks for: the assertion that
// *separates* the fixed build from the broken one, with the broken build's
// behaviour named in the doc comment.
// ══════════════════════════════════════════════════════════════════════
/// **The drain contract holds across the wire's yield: a CLOSE sealed while
/// `send_to` is suspended still reaches the peer.**
///
/// §16.4: `poll_output()`'s terminal `Timeout` "is simultaneously the drain
/// sentinel and the next-deadline announcement", and the core's
/// `poll_output` **pops** — for `core::Connection` it is
/// `self.outputs.pop_front().unwrap_or_else(…)`. When this test was written
/// the driver collected deadlines with `poll_output`, so reading one was a
/// pure read only while the queue was provably empty, and the only thing
/// that established that was a drain with **no intervening yield**.
///
/// **[ruling 262]** The driver now collects with `next_deadline`, which
/// reads without popping, so the destruction this test was written against
/// is gone at the root. The obligation it pins is unchanged and is the one
/// that actually matters to a peer: **a CLOSE sealed while `send_to` is
/// suspended still reaches the wire.** That is a statement about the drain
/// contract, not about where the deadline is read, and it would still fail
/// on a driver that dropped the handle-side mutation on the floor for any
/// other reason.
///
/// # The mutation this catches
///
/// The driver's loop was
///
/// ```text
/// serve() → transmit(outgoing).await → handles check → deadline() → select!
/// ```
///
/// and `transmit()` is the one yield point between the drain and
/// `deadline()`. §16.3 puts `close()` on the **handle** side of the seam
/// (ruling 53): it mutates the core on the *caller's* stack. So a `close()`
/// that lands while the driver is suspended inside `send_to` queues
/// `Transmit(CLOSE)` on a core the driver is about to call `poll_output()`
/// on outside a drain — and `deadline()` popped it and threw it away. In
/// release that was a silently lost CLOSE and 25 s of `DEAD_TIMEOUT` for the
/// peer, which is precisely the cost §15.1 says CLOSE exists to avoid; in
/// debug the `debug_assert!` beside it panicked the driver instead.
///
/// The first fix was to read the deadline **before** the yield, where the
/// drain has just finished and `deadline()`'s own doc comment already
/// claimed it was — every handle-side mutation sends a command, and the
/// command arm is `biased` first, so a deadline made stale during the yield
/// is recomputed on the very next iteration rather than obeyed. **Ruling 262
/// then removed the destructive read itself**, after measuring that position
/// alone was never sufficient: `serve()`'s own post-drain tail calls into
/// consumer code, so "no yield since the drain" did not imply "no mutation
/// since the drain". The deadline is still read here, and now nothing is
/// riding on that.
///
/// # Why the assertion separates them
///
/// The broken build loses `c_to_a`'s CLOSE: peer C learns nothing and is
/// reaped at `DEAD_TIMEOUT` with `TimedOut`, so the `PeerClosed { code: 2 }`
/// assertion fails in **release**; in **debug** the driver panics before
/// the CLOSE can leave and — since the panic now runs the stop path — C's
/// peer handle still never sees `PeerClosed`. Red in both profiles.
///
/// The B assertion is the control: B's CLOSE was already in `outgoing` when
/// the yield happened, so it survives *either* build. A test that asserted
/// only on B would pass against the broken driver. Two connections are also
/// what makes the case reachable at all — with one, there is no second core
/// to hold an undrained output.
async
/// **§6.4's PENDING branch, reached — the accept-vs-connect race after
/// ruling 90.**
///
/// # What this test used to be, and why it is not that any more
///
/// It was the C-B1 regression: the shell kept a **mirror** of the endpoint
/// core's static map, the two could disagree for the width of one command,
/// and this pinned that the driver survived the disagreement and the losing
/// dial resolved `AlreadyConnected`. **Ruling 90 deleted the mirror.** There
/// is one map now, `Driver::command_connect` has no `Err` arm at all, and
/// the divergence is impossible rather than handled — so the thing this
/// test was written to catch cannot be built, and two of its three original
/// assertions are **no longer pinnable by anything**:
///
/// * the two maps disagreeing (there is no second map), and
/// * `release_static`'s stamp check (there are no stamps).
///
/// Saying that out loud is the point. A test renamed onto new ground while
/// quietly pinning less than its name claims is how slice 3's seam review
/// mutated §16.4's central MUST with 454/454 still green.
///
/// # What it pins now
///
/// The same interleaving, with the arbitration moved. `Endpoint::connect`
/// is synchronous and its first half — `core::Endpoint::mint_pending`, 0 DH
/// — writes §5.4's PENDING row **at the instant of the call**, while
/// `Command::AcceptChain` is still queued. So the accept no longer finds the
/// static NONE: it finds it **PENDING**, which routes it to §6.4's PENDING
/// branch. §6.6 names this exact ordering — "a chain staged while its static
/// was NONE and accepted after a `connect()` made that static PENDING
/// reaches §6.4's PENDING branch instead" — and §6.4 calls it "the branch
/// that closes the `read_identity()` → `connect()` → `accept()` ordering".
/// Under the mirror that branch was **unreachable** through the shell.
///
/// # The tie-break direction is checked, not assumed
///
/// §6.4's PENDING branch is not one answer but two, chosen by §6.7's
/// comparison over the **canonical static encoding** (§2.4): the peer's
/// static smaller ⇒ we are the loser and the accept cancels our pending and
/// installs; ours smaller ⇒ we are the winner, the accept returns
/// `AcceptError::Stale` and our pending stands. The seeds here put A below
/// B, so **A is the winner and `Stale` is the §6.7-correct answer** — and
/// the assertion below is guarded by an explicit key-order check, so a
/// future change of seeds turns this red instead of leaving it green for
/// the wrong reason.
///
/// # The interim boundary, and the exposure change it represents
///
/// §6.4's **loser** branch is not implemented: `core::Endpoint::accept`
/// returns `Stale` for PENDING *unconditionally* (`src/core/endpoint/mod.rs`
/// module docs — "PENDING needs §6.6–6.7's tie-break … slice 7"). Neither is
/// §6.5's hint check nor §6.6's internal completion. So ruling 90 changed
/// **which half of §6.4 is wrong**:
///
/// | | before ruling 90 | after |
/// |---|---|---|
/// | what the accept does | takes the **NONE** path and installs | takes the PENDING path and returns `Stale` |
/// | which §6.4 branch that is | the **loser**'s outcome, unconditionally | the **winner**'s outcome, unconditionally |
/// | outcome of this scenario | one session, immediately | **both dials run to `HANDSHAKE_GIVEUP`** |
///
/// The old behaviour converged because the install was always paired with a
/// *refusal* of the connect, so no msg1 of ours was ever in flight — it is
/// **not** §6.4's "mutually dark" divergence, which needs exactly that
/// in-flight msg1. What it was instead is an initiator role assigned by
/// **command order**, which §6.4 forbids in terms: the comparison is "a
/// two-sided agreement evaluated over the pair of statics, **never over
/// local state**".
///
/// The new behaviour assigns nothing locally and defers to a comparison
/// that does not exist yet, so in this slice neither dial completes on its
/// own. The blocks below pin **both** halves of that: the boundary while it
/// stands, and the recovery an application has meanwhile — drop the
/// `Connecting`, which frees the static in the core's own map synchronously
/// (ruling 50), and accept the peer's next retransmission.
///
/// **When slice 7 lands §6.5/§6.6, the INTERIM block must go red** — B would
/// lose §6.6's internal tie-break and install as responder, and both dials
/// would complete without the application dropping anything. That red is
/// the signal, not a regression; replace the block with the completion.
///
/// # The mutation this catches, executed rather than claimed
///
/// **Putting the mirror back**, in any form that leaves the core's map free
/// of the pending until the driver runs: the accept then finds NONE,
/// installs, and `accepted` is `Ok`. That is the one assertion that
/// separates the two architectures, and it is the second one below.
///
/// Run as `if self.statics.get(&peer_key).is_some_and(|e| matches!(e.state,
/// StaticState::Live))` in `core::Endpoint::accept` — the mirror's effect,
/// expressed inside the core. It does not merely fail this assertion: it
/// detonates `StaticMap::insert`'s own `debug_assert!("§16.1: one session
/// per peer static")`, because the accept installs a LIVE row over the
/// PENDING one the dial holds. **The state the mirror produced is a state
/// the core will not represent** — it escaped the assertion only because the
/// mirror kept that row out of the core's map. Nothing short of §6.4's loser
/// branch, which *cancels* the pending first, can install here.
///
/// # Two things this test does NOT catch, stated so nobody assumes it does
///
/// * **`Connecting::drop` deferring the retirement to the driver.** The
/// recovery block below drops the dial and re-accepts — but the fresh
/// `Intro` it needs only exists after B retransmits, so there is a clock
/// advance and a driver turn in the gap, and a deferred `Retired` lands in
/// time. Verified by running that mutation: this test stays **green**.
/// Ruling 50's no-clock-advance ordering is pinned by
/// `s29_cancel_then_immediate_redial` and
/// `s29_retry_loop_replaces_rather_than_accumulates` in
/// `tests/story_lifecycle.rs`, and by
/// `a_cancelled_dial_frees_the_static_with_no_clock_advance` in
/// `src/shell/mod.rs` — all three go red under it.
/// * **A driver frozen after establishment.** The last phase is
/// wire-observable work — A closes and B's *independent* handle must see
/// `PeerClosed`, which no stale cell can fake — but the mutation that
/// isolates it, a driver that stops transmitting only after the session
/// exists, is not expressible with `FlakyWire`: cutting transmits wholesale
/// hangs the test at the *first* `accept()` instead of failing the last
/// phase. That is working rule 13's fixture bound, not a gap the authors
/// could close here. Driver death itself is pinned by
/// `a_panicking_driver_resolves_every_waiter_instead_of_parking_it` below.
async
/// **A driver that panics resolves every waiter instead of parking it.**
///
/// §16.3 makes the driver a single task, and `tokio::task::spawn_local`
/// stores its panic in a `JoinHandle` the shell drops — so a driver panic
/// is **invisible**: nothing propagates, and the test harness prints `ok`.
/// Before the `Drop` guard this test pins, that silence was permanent as
/// well as invisible. `Driver::stop` — which sets `driver_stopped`, latches
/// `ConnectionLost::EndpointDropped` over every connection and drops the
/// parked `accept()` senders — ran only on the loop's ordinary exit.
///
/// # What the broken build does, waiter by waiter
///
/// With no unwind guard, an unwind skips `stop()` and leaves
/// `driver_stopped == false`. Then:
///
/// * `Connection::closed()` parks in `closed_wakers` with nobody left to
/// wake it — **for ever**;
/// * a `Connecting` whose `Command::Connect` the driver *did* process parks
/// in its `PendingSlot` — the slot's `Rc` is dropped with the record and
/// never resolved;
/// * a `Connecting` whose `Command::Connect` is *still in the channel* parks
/// the same way, and is worse: no record ever named it, so even a
/// record-sweeping `stop()` misses it unless the channel is drained;
/// * `is_established()` keeps answering `true` from a cell nobody will
/// write again, and `Endpoint::connect` keeps handing out fresh
/// `Connecting`s that can never resolve.
///
/// Only the `oneshot`-backed verbs degrade on their own, because their
/// senders die with the `Driver` — which is why the failure looks like
/// "some things still work" rather than "the endpoint is dead", and why it
/// went unnoticed.
///
/// # Why the assertions separate the builds
///
/// Every one is a `poll_once` with **no clock advance and no timeout**. The
/// fixed build resolves each waiter synchronously during the unwind, so
/// `Ready` is available on the next poll; the broken build answers
/// `Pending` to all four, for ever. A `timeout()`-shaped assertion would
/// also pass, but slowly and only by exhausting virtual time — this states
/// the property directly.
///
/// Two dials are issued back-to-back on purpose. The driver handles exactly
/// one command per loop iteration, so the first becomes a `ConnRecord` and
/// the second is still sitting in the command channel when the panic lands.
/// They are the two different parking places above, and a `stop()` that
/// only swept its own records would leave the second hung.
///
/// **`cargo test -- --nocapture` prints this driver's panic and still
/// reports `ok`.** That is the behaviour under test, not a failure of it —
/// and the reason the finding survived a green suite for a whole slice.
async