hibana 0.9.6

Choreography-derived runtime enforcement kernel for no_std Rust multiparty protocols
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
mod common;
#[path = "support/runtime.rs"]
mod runtime_support;
#[path = "support/tls_ref.rs"]
mod tls_ref_support;

use core::cell::UnsafeCell;

use common::TestTransport;
use hibana::g::{self, Msg};
use hibana::runtime::program::{RoleProgram, project};
use hibana::runtime::{SessionKitStorage, ids::SessionId};
use runtime_support::with_runtime_workspace;
use tls_ref_support::with_resident_tls_ref;

type TestKitStorage = SessionKitStorage<'static, TestTransport>;

const LOCAL_ROLE: u8 = 1;
const WORKER_ROLE: u8 = 2;
const SIDE_ROLE: u8 = 3;
const OBSERVER_ROLE: u8 = 4;

const ROUTE_PAYLOAD: u8 = 173;
const ROUTE_OTHER: u8 = 174;
const SIDE_REQ: u8 = 175;
const SIDE_RET: u8 = 176;
const JOIN: u8 = 177;
const PAR_A: u8 = 201;
const PAR_B: u8 = 202;
const PAR_D: u8 = 203;
const PAR_E: u8 = 204;
const PAR_POST: u8 = 205;
const ROUTE_PAR_A: u8 = 221;
const ROUTE_PAR_B: u8 = 222;
const ROUTE_PAR_C: u8 = 223;
const ROUTE_PAR_D: u8 = 224;
const ROUTE_PAR_R: u8 = 225;
const ROUTE_PAR_POST: u8 = 226;
const ROUTE_PAR_RIGHT_SIDE: u8 = 233;
const ROUTE_PAR_RIGHT_OBSERVER: u8 = 234;
const DEAD_RIGHT_A: u8 = 227;
const DEAD_RIGHT_B: u8 = 228;
const DEAD_RIGHT_C: u8 = 229;
const DEAD_RIGHT_E: u8 = 230;
const DEAD_RIGHT_D: u8 = 231;
const DEAD_RIGHT_POST: u8 = 232;

std::thread_local! {
    static SESSION_SLOT: UnsafeCell<TestKitStorage> = const {
        UnsafeCell::new(SessionKitStorage::uninit())
    };
}

fn program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let routed = g::route(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<ROUTE_PAYLOAD, u8>>(),
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<ROUTE_OTHER, u8>>(),
    );
    let side = g::seq(
        g::send::<LOCAL_ROLE, SIDE_ROLE, Msg<SIDE_REQ, u8>>(),
        g::send::<SIDE_ROLE, LOCAL_ROLE, Msg<SIDE_RET, u8>>(),
    );
    project(&g::seq(
        g::par(routed, side),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<JOIN, u8>>(),
    ))
}

fn nested_parallel_join_program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let inner = g::par(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<PAR_A, u8>>(),
        g::send::<LOCAL_ROLE, SIDE_ROLE, Msg<PAR_B, u8>>(),
    );
    let left = g::seq(inner, g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<PAR_D, u8>>());
    let right = g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<PAR_E, u8>>();
    project(&g::seq(
        g::par(left, right),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<PAR_POST, u8>>(),
    ))
}

fn route_left_nested_parallel_program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let nested_join = g::par(
        g::par(
            g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<ROUTE_PAR_A, u8>>(),
            g::send::<LOCAL_ROLE, SIDE_ROLE, Msg<ROUTE_PAR_B, u8>>(),
        ),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<ROUTE_PAR_C, u8>>(),
    );
    let left = g::seq(
        nested_join,
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<ROUTE_PAR_D, u8>>(),
    );
    let right = g::par(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<ROUTE_PAR_R, u8>>(),
        g::par(
            g::send::<LOCAL_ROLE, SIDE_ROLE, Msg<ROUTE_PAR_RIGHT_SIDE, u8>>(),
            g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<ROUTE_PAR_RIGHT_OBSERVER, u8>>(),
        ),
    );
    project(&g::seq(
        g::route(left, right),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<ROUTE_PAR_POST, u8>>(),
    ))
}

fn route_right_parallel_dead_program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let left = g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_A, u8>>();
    let right = g::par(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_B, u8>>(),
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_C, u8>>(),
    );
    project(&g::seq(
        g::route(left, right),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<DEAD_RIGHT_POST, u8>>(),
    ))
}

fn parallel_route_right_parallel_dead_program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let left = g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_A, u8>>();
    let right = g::par(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_B, u8>>(),
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_C, u8>>(),
    );
    let routed = g::route(left, right);
    let sibling = g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<DEAD_RIGHT_E, u8>>();
    project(&g::seq(
        g::par(routed, sibling),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<DEAD_RIGHT_POST, u8>>(),
    ))
}

fn outer_left_kills_nested_right_route_program<const ROLE: u8>() -> RoleProgram<ROLE> {
    let left = g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_A, u8>>();
    let inner_left = g::par(
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_B, u8>>(),
        g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_C, u8>>(),
    );
    let inner_right = g::send::<LOCAL_ROLE, WORKER_ROLE, Msg<DEAD_RIGHT_D, u8>>();
    let right = g::route(inner_left, inner_right);
    project(&g::seq(
        g::route(left, right),
        g::send::<LOCAL_ROLE, OBSERVER_ROLE, Msg<DEAD_RIGHT_POST, u8>>(),
    ))
}

fn assert_join_blocked(rendered: &str) {
    assert!(
        rendered.contains("LabelMismatch") || rendered.contains("PhaseInvariant"),
        "post-par join must be rejected by resident progress evidence: {rendered}"
    );
}

async fn assert_send_rejected<F>(future: F, context: &str)
where
    F: core::future::Future<Output = core::result::Result<(), hibana::EndpointError>>,
{
    let err = future.await.expect_err(context);
    assert_join_blocked(&format!("{err:?}"));
}

macro_rules! attach_three_roles {
    ($rv:expr, $sid:expr, $program:ident) => {{
        let sid = SessionId::new($sid);
        (
            $rv.enter(sid, &$program::<LOCAL_ROLE>())
                .expect("attach local role"),
            $rv.enter(sid, &$program::<WORKER_ROLE>())
                .expect("attach worker role"),
            $rv.enter(sid, &$program::<OBSERVER_ROLE>())
                .expect("attach observer role"),
        )
    }};
}

macro_rules! attach_four_roles {
    ($rv:expr, $sid:expr, $program:ident) => {{
        let sid = SessionId::new($sid);
        (
            $rv.enter(sid, &$program::<LOCAL_ROLE>())
                .expect("attach local role"),
            $rv.enter(sid, &$program::<WORKER_ROLE>())
                .expect("attach worker role"),
            $rv.enter(sid, &$program::<SIDE_ROLE>())
                .expect("attach side role"),
            $rv.enter(sid, &$program::<OBSERVER_ROLE>())
                .expect("attach observer role"),
        )
    }};
}

#[test]
fn unselected_route_arm_parallel_events_are_dead_and_not_join_obligations() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                {
                    let (mut local, mut worker, observer) =
                        attach_three_roles!(rv, 98, route_right_parallel_dead_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_send_rejected(
                        local.send::<Msg<DEAD_RIGHT_B, u8>>(&0),
                        "unselected right nested-par B must be dead",
                    )
                    .await;
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, observer) =
                        attach_three_roles!(rv, 99, route_right_parallel_dead_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_send_rejected(
                        local.send::<Msg<DEAD_RIGHT_C, u8>>(&0),
                        "unselected right nested-par C must be dead",
                    )
                    .await;
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, mut observer) =
                        attach_three_roles!(rv, 100, route_right_parallel_dead_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    local
                        .send::<Msg<DEAD_RIGHT_POST, u8>>(&2)
                        .await
                        .expect("send post route");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<DEAD_RIGHT_POST, u8>>()
                            .await
                            .expect("recv post"),
                        2
                    );
                }
            });
        });
    });
}

#[test]
fn unselected_route_arm_parallel_events_do_not_block_parallel_join() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                {
                    let (mut local, mut worker, observer) =
                        attach_three_roles!(rv, 101, parallel_route_right_parallel_dead_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_send_rejected(
                        local.send::<Msg<DEAD_RIGHT_POST, u8>>(&0),
                        "outer par join must still wait for sibling E",
                    )
                    .await;
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, mut observer) =
                        attach_three_roles!(rv, 102, parallel_route_right_parallel_dead_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    local
                        .send::<Msg<DEAD_RIGHT_E, u8>>(&2)
                        .await
                        .expect("send E");
                    local
                        .send::<Msg<DEAD_RIGHT_POST, u8>>(&3)
                        .await
                        .expect("send post");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<DEAD_RIGHT_E, u8>>()
                            .await
                            .expect("recv E"),
                        2
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<DEAD_RIGHT_POST, u8>>()
                            .await
                            .expect("recv post"),
                        3
                    );
                }
            });
        });
    });
}

#[test]
fn outer_left_selection_kills_nested_right_route_and_parallel_body() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                for (sid, label) in [
                    (103, DEAD_RIGHT_B),
                    (104, DEAD_RIGHT_C),
                    (105, DEAD_RIGHT_D),
                ] {
                    let (mut local, mut worker, observer) =
                        attach_three_roles!(rv, sid, outer_left_kills_nested_right_route_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    let rejected = match label {
                        DEAD_RIGHT_B => local.send::<Msg<DEAD_RIGHT_B, u8>>(&0).await,
                        DEAD_RIGHT_C => local.send::<Msg<DEAD_RIGHT_C, u8>>(&0).await,
                        DEAD_RIGHT_D => local.send::<Msg<DEAD_RIGHT_D, u8>>(&0).await,
                        _ => unreachable!(),
                    }
                    .expect_err("nested right event must be dead after outer left selection");
                    assert_join_blocked(&format!("{rejected:?}"));
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, mut observer) =
                        attach_three_roles!(rv, 106, outer_left_kills_nested_right_route_program);
                    local
                        .send::<Msg<DEAD_RIGHT_A, u8>>(&1)
                        .await
                        .expect("send A");
                    local
                        .send::<Msg<DEAD_RIGHT_POST, u8>>(&2)
                        .await
                        .expect("send post route");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch
                            .recv::<Msg<DEAD_RIGHT_A, u8>>()
                            .await
                            .expect("recv A"),
                        1
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<DEAD_RIGHT_POST, u8>>()
                            .await
                            .expect("recv post"),
                        2
                    );
                }
            });
        });
    });
}

#[test]
fn route_selected_left_keeps_entire_nested_parallel_path_live() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                {
                    let (mut local, mut worker, side, observer) =
                        attach_four_roles!(rv, 107, route_left_nested_parallel_program);
                    local
                        .send::<Msg<ROUTE_PAR_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAR_A, u8>>().await.expect("recv A"),
                        1
                    );
                    assert_send_rejected(
                        local.send::<Msg<ROUTE_PAR_R, u8>>(&0),
                        "right arm must be unselected after A commits",
                    )
                    .await;
                    core::hint::black_box((side, observer));
                }
                {
                    let (mut local, mut worker, side, observer) =
                        attach_four_roles!(rv, 108, route_left_nested_parallel_program);
                    local
                        .send::<Msg<ROUTE_PAR_A, u8>>(&1)
                        .await
                        .expect("send A");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAR_A, u8>>().await.expect("recv A"),
                        1
                    );
                    assert_send_rejected(
                        local.send::<Msg<ROUTE_PAR_D, u8>>(&0),
                        "D must wait for B and C",
                    )
                    .await;
                    core::hint::black_box((side, observer));
                }
                {
                    let (mut local, mut worker, mut side, observer) =
                        attach_four_roles!(rv, 109, route_left_nested_parallel_program);
                    local
                        .send::<Msg<ROUTE_PAR_A, u8>>(&1)
                        .await
                        .expect("send A");
                    local
                        .send::<Msg<ROUTE_PAR_B, u8>>(&2)
                        .await
                        .expect("send B");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAR_A, u8>>().await.expect("recv A"),
                        1
                    );
                    assert_eq!(
                        side.recv::<Msg<ROUTE_PAR_B, u8>>().await.expect("recv B"),
                        2
                    );
                    assert_send_rejected(
                        local.send::<Msg<ROUTE_PAR_D, u8>>(&0),
                        "D must still wait for C",
                    )
                    .await;
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, mut side, mut observer) =
                        attach_four_roles!(rv, 110, route_left_nested_parallel_program);
                    local
                        .send::<Msg<ROUTE_PAR_A, u8>>(&1)
                        .await
                        .expect("send A");
                    local
                        .send::<Msg<ROUTE_PAR_B, u8>>(&2)
                        .await
                        .expect("send B");
                    local
                        .send::<Msg<ROUTE_PAR_C, u8>>(&3)
                        .await
                        .expect("send C");
                    local
                        .send::<Msg<ROUTE_PAR_D, u8>>(&4)
                        .await
                        .expect("send D");
                    local
                        .send::<Msg<ROUTE_PAR_POST, u8>>(&5)
                        .await
                        .expect("send Post");
                    let branch = worker.offer().await.expect("offer A");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAR_A, u8>>().await.expect("recv A"),
                        1
                    );
                    assert_eq!(
                        side.recv::<Msg<ROUTE_PAR_B, u8>>().await.expect("recv B"),
                        2
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<ROUTE_PAR_C, u8>>()
                            .await
                            .expect("recv C"),
                        3
                    );
                    assert_eq!(
                        worker.recv::<Msg<ROUTE_PAR_D, u8>>().await.expect("recv D"),
                        4
                    );
                    assert_eq!(
                        observer
                            .recv::<Msg<ROUTE_PAR_POST, u8>>()
                            .await
                            .expect("recv Post"),
                        5
                    );
                }
            });
        });
    });
}

#[test]
fn route_inside_parallel_lane_cannot_release_join_before_sibling_lane() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                {
                    let (mut local, mut worker, side, observer) =
                        attach_four_roles!(rv, 111, program);
                    local
                        .send::<Msg<ROUTE_PAYLOAD, u8>>(&10)
                        .await
                        .expect("send route payload");
                    let branch = worker.offer().await.expect("offer route payload");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAYLOAD, u8>>().await.expect("recv"),
                        10
                    );
                    assert_send_rejected(
                        local.send::<Msg<JOIN, u8>>(&0),
                        "join must wait for the sibling parallel lane",
                    )
                    .await;
                    core::hint::black_box((side, observer));
                }
                {
                    let (mut local, mut worker, mut side, observer) =
                        attach_four_roles!(rv, 112, program);
                    local
                        .send::<Msg<ROUTE_PAYLOAD, u8>>(&10)
                        .await
                        .expect("send route payload");
                    local
                        .send::<Msg<SIDE_REQ, u8>>(&20)
                        .await
                        .expect("send side");
                    let branch = worker.offer().await.expect("offer route payload");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAYLOAD, u8>>().await.expect("recv"),
                        10
                    );
                    assert_eq!(
                        side.recv::<Msg<SIDE_REQ, u8>>().await.expect("recv side"),
                        20
                    );
                    assert_send_rejected(
                        local.send::<Msg<JOIN, u8>>(&0),
                        "join must wait for the sibling lane response",
                    )
                    .await;
                    core::hint::black_box(observer);
                }
                {
                    let (mut local, mut worker, mut side, mut observer) =
                        attach_four_roles!(rv, 113, program);
                    local
                        .send::<Msg<ROUTE_PAYLOAD, u8>>(&10)
                        .await
                        .expect("send route payload");
                    local
                        .send::<Msg<SIDE_REQ, u8>>(&20)
                        .await
                        .expect("send side");
                    let branch = worker.offer().await.expect("offer route payload");
                    assert_eq!(
                        branch.recv::<Msg<ROUTE_PAYLOAD, u8>>().await.expect("recv"),
                        10
                    );
                    assert_eq!(
                        side.recv::<Msg<SIDE_REQ, u8>>().await.expect("recv side"),
                        20
                    );
                    side.send::<Msg<SIDE_RET, u8>>(&30)
                        .await
                        .expect("send response");
                    assert_eq!(
                        local
                            .recv::<Msg<SIDE_RET, u8>>()
                            .await
                            .expect("recv response"),
                        30
                    );
                    local.send::<Msg<JOIN, u8>>(&40).await.expect("send join");
                    assert_eq!(
                        observer.recv::<Msg<JOIN, u8>>().await.expect("recv join"),
                        40
                    );
                }
            });
        });
    });
}

#[test]
fn nested_parallel_join_requires_every_dependency_before_post() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            futures::executor::block_on(async {
                {
                    let (mut local, worker, side, mut observer) =
                        attach_four_roles!(rv, 114, nested_parallel_join_program);
                    local.send::<Msg<PAR_E, u8>>(&4).await.expect("send E");
                    assert_eq!(observer.recv::<Msg<PAR_E, u8>>().await.expect("recv E"), 4);
                    assert_send_rejected(
                        local.send::<Msg<PAR_POST, u8>>(&0),
                        "Post must still wait for the left parallel branch",
                    )
                    .await;
                    core::hint::black_box((worker, side));
                }
                {
                    let (mut local, mut worker, side, observer) =
                        attach_four_roles!(rv, 115, nested_parallel_join_program);
                    local.send::<Msg<PAR_A, u8>>(&1).await.expect("send A");
                    assert_eq!(worker.recv::<Msg<PAR_A, u8>>().await.expect("recv A"), 1);
                    assert_send_rejected(local.send::<Msg<PAR_D, u8>>(&0), "D must wait for B")
                        .await;
                    core::hint::black_box((side, observer));
                }
            });
        });
    });
}

#[test]
fn nested_parallel_join_commits_post_after_sibling_first_completion() {
    with_runtime_workspace(|slab| {
        with_resident_tls_ref(&SESSION_SLOT, |cluster| {
            let transport = TestTransport::new();
            let rv = cluster
                .rendezvous(slab, transport)
                .expect("register rendezvous");
            let sid = SessionId::new(94);

            let mut local = rv
                .enter(sid, &nested_parallel_join_program::<LOCAL_ROLE>())
                .expect("attach local role");
            let mut worker = rv
                .enter(sid, &nested_parallel_join_program::<WORKER_ROLE>())
                .expect("attach worker role");
            let mut side = rv
                .enter(sid, &nested_parallel_join_program::<SIDE_ROLE>())
                .expect("attach side role");
            let mut observer = rv
                .enter(sid, &nested_parallel_join_program::<OBSERVER_ROLE>())
                .expect("attach observer role");

            futures::executor::block_on(async {
                local
                    .send::<Msg<PAR_E, u8>>(&4)
                    .await
                    .expect("send E before nested left branch completes");
                local.send::<Msg<PAR_A, u8>>(&1).await.expect("send A");
                local.send::<Msg<PAR_B, u8>>(&2).await.expect("send B");
                local.send::<Msg<PAR_D, u8>>(&3).await.expect("send D");
                local
                    .send::<Msg<PAR_POST, u8>>(&5)
                    .await
                    .expect("send Post");

                assert_eq!(worker.recv::<Msg<PAR_A, u8>>().await.expect("recv A"), 1);
                assert_eq!(side.recv::<Msg<PAR_B, u8>>().await.expect("recv B"), 2);
                assert_eq!(worker.recv::<Msg<PAR_D, u8>>().await.expect("recv D"), 3);
                assert_eq!(observer.recv::<Msg<PAR_E, u8>>().await.expect("recv E"), 4);
                assert_eq!(
                    observer
                        .recv::<Msg<PAR_POST, u8>>()
                        .await
                        .expect("recv Post"),
                    5
                );
            });
        });
    });
}