loopflow 0.9.10

Run steps and flows with coding agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
use std::path::Path;
use std::sync::Arc;
use std::time::Duration;

use anyhow::anyhow;
use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;

use super::common::{create_parallel_wave_run, create_wave_run_with_id, spawn_run_task_with_slot};
use crate::lfd::events::EventHub;
use crate::lfd::executor::cleanup_workspace_worktree;
use crate::lfd::executor::WaveExecutor;
use crate::lfd::id::LfdId;
use crate::lfd::scheduler::Scheduler;
use crate::lfd::store::SharedStore;
use crate::lfd::types::{
    ActivationLog, ActivationOutcome, Event, PendingActivation, Wave, WaveRun, WaveStatus,
};
use crate::ops::{ingest, IngestOptions, NullProgress};

pub const DEFAULT_ACTIVATION_QUEUE_LIMIT: usize = 20;

fn activation_requires_manual_resolution(error: &anyhow::Error) -> bool {
    error
        .to_string()
        .to_ascii_lowercase()
        .contains("manual resolution required")
}

async fn pause_wave_after_activation_conflict(
    store: &SharedStore,
    event_hub: &EventHub,
    wave: &Wave,
    error: &anyhow::Error,
) {
    let Some(mut paused_wave) = store.get_wave(wave.id()).await.ok().flatten() else {
        return;
    };
    if paused_wave.status == WaveStatus::Paused {
        return;
    }
    paused_wave.status = WaveStatus::Paused;
    if let Err(update_error) = store.update_wave(&paused_wave).await {
        tracing::warn!(
            wave_id = %wave.id(),
            error = %update_error,
            "failed to pause wave after activation conflict"
        );
        return;
    }
    tracing::warn!(
        wave_id = %wave.id(),
        error = %error,
        "paused wave after activation conflict to stop retry loop"
    );
    event_hub.send(Event::wave_updated(wave.id().clone()));
}

async fn create_wave_run(
    store: &SharedStore,
    wave: &Wave,
    run_id: &LfdId,
    force_parallel: bool,
    target_branch: Option<&str>,
) -> anyhow::Result<WaveRun> {
    if force_parallel || wave.workers() != 1 {
        create_parallel_wave_run(store, wave, run_id, target_branch).await
    } else {
        create_wave_run_with_id(store, wave, run_id, target_branch).await
    }
}

fn target_branch_ref(target_branch: &str) -> Option<&str> {
    match target_branch {
        "" | "main" => None,
        branch => Some(branch),
    }
}

fn ingest_roadmap_item_for_run(wave: &Wave, run: &WaveRun, item: &str) -> anyhow::Result<()> {
    ingest(
        Path::new(&run.worktree),
        &IngestOptions {
            wave: Some(wave.name().clone()),
            item: Some(item.to_string()),
        },
        &NullProgress,
    )
    .map_err(|err| anyhow!("ingest failed: {err}"))?;

    Ok(())
}

async fn fail_immediate_activation(
    store: &SharedStore,
    event_hub: &EventHub,
    wave: &Wave,
    run: &mut WaveRun,
    error: &anyhow::Error,
) {
    run.status = crate::lfd::types::WaveRunStatus::Failed;
    run.ended_at = Some(time::OffsetDateTime::now_utc());
    run.error = Some(error.to_string());
    let _ = store.update_wave_run(run).await;

    if let Ok(Some(mut stored_wave)) = store.get_wave(wave.id()).await {
        stored_wave.status = WaveStatus::Idle;
        let _ = store.update_wave(&stored_wave).await;
    }

    let _ = cleanup_workspace_worktree(Path::new(&run.worktree));
    event_hub.send(Event::wave_updated(wave.id().clone()));
}

#[derive(Debug, Clone)]
pub struct ActivationEnvelope {
    pub wave_id: LfdId,
    pub trigger_id: Option<LfdId>,
    pub reason: String,
    pub from_sha: String,
    pub to_sha: String,
    pub target_branch: String,
}

impl ActivationEnvelope {
    pub fn new(
        wave_id: &LfdId,
        trigger_id: Option<&LfdId>,
        reason: impl Into<String>,
        from_sha: impl Into<String>,
        to_sha: impl Into<String>,
        target_branch: impl Into<String>,
    ) -> Self {
        Self {
            wave_id: wave_id.clone(),
            trigger_id: trigger_id.cloned(),
            reason: reason.into(),
            from_sha: from_sha.into(),
            to_sha: to_sha.into(),
            target_branch: target_branch.into(),
        }
    }
}

#[derive(Debug, Clone)]
pub struct ImmediateActivation<'a> {
    pub wave: &'a Wave,
    pub flow_override: Option<String>,
    pub roadmap_item: Option<String>,
    pub force_parallel: bool,
    pub envelope: ActivationEnvelope,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EnqueueOutcome {
    Queued,
    Coalesced,
    Dropped,
}

pub fn spawn_activation_dispatcher(
    store: SharedStore,
    executor: WaveExecutor,
    scheduler: Arc<Scheduler>,
    event_hub: EventHub,
    cancel: CancellationToken,
) -> JoinHandle<()> {
    tokio::spawn(async move {
        let mut interval = tokio::time::interval(Duration::from_secs(1));
        loop {
            tokio::select! {
                _ = cancel.cancelled() => {
                    tracing::info!("activation_dispatcher shutting down");
                    break;
                }
                _ = interval.tick() => {
                    dispatch_pending_activations(&store, &executor, &scheduler, &event_hub).await;
                }
            }
        }
    })
}

pub async fn enqueue_pending_activation(
    store: &SharedStore,
    event_hub: &EventHub,
    envelope: ActivationEnvelope,
) -> Option<EnqueueOutcome> {
    match store
        .get_pending_for_trigger(&envelope.wave_id, envelope.trigger_id.as_ref())
        .await
    {
        Ok(Some(mut existing)) => {
            existing.reason = envelope.reason.clone();
            if !envelope.from_sha.is_empty() && existing.from_sha.is_empty() {
                existing.from_sha = envelope.from_sha.clone();
            }
            if !envelope.to_sha.is_empty() {
                existing.to_sha = envelope.to_sha.clone();
            }
            if let Err(err) = store.update_pending_activation(&existing).await {
                tracing::error!(
                    wave_id = %envelope.wave_id,
                    trigger_id = ?envelope.trigger_id,
                    error = %err,
                    "failed to coalesce pending activation"
                );
                return None;
            }
            let queue_depth = store
                .list_pending_activations(&envelope.wave_id)
                .await
                .map(|items| items.len() as u32)
                .unwrap_or_default();
            record_activation_log(
                store,
                event_hub,
                &envelope,
                ActivationOutcome::Coalesced,
                queue_depth,
            )
            .await;
            Some(EnqueueOutcome::Coalesced)
        }
        Ok(None) => {
            let queue_depth = match store.list_pending_activations(&envelope.wave_id).await {
                Ok(items) => items.len(),
                Err(err) => {
                    tracing::error!(
                        wave_id = %envelope.wave_id,
                        trigger_id = ?envelope.trigger_id,
                        error = %err,
                        "failed to inspect pending activation queue"
                    );
                    return None;
                }
            };
            if queue_depth >= DEFAULT_ACTIVATION_QUEUE_LIMIT {
                record_activation_log(
                    store,
                    event_hub,
                    &envelope,
                    ActivationOutcome::Dropped,
                    queue_depth as u32,
                )
                .await;
                return Some(EnqueueOutcome::Dropped);
            }

            let activation = PendingActivation {
                id: LfdId::new(),
                wave_id: envelope.wave_id.clone(),
                trigger_id: envelope.trigger_id.clone(),
                reason: envelope.reason.clone(),
                from_sha: envelope.from_sha.clone(),
                to_sha: envelope.to_sha.clone(),
                queued_at: time::OffsetDateTime::now_utc().unix_timestamp(),
                target_branch: envelope.target_branch.clone(),
            };
            if let Err(err) = store.create_pending_activation(&activation).await {
                tracing::error!(
                    wave_id = %envelope.wave_id,
                    trigger_id = ?envelope.trigger_id,
                    error = %err,
                    "failed to queue pending activation"
                );
                return None;
            }
            record_activation_log(
                store,
                event_hub,
                &envelope,
                ActivationOutcome::Queued,
                (queue_depth + 1) as u32,
            )
            .await;
            Some(EnqueueOutcome::Queued)
        }
        Err(err) => {
            tracing::error!(
                wave_id = %envelope.wave_id,
                trigger_id = ?envelope.trigger_id,
                error = %err,
                "failed to read pending activation for trigger"
            );
            None
        }
    }
}

/// Bypass the activation queue and spawn a run immediately.
///
/// Used for non-serialized (parallel) waves: the trigger creates a run
/// directly without going through the pending activation queue. Returns
/// the WaveRun if a scheduler slot was available.
pub async fn spawn_immediate_activation(
    store: &SharedStore,
    executor: &WaveExecutor,
    scheduler: &Arc<Scheduler>,
    event_hub: &EventHub,
    activation: ImmediateActivation<'_>,
) -> anyhow::Result<Option<WaveRun>> {
    let ImmediateActivation {
        wave,
        flow_override,
        roadmap_item,
        force_parallel,
        envelope,
    } = activation;

    if wave.status() == WaveStatus::Paused {
        return Ok(None);
    }
    if scheduler.has_active_session(wave.id().as_str()) {
        return Ok(None);
    }

    let run_id = LfdId::new();
    let slot_guard = match scheduler.acquire_guard(run_id.as_str()).await {
        Ok(guard) => guard,
        Err(_reason) => {
            // Fall back to queue when scheduler is full.
            let _ = enqueue_pending_activation(store, event_hub, envelope).await;
            return Ok(None);
        }
    };

    let dispatch_log = ActivationLog::new(
        wave.id().clone(),
        envelope.trigger_id.clone(),
        envelope.reason.clone(),
        ActivationOutcome::Dispatched,
    );
    if let Err(err) = store.create_activation_log(&dispatch_log).await {
        tracing::error!(
            wave_id = %wave.id(),
            trigger_id = ?envelope.trigger_id,
            error = %err,
            "failed to write immediate activation dispatch log"
        );
        return Err(anyhow!("failed to write activation log: {err}"));
    }

    let target = target_branch_ref(&envelope.target_branch);
    let mut run = match create_wave_run(store, wave, &run_id, force_parallel, target).await {
        Ok(run) => run,
        Err(err) => {
            tracing::error!(
                wave_id = %wave.id(),
                error = %err,
                "failed to create wave run for immediate activation"
            );
            if activation_requires_manual_resolution(&err) {
                pause_wave_after_activation_conflict(store, event_hub, wave, &err).await;
            }
            return Err(err);
        }
    };
    if let Some(flow_override) = flow_override {
        run.snapshot.flow = flow_override;
    }
    if let Some(item) = roadmap_item {
        // `ingest` is sync and, when PM is enabled, calls `block_on_pm` which
        // tries to spin up a fresh Tokio runtime. Running it directly on the
        // axum handler's async worker thread panics with "Cannot start a
        // runtime from within a runtime" and leaves the HTTP response dangling.
        // Punt to the blocking pool where `block_on` is legal.
        let wave_for_ingest = wave.clone();
        let run_for_ingest = run.clone();
        let item_for_log = item.clone();
        let ingest_result = tokio::task::spawn_blocking(move || {
            ingest_roadmap_item_for_run(&wave_for_ingest, &run_for_ingest, &item)
        })
        .await
        .unwrap_or_else(|join_err| Err(anyhow!("ingest task panicked: {join_err}")));
        if let Err(err) = ingest_result {
            tracing::error!(
                wave_id = %wave.id(),
                run_id = %run.id,
                item = %item_for_log,
                error = %err,
                "failed targeted ingest before immediate activation"
            );
            fail_immediate_activation(store, event_hub, wave, &mut run, &err).await;
            return Err(err);
        }
    }
    run.target_branch = envelope.target_branch.clone();
    run.activation_log_id = Some(dispatch_log.id.clone());
    if let Err(err) = store.update_wave_run(&run).await {
        tracing::error!(
            wave_id = %wave.id(),
            run_id = %run.id,
            error = %err,
            "failed to attach activation log to immediate run"
        );
    }

    spawn_run_task_with_slot(
        store.clone(),
        executor.clone(),
        event_hub.clone(),
        run.clone(),
        slot_guard,
    );
    Ok(Some(run))
}

pub async fn dispatch_pending_activations(
    store: &SharedStore,
    executor: &WaveExecutor,
    scheduler: &Arc<Scheduler>,
    event_hub: &EventHub,
) {
    let waves = match store.list_waves(None).await {
        Ok(waves) => waves,
        Err(err) => {
            tracing::error!(error = %err, "failed to list waves for activation dispatch");
            return;
        }
    };

    for wave in waves {
        let _ = dispatch_wave_if_ready(store, executor, scheduler, event_hub, &wave).await;
    }
}

pub async fn dispatch_wave_if_ready(
    store: &SharedStore,
    executor: &WaveExecutor,
    scheduler: &Arc<Scheduler>,
    event_hub: &EventHub,
    wave: &Wave,
) -> Option<WaveRun> {
    if wave.status() == WaveStatus::Paused {
        return None;
    }
    if scheduler.has_active_session(wave.id().as_str()) {
        return None;
    }
    let active_runs = match store.count_active_wave_runs(wave.id()).await {
        Ok(count) => count,
        Err(err) => {
            tracing::error!(wave_id = %wave.id(), error = %err, "failed to count active wave runs");
            return None;
        }
    };
    if active_runs >= wave.workers() {
        return None;
    }

    let pending = match store.list_pending_activations(wave.id()).await {
        Ok(mut pending) => {
            pending.sort_by_key(|activation| activation.queued_at);
            pending
        }
        Err(err) => {
            tracing::error!(wave_id = %wave.id(), error = %err, "failed to list pending activations");
            return None;
        }
    };
    let activation = pending.into_iter().next()?;

    let run_id = LfdId::new();
    let slot_guard = match scheduler.acquire_guard(run_id.as_str()).await {
        Ok(guard) => guard,
        Err(reason) => {
            tracing::debug!(wave_id = %wave.id(), reason = %reason, "scheduler at capacity; activation dispatch deferred");
            return None;
        }
    };

    let dispatch_log = ActivationLog::new(
        wave.id().clone(),
        activation.trigger_id.clone(),
        activation.reason.clone(),
        ActivationOutcome::Dispatched,
    );
    if let Err(err) = store.create_activation_log(&dispatch_log).await {
        tracing::error!(
            wave_id = %wave.id(),
            trigger_id = ?activation.trigger_id,
            error = %err,
            "failed to write activation dispatch log"
        );
        return None;
    }

    let trigger_flow_override = match &activation.trigger_id {
        Some(trigger_id) => store
            .get_trigger(trigger_id)
            .await
            .ok()
            .flatten()
            .and_then(|trigger| trigger.flow),
        None => None,
    };

    let target = target_branch_ref(&activation.target_branch);
    let mut run = match create_wave_run(store, wave, &run_id, false, target).await {
        Ok(run) => run,
        Err(err) => {
            tracing::error!(wave_id = %wave.id(), error = %err, "failed to create wave run for pending activation");
            if activation_requires_manual_resolution(&err) {
                pause_wave_after_activation_conflict(store, event_hub, wave, &err).await;
            }
            return None;
        }
    };
    if let Some(flow_override) = trigger_flow_override {
        run.snapshot.flow = flow_override;
    }
    run.target_branch = activation.target_branch.clone();
    run.activation_log_id = Some(dispatch_log.id.clone());
    if let Err(err) = store.update_wave_run(&run).await {
        tracing::error!(wave_id = %wave.id(), run_id = %run.id, error = %err, "failed to attach activation log to run");
    }

    if let Err(err) = store.delete_pending_activation_by_id(&activation.id).await {
        tracing::error!(
            wave_id = %wave.id(),
            activation_id = %activation.id,
            error = %err,
            "failed to delete dispatched pending activation"
        );
    }

    spawn_run_task_with_slot(
        store.clone(),
        executor.clone(),
        event_hub.clone(),
        run.clone(),
        slot_guard,
    );
    Some(run)
}

async fn record_activation_log(
    store: &SharedStore,
    event_hub: &EventHub,
    envelope: &ActivationEnvelope,
    outcome: ActivationOutcome,
    queue_depth: u32,
) {
    let log = ActivationLog::new(
        envelope.wave_id.clone(),
        envelope.trigger_id.clone(),
        envelope.reason.clone(),
        outcome,
    );
    if let Err(err) = store.create_activation_log(&log).await {
        tracing::error!(
            wave_id = %envelope.wave_id,
            trigger_id = ?envelope.trigger_id,
            error = %err,
            "failed to write activation log"
        );
        return;
    }

    tracing::info!(
        wave_id = %envelope.wave_id,
        trigger_id = ?envelope.trigger_id,
        reason = %envelope.reason,
        queue_depth,
        outcome = outcome.as_str(),
        "activation queue event"
    );

    match outcome {
        ActivationOutcome::Queued => event_hub.send(Event::activation_queued(
            envelope.wave_id.clone(),
            envelope.trigger_id.clone(),
            envelope.reason.clone(),
            queue_depth,
        )),
        ActivationOutcome::Coalesced => event_hub.send(Event::activation_coalesced(
            envelope.wave_id.clone(),
            envelope.trigger_id.clone(),
            envelope.reason.clone(),
            queue_depth,
        )),
        ActivationOutcome::Dropped => event_hub.send(Event::activation_dropped(
            envelope.wave_id.clone(),
            envelope.trigger_id.clone(),
            envelope.reason.clone(),
            queue_depth,
        )),
        ActivationOutcome::Dispatched => {}
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::lfd::store::{open_store, StorageConfig};
    use crate::lfd::types::{Signal, Trigger, Wave, WaveMode};
    use time::OffsetDateTime;

    async fn create_store() -> SharedStore {
        let path = std::env::temp_dir().join(format!("lfd-activation-test-{}.db", LfdId::new()));
        open_store(&StorageConfig::sqlite(path))
            .await
            .map(Arc::new)
            .expect("store")
    }

    async fn create_wave(store: &SharedStore) -> Wave {
        let wave = Wave {
            id: LfdId::new(),
            name: "activation-wave".to_string(),
            repo: ".".to_string(),
            mode: WaveMode::Loop,
            primary_flow: "ship-roadmap".to_string(),
            crons: Vec::new(),
            direction: Vec::new(),
            area: Vec::new(),
            status: WaveStatus::Idle,
            iteration: 0,
            cycle_start_iteration: 0,
            created_at: Some(OffsetDateTime::now_utc()),
            workers: 1,
        };
        store.create_wave(&wave).await.expect("create wave");
        wave
    }

    async fn create_trigger(store: &SharedStore, wave_id: &LfdId) -> Trigger {
        let trigger = Trigger {
            id: LfdId::new(),
            wave_id: wave_id.clone(),
            source_wave_id: None,
            signal: Signal::Repo,
            flow: None,
            last_main_sha: None,
            last_triggered_at: None,
            created_at: Some(OffsetDateTime::now_utc()),
            enabled: true,
            max_iterations: None,
        };
        store
            .create_trigger(&trigger)
            .await
            .expect("create trigger");
        trigger
    }

    #[tokio::test]
    async fn enqueue_coalesces_pending_activation_for_same_trigger() {
        let store = create_store().await;
        let event_hub = EventHub::new(16);
        let mut events = event_hub.subscribe();
        let wave = create_wave(&store).await;
        let trigger = create_trigger(&store, &wave.id).await;

        let first = enqueue_pending_activation(
            &store,
            &event_hub,
            ActivationEnvelope::new(
                &wave.id,
                Some(&trigger.id),
                "watch poll",
                "abc",
                "def",
                "main",
            ),
        )
        .await;
        let second = enqueue_pending_activation(
            &store,
            &event_hub,
            ActivationEnvelope::new(
                &wave.id,
                Some(&trigger.id),
                "push webhook",
                "def",
                "fed",
                "main",
            ),
        )
        .await;

        assert_eq!(first, Some(EnqueueOutcome::Queued));
        assert_eq!(second, Some(EnqueueOutcome::Coalesced));

        let pending = store
            .list_pending_activations(&wave.id)
            .await
            .expect("list pending");
        assert_eq!(pending.len(), 1);
        assert_eq!(pending[0].to_sha, "fed");

        let queued = events.try_recv().expect("queued event");
        let coalesced = events.try_recv().expect("coalesced event");
        assert!(matches!(queued, Event::ActivationQueued { .. }));
        assert!(matches!(coalesced, Event::ActivationCoalesced { .. }));
    }

    #[tokio::test]
    async fn enqueue_drops_when_wave_queue_is_full() {
        let store = create_store().await;
        let event_hub = EventHub::new(64);
        let wave = create_wave(&store).await;

        for _ in 0..DEFAULT_ACTIVATION_QUEUE_LIMIT {
            let trigger = create_trigger(&store, &wave.id).await;
            let outcome = enqueue_pending_activation(
                &store,
                &event_hub,
                ActivationEnvelope::new(&wave.id, Some(&trigger.id), "fill queue", "", "", "main"),
            )
            .await;
            assert_eq!(outcome, Some(EnqueueOutcome::Queued));
        }

        let overflow_trigger = create_trigger(&store, &wave.id).await;
        let outcome = enqueue_pending_activation(
            &store,
            &event_hub,
            ActivationEnvelope::new(
                &wave.id,
                Some(&overflow_trigger.id),
                "overflow",
                "",
                "",
                "main",
            ),
        )
        .await;
        assert_eq!(outcome, Some(EnqueueOutcome::Dropped));

        let pending = store
            .list_pending_activations(&wave.id)
            .await
            .expect("list pending");
        assert_eq!(pending.len(), DEFAULT_ACTIVATION_QUEUE_LIMIT);
    }
}