Skip to main content

harn_vm/vm/
execution_evidence.rs

1use super::Vm;
2
3impl Vm {
4    /// Enable exact, value-free source-path recording for this VM execution
5    /// tree. Child VMs inherit the same bounded recorder.
6    pub fn enable_flight_recorder(&mut self, max_events: usize) {
7        self.flight_recorder_max_events = Some(max_events.max(1));
8        self.flight_recorder = Some(crate::flight_recorder::FlightRecorder::new(
9            self.execution_id.to_string(),
10            max_events,
11        ));
12    }
13
14    pub(crate) fn prepare_execution_for_top_level(&mut self) {
15        if !self.owns_execution {
16            return;
17        }
18        self.execution_id = crate::observability::execution_scope::mint_execution_scope();
19        self.flight_recorder = self.flight_recorder_max_events.map(|max_events| {
20            crate::flight_recorder::FlightRecorder::new(self.execution_id.to_string(), max_events)
21        });
22    }
23
24    /// Durable identity of the current or most recently completed execution.
25    pub fn execution_id(&self) -> &str {
26        &self.execution_id
27    }
28
29    /// Snapshot the current flight recording without disabling it.
30    pub fn flight_recording(&self) -> Option<crate::flight_recorder::FlightRecording> {
31        self.flight_recorder
32            .as_ref()
33            .map(|recorder| recorder.snapshot())
34    }
35}