Skip to main content

aisimulate_core/replay/
capture.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6/// Seed used by placement implementations that support canonical worker
7/// selection. Random replay never receives this seed.
8pub const CANONICAL_SELECTOR_SEED: u64 = 0xd1a0_5eed;
9
10/// Identity and selection semantics for one replay execution.
11#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
12#[serde(rename_all = "snake_case")]
13pub enum ReplayDeterminism {
14    /// Preserve normal runtime randomness.
15    #[default]
16    Random,
17    /// Use ordinal request UUIDs and the canonical selector seed.
18    CanonicalV1,
19}
20
21impl ReplayDeterminism {
22    /// Return a selector seed only when canonical replay was explicitly
23    /// requested. This prevents deterministic benchmark policy from leaking
24    /// into ordinary simulations.
25    pub const fn selector_seed(self) -> Option<u64> {
26        match self {
27            Self::Random => None,
28            Self::CanonicalV1 => Some(CANONICAL_SELECTOR_SEED),
29        }
30    }
31}
32
33/// Replay-owned controls for optional detailed capture.
34#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
35pub struct ReplayCaptureOptions {
36    #[serde(default)]
37    pub capture_per_request: bool,
38    #[serde(default)]
39    pub capture_lifecycle_evidence: bool,
40    #[serde(default)]
41    pub capture_canonical_evidence: bool,
42    #[serde(default)]
43    pub determinism: ReplayDeterminism,
44}
45
46impl ReplayCaptureOptions {
47    /// Canonical evidence references request records, so enabling it implies
48    /// per-request capture even if the caller did not request a separate
49    /// per-request JSONL file.
50    pub const fn effective_per_request(self) -> bool {
51        self.capture_per_request || self.capture_canonical_evidence
52    }
53}