Skip to main content

agentmux_srv_core/backend/
drone_run_event.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! A drone run's event stream. It lives in the core so `backend/mps_events.rs` names it without reaching up into
5//! `drone/`; the executor re-exports it under its old path. The wire shape is pinned by
6//! `sagas/prompt_events_tests.rs`.
7
8use serde_json::Value;
9
10/// Streaming events emitted to the frontend during a run.
11#[derive(Debug, Clone, serde::Serialize, ts_rs::TS)]
12#[ts(export, export_to = "../../../frontend/types/rpc/")]
13#[serde(tag = "kind", rename_all = "snake_case")]
14pub enum RunEvent {
15    RunStarted { run_id: String, drone_id: String },
16    BlockStarted { run_id: String, block_id: String },
17    BlockDone {
18        run_id: String,
19        block_id: String,
20        #[ts(type = "unknown")]
21        output: Value,
22    },
23    BlockError {
24        run_id: String,
25        block_id: String,
26        error: String,
27    },
28    RunDone {
29        run_id: String,
30        #[ts(type = "unknown")]
31        output: Value,
32    },
33    RunFailed { run_id: String, error: String },
34    /// The run was taken up again after AgentMux restarted, from checkpoint
35    /// `step`: the blocks before it are not run again.
36    Resumed { run_id: String, step: u32 },
37    /// A step that may already have done its work before the restart was found
38    /// running: the run waits, `needs_attention`, for it to be run again, skipped
39    /// (with an output) or the run cancelled (`resolvedronerun`).
40    NeedsAttention { run_id: String, block_id: String, reason: String },
41    /// The run stopped at a Wait block and holds no process while it waits.
42    /// `resume_at` is the time it goes on (milliseconds since 1970); `on` and
43    /// `key` are for a wait on an event: what it is for, and the key that ends it
44    /// (`resumedronewait`). A restart sends it again for the wait it took up.
45    Waiting {
46        run_id: String,
47        block_id: String,
48        #[serde(skip_serializing_if = "Option::is_none")]
49        #[ts(optional)]
50        resume_at: Option<i64>,
51        #[serde(skip_serializing_if = "Option::is_none")]
52        #[ts(optional)]
53        on: Option<String>,
54        #[serde(skip_serializing_if = "Option::is_none")]
55        #[ts(optional)]
56        key: Option<String>,
57    },
58    /// A Drone block started the drone `drone_id` (saved version `version`, 0 when
59    /// it was never saved) as a child run. Its own events are not sent here.
60    ChildStarted { run_id: String, block_id: String, child_run_id: String, drone_id: String, version: i64 },
61    /// The child run ended: `status` is `done`, `failed` or `cancelled`; `cost_usd`
62    /// is what it spent, which counts against the caller.
63    ChildEnded { run_id: String, block_id: String, child_run_id: String, status: String, cost_usd: f64 },
64    /// The wait at `block_id` is over; `late` when the run was taken up after its time.
65    WaitEnded { run_id: String, block_id: String, late: bool },
66    /// The run's wait was answered: `choice` is `run_again` or `skip`. (A run that
67    /// is cancelled ends with `RunCancelled`.)
68    AttentionAnswered { run_id: String, block_id: String, choice: String },
69    /// The run's state was kept as checkpoint `step` (0 is the start, before any
70    /// block); `block_id` is the block it follows.
71    StepCheckpointed {
72        run_id: String,
73        step: u32,
74        #[serde(skip_serializing_if = "Option::is_none")]
75        #[ts(optional)]
76        block_id: Option<String>,
77    },
78    /// A loop's guard sent the run round again: `iteration` is the pass that is
79    /// starting (the first pass has no event).
80    LoopIteration { run_id: String, block_id: String, iteration: u32 },
81    /// A limit (a loop's iterations, cost or time, a for-each's items, the run's
82    /// dollar cap) stopped something; `block_id` is the block it was met at.
83    /// The run may go on (`on_cap: exit_loop`) or end, as the reason says.
84    CapReached { run_id: String, block_id: String, reason: String },
85    /// The run was stopped on purpose (`cancel_run`): a person, an agent, the
86    /// job's timeout or the job's next run. `reason` says which, in plain words.
87    RunCancelled { run_id: String, reason: String },
88}