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
//! Runtime observer trait and metadata types for workflow telemetry hooks.
//!
//! `RuntimeObserver` is an opt-in interface that receives structured callbacks
//! at key points during graph execution: invocation boundaries, per-node
//! completion, checkpoint operations, and event-bus emissions. All methods
//! have default no-op implementations, so implementors only override the hooks
//! they care about.
//!
//! # Usage
//!
//! Register an observer when building a runner:
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use weavegraph::runtimes::{AppRunner, observer::{RuntimeObserver, NodeFinishMeta}};
//! use weavegraph::app::App;
//!
//! #[derive(Debug)]
//! struct CountingObserver {
//! count: std::sync::atomic::AtomicU64,
//! }
//!
//! impl RuntimeObserver for CountingObserver {
//! fn on_node_finish(&self, meta: &NodeFinishMeta<'_>) {
//! self.count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
//! }
//! }
//!
//! # async fn example(app: App) {
//! let observer = Arc::new(CountingObserver { count: Default::default() });
//! let runner = AppRunner::builder()
//! .app(app)
//! .observer(observer)
//! .build()
//! .await;
//! # }
//! ```
//!
//! # Performance contract
//!
//! Observer hooks are called **synchronously** on the execution thread. They must
//! be fast and non-blocking. Panics inside hooks are caught by the runner, which
//! logs a warning via [`tracing`] and continues execution — the graph is never
//! brought down by an observer failure.
//!
//! # Note on per-node timing in 0.6.0
//!
//! In this release, `step_duration_ms` in [`NodeFinishMeta`] reflects the elapsed
//! time for the **entire superstep** that contained the node, not the per-node
//! wall time. Nodes within the same superstep share the step's duration. Per-node
//! timing would require scheduler-level instrumentation and is planned for a
//! future release.
use fmt;
use RefUnwindSafe;
use crateNodeKind;
// ============================================================================
// Outcome enums
// ============================================================================
/// Outcome of a completed workflow invocation.
/// Outcome of a completed node execution within a superstep.
// ============================================================================
// Metadata structs — all #[non_exhaustive] so fields can be added without
// breaking implementors that destructure them (though &-access is idiomatic).
// ============================================================================
/// Metadata supplied to [`RuntimeObserver::on_invocation_start`].
/// Metadata supplied to [`RuntimeObserver::on_invocation_finish`].
/// Metadata supplied to [`RuntimeObserver::on_node_finish`].
///
/// See [module-level note](self) on per-node timing in 0.6.0.
/// Metadata supplied to [`RuntimeObserver::on_checkpoint_load`].
/// Metadata supplied to [`RuntimeObserver::on_checkpoint_save`].
/// Metadata supplied to [`RuntimeObserver::on_event_bus_emit`].
// ============================================================================
// RuntimeObserver trait
// ============================================================================
/// Observer interface for runtime telemetry hooks.
///
/// Register an implementation with
/// [`AppRunnerBuilder::observer`](crate::runtimes::runner::AppRunnerBuilder::observer).
/// All methods default to no-ops; implement only the callbacks you need.
///
/// # Safety contract
///
/// Implementations **must not panic** — panics are caught by the runner and
/// produce a `tracing::warn!` log entry. The supertrait bound [`RefUnwindSafe`]
/// is required to make this catch-and-continue safe without `AssertUnwindSafe`
/// wrappers at every callsite.
///
/// Implementations must be `Send + Sync` as the runner can share them across
/// async tasks.