Skip to main content

visual_rubric/pool/
config.rs

1use std::ffi::OsString;
2use std::path::PathBuf;
3use std::time::Duration;
4
5#[cfg(feature = "codex-acp")]
6use crate::{
7    DEFAULT_CODEX_ACP_MODEL, DEFAULT_CODEX_ACP_REASONING_EFFORT, RubricEffort,
8    default_codex_acp_binary,
9};
10use crate::{DEFAULT_SYSTEM_PROMPT, RubricOptions};
11
12pub(super) const DEFAULT_SUBMIT_TIMEOUT: Duration = Duration::from_secs(600);
13
14/// Configuration for a [`crate::RubricPool`].
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct PoolConfig {
17    /// Number of worker processes to keep alive.
18    pub workers: usize,
19    /// Number of prompts after which a worker is recycled.
20    pub max_prompts_per_worker: u32,
21    /// Number of retries for recoverable worker or rate-limit failures.
22    pub max_retries: u32,
23    /// Initial retry backoff.
24    pub backoff_base: Duration,
25    /// Maximum retry backoff.
26    pub backoff_cap: Duration,
27    /// Options applied when a submitted job omits an override.
28    pub default_options: RubricOptions,
29    /// Path to the ACP executable.
30    pub codex_acp_binary: PathBuf,
31    /// Extra CLI arguments for the ACP binary.
32    /// When empty, the ACP v1 session advertises and receives model/reasoning
33    /// settings through `session/set_config_option`. Explicit arguments remain
34    /// available for provider launch modes such as `opencode acp`.
35    pub acp_args: Vec<String>,
36    /// Extra environment variables for worker processes.
37    pub extra_env: Vec<(OsString, OsString)>,
38    /// Maximum time to wait for one submitted job.
39    pub submit_timeout: Duration,
40    /// Optional Codex home directory to seed into worker-local homes.
41    #[cfg(feature = "codex-acp")]
42    pub source_codex_home: Option<PathBuf>,
43    /// Optional ACP log capture directories.
44    pub log_capture: Option<LogCaptureConfig>,
45}
46
47impl Default for PoolConfig {
48    fn default() -> Self {
49        Self {
50            workers: 4,
51            max_prompts_per_worker: 50,
52            max_retries: 4,
53            backoff_base: Duration::from_secs(30),
54            backoff_cap: Duration::from_secs(300),
55            default_options: default_pool_options(),
56            #[cfg(feature = "codex-acp")]
57            codex_acp_binary: default_codex_acp_binary(),
58            #[cfg(not(feature = "codex-acp"))]
59            codex_acp_binary: PathBuf::from("opencode"),
60            acp_args: Vec::new(),
61            extra_env: Vec::new(),
62            submit_timeout: DEFAULT_SUBMIT_TIMEOUT,
63            #[cfg(feature = "codex-acp")]
64            source_codex_home: None,
65            log_capture: None,
66        }
67    }
68}
69
70fn default_pool_options() -> RubricOptions {
71    #[cfg(feature = "codex-acp")]
72    {
73        RubricOptions {
74            model: Some(DEFAULT_CODEX_ACP_MODEL.to_string()),
75            effort: Some(RubricEffort::from(DEFAULT_CODEX_ACP_REASONING_EFFORT)),
76            system_prompt: Some(DEFAULT_SYSTEM_PROMPT.to_string()),
77        }
78    }
79    #[cfg(not(feature = "codex-acp"))]
80    {
81        RubricOptions {
82            model: None,
83            effort: None,
84            system_prompt: Some(DEFAULT_SYSTEM_PROMPT.to_string()),
85        }
86    }
87}
88
89/// Directories used to capture logs produced by Codex ACP.
90#[derive(Clone, Debug, PartialEq, Eq)]
91pub struct LogCaptureConfig {
92    /// Temporary root exposed to worker processes through `TMPDIR`.
93    pub temp_dir: PathBuf,
94    /// Destination directory where selected log files are copied.
95    pub output_dir: PathBuf,
96    /// How copied log paths are represented in reports.
97    pub path_mode: LogPathMode,
98}
99
100/// Path representation for copied ACP logs in batch reports.
101#[derive(Clone, Debug, Default, PartialEq, Eq)]
102pub enum LogPathMode {
103    /// Report paths relative to this root when possible.
104    RelativeTo(PathBuf),
105    /// Report absolute paths.
106    #[default]
107    Absolute,
108}
109
110/// Snapshot of pool execution counters.
111#[derive(Clone, Debug, Default, PartialEq, Eq)]
112pub struct PoolStats {
113    /// Successfully completed jobs.
114    pub completed: u64,
115    /// Failed jobs.
116    pub failures: u64,
117    /// Rate-limit events observed by workers.
118    pub rate_limit_events: Vec<crate::RateLimitEvent>,
119    /// Number of worker runtime recycles.
120    pub worker_recycles: u64,
121}