ruau 0.4.0

Pure Rust implementation of Luau and its analyzer.
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
//! Concurrency and failure-pressure checks for the production request executor.

#[cfg(test)]
mod tests {
    use std::{
        sync::{
            Arc,
            atomic::{AtomicUsize, Ordering},
        },
        time::{Duration, Instant},
    };

    use ruau::{
        executor::{
            AdmissionLimits, Executor, IngressLimits, Request, RequestError, RunControl, TenantId,
        },
        surface::Surface,
        vm::{
            Ambient, Cancel, CancellationToken, ExecutionFeatures, HostReturn, HostValue, Limits,
            ModuleBinding, NativeModule, OwnedValue, ValueSnapshot,
            module::Installer as ModuleBuilder,
        },
    };
    // These test-only host functions exercise the engine-facing trait directly;
    // ordinary facade callers name host/native-module types through ruau::vm.
    use ruau_vm::{HostCall, HostContext, HostError, HostFunction};

    fn default_surface() -> Surface {
        Surface::new()
    }

    fn surface_with_module(module: Arc<dyn NativeModule>) -> Surface {
        Surface::builder()
            .module(module)
            .build()
            .expect("module surface validates")
    }

    fn executor_with_limits(gas: u64, max_memory_bytes: usize) -> Executor {
        Executor::builder()
            .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
            .surface(default_surface())
            .ambient(Ambient::production(0))
            .features(ExecutionFeatures::all_off())
            // These tests stress raw concurrency; opt out of the fail-closed
            // admission defaults explicitly.
            .ingress_limits(IngressLimits {
                max_in_flight: usize::MAX,
                max_in_flight_per_tenant: usize::MAX,
            })
            .lane_admission_limits(AdmissionLimits::unlimited())
            .max_source_bytes(256 * 1024)
            .limits(Limits {
                gas: Some(gas),
                max_memory_bytes: Some(max_memory_bytes),
                ..Limits::unlimited()
            })
            .build()
            .expect("executor builds")
    }

    fn budget(timeout: Duration) -> RunControl {
        RunControl::with_timeout(timeout).expect("test run control has a future deadline")
    }

    fn assert_number(values: &[ValueSnapshot], expected: f64) {
        match values {
            [ValueSnapshot::Number(actual)] => {
                assert!(
                    (*actual - expected).abs() < f64::EPSILON,
                    "expected {expected}, got {actual}"
                );
            }
            other => panic!("expected one number result, got {other:?}"),
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn a_thousand_concurrent_tiny_requests_complete() {
        let executor = Arc::new(executor_with_limits(1_000_000, 8 * 1024 * 1024));
        let mut tasks = Vec::new();
        for _ in 0..1_000 {
            let executor = Arc::clone(&executor);
            tasks.push(tokio::spawn(async move {
                // Generous budget: type checks run on a bounded pool, so a
                // thousand-deep burst drains in series under full-suite CPU
                // contention; this asserts completion, not latency.
                executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\nreturn 1 + 1",
                        budget(Duration::from_secs(60)),
                    ))
                    .await
            }));
        }

        for task in tasks {
            let outcome = task
                .await
                .expect("request task joins")
                .expect("request succeeds");
            assert_number(&outcome.values, 2.0);
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn cancellation_storms_do_not_poison_the_executor() {
        let executor = Arc::new(executor_with_limits(1_000_000, 8 * 1024 * 1024));
        let mut tasks = Vec::new();
        for _ in 0..128 {
            let executor = Arc::clone(&executor);
            tasks.push(tokio::spawn(async move {
                // Built from the facade-re-exported token type: embedders link
                // external cancellation without a direct tokio-util dependency.
                let cancel = Cancel::new(CancellationToken::new());
                cancel.cancel();
                executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\nreturn 1",
                        RunControl::new(Instant::now() + Duration::from_secs(5), cancel)
                            .expect("future cancellation budget"),
                    ))
                    .await
            }));
        }

        for task in tasks {
            let error = task
                .await
                .expect("request task joins")
                .expect_err("pre-cancelled request fails");
            assert!(matches!(error, RequestError::Cancelled), "got {error:?}");
        }

        let outcome = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 7",
                budget(Duration::from_secs(5)),
            ))
            .await
            .expect("executor remains healthy");
        assert_number(&outcome.values, 7.0);
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn jittered_mid_flight_cancellation_storm_stays_healthy() {
        // Mixed CPU and host-await workloads on a multi-lane pool, each with a
        // jittered mid-flight cancel: every outcome must be Ok or Cancelled,
        // and the executor must stay healthy afterwards.
        let calls = Arc::new(AtomicUsize::new(0));
        let executor = Arc::new(
            Executor::builder()
                .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
                .surface(surface_with_module(Arc::new(DelayModule {
                    delay: Duration::from_millis(40),
                    calls: Arc::clone(&calls),
                })))
                .ambient(Ambient::production(0))
                .features(ExecutionFeatures::all_off())
                .ingress_limits(IngressLimits {
                    max_in_flight: usize::MAX,
                    max_in_flight_per_tenant: usize::MAX,
                })
                .lane_admission_limits(AdmissionLimits::unlimited())
                .lane_count(4)
                .max_source_bytes(256 * 1024)
                .limits(Limits {
                    gas: Some(50_000_000),
                    max_memory_bytes: Some(16 * 1024 * 1024),
                    ..Limits::unlimited()
                })
                .build()
                .expect("executor builds"),
        );

        let mut tasks = Vec::new();
        for index in 0..96_u64 {
            let executor = Arc::clone(&executor);
            tasks.push(tokio::spawn(async move {
                let cancel = Cancel::manual();
                let canceller = cancel.clone();
                // Jitter across the whole request lifetime: parse/check,
                // mid-dispatch, and mid-host-await all get hit.
                let cancel_after = Duration::from_micros((index % 29) * 700);
                tokio::spawn(async move {
                    tokio::time::sleep(cancel_after).await;
                    canceller.cancel();
                });
                let source: &[u8] = if index % 2 == 0 {
                    b"--!nocheck\nlocal s = 0\nfor i = 1, 400000 do s = s + i end\nreturn s"
                } else {
                    b"--!nocheck\nreturn host_delay(1)"
                };
                executor
                    .run(Request::new(
                        TenantId(0),
                        source,
                        RunControl::new(Instant::now() + Duration::from_secs(10), cancel)
                            .expect("future storm budget"),
                    ))
                    .await
            }));
        }

        let mut completed = 0_usize;
        let mut cancelled = 0_usize;
        for task in tasks {
            match task.await.expect("storm task joins") {
                Ok(_) => completed += 1,
                Err(RequestError::Cancelled) => cancelled += 1,
                Err(other) => panic!("storm outcome must be Ok or Cancelled, got {other:?}"),
            }
        }
        assert_eq!(completed + cancelled, 96);

        let outcome = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 21",
                budget(Duration::from_secs(5)),
            ))
            .await
            .expect("executor remains healthy after the storm");
        assert_number(&outcome.values, 21.0);
    }

    struct DelayModule {
        delay: Duration,
        calls: Arc<AtomicUsize>,
    }

    impl NativeModule for DelayModule {
        fn name(&self) -> &'static str {
            "delay"
        }

        fn declaration(&self) -> ruau_declaration::DeclarationSource<'_> {
            ruau_declaration::DeclarationSource::Text(
                "declare function host_delay(value: number): number",
            )
        }

        fn install(&self, builder: &mut dyn ModuleBuilder) {
            builder.function(
                "host_delay",
                ModuleBinding::Global,
                Box::new(DelayHost {
                    delay: self.delay,
                    calls: Arc::clone(&self.calls),
                }),
            );
        }
    }

    struct DelayHost {
        delay: Duration,
        calls: Arc<AtomicUsize>,
    }

    impl HostFunction for DelayHost {
        fn call(&self, ctx: &mut dyn HostContext) -> HostCall {
            let value = match ctx.arg(0) {
                Some(HostValue::Integer(value)) => value as f64,
                Some(HostValue::Number(value)) => value,
                _ => 0.0,
            };
            self.calls.fetch_add(1, Ordering::SeqCst);
            let delay = self.delay;
            HostCall::Pending(Box::pin(async move {
                tokio::time::sleep(delay).await;
                Ok::<HostReturn, HostError>(HostReturn {
                    values: vec![OwnedValue::Number(value + 1.0)],
                })
            }))
        }
    }

    fn delay_executor(delay: Duration, calls: Arc<AtomicUsize>) -> Executor {
        Executor::builder()
            .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
            .surface(surface_with_module(Arc::new(DelayModule { delay, calls })))
            .ambient(Ambient::production(0))
            .features(ExecutionFeatures::all_off())
            .ingress_limits(IngressLimits {
                max_in_flight: usize::MAX,
                max_in_flight_per_tenant: usize::MAX,
            })
            .lane_admission_limits(AdmissionLimits::unlimited())
            .max_source_bytes(256 * 1024)
            .limits(Limits {
                gas: Some(2_000_000),
                max_memory_bytes: Some(8 * 1024 * 1024),
                ..Limits::unlimited()
            })
            .build()
            .expect("executor builds")
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn long_host_awaits_do_not_starve_ordinary_requests() {
        let host_calls = Arc::new(AtomicUsize::new(0));
        let executor = Arc::new(delay_executor(
            Duration::from_secs(2),
            Arc::clone(&host_calls),
        ));
        let mut waits = Vec::new();
        for _ in 0..16 {
            let executor = Arc::clone(&executor);
            waits.push(tokio::spawn(async move {
                executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\nreturn host_delay(41)",
                        budget(Duration::from_secs(10)),
                    ))
                    .await
            }));
        }

        let wait_started = Instant::now();
        while host_calls.load(Ordering::SeqCst) < 16 {
            assert!(
                wait_started.elapsed() < Duration::from_secs(2),
                "host awaits should reach their parked futures"
            );
            tokio::time::sleep(Duration::from_millis(5)).await;
        }

        let started = Instant::now();
        let ordinary = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 3",
                budget(Duration::from_secs(3)),
            ))
            .await
            .expect("ordinary request succeeds while host awaits are parked");
        let ordinary_elapsed = started.elapsed();
        assert!(
            ordinary_elapsed < Duration::from_secs(1),
            "ordinary request should run while host awaits are parked; took {ordinary_elapsed:?}"
        );
        assert_number(&ordinary.values, 3.0);

        for task in waits {
            let outcome = task
                .await
                .expect("host-await task joins")
                .expect("host await succeeds");
            assert_number(&outcome.values, 42.0);
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn cpu_bound_tenants_hit_deadlines_without_starving_tiny_requests() {
        let executor = Arc::new(executor_with_limits(1 << 60, 8 * 1024 * 1024));
        let mut loops = Vec::new();
        for _ in 0..8 {
            let executor = Arc::clone(&executor);
            loops.push(tokio::spawn(async move {
                executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\nwhile true do end",
                        budget(Duration::from_millis(50)),
                    ))
                    .await
            }));
        }

        let started = Instant::now();
        let ordinary = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 5",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect("ordinary request succeeds while CPU tenants are bounded");
        let ordinary_elapsed = started.elapsed();
        assert!(
            ordinary_elapsed < Duration::from_millis(1_500),
            "ordinary request should not starve behind CPU-bound tenants; took {ordinary_elapsed:?}"
        );
        assert_number(&ordinary.values, 5.0);

        for task in loops {
            let error = task
                .await
                .expect("CPU tenant task joins")
                .expect_err("CPU loop hits deadline");
            assert!(
                matches!(error, RequestError::DeadlineExceeded),
                "got {error:?}"
            );
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn hostile_memory_pressure_fails_closed_without_worker_damage() {
        let executor = Arc::new(executor_with_limits(1 << 60, 1024 * 1024));
        let mut tasks = Vec::new();
        for _ in 0..16 {
            let executor = Arc::clone(&executor);
            tasks.push(tokio::spawn(async move {
                executor
                    .run(Request::new(TenantId(0),
                        b"--!nocheck\nlocal t = {}\nwhile true do t[#t + 1] = string.rep('x', 1024) end",
                        budget(Duration::from_secs(2)),
                    ))
                    .await
            }));
        }

        for task in tasks {
            let error = task
                .await
                .expect("memory-pressure task joins")
                .expect_err("memory pressure fails closed");
            assert!(
                matches!(
                    error,
                    RequestError::OutOfMemory(_) | RequestError::DeadlineExceeded
                ),
                "got {error:?}"
            );
        }

        let outcome = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 11",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect("executor remains healthy after memory pressure");
        assert_number(&outcome.values, 11.0);
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn pattern_pressure_fails_closed_without_worker_damage() {
        let executor = Arc::new(
            Executor::builder()
                .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
                .surface(default_surface())
                .ambient(Ambient::production(0))
                .features(ExecutionFeatures::all_off())
                .ingress_limits(IngressLimits {
                    max_in_flight: usize::MAX,
                    max_in_flight_per_tenant: usize::MAX,
                })
                .lane_admission_limits(AdmissionLimits::unlimited())
                .max_source_bytes(256 * 1024)
                .limits(Limits {
                    gas: Some(1 << 60),
                    max_memory_bytes: Some(8 * 1024 * 1024),
                    max_pattern_steps: Some(128),
                    ..Limits::unlimited()
                })
                .build()
                .expect("executor builds"),
        );

        let started = Instant::now();
        let error = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn string.match(string.rep('a', 128), '.*.*.*.*.*.*.*.*z')",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect_err("pattern pressure fails closed");
        assert!(
            started.elapsed() < Duration::from_secs(1),
            "pattern pressure should stop at the 128-step limit, not run until the deadline"
        );
        match error {
            RequestError::Runtime(ValueSnapshot::String(bytes)) => {
                let message = String::from_utf8_lossy(&bytes);
                assert!(
                    message.contains("pattern match is too complex"),
                    "got runtime error {message:?}"
                );
            }
            other => panic!("expected pattern runtime failure, got {other:?}"),
        }

        let outcome = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 13",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect("executor remains healthy after pattern pressure");
        assert_number(&outcome.values, 13.0);
    }

    struct PanicModule;

    impl NativeModule for PanicModule {
        fn name(&self) -> &'static str {
            "panic_probe"
        }

        fn declaration(&self) -> ruau_declaration::DeclarationSource<'_> {
            ruau_declaration::DeclarationSource::Text("declare function panic_probe(): ()")
        }

        fn install(&self, builder: &mut dyn ModuleBuilder) {
            builder.function("panic_probe", ModuleBinding::Global, Box::new(PanicHost));
        }
    }

    struct PanicHost;

    impl HostFunction for PanicHost {
        fn call(&self, _ctx: &mut dyn HostContext) -> HostCall {
            panic!("host panic probe");
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn host_panic_pressure_fails_closed_without_worker_damage() {
        let executor = Arc::new(
            Executor::builder()
                .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
                .surface(surface_with_module(Arc::new(PanicModule)))
                .ambient(Ambient::production(0))
                .features(ExecutionFeatures::all_off())
                .ingress_limits(IngressLimits {
                    max_in_flight: usize::MAX,
                    max_in_flight_per_tenant: usize::MAX,
                })
                .lane_admission_limits(AdmissionLimits::unlimited())
                .max_source_bytes(256 * 1024)
                .limits(Limits {
                    gas: Some(1_000_000),
                    max_memory_bytes: Some(8 * 1024 * 1024),
                    ..Limits::unlimited()
                })
                .build()
                .expect("executor builds"),
        );

        let prev = std::panic::take_hook();
        std::panic::set_hook(Box::new(|_| {}));
        let mut panic_tasks = Vec::new();
        for _ in 0..8 {
            let executor = Arc::clone(&executor);
            panic_tasks.push(tokio::spawn(async move {
                executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\npanic_probe()\nreturn 99",
                        budget(Duration::from_secs(2)),
                    ))
                    .await
            }));
        }

        let ordinary = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 17",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect("ordinary request runs during host-panic pressure");
        assert_number(&ordinary.values, 17.0);

        for task in panic_tasks {
            let error = task
                .await
                .expect("host-panic task joins")
                .expect_err("host panic fails closed");
            assert!(
                matches!(error, RequestError::PanicPoison(_)),
                "got {error:?}"
            );
        }
        std::panic::set_hook(prev);

        let outcome = executor
            .run(Request::new(
                TenantId(0),
                b"--!nocheck\nreturn 19",
                budget(Duration::from_secs(2)),
            ))
            .await
            .expect("executor remains healthy after host panic");
        assert_number(&outcome.values, 19.0);
    }
}

#[cfg(test)]
mod fail_closed_admission {
    use std::{
        sync::{
            Arc,
            atomic::{AtomicUsize, Ordering},
        },
        time::Duration,
    };

    use ruau::{
        executor::{Executor, Request, RequestError, RunControl, TenantId},
        surface::Surface,
        vm::{
            Ambient, ExecutionFeatures, HostReturn, Limits, ModuleBinding, NativeModule,
            OwnedValue, module::Installer as ModuleBuilder,
        },
    };
    use ruau_vm::{HostCall, HostContext, HostError, HostFunction};

    fn surface_with_module(module: Arc<dyn NativeModule>) -> Surface {
        Surface::builder()
            .module(module)
            .build()
            .expect("module surface validates")
    }

    struct SlowModule;

    impl NativeModule for SlowModule {
        fn name(&self) -> &'static str {
            "slow"
        }

        fn declaration(&self) -> ruau_declaration::DeclarationSource<'_> {
            ruau_declaration::DeclarationSource::Text("declare function slow_probe(): number")
        }

        fn install(&self, builder: &mut dyn ModuleBuilder) {
            builder.function("slow_probe", ModuleBinding::Global, Box::new(SlowHost));
        }
    }

    struct SlowHost;

    impl HostFunction for SlowHost {
        fn call(&self, _ctx: &mut dyn HostContext) -> HostCall {
            HostCall::Pending(Box::pin(async {
                tokio::time::sleep(Duration::from_millis(500)).await;
                Ok::<HostReturn, HostError>(HostReturn {
                    values: vec![OwnedValue::Number(1.0)],
                })
            }))
        }
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
    async fn unconfigured_admission_rejects_a_same_tenant_burst() {
        // No explicit ingress/lane admission: the builder's fail-closed
        // defaults (derived from the single lane) must bound a same-tenant
        // burst instead of admitting it unbounded.
        let executor = Arc::new(
            Executor::builder()
                .aggregate_resource_limits(ruau::executor::AggregateResourceLimits::unlimited())
                .surface(surface_with_module(Arc::new(SlowModule)))
                .ambient(Ambient::production(0))
                .features(ExecutionFeatures::all_off())
                .max_source_bytes(64 * 1024)
                .limits(Limits {
                    gas: Some(10_000_000),
                    max_memory_bytes: Some(8 * 1024 * 1024),
                    ..Limits::unlimited()
                })
                .build()
                .expect("executor builds"),
        );

        let rejections = Arc::new(AtomicUsize::new(0));
        let mut tasks = Vec::new();
        for _ in 0..16 {
            let executor = Arc::clone(&executor);
            let rejections = Arc::clone(&rejections);
            tasks.push(tokio::spawn(async move {
                let budget = RunControl::with_timeout(Duration::from_secs(5))
                    .expect("test budget has a future deadline");
                match executor
                    .run(Request::new(
                        TenantId(0),
                        b"--!nocheck\nreturn slow_probe()",
                        budget,
                    ))
                    .await
                {
                    Ok(_) => {}
                    Err(RequestError::IngressRejected { .. }) => {
                        rejections.fetch_add(1, Ordering::Relaxed);
                    }
                    Err(other) => panic!("unexpected error under burst: {other:?}"),
                }
            }));
        }
        for task in tasks {
            task.await.expect("burst task completes");
        }

        assert!(
            rejections.load(Ordering::Relaxed) > 0,
            "the fail-closed defaults bound a 16-deep same-tenant burst"
        );

        let budget = RunControl::with_timeout(Duration::from_secs(5))
            .expect("test budget has a future deadline");
        let outcome = executor
            .run(Request::new(TenantId(0), b"--!nocheck\nreturn 7", budget))
            .await
            .expect("the executor stays healthy after rejections");
        assert!(!outcome.values.is_empty());
    }
}