Skip to main content

agent_queue/
events.rs

1use serde::{Deserialize, Serialize};
2
3// ── Phase status: compatibility / migration-only ──
4//
5// All event types below use `trace_id: Option<String>` and `attempt_count: Option<u32>`
6// for backward compatibility. The canonical replacements are:
7//   - `trace_ctx: Option<stack_ids::TraceCtx>` (for trace_id)
8//   - `attempt_id: Option<stack_ids::AttemptId>` (for attempt identity)
9//   - `trial_id: Option<stack_ids::TrialId>` (for per-execution identity)
10//
11// Use `stack_ids::TraceCtx::from_legacy_trace_id()` to convert trace IDs.
12// The `attempt_count: u32` counter semantics map to one `AttemptId` per
13// re-enqueue (queue is the retry owner), with each re-enqueue creating
14// a new logical retry family.
15//
16// Removal condition: replaced when all event consumers migrate to canonical types.
17
18/// Emitted when a job starts executing.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct JobStartedEvent {
22    pub job_id: String,
23    /// **Deprecated — Phase status: compatibility / migration-only.**
24    /// Use [`trace_ctx`](Self::trace_ctx) instead.
25    /// Removal condition: removed when all event consumers migrate to `TraceCtx`.
26    #[deprecated(note = "Use trace_ctx instead. Will be removed when all consumers migrate.")]
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub trace_id: Option<String>,
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub worker_id: Option<String>,
31    /// **Deprecated — Phase status: compatibility / migration-only.**
32    /// Use [`attempt_id`](Self::attempt_id) / [`trial_id`](Self::trial_id) instead.
33    /// Removal condition: removed when all event consumers migrate to `AttemptId`/`TrialId`.
34    #[deprecated(
35        note = "Use attempt_id/trial_id instead. Will be removed when all consumers migrate."
36    )]
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub attempt_count: Option<u32>,
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub status: Option<String>,
41    /// Canonical trace context (replaces `trace_id`).
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub trace_ctx: Option<stack_ids::TraceCtx>,
44    /// Canonical attempt identity — one per re-enqueue.
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub attempt_id: Option<stack_ids::AttemptId>,
47    /// Canonical trial identity — one per concrete execution.
48    #[serde(default, skip_serializing_if = "Option::is_none")]
49    pub trial_id: Option<stack_ids::TrialId>,
50}
51
52/// Emitted when a job completes successfully.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct JobCompletedEvent {
56    pub job_id: String,
57    pub output: Option<String>,
58    /// **Deprecated — Phase status: compatibility / migration-only.**
59    /// Use [`trace_ctx`](Self::trace_ctx) instead.
60    /// Removal condition: removed when all event consumers migrate to `TraceCtx`.
61    #[deprecated(note = "Use trace_ctx instead. Will be removed when all consumers migrate.")]
62    #[serde(default, skip_serializing_if = "Option::is_none")]
63    pub trace_id: Option<String>,
64    #[serde(default, skip_serializing_if = "Option::is_none")]
65    pub worker_id: Option<String>,
66    /// **Deprecated — Phase status: compatibility / migration-only.**
67    /// Use [`attempt_id`](Self::attempt_id) / [`trial_id`](Self::trial_id) instead.
68    /// Removal condition: removed when all event consumers migrate to `AttemptId`/`TrialId`.
69    #[deprecated(
70        note = "Use attempt_id/trial_id instead. Will be removed when all consumers migrate."
71    )]
72    #[serde(default, skip_serializing_if = "Option::is_none")]
73    pub attempt_count: Option<u32>,
74    #[serde(default, skip_serializing_if = "Option::is_none")]
75    pub status: Option<String>,
76    /// Canonical trace context (replaces `trace_id`).
77    #[serde(default, skip_serializing_if = "Option::is_none")]
78    pub trace_ctx: Option<stack_ids::TraceCtx>,
79    /// Canonical attempt identity — one per re-enqueue.
80    #[serde(default, skip_serializing_if = "Option::is_none")]
81    pub attempt_id: Option<stack_ids::AttemptId>,
82    /// Canonical trial identity — one per concrete execution.
83    #[serde(default, skip_serializing_if = "Option::is_none")]
84    pub trial_id: Option<stack_ids::TrialId>,
85}
86
87/// Emitted when a job fails.
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(rename_all = "camelCase")]
90pub struct JobFailedEvent {
91    pub job_id: String,
92    pub error: String,
93    /// **Deprecated — Phase status: compatibility / migration-only.**
94    /// Use [`trace_ctx`](Self::trace_ctx) instead.
95    /// Removal condition: removed when all event consumers migrate to `TraceCtx`.
96    #[deprecated(note = "Use trace_ctx instead. Will be removed when all consumers migrate.")]
97    #[serde(default, skip_serializing_if = "Option::is_none")]
98    pub trace_id: Option<String>,
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub worker_id: Option<String>,
101    /// **Deprecated — Phase status: compatibility / migration-only.**
102    /// Use [`attempt_id`](Self::attempt_id) / [`trial_id`](Self::trial_id) instead.
103    /// Removal condition: removed when all event consumers migrate to `AttemptId`/`TrialId`.
104    #[deprecated(
105        note = "Use attempt_id/trial_id instead. Will be removed when all consumers migrate."
106    )]
107    #[serde(default, skip_serializing_if = "Option::is_none")]
108    pub attempt_count: Option<u32>,
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    pub status: Option<String>,
111    #[serde(default, skip_serializing_if = "Option::is_none")]
112    pub failure_class: Option<String>,
113    #[serde(default, skip_serializing_if = "Option::is_none")]
114    pub next_retry_at: Option<String>,
115    /// Canonical trace context (replaces `trace_id`).
116    #[serde(default, skip_serializing_if = "Option::is_none")]
117    pub trace_ctx: Option<stack_ids::TraceCtx>,
118    /// Canonical attempt identity — one per re-enqueue.
119    #[serde(default, skip_serializing_if = "Option::is_none")]
120    pub attempt_id: Option<stack_ids::AttemptId>,
121    /// Canonical trial identity — one per concrete execution.
122    #[serde(default, skip_serializing_if = "Option::is_none")]
123    pub trial_id: Option<stack_ids::TrialId>,
124}
125
126/// Emitted during job execution to report progress.
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(rename_all = "camelCase")]
129pub struct JobProgressEvent {
130    pub job_id: String,
131    pub current_step: u32,
132    pub total_steps: u32,
133    pub progress: f64,
134    /// **Deprecated — Phase status: compatibility / migration-only.**
135    /// Use [`trace_ctx`](Self::trace_ctx) instead.
136    /// Removal condition: removed when all event consumers migrate to `TraceCtx`.
137    #[deprecated(note = "Use trace_ctx instead. Will be removed when all consumers migrate.")]
138    #[serde(default, skip_serializing_if = "Option::is_none")]
139    pub trace_id: Option<String>,
140    #[serde(default, skip_serializing_if = "Option::is_none")]
141    pub worker_id: Option<String>,
142    /// **Deprecated — Phase status: compatibility / migration-only.**
143    /// Use [`attempt_id`](Self::attempt_id) / [`trial_id`](Self::trial_id) instead.
144    /// Removal condition: removed when all event consumers migrate to `AttemptId`/`TrialId`.
145    #[deprecated(
146        note = "Use attempt_id/trial_id instead. Will be removed when all consumers migrate."
147    )]
148    #[serde(default, skip_serializing_if = "Option::is_none")]
149    pub attempt_count: Option<u32>,
150    #[serde(default, skip_serializing_if = "Option::is_none")]
151    pub status: Option<String>,
152    /// Canonical trace context (replaces `trace_id`).
153    #[serde(default, skip_serializing_if = "Option::is_none")]
154    pub trace_ctx: Option<stack_ids::TraceCtx>,
155    /// Canonical attempt identity — one per re-enqueue.
156    #[serde(default, skip_serializing_if = "Option::is_none")]
157    pub attempt_id: Option<stack_ids::AttemptId>,
158    /// Canonical trial identity — one per concrete execution.
159    #[serde(default, skip_serializing_if = "Option::is_none")]
160    pub trial_id: Option<stack_ids::TrialId>,
161}
162
163/// Emitted when a job is cancelled.
164#[derive(Debug, Clone, Serialize, Deserialize)]
165#[serde(rename_all = "camelCase")]
166pub struct JobCancelledEvent {
167    pub job_id: String,
168    /// **Deprecated — Phase status: compatibility / migration-only.**
169    /// Use [`trace_ctx`](Self::trace_ctx) instead.
170    /// Removal condition: removed when all event consumers migrate to `TraceCtx`.
171    #[deprecated(note = "Use trace_ctx instead. Will be removed when all consumers migrate.")]
172    #[serde(default, skip_serializing_if = "Option::is_none")]
173    pub trace_id: Option<String>,
174    #[serde(default, skip_serializing_if = "Option::is_none")]
175    pub worker_id: Option<String>,
176    /// **Deprecated — Phase status: compatibility / migration-only.**
177    /// Use [`attempt_id`](Self::attempt_id) / [`trial_id`](Self::trial_id) instead.
178    /// Removal condition: removed when all event consumers migrate to `AttemptId`/`TrialId`.
179    #[deprecated(
180        note = "Use attempt_id/trial_id instead. Will be removed when all consumers migrate."
181    )]
182    #[serde(default, skip_serializing_if = "Option::is_none")]
183    pub attempt_count: Option<u32>,
184    #[serde(default, skip_serializing_if = "Option::is_none")]
185    pub status: Option<String>,
186    /// Canonical trace context (replaces `trace_id`).
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub trace_ctx: Option<stack_ids::TraceCtx>,
189    /// Canonical attempt identity — one per re-enqueue.
190    #[serde(default, skip_serializing_if = "Option::is_none")]
191    pub attempt_id: Option<stack_ids::AttemptId>,
192    /// Canonical trial identity — one per concrete execution.
193    #[serde(default, skip_serializing_if = "Option::is_none")]
194    pub trial_id: Option<stack_ids::TrialId>,
195}