astrs_node_api/node/mod.rs
1//! [`Node`] — the flagship surface of blueprint §9.1.
2//!
3//! ```no_run
4//! use astrs_node_api::prelude::*;
5//!
6//! fn main() -> Result<(), NodeError> {
7//! let (mut node, mut events) = Node::init_from_env()?;
8//! let mut echo = node.raw_output("echo")?;
9//!
10//! while let Some(event) = events.recv() {
11//! match event {
12//! Event::Input { id, data, meta } if id == "frames" => {
13//! echo.send_bytes(data.to_vec(), meta.follow())?;
14//! }
15//! Event::Stop(_) => break,
16//! _ => {}
17//! }
18//! }
19//! Ok(())
20//! }
21//! ```
22//!
23//! # Four ways in
24//!
25//! | Constructor | For |
26//! |---|---|
27//! | [`Node::init_from_env`] | A node the daemon spawned (§24.2's `ASTRS_NODE_CONFIG`) |
28//! | [`Node::builder`] | A node that wants to override the id, endpoint or token |
29//! | [`Node::init_from_node_id`] | A `path: dynamic` node attaching itself (§8.3) |
30//! | [`Node::init_testing`] | A unit test, against an in-process daemon |
31//!
32//! All four produce the same `(Node, EventStream)` pair, so a node's body does
33//! not know which one started it — which is exactly what makes
34//! [`Node::init_testing`] able to exercise the real thing.
35//!
36//! # Ownership
37//!
38//! [`Node`] owns the session; [`crate::EventStream`] owns the
39//! reading end. Dropping the node closes its outputs and ends the session;
40//! dropping the stream tells the daemon to stop queueing (§7.3
41//! `EventStreamDropped`). Either can be dropped first.
42
43pub mod builder;
44pub mod extension;
45pub mod init;
46pub mod logging;
47
48use std::collections::BTreeSet;
49use std::sync::Arc;
50use std::time::Duration;
51
52use astrs_data::AstrsMessage;
53use astrs_time::HlcTimestamp;
54use astrs_wire::{
55 DataId, DataflowId, NodeId, NodeRequest, NodeSpawnSpec, PortRef, SessionId, StopCause,
56};
57
58use astrs_scheduler::QueueSnapshot;
59
60use crate::env::TypeCheckMode;
61use crate::error::{NodeError, Result};
62use crate::events::EventStream;
63use crate::events::source::StreamStats;
64use crate::orphan::OrphanGuard;
65use crate::output::{Output, RawOutput};
66use crate::session::pump::SessionTasks;
67use crate::session::{SessionShared, SessionStats};
68
69/// How long [`Node`]'s drop waits for the writer to flush what it queued.
70///
71/// The messages are already in the outgoing channel, so this is a scheduling
72/// wait rather than a transfer: it expires only if the writer is wedged or
73/// the daemon has stopped reading, and in either case a departing node cannot
74/// improve matters by waiting longer.
75const SHUTDOWN_DRAIN: Duration = Duration::from_secs(5);
76
77pub use builder::NodeBuilder;
78pub use init::Registration;
79
80/// A live participant in a dataflow.
81pub struct Node {
82 /// The session this node speaks through.
83 shared: Arc<SessionShared>,
84 /// The reader and writer tasks.
85 tasks: Option<SessionTasks>,
86 /// How strictly typed handles check declared types (§9.2).
87 type_check: TypeCheckMode,
88 /// The orphan guard, when one was requested (§4.2).
89 orphan: Option<OrphanGuard>,
90 /// Which outputs have handed out a handle, so a second one is refused.
91 opened: BTreeSet<DataId>,
92}
93
94impl core::fmt::Debug for Node {
95 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96 f.debug_struct("Node")
97 .field("id", &self.shared.node)
98 .field("dataflow", &self.shared.dataflow)
99 .field("generation", &self.shared.generation)
100 .field("type_check", &self.type_check)
101 .field("orphan_guard", &self.orphan.is_some())
102 .finish_non_exhaustive()
103 }
104}
105
106impl Node {
107 /// Builds a node around a completed registration.
108 #[must_use]
109 pub fn from_registration(
110 registration: Registration,
111 type_check: TypeCheckMode,
112 orphan: Option<OrphanGuard>,
113 ) -> (Self, EventStream) {
114 let Registration {
115 shared,
116 events,
117 tasks,
118 spec: _,
119 } = registration;
120 (
121 Self {
122 shared,
123 tasks: Some(tasks),
124 type_check,
125 orphan,
126 opened: BTreeSet::new(),
127 },
128 events,
129 )
130 }
131
132 /// Joins a dataflow using the `ASTRS_NODE_CONFIG` blob (§24.2).
133 ///
134 /// # Errors
135 ///
136 /// [`NodeError::Config`] when the blob is missing or malformed, and
137 /// whatever [`NodeBuilder::connect`] reports.
138 pub fn init_from_env() -> Result<(Self, EventStream)> {
139 NodeBuilder::from_env()?.connect()
140 }
141
142 /// A builder for a node that needs to override something.
143 #[must_use]
144 pub fn builder() -> NodeBuilder {
145 NodeBuilder::new()
146 }
147
148 /// Attaches a `path: dynamic` node under `node_id` (§8.3).
149 ///
150 /// # Errors
151 ///
152 /// As [`NodeBuilder::connect`].
153 pub fn init_from_node_id(node_id: impl AsRef<str>) -> Result<(Self, EventStream)> {
154 NodeBuilder::new().node_id(node_id)?.dynamic(true).connect()
155 }
156
157 /// Spins an in-process mock daemon and joins it (§9.1's `init_testing`).
158 ///
159 /// # Errors
160 ///
161 /// [`NodeError::Testing`] when the harness cannot be started.
162 pub fn init_testing() -> Result<crate::testing::TestHarness> {
163 crate::testing::TestHarness::start()
164 }
165
166 // ---------------------------------------------------------------- ports
167
168 /// A typed publishing handle for `output` (§9.1).
169 ///
170 /// # Errors
171 ///
172 /// [`NodeError::UnknownOutput`] when the node does not declare it or a
173 /// handle is already open, and [`NodeError::TypeMismatch`] when the
174 /// port's declared URN disagrees with `T` under
175 /// `ASTRS_TYPE_CHECK=error` (§9.2).
176 pub fn output<T: AstrsMessage>(&mut self, output: impl AsRef<str>) -> Result<Output<T>> {
177 let id = DataId::new(output.as_ref())?;
178 self.check_declared_type(&id, T::URN)?;
179 Ok(Output::new(self.claim_output(id)?))
180 }
181
182 /// An untyped publishing handle for `output`.
183 ///
184 /// # Errors
185 ///
186 /// [`NodeError::UnknownOutput`] when the node does not declare it or a
187 /// handle is already open.
188 pub fn raw_output(&mut self, output: impl AsRef<str>) -> Result<RawOutput> {
189 let id = DataId::new(output.as_ref())?;
190 self.claim_output(id)
191 }
192
193 /// The producer port behind one of this node's inputs.
194 ///
195 /// `Event::Input` deliberately does not carry it — a node's input has one
196 /// source in the manifest, so it is a property of the wiring rather than
197 /// of the message.
198 #[must_use]
199 pub fn input_source(&self, input: impl AsRef<str>) -> Option<PortRef> {
200 let id = DataId::new(input.as_ref()).ok()?;
201 self.shared.input_source(&id)
202 }
203
204 /// Asks the daemon for the next event(s) explicitly (§7.3 `NextEvent`).
205 ///
206 /// The node API is push-based: a node that simply reads its stream never
207 /// needs this, and the daemon delivers as messages arrive. A node running
208 /// its *own* event loop — an operator host, a bridge draining another
209 /// runtime — uses it to control when work arrives, which is exactly what
210 /// the verb exists for.
211 ///
212 /// `max_batch` bounds how many events one answer may carry; `timeout`
213 /// asks the daemon to answer with an empty batch rather than blocking
214 /// forever.
215 ///
216 /// # Errors
217 ///
218 /// [`NodeError::DaemonGone`] once the session has ended.
219 pub fn request_events(&self, max_batch: u32, timeout: Option<Duration>) -> Result<()> {
220 self.shared.send_request(NodeRequest::NextEvent {
221 timeout: timeout.map(astrs_wire::DurationMs::from_duration),
222 max_batch: max_batch.max(1),
223 })
224 }
225
226 /// [`Node::request_events`] with the protocol's default batch size.
227 ///
228 /// # Errors
229 ///
230 /// As [`Node::request_events`].
231 pub fn request_next_event(&self) -> Result<()> {
232 self.request_events(astrs_wire::DEFAULT_EVENT_BATCH, None)
233 }
234
235 /// Closes every output at once, which is what a node does as it exits
236 /// (§7.3 `CloseOutputs`).
237 ///
238 /// # Errors
239 ///
240 /// [`NodeError::DaemonGone`] once the session has ended.
241 pub fn close_outputs(&mut self) -> Result<()> {
242 self.shared.send_request(NodeRequest::CloseOutputs {
243 outputs: Vec::new(),
244 })
245 }
246
247 // ------------------------------------------------------- introspection
248
249 /// The node's id (§9.1).
250 #[must_use]
251 pub fn id(&self) -> &NodeId {
252 &self.shared.node
253 }
254
255 /// The dataflow this node belongs to.
256 #[must_use]
257 pub fn dataflow_id(&self) -> DataflowId {
258 self.shared.dataflow
259 }
260
261 /// The connection's session id (§7.2).
262 #[must_use]
263 pub fn session_id(&self) -> SessionId {
264 self.shared.session
265 }
266
267 /// The node's effective specification, as the daemon assigned it.
268 #[must_use]
269 pub fn descriptor(&self) -> &NodeSpawnSpec {
270 &self.shared.spec
271 }
272
273 /// Whether this process is a restart of a node that ran before (§12).
274 #[must_use]
275 pub fn is_restart(&self) -> bool {
276 self.shared.generation > 0
277 }
278
279 /// How many times this node has been restarted; `0` on a first spawn.
280 #[must_use]
281 pub fn restart_count(&self) -> u64 {
282 self.shared.generation
283 }
284
285 /// This node's incarnation counter — the same number as
286 /// [`Node::restart_count`], under the name the wire uses.
287 #[must_use]
288 pub fn generation(&self) -> u64 {
289 self.shared.generation
290 }
291
292 /// The next hybrid-logical-clock reading (§4.3).
293 #[must_use]
294 pub fn hlc_now(&self) -> HlcTimestamp {
295 self.shared.hlc_now()
296 }
297
298 /// A fresh metadata block stamped with [`Node::hlc_now`].
299 #[must_use]
300 pub fn metadata(&self) -> astrs_wire::Metadata {
301 astrs_wire::Metadata::new(self.hlc_now())
302 }
303
304 /// How strictly typed handles check declared types (§9.2).
305 #[must_use]
306 pub const fn type_check(&self) -> TypeCheckMode {
307 self.type_check
308 }
309
310 /// A snapshot of the session's counters.
311 #[must_use]
312 pub fn stats(&self) -> SessionStats {
313 self.shared.stats()
314 }
315
316 /// The inputs this node reads, in name order.
317 #[must_use]
318 pub fn input_ids(&self) -> Vec<DataId> {
319 self.shared.source.input_ids()
320 }
321
322 /// A point-in-time reading of one input's queue (§11.2).
323 ///
324 /// The counters `astrs list` and the TUI show per node: depth, how many
325 /// of those are eviction-immune, and how many messages the policy has
326 /// dropped.
327 #[must_use]
328 pub fn queue_snapshot(&self, input: impl AsRef<str>) -> Option<QueueSnapshot> {
329 let id = DataId::new(input.as_ref()).ok()?;
330 self.shared.source.queue_snapshot(&id)
331 }
332
333 /// Every input's queue counters, in name order.
334 #[must_use]
335 pub fn queue_snapshots(&self) -> Vec<(DataId, QueueSnapshot)> {
336 self.shared
337 .source
338 .input_ids()
339 .into_iter()
340 .filter_map(|id| {
341 self.shared
342 .source
343 .queue_snapshot(&id)
344 .map(|snapshot| (id, snapshot))
345 })
346 .collect()
347 }
348
349 /// The event stream's own counters.
350 #[must_use]
351 pub fn stream_stats(&self) -> StreamStats {
352 self.shared.source.stats()
353 }
354
355 /// Which plane every known output is publishing on (§6.3).
356 ///
357 /// The producer end of the route. [`Node::input_planes`] is the consumer
358 /// end, and the two are kept apart because an id names an output *or* an
359 /// input, never both, and a node with an `image` input and an `image`
360 /// output would otherwise have two rows nobody could tell apart.
361 #[must_use]
362 pub fn route_planes(&self) -> Vec<(DataId, crate::session::RoutePlane)> {
363 self.shared.routes.planes()
364 }
365
366 /// Which plane every input the daemon has spoken about is read from
367 /// (§6.3).
368 ///
369 /// An input reaches [`RoutePlane::Shm`](crate::session::RoutePlane::Shm)
370 /// on its own: the daemon says which segment feeds it, the session
371 /// attaches, and the payloads that arrive are
372 /// [`Payload::is_zero_copy`](crate::Payload::is_zero_copy). An input the
373 /// daemon has never mentioned does not appear at all.
374 #[must_use]
375 pub fn input_planes(&self) -> Vec<(DataId, crate::session::RoutePlane)> {
376 self.shared.inputs.planes()
377 }
378
379 /// Which plane one input is read from (§6.3).
380 ///
381 /// [`RoutePlane::Daemon`](crate::session::RoutePlane::Daemon) for an input
382 /// that is not on a ring, including one this node does not declare.
383 #[must_use]
384 pub fn input_plane(&self, input: impl AsRef<str>) -> crate::session::RoutePlane {
385 match DataId::new(input.as_ref()) {
386 Ok(id) => self.shared.inputs.plane(&id),
387 Err(_) => crate::session::RoutePlane::Daemon,
388 }
389 }
390
391 /// What the consumer-side plane has done: attachments, samples read
392 /// straight out of a ring, and the §6.2 fallbacks (§6.3, §13).
393 #[must_use]
394 pub fn input_plane_stats(&self) -> crate::session::InputPlaneStats {
395 self.shared.inputs.stats()
396 }
397
398 /// The segment one input reads from, when it is on a ring (§6.2).
399 ///
400 /// The geometry the daemon chose — name, generation, slot count and slot
401 /// size — which is what a probe needs to say whether the addresses it saw
402 /// cycled through the ring.
403 #[must_use]
404 pub fn input_segment(&self, input: impl AsRef<str>) -> Option<astrs_wire::ShmSegmentSpec> {
405 let id = DataId::new(input.as_ref()).ok()?;
406 self.shared.inputs.segment(&id)
407 }
408
409 /// Whether the orphan guard has observed its parent's disappearance
410 /// (§4.2).
411 #[must_use]
412 pub fn is_orphaned(&self) -> bool {
413 self.orphan.as_ref().is_some_and(OrphanGuard::has_fired)
414 }
415
416 /// Whether the session has ended.
417 #[must_use]
418 pub fn is_closed(&self) -> bool {
419 self.shared.is_closed()
420 }
421
422 /// The shared session state, for the patterns and the testing harness.
423 #[must_use]
424 pub fn session(&self) -> &Arc<SessionShared> {
425 &self.shared
426 }
427
428 // ------------------------------------------------------------ shutdown
429
430 /// Closes every output and ends the session.
431 ///
432 /// Called by [`Drop`]; explicit when a node wants to observe the result.
433 ///
434 /// # Errors
435 ///
436 /// [`NodeError::DaemonGone`] when the session had already ended, which is
437 /// not a failure so much as a statement of fact.
438 pub fn shutdown(&mut self) -> Result<()> {
439 if self.shared.is_closed() {
440 return Ok(());
441 }
442 // Order matters: the close has to be *queued* before the sentinel,
443 // and the sentinel before the session is marked closed — otherwise
444 // `try_send` would refuse them and a consumer would never learn that
445 // this producer finished.
446 let result = self.close_outputs();
447 let _ = self.shared.request_drain();
448 self.shared.close();
449 result
450 }
451
452 /// Waits for the session's tasks to finish, after [`Node::shutdown`].
453 ///
454 /// Used by the testing harness to make shutdown deterministic.
455 pub async fn join(&mut self) {
456 if let Some(tasks) = self.tasks.take() {
457 tasks.join().await;
458 }
459 }
460
461 /// This node's private `drain_writer`'s safe-to-call-from-anywhere
462 /// twin: waits, asynchronously, for the writer task to finish
463 /// sending everything already queued (typically right after
464 /// [`Node::shutdown`] or a last `RawOutput::send_batch`), bounded by
465 /// the same `SHUTDOWN_DRAIN` timeout.
466 ///
467 /// `drain_writer` exists for exactly one caller — [`Drop`] — which
468 /// cannot `.await`, so on a current-thread runtime it can only bail
469 /// out rather than risk blocking that runtime's one worker on the
470 /// very task that has to do the flushing (see its own docs for the
471 /// loss that leaves open: the M1 pipeline losing its last frame on
472 /// one run in twenty). A caller that is *already* inside an async
473 /// context — a node built with [`NodeBuilder::connect_async`], which
474 /// is precisely a caller for whom blocking was never on the table —
475 /// has no such excuse: awaiting the writer here is cooperative, not
476 /// blocking, and closes the gap `drain_writer` cannot on exactly the
477 /// runtime flavor that gap matters most on.
478 ///
479 /// Only the writer is awaited, matching `drain_writer`: the reader
480 /// lives until the *daemon* closes the socket, and a caller flushing
481 /// its own outputs has no reason to wait for that. Idempotent —
482 /// calling this (or letting the node drop) again afterward is a
483 /// no-op, since the tasks are taken once.
484 pub async fn flush_outputs(&mut self) {
485 let Some(tasks) = self.tasks.take() else {
486 return;
487 };
488 let _ = tokio::time::timeout(SHUTDOWN_DRAIN, tasks.writer).await;
489 // `tasks.reader` (not moved above) drops here, detaching rather
490 // than aborting it — see `drain_writer`'s identical reasoning.
491 }
492
493 /// Waits for the writer to send everything [`Node::shutdown`] queued.
494 ///
495 /// [`Node::shutdown`] only *queues* the output closures and the drain
496 /// sentinel; the writer task is what puts them on the socket, and nothing
497 /// waited for it. A node that published and then returned from `main`
498 /// therefore raced its own runtime shutdown — [`crate::runtime`]'s owned
499 /// runtime detaches its workers rather than joining them — and messages
500 /// it had successfully sent were lost before reaching the daemon.
501 /// Observed as the M1 pipeline recording 11 of its 12 frames on roughly
502 /// one run in twenty, with the daemon confirming it was never given the
503 /// twelfth.
504 ///
505 /// Only the writer is awaited. The reader lives until the *daemon* closes
506 /// the socket, and a departing node has no reason to wait for that.
507 fn drain_writer(&mut self) {
508 let Some(tasks) = self.tasks.take() else {
509 return;
510 };
511 if !self.shared.runtime.can_block() {
512 // This thread is a current-thread runtime's only worker, so
513 // blocking here would deadlock the very task that has to do the
514 // flushing. Dropping the handles detaches those tasks rather than
515 // aborting them, which still leaves them able to finish.
516 return;
517 }
518 let runtime = self.shared.runtime.clone();
519 let _ = runtime.block_on("Node::drop", "Node::join", async move {
520 let _ = tokio::time::timeout(SHUTDOWN_DRAIN, tasks.writer).await;
521 });
522 }
523
524 /// The stop cause a node should report for `error`, or `None` when it is
525 /// not an ending.
526 #[must_use]
527 pub fn stop_cause_of(error: &NodeError) -> Option<StopCause> {
528 error.stop_cause()
529 }
530
531 // ------------------------------------------------------------- private
532
533 /// Hands out a handle for `output`, refusing a second one.
534 fn claim_output(&mut self, id: DataId) -> Result<RawOutput> {
535 if !self.shared.spec.outputs.is_empty() && !self.shared.declares_output(&id) {
536 return Err(NodeError::UnknownOutput { output: id });
537 }
538 if !self.opened.insert(id.clone()) {
539 return Err(NodeError::UnknownOutput { output: id });
540 }
541 Ok(RawOutput::new(Arc::clone(&self.shared), id))
542 }
543
544 /// Applies the §9.2 type-check policy to a typed handle.
545 fn check_declared_type(&self, id: &DataId, requested: &str) -> Result<()> {
546 if !self.type_check.is_enabled() {
547 return Ok(());
548 }
549 let Some(declared) = self
550 .shared
551 .spec
552 .output(id)
553 .and_then(|spec| spec.type_urn.as_ref())
554 else {
555 return Ok(());
556 };
557 if declared.base() == requested || declared.as_str() == requested {
558 return Ok(());
559 }
560 let mismatch = NodeError::TypeMismatch {
561 port: id.clone(),
562 declared: declared.as_str().to_owned(),
563 requested: requested.to_owned(),
564 };
565 if self.type_check.is_fatal() {
566 return Err(mismatch);
567 }
568 tracing::warn!(
569 node = %self.shared.node,
570 port = %id,
571 declared = %declared,
572 requested = requested,
573 "port type mismatch (ASTRS_TYPE_CHECK=warn)"
574 );
575 Ok(())
576 }
577
578 /// The default timeout reply-carrying calls use.
579 pub(crate) const fn reply_timeout() -> Duration {
580 crate::session::DEFAULT_REPLY_TIMEOUT
581 }
582}
583
584impl Drop for Node {
585 fn drop(&mut self) {
586 let _ = self.shutdown();
587 self.drain_writer();
588 }
589}
590
591#[cfg(test)]
592mod tests {
593 #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
594
595 use super::*;
596 use crate::message::Vector3;
597 use crate::testing::TestHarness;
598
599 #[test]
600 fn introspection_reports_what_the_daemon_assigned() {
601 let harness = TestHarness::start().unwrap();
602 let node = &harness.node;
603 assert_eq!(node.id().as_str(), TestHarness::DEFAULT_NODE);
604 assert_eq!(node.dataflow_id(), harness.daemon.dataflow());
605 assert!(!node.is_restart());
606 assert_eq!(node.restart_count(), 0);
607 assert_eq!(node.generation(), 0);
608 assert!(!node.is_orphaned());
609 assert!(!node.is_closed());
610 assert_eq!(node.type_check(), TypeCheckMode::Warn);
611 assert!(node.hlc_now() <= node.hlc_now());
612 assert!(format!("{node:?}").contains(TestHarness::DEFAULT_NODE));
613 }
614
615 #[test]
616 fn an_output_handle_is_handed_out_once() {
617 let mut harness = TestHarness::start().unwrap();
618 let first = harness.node.raw_output("out");
619 assert!(first.is_ok());
620 let second = harness.node.raw_output("out");
621 assert!(matches!(second, Err(NodeError::UnknownOutput { .. })));
622 }
623
624 #[test]
625 fn a_typed_handle_carries_its_urn() {
626 let mut harness = TestHarness::start().unwrap();
627 let output = harness
628 .node
629 .output::<Vector3>(TestHarness::DEFAULT_OUTPUT)
630 .unwrap();
631 assert_eq!(output.type_urn(), "std/geometry/v1/Vector3");
632 }
633
634 #[test]
635 fn shutdown_is_idempotent_and_closes_the_session() {
636 let mut harness = TestHarness::start().unwrap();
637 harness.node.shutdown().unwrap();
638 assert!(harness.node.is_closed());
639 harness.node.shutdown().unwrap();
640 }
641
642 #[test]
643 fn a_node_can_read_its_own_queue_counters() {
644 let mut harness = TestHarness::start().unwrap();
645 assert_eq!(
646 harness.node.input_ids(),
647 vec![astrs_wire::DataId::new(TestHarness::DEFAULT_INPUT).unwrap()]
648 );
649 let snapshot = harness
650 .node
651 .queue_snapshot(TestHarness::DEFAULT_INPUT)
652 .expect("the queue");
653 assert_eq!(snapshot.depth, 0);
654 assert_eq!(snapshot.capacity, astrs_wire::DEFAULT_QUEUE_SIZE);
655 assert!(harness.node.queue_snapshot("absent").is_none());
656 assert_eq!(harness.node.queue_snapshots().len(), 1);
657 assert_eq!(harness.node.stream_stats().delivered, 0);
658
659 harness.feed(vec![1]).unwrap();
660 let event = harness.next_event().unwrap();
661 assert!(event.is_input());
662 assert_eq!(harness.node.stream_stats().delivered, 1);
663 }
664
665 #[test]
666 fn the_reply_timeout_is_the_session_default() {
667 assert_eq!(Node::reply_timeout(), crate::session::DEFAULT_REPLY_TIMEOUT);
668 assert_eq!(
669 Node::stop_cause_of(&NodeError::Stopped),
670 Some(StopCause::Requested)
671 );
672 }
673}