diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 2f035437..8ddd4af3 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/vendor/codex/codex-rs/app-server/README.md b/vendor/codex/codex-rs/app-server/README.md index 69803fd2..c3ab2c9c 100644 --- a/vendor/codex/codex-rs/app-server/README.md +++ b/vendor/codex/codex-rs/app-server/README.md @@ -148,7 +148,7 @@ Experimental Epiphany retrieval: - `thread/epiphany/promote` is an explicit loaded-thread-only promotion gate. It evaluates a patch plus verifier evidence, rejects with reasons without mutating state when policy fails, and applies the patch through the durable update path when accepted. Accepted responses include the landed `revision` and `changedFields`. - `thread/epiphany/update` is the explicit loaded-thread-only control-plane write path for Epiphany state. It can append observations/evidence and replace bounded typed state fields such as objective, subgoals, graph frontier/checkpoint, scratch, churn, and mode; it bumps the Epiphany revision, returns `revision` plus `changedFields`, and persists a rollout snapshot immediately. - `thread/epiphany/stateUpdated` is an experimental server notification emitted after successful `thread/epiphany/update` and accepted `thread/epiphany/promote`. It carries the updated typed `epiphanyState`, a `source` of `update` or `promote`, event-level `revision`, and typed `changedFields`; rejected promotions do not emit it. -- `thread/epiphany/jobsUpdated` is an experimental server notification emitted from live `agent_job_progress:{json}` background events when a launcher-bound `agent_jobs` backend owner advances and the mapped job payload actually changes. It carries the current `stateRevision` plus the changed job snapshots, including launcher metadata such as `launcherJobId`, `authorityScope`, `backendKind`, and `backendJobId`; it does not turn `thread/epiphany/jobs` into a writer or scheduler. +- `thread/epiphany/jobsUpdated` is a sealed legacy notification shape. Epiphany no longer emits it from Codex batch-job progress; heartbeat/runtime-spine owns live activation telemetry, while `thread/epiphany/jobs` remains a read-only projection over current typed state. - `thread/epiphany/freshness` is a read-only reflection surface for retrieval and graph staleness. It reports revision/source identity, retrieval freshness, graph freshness, and exact dirty-path pressure, and for loaded threads now also reports watcher-backed invalidation inputs with watched root, changed paths, mapped graph-node hits, and active-frontier hits. It still does not mutate state, schedule refresh work, or perform automatic watcher-driven semantic invalidation. - `thread/epiphany/reorient` is a read-only CRRC policy surface. It consumes the durable investigation checkpoint plus freshness, watcher, and pressure signals to return a bounded `resume` versus `regather` verdict with explicit checkpoint-path/frontier reasons. It does not mutate state, compact, notify, schedule, or silently continue work on the caller's behalf. The request envelope is camelCase, but nested reused Epiphany core DTOs currently keep their core snake_case fields, such as `source_kind`, `understanding_status`, and `diff_pressure`. diff --git a/vendor/codex/codex-rs/config/src/config_toml.rs b/vendor/codex/codex-rs/config/src/config_toml.rs index 40f384f4..b8cbf8d0 100644 --- a/vendor/codex/codex-rs/config/src/config_toml.rs +++ b/vendor/codex/codex-rs/config/src/config_toml.rs @@ -557,7 +557,6 @@ pub struct AgentsToml { pub max_depth: Option, /// Default maximum runtime in seconds for agent job workers. #[schemars(range(min = 1))] - pub job_max_runtime_seconds: Option, /// User-defined role declarations keyed by role name. /// diff --git a/vendor/codex/codex-rs/core/src/agent/control.rs b/vendor/codex/codex-rs/core/src/agent/control.rs index 757c387f..08579536 100644 --- a/vendor/codex/codex-rs/core/src/agent/control.rs +++ b/vendor/codex/codex-rs/core/src/agent/control.rs @@ -496,7 +496,6 @@ impl AgentControl { if let SessionSource::SubAgent(SubAgentSource::ThreadSpawn { depth, .. }) = &session_source && *depth >= config.agent_max_depth { - let _ = config.features.disable(Feature::SpawnCsv); let _ = config.features.disable(Feature::Collab); } let state = self.upgrade()?; diff --git a/vendor/codex/codex-rs/core/src/config/config_tests.rs b/vendor/codex/codex-rs/core/src/config/config_tests.rs index 500483f6..43471d7d 100644 --- a/vendor/codex/codex-rs/core/src/config/config_tests.rs +++ b/vendor/codex/codex-rs/core/src/config/config_tests.rs @@ -3967,7 +3967,6 @@ async fn load_config_rejects_missing_agent_role_config_file() -> std::io::Result agents: Some(AgentsToml { max_threads: None, max_depth: None, - job_max_runtime_seconds: None, roles: BTreeMap::from([( "researcher".to_string(), AgentRoleToml { @@ -4833,7 +4832,6 @@ async fn load_config_normalizes_agent_role_nickname_candidates() -> std::io::Res agents: Some(AgentsToml { max_threads: None, max_depth: None, - job_max_runtime_seconds: None, roles: BTreeMap::from([( "researcher".to_string(), AgentRoleToml { @@ -4875,7 +4873,6 @@ async fn load_config_rejects_empty_agent_role_nickname_candidates() -> std::io:: agents: Some(AgentsToml { max_threads: None, max_depth: None, - job_max_runtime_seconds: None, roles: BTreeMap::from([( "researcher".to_string(), AgentRoleToml { @@ -4911,7 +4908,6 @@ async fn load_config_rejects_duplicate_agent_role_nickname_candidates() -> std:: agents: Some(AgentsToml { max_threads: None, max_depth: None, - job_max_runtime_seconds: None, roles: BTreeMap::from([( "researcher".to_string(), AgentRoleToml { @@ -4947,7 +4943,6 @@ async fn load_config_rejects_unsafe_agent_role_nickname_candidates() -> std::io: agents: Some(AgentsToml { max_threads: None, max_depth: None, - job_max_runtime_seconds: None, roles: BTreeMap::from([( "researcher".to_string(), AgentRoleToml { @@ -5203,7 +5198,6 @@ async fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> { agent_max_depth: DEFAULT_AGENT_MAX_DEPTH, agent_roles: BTreeMap::new(), memories: MemoriesConfig::default(), - agent_job_max_runtime_seconds: DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS, codex_home: fixture.codex_home(), sqlite_home: fixture.codex_home().to_path_buf(), log_dir: fixture.codex_home().join("log").to_path_buf(), @@ -5355,7 +5349,6 @@ async fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> { agent_max_depth: DEFAULT_AGENT_MAX_DEPTH, agent_roles: BTreeMap::new(), memories: MemoriesConfig::default(), - agent_job_max_runtime_seconds: DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS, codex_home: fixture.codex_home(), sqlite_home: fixture.codex_home().to_path_buf(), log_dir: fixture.codex_home().join("log").to_path_buf(), @@ -5505,7 +5498,6 @@ async fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> { agent_max_depth: DEFAULT_AGENT_MAX_DEPTH, agent_roles: BTreeMap::new(), memories: MemoriesConfig::default(), - agent_job_max_runtime_seconds: DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS, codex_home: fixture.codex_home(), sqlite_home: fixture.codex_home().to_path_buf(), log_dir: fixture.codex_home().join("log").to_path_buf(), @@ -5640,7 +5632,6 @@ async fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> { agent_max_depth: DEFAULT_AGENT_MAX_DEPTH, agent_roles: BTreeMap::new(), memories: MemoriesConfig::default(), - agent_job_max_runtime_seconds: DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS, codex_home: fixture.codex_home(), sqlite_home: fixture.codex_home().to_path_buf(), log_dir: fixture.codex_home().join("log").to_path_buf(), diff --git a/vendor/codex/codex-rs/core/src/config/mod.rs b/vendor/codex/codex-rs/core/src/config/mod.rs index e89cb7ca..93724aac 100644 --- a/vendor/codex/codex-rs/core/src/config/mod.rs +++ b/vendor/codex/codex-rs/core/src/config/mod.rs @@ -127,7 +127,6 @@ pub use codex_git_utils::GhostSnapshotConfig; pub(crate) const AGENTS_MD_MAX_BYTES: usize = 32 * 1024; // 32 KiB pub(crate) const DEFAULT_AGENT_MAX_THREADS: Option = Some(6); pub(crate) const DEFAULT_AGENT_MAX_DEPTH: i32 = 1; -pub(crate) const DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS: Option = None; const LOCAL_DEV_BUILD_VERSION: &str = "0.0.0"; pub const CONFIG_TOML_FILE: &str = "config.toml"; @@ -427,9 +426,6 @@ pub struct Config { /// Maximum number of agent threads that can be open concurrently. pub agent_max_threads: Option, - /// Maximum runtime in seconds for agent job workers before they are failed. - pub agent_job_max_runtime_seconds: Option, - /// Maximum nesting depth allowed for spawned agent threads. pub agent_max_depth: i32, @@ -1965,25 +1961,6 @@ impl Config { "agents.max_depth must be at least 1", )); } - let agent_job_max_runtime_seconds = cfg - .agents - .as_ref() - .and_then(|agents| agents.job_max_runtime_seconds) - .or(DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS); - if agent_job_max_runtime_seconds == Some(0) { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "agents.job_max_runtime_seconds must be at least 1", - )); - } - if let Some(max_runtime_seconds) = agent_job_max_runtime_seconds - && max_runtime_seconds > i64::MAX as u64 - { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "agents.job_max_runtime_seconds must fit within a 64-bit signed integer", - )); - } let background_terminal_max_timeout = cfg .background_terminal_max_timeout .unwrap_or(DEFAULT_MAX_BACKGROUND_TERMINAL_TIMEOUT_MS) @@ -2337,7 +2314,6 @@ impl Config { agent_max_depth, agent_roles, memories: cfg.memories.unwrap_or_default().into(), - agent_job_max_runtime_seconds, codex_home, sqlite_home, log_dir, diff --git a/vendor/codex/codex-rs/core/src/guardian/review_session.rs b/vendor/codex/codex-rs/core/src/guardian/review_session.rs index 50123ef5..0da74d3e 100644 --- a/vendor/codex/codex-rs/core/src/guardian/review_session.rs +++ b/vendor/codex/codex-rs/core/src/guardian/review_session.rs @@ -871,7 +871,6 @@ pub(crate) fn build_guardian_review_session_config( )?); } for feature in [ - Feature::SpawnCsv, Feature::Collab, Feature::CodexHooks, Feature::Apps, diff --git a/vendor/codex/codex-rs/core/src/memories/phase2.rs b/vendor/codex/codex-rs/core/src/memories/phase2.rs index ffabb06e..38e59411 100644 --- a/vendor/codex/codex-rs/core/src/memories/phase2.rs +++ b/vendor/codex/codex-rs/core/src/memories/phase2.rs @@ -306,7 +306,6 @@ mod agent { // Approval policy agent_config.permissions.approval_policy = Constrained::allow_only(AskForApproval::Never); // Consolidation runs as an internal sub-agent and must not recursively delegate. - let _ = agent_config.features.disable(Feature::SpawnCsv); let _ = agent_config.features.disable(Feature::Collab); let _ = agent_config.features.disable(Feature::MemoryTool); diff --git a/vendor/codex/codex-rs/core/src/session/mod.rs b/vendor/codex/codex-rs/core/src/session/mod.rs index 97e885c9..2fa187e5 100644 --- a/vendor/codex/codex-rs/core/src/session/mod.rs +++ b/vendor/codex/codex-rs/core/src/session/mod.rs @@ -484,7 +484,6 @@ impl Codex { if let SessionSource::SubAgent(SubAgentSource::ThreadSpawn { depth, .. }) = session_source && depth >= config.agent_max_depth { - let _ = config.features.disable(Feature::SpawnCsv); let _ = config.features.disable(Feature::Collab); } diff --git a/vendor/codex/codex-rs/core/src/tasks/review.rs b/vendor/codex/codex-rs/core/src/tasks/review.rs index c844f6ce..57e20e4f 100644 --- a/vendor/codex/codex-rs/core/src/tasks/review.rs +++ b/vendor/codex/codex-rs/core/src/tasks/review.rs @@ -108,7 +108,6 @@ async fn start_review_conversation( { panic!("by construction Constrained must always support Disabled: {err}"); } - let _ = sub_agent_config.features.disable(Feature::SpawnCsv); let _ = sub_agent_config.features.disable(Feature::Collab); // Set explicit review rubric for the sub-agent diff --git a/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs.rs b/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs.rs deleted file mode 100644 index 3f3f10bf..00000000 --- a/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs.rs +++ /dev/null @@ -1,1286 +0,0 @@ -use crate::agent::exceeds_thread_spawn_depth_limit; -use crate::agent::next_thread_spawn_depth; -use crate::agent::status::is_final; -use crate::config::Config; -use crate::function_tool::FunctionCallError; -use crate::session::session::Session; -use crate::session::turn_context::TurnContext; -use crate::tools::context::FunctionToolOutput; -use crate::tools::context::ToolInvocation; -use crate::tools::context::ToolPayload; -use crate::tools::handlers::multi_agents::build_agent_spawn_config; -use crate::tools::handlers::parse_arguments; -use crate::tools::registry::ToolHandler; -use crate::tools::registry::ToolKind; -use codex_protocol::ThreadId; -use codex_protocol::error::CodexErr; -use codex_protocol::protocol::AgentStatus; -use codex_protocol::protocol::SessionSource; -use codex_protocol::protocol::SubAgentSource; -use codex_protocol::user_input::UserInput; -use codex_utils_absolute_path::AbsolutePathBuf; -use futures::StreamExt; -use futures::stream::FuturesUnordered; -use serde::Deserialize; -use serde::Serialize; -use serde_json::Value; -use std::collections::HashMap; -use std::collections::HashSet; -use std::path::PathBuf; -use std::sync::Arc; -use tokio::sync::watch::Receiver; -use tokio::time::Duration; -use tokio::time::Instant; -use tokio::time::timeout; -use uuid::Uuid; - -pub struct BatchJobHandler; - -const DEFAULT_AGENT_JOB_CONCURRENCY: usize = 16; -const MAX_AGENT_JOB_CONCURRENCY: usize = 64; -const STATUS_POLL_INTERVAL: Duration = Duration::from_millis(250); -const PROGRESS_EMIT_INTERVAL: Duration = Duration::from_secs(1); -const DEFAULT_AGENT_JOB_ITEM_TIMEOUT: Duration = Duration::from_secs(60 * 30); - -#[derive(Debug, Deserialize)] -struct SpawnAgentsOnCsvArgs { - csv_path: String, - instruction: String, - id_column: Option, - output_csv_path: Option, - output_schema: Option, - max_concurrency: Option, - max_workers: Option, - max_runtime_seconds: Option, -} - -#[derive(Debug, Deserialize)] -struct ReportAgentJobResultArgs { - job_id: String, - item_id: String, - result: Value, - stop: Option, -} - -#[derive(Debug, Serialize)] -struct SpawnAgentsOnCsvResult { - job_id: String, - status: String, - output_csv_path: String, - total_items: usize, - completed_items: usize, - failed_items: usize, - job_error: Option, - failed_item_errors: Option>, -} - -#[derive(Debug, Serialize)] -struct AgentJobFailureSummary { - item_id: String, - source_id: Option, - last_error: String, -} - -#[derive(Debug, Serialize)] -struct AgentJobProgressUpdate { - job_id: String, - total_items: usize, - pending_items: usize, - running_items: usize, - completed_items: usize, - failed_items: usize, - eta_seconds: Option, -} - -#[derive(Debug, Serialize)] -struct ReportAgentJobResultToolResult { - accepted: bool, -} - -#[derive(Debug, Clone)] -pub(crate) struct JobRunnerOptions { - max_concurrency: usize, - spawn_config: Config, -} - -#[derive(Debug, Clone)] -struct ActiveJobItem { - item_id: String, - started_at: Instant, - status_rx: Option>, -} - -struct JobProgressEmitter { - started_at: Instant, - last_emit_at: Instant, - last_processed: usize, - last_failed: usize, -} - -impl JobProgressEmitter { - fn new() -> Self { - let now = Instant::now(); - let last_emit_at = now.checked_sub(PROGRESS_EMIT_INTERVAL).unwrap_or(now); - Self { - started_at: now, - last_emit_at, - last_processed: 0, - last_failed: 0, - } - } - - async fn maybe_emit( - &mut self, - session: &Session, - turn: &TurnContext, - job_id: &str, - progress: &codex_state::AgentJobProgress, - force: bool, - ) -> anyhow::Result<()> { - let processed = progress.completed_items + progress.failed_items; - let should_emit = force - || processed != self.last_processed - || progress.failed_items != self.last_failed - || self.last_emit_at.elapsed() >= PROGRESS_EMIT_INTERVAL; - if !should_emit { - return Ok(()); - } - let elapsed = self.started_at.elapsed().as_secs_f64(); - let eta_seconds = if processed > 0 && elapsed > 0.0 { - let remaining = progress.total_items.saturating_sub(processed) as f64; - let rate = processed as f64 / elapsed; - if rate > 0.0 { - Some((remaining / rate).round() as u64) - } else { - None - } - } else { - None - }; - let update = AgentJobProgressUpdate { - job_id: job_id.to_string(), - total_items: progress.total_items, - pending_items: progress.pending_items, - running_items: progress.running_items, - completed_items: progress.completed_items, - failed_items: progress.failed_items, - eta_seconds, - }; - let payload = serde_json::to_string(&update)?; - session - .notify_background_event(turn, format!("agent_job_progress:{payload}")) - .await; - self.last_emit_at = Instant::now(); - self.last_processed = processed; - self.last_failed = progress.failed_items; - Ok(()) - } -} - -impl ToolHandler for BatchJobHandler { - type Output = FunctionToolOutput; - - fn kind(&self) -> ToolKind { - ToolKind::Function - } - - fn matches_kind(&self, payload: &ToolPayload) -> bool { - matches!(payload, ToolPayload::Function { .. }) - } - - async fn handle(&self, invocation: ToolInvocation) -> Result { - let ToolInvocation { - session, - turn, - tool_name, - payload, - .. - } = invocation; - - let arguments = match payload { - ToolPayload::Function { arguments } => arguments, - _ => { - return Err(FunctionCallError::RespondToModel( - "agent jobs handler received unsupported payload".to_string(), - )); - } - }; - - match tool_name.name.as_str() { - "spawn_agents_on_csv" => spawn_agents_on_csv::handle(session, turn, arguments).await, - "report_agent_job_result" => report_agent_job_result::handle(session, arguments).await, - other => Err(FunctionCallError::RespondToModel(format!( - "unsupported agent job tool {other}" - ))), - } - } -} - -mod spawn_agents_on_csv { - use super::*; - - /// Create a new agent job from a CSV and run it to completion. - /// - /// Each CSV row becomes a job item. The instruction string is a template where `{column}` - /// placeholders are filled with values from that row. Results are reported by workers via - /// `report_agent_job_result`, then exported to CSV on completion. - pub async fn handle( - session: Arc, - turn: Arc, - arguments: String, - ) -> Result { - let args: SpawnAgentsOnCsvArgs = parse_arguments(arguments.as_str())?; - if args.instruction.trim().is_empty() { - return Err(FunctionCallError::RespondToModel( - "instruction must be non-empty".to_string(), - )); - } - - let db = required_state_db(&session).await?; - let input_path = turn.resolve_path(Some(args.csv_path)); - let input_path_display = input_path.display().to_string(); - let csv_content = tokio::fs::read_to_string(&input_path) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!( - "failed to read csv input {input_path_display}: {err}" - )) - })?; - let (headers, rows) = parse_csv(csv_content.as_str()).map_err(|err| { - FunctionCallError::RespondToModel(format!("failed to parse csv input: {err}")) - })?; - if headers.is_empty() { - return Err(FunctionCallError::RespondToModel( - "csv input must include a header row".to_string(), - )); - } - ensure_unique_headers(headers.as_slice())?; - - let id_column_index = args.id_column.as_ref().map_or(Ok(None), |column_name| { - headers - .iter() - .position(|header| header == column_name) - .map(Some) - .ok_or_else(|| { - FunctionCallError::RespondToModel(format!( - "id_column {column_name} was not found in csv headers" - )) - }) - })?; - - let mut items = Vec::with_capacity(rows.len()); - let mut seen_ids = HashSet::new(); - for (idx, row) in rows.into_iter().enumerate() { - if row.len() != headers.len() { - let row_index = idx + 2; - let row_len = row.len(); - let header_len = headers.len(); - return Err(FunctionCallError::RespondToModel(format!( - "csv row {row_index} has {row_len} fields but header has {header_len}" - ))); - } - - let source_id = id_column_index - .and_then(|index| row.get(index).cloned()) - .filter(|value| !value.trim().is_empty()); - let row_index = idx + 1; - let base_item_id = source_id - .clone() - .unwrap_or_else(|| format!("row-{row_index}")); - let mut item_id = base_item_id.clone(); - let mut suffix = 2usize; - while !seen_ids.insert(item_id.clone()) { - item_id = format!("{base_item_id}-{suffix}"); - suffix = suffix.saturating_add(1); - } - - let row_object = headers - .iter() - .zip(row.iter()) - .map(|(header, value)| (header.clone(), Value::String(value.clone()))) - .collect::>(); - items.push(codex_state::AgentJobItemCreateParams { - item_id, - row_index: idx as i64, - source_id, - row_json: Value::Object(row_object), - }); - } - - let job_id = Uuid::new_v4().to_string(); - let output_csv_path = args.output_csv_path.map_or_else( - || default_output_csv_path(&input_path, job_id.as_str()), - |path| turn.resolve_path(Some(path)), - ); - let job_suffix = &job_id[..8]; - let job_name = format!("agent-job-{job_suffix}"); - let max_runtime_seconds = normalize_max_runtime_seconds( - args.max_runtime_seconds - .or(turn.config.agent_job_max_runtime_seconds), - )?; - let _job = db - .create_agent_job( - &codex_state::AgentJobCreateParams { - id: job_id.clone(), - name: job_name, - instruction: args.instruction, - auto_export: true, - max_runtime_seconds, - output_schema_json: args.output_schema, - input_headers: headers, - input_csv_path: input_path.display().to_string(), - output_csv_path: output_csv_path.display().to_string(), - }, - items.as_slice(), - ) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!("failed to create agent job: {err}")) - })?; - - let requested_concurrency = args.max_concurrency.or(args.max_workers); - let options = match build_runner_options(&session, &turn, requested_concurrency).await { - Ok(options) => options, - Err(err) => { - let error_message = err.to_string(); - let _ = db - .mark_agent_job_failed(job_id.as_str(), error_message.as_str()) - .await; - return Err(err); - } - }; - db.mark_agent_job_running(job_id.as_str()) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!( - "failed to transition agent job {job_id} to running: {err}" - )) - })?; - let max_threads = turn.config.agent_max_threads; - let effective_concurrency = options.max_concurrency; - let message = format!( - "agent job concurrency: job_id={job_id} requested={requested_concurrency:?} max_threads={max_threads:?} effective={effective_concurrency}" - ); - let _ = session.notify_background_event(&turn, message).await; - if let Err(err) = run_agent_job_loop( - session.clone(), - turn.clone(), - db.clone(), - job_id.clone(), - options, - ) - .await - { - let error_message = format!("job runner failed: {err}"); - let _ = db - .mark_agent_job_failed(job_id.as_str(), error_message.as_str()) - .await; - return Err(FunctionCallError::RespondToModel(format!( - "agent job {job_id} failed: {err}" - ))); - } - - let job = db - .get_agent_job(job_id.as_str()) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!( - "failed to load agent job {job_id}: {err}" - )) - })? - .ok_or_else(|| { - FunctionCallError::RespondToModel(format!("agent job {job_id} not found")) - })?; - let output_path = PathBuf::from(job.output_csv_path.clone()); - if !tokio::fs::try_exists(&output_path).await.unwrap_or(false) { - export_job_csv_snapshot(db.clone(), &job) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!( - "failed to export output csv {job_id}: {err}" - )) - })?; - } - let progress = db - .get_agent_job_progress(job_id.as_str()) - .await - .map_err(|err| { - FunctionCallError::RespondToModel(format!( - "failed to load agent job progress {job_id}: {err}" - )) - })?; - let mut job_error = job.last_error.clone().filter(|err| !err.trim().is_empty()); - let failed_item_errors = if progress.failed_items > 0 { - let items = db - .list_agent_job_items( - job_id.as_str(), - Some(codex_state::AgentJobItemStatus::Failed), - Some(5), - ) - .await - .unwrap_or_default(); - let summaries: Vec<_> = items - .into_iter() - .filter_map(|item| { - let last_error = item.last_error.unwrap_or_default(); - if last_error.trim().is_empty() { - return None; - } - Some(AgentJobFailureSummary { - item_id: item.item_id, - source_id: item.source_id, - last_error, - }) - }) - .collect(); - if summaries.is_empty() { - if job_error.is_none() { - job_error = Some( - "agent job has failed items but no error details were recorded".to_string(), - ); - } - None - } else { - Some(summaries) - } - } else { - None - }; - let content = serde_json::to_string(&SpawnAgentsOnCsvResult { - job_id, - status: job.status.as_str().to_string(), - output_csv_path: job.output_csv_path, - total_items: progress.total_items, - completed_items: progress.completed_items, - failed_items: progress.failed_items, - job_error, - failed_item_errors, - }) - .map_err(|err| { - FunctionCallError::Fatal(format!( - "failed to serialize spawn_agents_on_csv result: {err}" - )) - })?; - Ok(FunctionToolOutput::from_text(content, Some(true))) - } -} - -mod report_agent_job_result { - use super::*; - - pub async fn handle( - session: Arc, - arguments: String, - ) -> Result { - let args: ReportAgentJobResultArgs = parse_arguments(arguments.as_str())?; - if !args.result.is_object() { - return Err(FunctionCallError::RespondToModel( - "result must be a JSON object".to_string(), - )); - } - let db = required_state_db(&session).await?; - let reporting_thread_id = session.conversation_id.to_string(); - let accepted = db - .report_agent_job_item_result( - args.job_id.as_str(), - args.item_id.as_str(), - reporting_thread_id.as_str(), - &args.result, - ) - .await - .map_err(|err| { - let job_id = args.job_id.as_str(); - let item_id = args.item_id.as_str(); - FunctionCallError::RespondToModel(format!( - "failed to record agent job result for {job_id} / {item_id}: {err}" - )) - })?; - if accepted && args.stop.unwrap_or(false) { - let message = "cancelled by worker request"; - let _ = db - .mark_agent_job_cancelled(args.job_id.as_str(), message) - .await; - } - let content = - serde_json::to_string(&ReportAgentJobResultToolResult { accepted }).map_err(|err| { - FunctionCallError::Fatal(format!( - "failed to serialize report_agent_job_result result: {err}" - )) - })?; - Ok(FunctionToolOutput::from_text(content, Some(true))) - } -} - -async fn required_state_db( - session: &Arc, -) -> Result, FunctionCallError> { - if let Some(state_db) = session.state_db() { - return Ok(state_db); - } - - let config = session.get_config().await; - codex_state::StateRuntime::init( - config.codex_home.to_path_buf(), - config.model_provider_id.clone(), - ) - .await - .map_err(|err| { - FunctionCallError::Fatal(format!( - "sqlite state db is unavailable for this session and fallback init failed: {err}" - )) - }) -} - -pub(crate) async fn build_runner_options( - session: &Arc, - turn: &Arc, - requested_concurrency: Option, -) -> Result { - let session_source = turn.session_source.clone(); - let child_depth = next_thread_spawn_depth(&session_source); - let max_depth = turn.config.agent_max_depth; - if exceeds_thread_spawn_depth_limit(child_depth, max_depth) { - return Err(FunctionCallError::RespondToModel( - "agent depth limit reached; this session cannot spawn more subagents".to_string(), - )); - } - let max_concurrency = - normalize_concurrency(requested_concurrency, turn.config.agent_max_threads); - let base_instructions = session.get_base_instructions().await; - let spawn_config = build_agent_spawn_config(&base_instructions, turn.as_ref())?; - Ok(JobRunnerOptions { - max_concurrency, - spawn_config, - }) -} - -fn normalize_concurrency(requested: Option, max_threads: Option) -> usize { - let requested = requested.unwrap_or(DEFAULT_AGENT_JOB_CONCURRENCY).max(1); - let requested = requested.min(MAX_AGENT_JOB_CONCURRENCY); - if let Some(max_threads) = max_threads { - requested.min(max_threads.max(1)) - } else { - requested - } -} - -fn normalize_max_runtime_seconds(requested: Option) -> Result, FunctionCallError> { - let Some(requested) = requested else { - return Ok(None); - }; - if requested == 0 { - return Err(FunctionCallError::RespondToModel( - "max_runtime_seconds must be >= 1".to_string(), - )); - } - Ok(Some(requested)) -} - -pub(crate) async fn run_agent_job_loop( - session: Arc, - turn: Arc, - db: Arc, - job_id: String, - options: JobRunnerOptions, -) -> anyhow::Result<()> { - let job = db - .get_agent_job(job_id.as_str()) - .await? - .ok_or_else(|| anyhow::anyhow!("agent job {job_id} was not found"))?; - let runtime_timeout = job_runtime_timeout(&job); - let mut active_items: HashMap = HashMap::new(); - let mut progress_emitter = JobProgressEmitter::new(); - recover_running_items( - session.clone(), - db.clone(), - job_id.as_str(), - &mut active_items, - runtime_timeout, - ) - .await?; - let initial_progress = db.get_agent_job_progress(job_id.as_str()).await?; - progress_emitter - .maybe_emit( - &session, - &turn, - job_id.as_str(), - &initial_progress, - /*force*/ true, - ) - .await?; - - let mut cancel_requested = db.is_agent_job_cancelled(job_id.as_str()).await?; - loop { - let mut progressed = false; - - if cancel_requested { - if clear_cancelled_active_items( - session.clone(), - db.clone(), - job_id.as_str(), - &mut active_items, - "agent job was cancelled before the worker completed", - ) - .await? - { - progressed = true; - } - } else if db.is_agent_job_cancelled(job_id.as_str()).await? { - cancel_requested = true; - let _ = session - .notify_background_event( - &turn, - format!("agent job {job_id} cancellation requested; stopping new workers"), - ) - .await; - if clear_cancelled_active_items( - session.clone(), - db.clone(), - job_id.as_str(), - &mut active_items, - "agent job was cancelled before the worker completed", - ) - .await? - { - progressed = true; - } - } - - if !cancel_requested && active_items.len() < options.max_concurrency { - let slots = options.max_concurrency - active_items.len(); - let pending_items = db - .list_agent_job_items( - job_id.as_str(), - Some(codex_state::AgentJobItemStatus::Pending), - Some(slots), - ) - .await?; - for item in pending_items { - let prompt = build_worker_prompt(&job, &item)?; - let items = vec![UserInput::Text { - text: prompt, - text_elements: Vec::new(), - }]; - let thread_id = match session - .services - .agent_control - .spawn_agent( - options.spawn_config.clone(), - items.into(), - Some(SessionSource::SubAgent(SubAgentSource::Other(format!( - "agent_job:{job_id}" - )))), - ) - .await - { - Ok(thread_id) => thread_id, - Err(CodexErr::AgentLimitReached { .. }) => { - db.mark_agent_job_item_pending( - job_id.as_str(), - item.item_id.as_str(), - /*error_message*/ None, - ) - .await?; - break; - } - Err(err) => { - let error_message = format!("failed to spawn worker: {err}"); - db.mark_agent_job_item_failed( - job_id.as_str(), - item.item_id.as_str(), - error_message.as_str(), - ) - .await?; - progressed = true; - continue; - } - }; - let assigned = db - .mark_agent_job_item_running_with_thread( - job_id.as_str(), - item.item_id.as_str(), - thread_id.to_string().as_str(), - ) - .await?; - if !assigned { - let _ = session - .services - .agent_control - .shutdown_live_agent(thread_id) - .await; - continue; - } - active_items.insert( - thread_id, - ActiveJobItem { - item_id: item.item_id.clone(), - started_at: Instant::now(), - status_rx: session - .services - .agent_control - .subscribe_status(thread_id) - .await - .ok(), - }, - ); - progressed = true; - } - } - - if reap_stale_active_items( - session.clone(), - db.clone(), - job_id.as_str(), - &mut active_items, - runtime_timeout, - ) - .await? - { - progressed = true; - } - - let finished = find_finished_threads(session.clone(), &active_items).await; - if finished.is_empty() { - let progress = db.get_agent_job_progress(job_id.as_str()).await?; - if cancel_requested { - if progress.running_items == 0 && active_items.is_empty() { - break; - } - } else if progress.pending_items == 0 - && progress.running_items == 0 - && active_items.is_empty() - { - break; - } - if !progressed { - wait_for_status_change(&active_items).await; - } - continue; - } - - for (thread_id, item_id) in finished { - finalize_finished_item( - session.clone(), - db.clone(), - job_id.as_str(), - item_id.as_str(), - thread_id, - ) - .await?; - active_items.remove(&thread_id); - let progress = db.get_agent_job_progress(job_id.as_str()).await?; - progress_emitter - .maybe_emit( - &session, - &turn, - job_id.as_str(), - &progress, - /*force*/ false, - ) - .await?; - } - } - - let progress = db.get_agent_job_progress(job_id.as_str()).await?; - if let Err(err) = export_job_csv_snapshot(db.clone(), &job).await { - let message = format!("auto-export failed: {err}"); - db.mark_agent_job_failed(job_id.as_str(), message.as_str()) - .await?; - return Ok(()); - } - let cancelled = cancel_requested || db.is_agent_job_cancelled(job_id.as_str()).await?; - if cancelled { - let pending_items = progress.pending_items; - let message = - format!("agent job {job_id} cancelled with {pending_items} unprocessed items"); - let _ = session.notify_background_event(&turn, message).await; - progress_emitter - .maybe_emit( - &session, - &turn, - job_id.as_str(), - &progress, - /*force*/ true, - ) - .await?; - return Ok(()); - } - if progress.failed_items > 0 { - let failed_items = progress.failed_items; - let message = format!("agent job completed with {failed_items} failed items"); - let _ = session.notify_background_event(&turn, message).await; - } - db.mark_agent_job_completed(job_id.as_str()).await?; - let progress = db.get_agent_job_progress(job_id.as_str()).await?; - progress_emitter - .maybe_emit( - &session, - &turn, - job_id.as_str(), - &progress, - /*force*/ true, - ) - .await?; - Ok(()) -} - -async fn export_job_csv_snapshot( - db: Arc, - job: &codex_state::AgentJob, -) -> anyhow::Result<()> { - let items = db - .list_agent_job_items(job.id.as_str(), /*status*/ None, /*limit*/ None) - .await?; - let csv_content = render_job_csv(job.input_headers.as_slice(), items.as_slice()) - .map_err(|err| anyhow::anyhow!("failed to render job csv for auto-export: {err}"))?; - let output_path = PathBuf::from(job.output_csv_path.clone()); - if let Some(parent) = output_path.parent() { - tokio::fs::create_dir_all(parent).await?; - } - tokio::fs::write(&output_path, csv_content).await?; - Ok(()) -} - -async fn recover_running_items( - session: Arc, - db: Arc, - job_id: &str, - active_items: &mut HashMap, - runtime_timeout: Duration, -) -> anyhow::Result<()> { - let running_items = db - .list_agent_job_items( - job_id, - Some(codex_state::AgentJobItemStatus::Running), - /*limit*/ None, - ) - .await?; - for item in running_items { - if is_item_stale(&item, runtime_timeout) { - let error_message = format!("worker exceeded max runtime of {runtime_timeout:?}"); - db.mark_agent_job_item_failed(job_id, item.item_id.as_str(), error_message.as_str()) - .await?; - if let Some(assigned_thread_id) = item.assigned_thread_id.as_ref() - && let Ok(thread_id) = ThreadId::from_string(assigned_thread_id.as_str()) - { - let _ = session - .services - .agent_control - .shutdown_live_agent(thread_id) - .await; - } - continue; - } - let Some(assigned_thread_id) = item.assigned_thread_id.clone() else { - db.mark_agent_job_item_failed( - job_id, - item.item_id.as_str(), - "running item is missing assigned_thread_id", - ) - .await?; - continue; - }; - let thread_id = match ThreadId::from_string(assigned_thread_id.as_str()) { - Ok(thread_id) => thread_id, - Err(err) => { - let error_message = format!("invalid assigned_thread_id: {err:?}"); - db.mark_agent_job_item_failed( - job_id, - item.item_id.as_str(), - error_message.as_str(), - ) - .await?; - continue; - } - }; - if is_final(&session.services.agent_control.get_status(thread_id).await) { - finalize_finished_item( - session.clone(), - db.clone(), - job_id, - item.item_id.as_str(), - thread_id, - ) - .await?; - } else { - active_items.insert( - thread_id, - ActiveJobItem { - item_id: item.item_id.clone(), - started_at: started_at_from_item(&item), - status_rx: session - .services - .agent_control - .subscribe_status(thread_id) - .await - .ok(), - }, - ); - } - } - Ok(()) -} - -async fn find_finished_threads( - session: Arc, - active_items: &HashMap, -) -> Vec<(ThreadId, String)> { - let mut finished = Vec::new(); - for (thread_id, item) in active_items { - let status = active_item_status(session.as_ref(), *thread_id, item).await; - if is_final(&status) { - finished.push((*thread_id, item.item_id.clone())); - } - } - finished -} - -async fn active_item_status( - session: &Session, - thread_id: ThreadId, - item: &ActiveJobItem, -) -> AgentStatus { - if let Some(status_rx) = item.status_rx.as_ref() - && status_rx.has_changed().is_ok() - { - return status_rx.borrow().clone(); - } - session.services.agent_control.get_status(thread_id).await -} - -async fn wait_for_status_change(active_items: &HashMap) { - let mut waiters = FuturesUnordered::new(); - for item in active_items.values() { - if let Some(status_rx) = item.status_rx.as_ref() { - let mut status_rx = status_rx.clone(); - waiters.push(async move { - let _ = status_rx.changed().await; - }); - } - } - if waiters.is_empty() { - tokio::time::sleep(STATUS_POLL_INTERVAL).await; - return; - } - let _ = timeout(STATUS_POLL_INTERVAL, waiters.next()).await; -} - -async fn reap_stale_active_items( - session: Arc, - db: Arc, - job_id: &str, - active_items: &mut HashMap, - runtime_timeout: Duration, -) -> anyhow::Result { - let mut stale = Vec::new(); - for (thread_id, item) in active_items.iter() { - if item.started_at.elapsed() >= runtime_timeout { - stale.push((*thread_id, item.item_id.clone())); - } - } - if stale.is_empty() { - return Ok(false); - } - for (thread_id, item_id) in stale { - let error_message = format!("worker exceeded max runtime of {runtime_timeout:?}"); - db.mark_agent_job_item_failed(job_id, item_id.as_str(), error_message.as_str()) - .await?; - let _ = session - .services - .agent_control - .shutdown_live_agent(thread_id) - .await; - active_items.remove(&thread_id); - } - Ok(true) -} - -async fn clear_cancelled_active_items( - session: Arc, - db: Arc, - job_id: &str, - active_items: &mut HashMap, - error_message: &str, -) -> anyhow::Result { - if active_items.is_empty() { - return Ok(false); - } - let active: Vec<(ThreadId, String)> = active_items - .iter() - .map(|(thread_id, item)| (*thread_id, item.item_id.clone())) - .collect(); - for (thread_id, item_id) in active { - db.mark_agent_job_item_failed(job_id, item_id.as_str(), error_message) - .await?; - let _ = session - .services - .agent_control - .shutdown_live_agent(thread_id) - .await; - active_items.remove(&thread_id); - } - Ok(true) -} - -async fn finalize_finished_item( - session: Arc, - db: Arc, - job_id: &str, - item_id: &str, - thread_id: ThreadId, -) -> anyhow::Result<()> { - let item = db - .get_agent_job_item(job_id, item_id) - .await? - .ok_or_else(|| { - anyhow::anyhow!("job item not found for finalization: {job_id}/{item_id}") - })?; - if matches!(item.status, codex_state::AgentJobItemStatus::Running) { - if item.result_json.is_some() { - let _ = db.mark_agent_job_item_completed(job_id, item_id).await?; - } else { - let _ = db - .mark_agent_job_item_failed( - job_id, - item_id, - "worker finished without calling report_agent_job_result", - ) - .await?; - } - } - let _ = session - .services - .agent_control - .shutdown_live_agent(thread_id) - .await; - Ok(()) -} - -fn build_worker_prompt( - job: &codex_state::AgentJob, - item: &codex_state::AgentJobItem, -) -> anyhow::Result { - let job_id = job.id.as_str(); - let item_id = item.item_id.as_str(); - let instruction = render_instruction_template(job.instruction.as_str(), &item.row_json); - let output_schema = job - .output_schema_json - .as_ref() - .map(serde_json::to_string_pretty) - .transpose()? - .unwrap_or_else(|| "{}".to_string()); - let row_json = serde_json::to_string_pretty(&item.row_json)?; - Ok(format!( - "You are processing one item for a generic agent job.\n\ -Job ID: {job_id}\n\ -Item ID: {item_id}\n\n\ -Task instruction:\n\ -{instruction}\n\n\ -Input row (JSON):\n\ -{row_json}\n\n\ -Expected result schema (JSON Schema or {{}}):\n\ -{output_schema}\n\n\ -You MUST call the `report_agent_job_result` tool exactly once with:\n\ -1. `job_id` = \"{job_id}\"\n\ -2. `item_id` = \"{item_id}\"\n\ -3. `result` = a JSON object that contains your analysis result for this row.\n\n\ -If you need to stop the job early, include `stop` = true in the tool call.\n\n\ -After the tool call succeeds, stop.", - )) -} - -fn render_instruction_template(instruction: &str, row_json: &Value) -> String { - const OPEN_BRACE_SENTINEL: &str = "__CODEX_OPEN_BRACE__"; - const CLOSE_BRACE_SENTINEL: &str = "__CODEX_CLOSE_BRACE__"; - - let mut rendered = instruction - .replace("{{", OPEN_BRACE_SENTINEL) - .replace("}}", CLOSE_BRACE_SENTINEL); - let Some(row) = row_json.as_object() else { - return rendered - .replace(OPEN_BRACE_SENTINEL, "{") - .replace(CLOSE_BRACE_SENTINEL, "}"); - }; - for (key, value) in row { - let placeholder = format!("{{{key}}}"); - let replacement = value - .as_str() - .map(str::to_string) - .unwrap_or_else(|| value.to_string()); - rendered = rendered.replace(placeholder.as_str(), replacement.as_str()); - } - rendered - .replace(OPEN_BRACE_SENTINEL, "{") - .replace(CLOSE_BRACE_SENTINEL, "}") -} - -fn ensure_unique_headers(headers: &[String]) -> Result<(), FunctionCallError> { - let mut seen = HashSet::new(); - for header in headers { - if !seen.insert(header) { - return Err(FunctionCallError::RespondToModel(format!( - "csv header {header} is duplicated" - ))); - } - } - Ok(()) -} - -fn job_runtime_timeout(job: &codex_state::AgentJob) -> Duration { - job.max_runtime_seconds - .map(Duration::from_secs) - .unwrap_or(DEFAULT_AGENT_JOB_ITEM_TIMEOUT) -} - -fn started_at_from_item(item: &codex_state::AgentJobItem) -> Instant { - let now = chrono::Utc::now(); - let age = now.signed_duration_since(item.updated_at); - if let Ok(age) = age.to_std() { - Instant::now().checked_sub(age).unwrap_or_else(Instant::now) - } else { - Instant::now() - } -} - -fn is_item_stale(item: &codex_state::AgentJobItem, runtime_timeout: Duration) -> bool { - let now = chrono::Utc::now(); - if let Ok(age) = now.signed_duration_since(item.updated_at).to_std() { - age >= runtime_timeout - } else { - false - } -} - -fn default_output_csv_path(input_csv_path: &AbsolutePathBuf, job_id: &str) -> AbsolutePathBuf { - let stem = input_csv_path - .as_path() - .file_stem() - .and_then(|stem| stem.to_str()) - .unwrap_or("agent_job_output"); - let job_suffix = &job_id[..8]; - let output_dir = input_csv_path - .parent() - .unwrap_or_else(|| input_csv_path.clone()); - output_dir.join(format!("{stem}.agent-job-{job_suffix}.csv")) -} - -fn parse_csv(content: &str) -> Result<(Vec, Vec>), String> { - let mut reader = csv::ReaderBuilder::new() - .has_headers(true) - .flexible(true) - .from_reader(content.as_bytes()); - let headers_record = reader.headers().map_err(|err| err.to_string())?; - let mut headers: Vec = headers_record.iter().map(str::to_string).collect(); - if let Some(first) = headers.first_mut() { - *first = first.trim_start_matches('\u{feff}').to_string(); - } - let mut rows = Vec::new(); - for record in reader.records() { - let record = record.map_err(|err| err.to_string())?; - let row: Vec = record.iter().map(str::to_string).collect(); - if row.iter().all(std::string::String::is_empty) { - continue; - } - rows.push(row); - } - Ok((headers, rows)) -} - -fn render_job_csv( - headers: &[String], - items: &[codex_state::AgentJobItem], -) -> Result { - let mut csv = String::new(); - let mut output_headers = headers.to_vec(); - output_headers.extend([ - "job_id".to_string(), - "item_id".to_string(), - "row_index".to_string(), - "source_id".to_string(), - "status".to_string(), - "attempt_count".to_string(), - "last_error".to_string(), - "result_json".to_string(), - "reported_at".to_string(), - "completed_at".to_string(), - ]); - csv.push_str( - output_headers - .iter() - .map(|header| csv_escape(header.as_str())) - .collect::>() - .join(",") - .as_str(), - ); - csv.push('\n'); - for item in items { - let row_object = item.row_json.as_object().ok_or_else(|| { - let item_id = item.item_id.as_str(); - FunctionCallError::RespondToModel(format!( - "row_json for item {item_id} is not a JSON object" - )) - })?; - let mut row_values = Vec::new(); - for header in headers { - let value = row_object - .get(header) - .map_or_else(String::new, value_to_csv_string); - row_values.push(csv_escape(value.as_str())); - } - row_values.push(csv_escape(item.job_id.as_str())); - row_values.push(csv_escape(item.item_id.as_str())); - row_values.push(csv_escape(item.row_index.to_string().as_str())); - row_values.push(csv_escape( - item.source_id.clone().unwrap_or_default().as_str(), - )); - row_values.push(csv_escape(item.status.as_str())); - row_values.push(csv_escape(item.attempt_count.to_string().as_str())); - row_values.push(csv_escape( - item.last_error.clone().unwrap_or_default().as_str(), - )); - row_values.push(csv_escape( - item.result_json - .as_ref() - .map_or_else(String::new, std::string::ToString::to_string) - .as_str(), - )); - row_values.push(csv_escape( - item.reported_at - .map(|value| value.to_rfc3339()) - .unwrap_or_default() - .as_str(), - )); - row_values.push(csv_escape( - item.completed_at - .map(|value| value.to_rfc3339()) - .unwrap_or_default() - .as_str(), - )); - csv.push_str(row_values.join(",").as_str()); - csv.push('\n'); - } - Ok(csv) -} - -fn value_to_csv_string(value: &Value) -> String { - match value { - Value::Null => String::new(), - Value::String(s) => s.clone(), - Value::Bool(b) => b.to_string(), - Value::Number(n) => n.to_string(), - Value::Array(_) | Value::Object(_) => value.to_string(), - } -} - -fn csv_escape(value: &str) -> String { - if value.contains(',') || value.contains('\n') || value.contains('\r') || value.contains('"') { - let escaped = value.replace('"', "\"\""); - format!("\"{escaped}\"") - } else { - value.to_string() - } -} - -#[cfg(test)] -#[path = "agent_jobs_tests.rs"] -mod tests; diff --git a/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs_tests.rs b/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs_tests.rs deleted file mode 100644 index a2dbe6a4..00000000 --- a/vendor/codex/codex-rs/core/src/tools/handlers/agent_jobs_tests.rs +++ /dev/null @@ -1,62 +0,0 @@ -use super::*; -use pretty_assertions::assert_eq; -use serde_json::json; - -#[test] -fn parse_csv_supports_quotes_and_commas() { - let input = "id,name\n1,\"alpha, beta\"\n2,gamma\n"; - let (headers, rows) = parse_csv(input).expect("csv parse"); - assert_eq!(headers, vec!["id".to_string(), "name".to_string()]); - assert_eq!( - rows, - vec![ - vec!["1".to_string(), "alpha, beta".to_string()], - vec!["2".to_string(), "gamma".to_string()] - ] - ); -} - -#[test] -fn csv_escape_quotes_when_needed() { - assert_eq!(csv_escape("simple"), "simple"); - assert_eq!(csv_escape("a,b"), "\"a,b\""); - assert_eq!(csv_escape("a\"b"), "\"a\"\"b\""); -} - -#[test] -fn render_instruction_template_expands_placeholders_and_escapes_braces() { - let row = json!({ - "path": "src/lib.rs", - "area": "test", - "file path": "docs/readme.md", - }); - let rendered = render_instruction_template( - "Review {path} in {area}. Also see {file path}. Use {{literal}}.", - &row, - ); - assert_eq!( - rendered, - "Review src/lib.rs in test. Also see docs/readme.md. Use {literal}." - ); -} - -#[test] -fn render_instruction_template_leaves_unknown_placeholders() { - let row = json!({ - "path": "src/lib.rs", - }); - let rendered = render_instruction_template("Check {path} then {missing}", &row); - assert_eq!(rendered, "Check src/lib.rs then {missing}"); -} - -#[test] -fn ensure_unique_headers_rejects_duplicates() { - let headers = vec!["path".to_string(), "path".to_string()]; - let Err(err) = ensure_unique_headers(headers.as_slice()) else { - panic!("expected duplicate header error"); - }; - assert_eq!( - err, - FunctionCallError::RespondToModel("csv header path is duplicated".to_string()) - ); -} diff --git a/vendor/codex/codex-rs/core/src/tools/handlers/mod.rs b/vendor/codex/codex-rs/core/src/tools/handlers/mod.rs index af4178f7..f9d719fb 100644 --- a/vendor/codex/codex-rs/core/src/tools/handlers/mod.rs +++ b/vendor/codex/codex-rs/core/src/tools/handlers/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod agent_jobs; pub(crate) mod apply_patch; mod dynamic; mod js_repl; diff --git a/vendor/codex/codex-rs/core/src/tools/handlers/multi_agents_common.rs b/vendor/codex/codex-rs/core/src/tools/handlers/multi_agents_common.rs index 5efe4e22..ac50dafa 100644 --- a/vendor/codex/codex-rs/core/src/tools/handlers/multi_agents_common.rs +++ b/vendor/codex/codex-rs/core/src/tools/handlers/multi_agents_common.rs @@ -281,7 +281,6 @@ pub(crate) fn apply_spawn_agent_runtime_overrides( pub(crate) fn apply_spawn_agent_overrides(config: &mut Config, child_depth: i32) { if child_depth >= config.agent_max_depth && !config.features.enabled(Feature::MultiAgentV2) { - let _ = config.features.disable(Feature::SpawnCsv); let _ = config.features.disable(Feature::Collab); } } diff --git a/vendor/codex/codex-rs/core/src/tools/spec.rs b/vendor/codex/codex-rs/core/src/tools/spec.rs index 41dc422e..220a079a 100644 --- a/vendor/codex/codex-rs/core/src/tools/spec.rs +++ b/vendor/codex/codex-rs/core/src/tools/spec.rs @@ -1,6 +1,5 @@ use crate::shell::Shell; use crate::shell::ShellType; -use crate::tools::handlers::agent_jobs::BatchJobHandler; use crate::tools::handlers::multi_agents_common::DEFAULT_WAIT_TIMEOUT_MS; use crate::tools::handlers::multi_agents_common::MAX_WAIT_TIMEOUT_MS; use crate::tools::handlers::multi_agents_common::MIN_WAIT_TIMEOUT_MS; @@ -188,9 +187,6 @@ pub(crate) fn build_specs_with_discoverable_tools( for handler in plan.handlers { match handler.kind { - ToolHandlerKind::AgentJobs => { - builder.register_handler(handler.name, Arc::new(BatchJobHandler)); - } ToolHandlerKind::ApplyPatch => { builder.register_handler(handler.name, apply_patch_handler.clone()); } diff --git a/vendor/codex/codex-rs/core/tests/suite/agent_jobs.rs b/vendor/codex/codex-rs/core/tests/suite/agent_jobs.rs deleted file mode 100644 index b275b187..00000000 --- a/vendor/codex/codex-rs/core/tests/suite/agent_jobs.rs +++ /dev/null @@ -1,448 +0,0 @@ -use anyhow::Result; -use codex_features::Feature; -use core_test_support::responses::ev_completed; -use core_test_support::responses::ev_function_call; -use core_test_support::responses::ev_response_created; -use core_test_support::responses::sse; -use core_test_support::responses::sse_response; -use core_test_support::responses::start_mock_server; -use core_test_support::test_codex::test_codex; -use regex_lite::Regex; -use serde_json::Value; -use serde_json::json; -use std::fs; -use std::sync::Arc; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use wiremock::Mock; -use wiremock::Respond; -use wiremock::ResponseTemplate; -use wiremock::matchers::method; -use wiremock::matchers::path_regex; - -struct AgentJobsResponder { - spawn_args_json: String, - seen_main: AtomicBool, - call_counter: AtomicUsize, -} - -impl AgentJobsResponder { - fn new(spawn_args_json: String) -> Self { - Self { - spawn_args_json, - seen_main: AtomicBool::new(false), - call_counter: AtomicUsize::new(0), - } - } -} - -struct StopAfterFirstResponder { - spawn_args_json: String, - seen_main: AtomicBool, - worker_calls: Arc, -} - -impl StopAfterFirstResponder { - fn new(spawn_args_json: String, worker_calls: Arc) -> Self { - Self { - spawn_args_json, - seen_main: AtomicBool::new(false), - worker_calls, - } - } -} - -impl Respond for StopAfterFirstResponder { - fn respond(&self, request: &wiremock::Request) -> ResponseTemplate { - let body_bytes = decode_body_bytes(request); - let body: Value = serde_json::from_slice(&body_bytes).unwrap_or(Value::Null); - - if has_function_call_output(&body) { - return sse_response(sse(vec![ - ev_response_created("resp-tool"), - ev_completed("resp-tool"), - ])); - } - - if let Some((job_id, item_id)) = extract_job_and_item(&body) { - let call_index = self.worker_calls.fetch_add(1, Ordering::SeqCst); - let call_id = format!("call-worker-{call_index}"); - let stop = call_index == 0; - let args = json!({ - "job_id": job_id, - "item_id": item_id, - "result": { "item_id": item_id }, - "stop": stop, - }); - let args_json = serde_json::to_string(&args).unwrap_or_else(|err| { - panic!("worker args serialize: {err}"); - }); - return sse_response(sse(vec![ - ev_response_created("resp-worker"), - ev_function_call(&call_id, "report_agent_job_result", &args_json), - ev_completed("resp-worker"), - ])); - } - - if !self.seen_main.swap(true, Ordering::SeqCst) { - return sse_response(sse(vec![ - ev_response_created("resp-main"), - ev_function_call("call-spawn", "spawn_agents_on_csv", &self.spawn_args_json), - ev_completed("resp-main"), - ])); - } - - sse_response(sse(vec![ - ev_response_created("resp-default"), - ev_completed("resp-default"), - ])) - } -} - -impl Respond for AgentJobsResponder { - fn respond(&self, request: &wiremock::Request) -> ResponseTemplate { - let body_bytes = decode_body_bytes(request); - let body: Value = serde_json::from_slice(&body_bytes).unwrap_or(Value::Null); - - if has_function_call_output(&body) { - return sse_response(sse(vec![ - ev_response_created("resp-tool"), - ev_completed("resp-tool"), - ])); - } - - if let Some((job_id, item_id)) = extract_job_and_item(&body) { - let call_id = format!( - "call-worker-{}", - self.call_counter.fetch_add(1, Ordering::SeqCst) - ); - let args = json!({ - "job_id": job_id, - "item_id": item_id, - "result": { "item_id": item_id } - }); - let args_json = serde_json::to_string(&args).unwrap_or_else(|err| { - panic!("worker args serialize: {err}"); - }); - return sse_response(sse(vec![ - ev_response_created("resp-worker"), - ev_function_call(&call_id, "report_agent_job_result", &args_json), - ev_completed("resp-worker"), - ])); - } - - if !self.seen_main.swap(true, Ordering::SeqCst) { - return sse_response(sse(vec![ - ev_response_created("resp-main"), - ev_function_call("call-spawn", "spawn_agents_on_csv", &self.spawn_args_json), - ev_completed("resp-main"), - ])); - } - - sse_response(sse(vec![ - ev_response_created("resp-default"), - ev_completed("resp-default"), - ])) - } -} - -fn decode_body_bytes(request: &wiremock::Request) -> Vec { - let Some(encoding) = request - .headers - .get("content-encoding") - .and_then(|value| value.to_str().ok()) - else { - return request.body.clone(); - }; - if encoding - .split(',') - .any(|entry| entry.trim().eq_ignore_ascii_case("zstd")) - { - zstd::stream::decode_all(std::io::Cursor::new(&request.body)) - .unwrap_or_else(|_| request.body.clone()) - } else { - request.body.clone() - } -} - -fn has_function_call_output(body: &Value) -> bool { - body.get("input") - .and_then(Value::as_array) - .is_some_and(|items| { - items.iter().any(|item| { - item.get("type").and_then(Value::as_str) == Some("function_call_output") - }) - }) -} - -fn extract_job_and_item(body: &Value) -> Option<(String, String)> { - let texts = message_input_texts(body); - let mut combined = texts.join("\n"); - if let Some(instructions) = body.get("instructions").and_then(Value::as_str) { - combined.push('\n'); - combined.push_str(instructions); - } - if !combined.contains("You are processing one item for a generic agent job.") { - return None; - } - let job_id = Regex::new(r"Job ID:\s*([^\n]+)") - .ok()? - .captures(&combined) - .and_then(|caps| caps.get(1)) - .map(|m| m.as_str().trim().to_string())?; - let item_id = Regex::new(r"Item ID:\s*([^\n]+)") - .ok()? - .captures(&combined) - .and_then(|caps| caps.get(1)) - .map(|m| m.as_str().trim().to_string())?; - Some((job_id, item_id)) -} - -fn message_input_texts(body: &Value) -> Vec { - let Some(items) = body.get("input").and_then(Value::as_array) else { - return Vec::new(); - }; - items - .iter() - .filter(|item| item.get("type").and_then(Value::as_str) == Some("message")) - .filter_map(|item| item.get("content").and_then(Value::as_array)) - .flatten() - .filter(|span| span.get("type").and_then(Value::as_str) == Some("input_text")) - .filter_map(|span| span.get("text").and_then(Value::as_str)) - .map(str::to_string) - .collect() -} - -fn parse_simple_csv_line(line: &str) -> Vec { - line.split(',').map(str::to_string).collect() -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn report_agent_job_result_rejects_wrong_thread() -> Result<()> { - let server = start_mock_server().await; - let mut builder = test_codex().with_config(|config| { - config - .features - .enable(Feature::SpawnCsv) - .expect("test config should allow feature update"); - config - .features - .enable(Feature::Sqlite) - .expect("test config should allow feature update"); - }); - let test = builder.build(&server).await?; - - let input_path = test.cwd_path().join("agent_jobs_wrong_thread.csv"); - let output_path = test.cwd_path().join("agent_jobs_wrong_thread_out.csv"); - fs::write(&input_path, "path\nfile-1\n")?; - - let args = json!({ - "csv_path": input_path.display().to_string(), - "instruction": "Return {path}", - "output_csv_path": output_path.display().to_string(), - }); - let args_json = serde_json::to_string(&args)?; - - let responder = AgentJobsResponder::new(args_json); - Mock::given(method("POST")) - .and(path_regex(".*/responses$")) - .respond_with(responder) - .mount(&server) - .await; - - test.submit_turn("run job").await?; - - let db = test.codex.state_db().expect("state db"); - let output = fs::read_to_string(&output_path)?; - let rows: Vec<&str> = output.lines().skip(1).collect(); - assert_eq!(rows.len(), 1); - let job_id = rows - .first() - .and_then(|line| { - parse_simple_csv_line(line) - .iter() - .find(|value| value.len() == 36) - .cloned() - }) - .expect("job_id from csv"); - let job = db.get_agent_job(job_id.as_str()).await?.expect("job"); - let items = db - .list_agent_job_items(job.id.as_str(), /*status*/ None, Some(10)) - .await?; - let item = items.first().expect("item"); - let wrong_thread_id = "00000000-0000-0000-0000-000000000000"; - let accepted = db - .report_agent_job_item_result( - job.id.as_str(), - item.item_id.as_str(), - wrong_thread_id, - &json!({ "wrong": true }), - ) - .await?; - assert!(!accepted); - Ok(()) -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn spawn_agents_on_csv_runs_and_exports() -> Result<()> { - let server = start_mock_server().await; - let mut builder = test_codex().with_config(|config| { - config - .features - .enable(Feature::SpawnCsv) - .expect("test config should allow feature update"); - config - .features - .enable(Feature::Sqlite) - .expect("test config should allow feature update"); - }); - let test = builder.build(&server).await?; - - let input_path = test.cwd_path().join("agent_jobs_input.csv"); - let output_path = test.cwd_path().join("agent_jobs_output.csv"); - fs::write(&input_path, "path,area\nfile-1,test\nfile-2,test\n")?; - - let args = json!({ - "csv_path": input_path.display().to_string(), - "instruction": "Return {path}", - "output_csv_path": output_path.display().to_string(), - }); - let args_json = serde_json::to_string(&args)?; - - let responder = AgentJobsResponder::new(args_json); - Mock::given(method("POST")) - .and(path_regex(".*/responses$")) - .respond_with(responder) - .mount(&server) - .await; - - test.submit_turn("run batch job").await?; - - let output = fs::read_to_string(&output_path)?; - assert!(output.contains("result_json")); - assert!(output.contains("item_id")); - assert!(output.contains("\"item_id\"")); - Ok(()) -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn spawn_agents_on_csv_dedupes_item_ids() -> Result<()> { - let server = start_mock_server().await; - - let mut builder = test_codex().with_config(|config| { - config - .features - .enable(Feature::SpawnCsv) - .expect("test config should allow feature update"); - config - .features - .enable(Feature::Sqlite) - .expect("test config should allow feature update"); - }); - let test = builder.build(&server).await?; - - let input_path = test.cwd_path().join("agent_jobs_dupe.csv"); - let output_path = test.cwd_path().join("agent_jobs_dupe_out.csv"); - fs::write(&input_path, "id,path\nfoo,alpha\nfoo,beta\n")?; - - let args = json!({ - "csv_path": input_path.display().to_string(), - "instruction": "Return {path}", - "id_column": "id", - "output_csv_path": output_path.display().to_string(), - }); - let args_json = serde_json::to_string(&args)?; - - let responder = AgentJobsResponder::new(args_json); - Mock::given(method("POST")) - .and(path_regex(".*/responses$")) - .respond_with(responder) - .mount(&server) - .await; - - test.submit_turn("run batch job with duplicate ids").await?; - - let output = fs::read_to_string(&output_path)?; - let mut lines = output.lines(); - let headers = lines.next().expect("csv headers"); - let header_cols = parse_simple_csv_line(headers); - let item_id_index = header_cols - .iter() - .position(|header| header == "item_id") - .expect("item_id column"); - - let mut item_ids = Vec::new(); - for line in lines { - let cols = parse_simple_csv_line(line); - item_ids.push(cols[item_id_index].clone()); - } - item_ids.sort(); - item_ids.dedup(); - assert_eq!(item_ids.len(), 2); - assert!(item_ids.contains(&"foo".to_string())); - assert!(item_ids.contains(&"foo-2".to_string())); - Ok(()) -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn spawn_agents_on_csv_stop_halts_future_items() -> Result<()> { - let server = start_mock_server().await; - let mut builder = test_codex().with_config(|config| { - config - .features - .enable(Feature::SpawnCsv) - .expect("test config should allow feature update"); - config - .features - .enable(Feature::Sqlite) - .expect("test config should allow feature update"); - }); - let test = builder.build(&server).await?; - - let input_path = test.cwd_path().join("agent_jobs_stop.csv"); - let output_path = test.cwd_path().join("agent_jobs_stop_out.csv"); - fs::write(&input_path, "path\nfile-1\nfile-2\nfile-3\n")?; - - let args = json!({ - "csv_path": input_path.display().to_string(), - "instruction": "Return {path}", - "output_csv_path": output_path.display().to_string(), - "max_concurrency": 1, - }); - let args_json = serde_json::to_string(&args)?; - - let worker_calls = Arc::new(AtomicUsize::new(0)); - let responder = StopAfterFirstResponder::new(args_json, worker_calls.clone()); - Mock::given(method("POST")) - .and(path_regex(".*/responses$")) - .respond_with(responder) - .mount(&server) - .await; - - test.submit_turn("run job").await?; - - let output = fs::read_to_string(&output_path)?; - let rows: Vec<&str> = output.lines().skip(1).collect(); - assert_eq!(rows.len(), 3); - let job_id = rows - .first() - .and_then(|line| { - parse_simple_csv_line(line) - .iter() - .find(|value| value.len() == 36) - .cloned() - }) - .expect("job_id from csv"); - let db = test.codex.state_db().expect("state db"); - let job = db.get_agent_job(job_id.as_str()).await?.expect("job"); - assert_eq!(job.status, codex_state::AgentJobStatus::Cancelled); - let progress = db.get_agent_job_progress(job_id.as_str()).await?; - assert_eq!(progress.total_items, 3); - assert_eq!(progress.completed_items, 1); - assert_eq!(progress.failed_items, 0); - assert_eq!(progress.running_items, 0); - assert_eq!(progress.pending_items, 2); - assert_eq!(worker_calls.load(Ordering::SeqCst), 1); - Ok(()) -} diff --git a/vendor/codex/codex-rs/core/tests/suite/mod.rs b/vendor/codex/codex-rs/core/tests/suite/mod.rs index 6c4cb198..313aad41 100644 --- a/vendor/codex/codex-rs/core/tests/suite/mod.rs +++ b/vendor/codex/codex-rs/core/tests/suite/mod.rs @@ -25,7 +25,6 @@ pub static CODEX_ALIASES_TEMP_DIR: Option = { #[cfg(not(target_os = "windows"))] mod abort_tasks; -mod agent_jobs; mod agent_websocket; mod agents_md; mod apply_patch_cli; diff --git a/vendor/codex/codex-rs/features/src/lib.rs b/vendor/codex/codex-rs/features/src/lib.rs index 9b9dddfc..295e4ce1 100644 --- a/vendor/codex/codex-rs/features/src/lib.rs +++ b/vendor/codex/codex-rs/features/src/lib.rs @@ -142,8 +142,6 @@ pub enum Feature { Collab, /// Enable task-path-based multi-agent routing. MultiAgentV2, - /// Enable CSV-backed agent job tools. - SpawnCsv, /// Enable apps. Apps, /// Enable the tool_search tool for apps. @@ -447,9 +445,6 @@ impl Features { } pub fn normalize_dependencies(&mut self) { - if self.enabled(Feature::SpawnCsv) && !self.enabled(Feature::Collab) { - self.enable(Feature::Collab); - } if self.enabled(Feature::CodeModeOnly) && !self.enabled(Feature::CodeMode) { self.enable(Feature::CodeMode); } @@ -814,12 +809,6 @@ pub const FEATURES: &[FeatureSpec] = &[ stage: Stage::UnderDevelopment, default_enabled: false, }, - FeatureSpec { - id: Feature::SpawnCsv, - key: "enable_fanout", - stage: Stage::UnderDevelopment, - default_enabled: false, - }, FeatureSpec { id: Feature::Apps, key: "apps", diff --git a/vendor/codex/codex-rs/features/src/tests.rs b/vendor/codex/codex-rs/features/src/tests.rs index f5704dd7..73ed0112 100644 --- a/vendor/codex/codex-rs/features/src/tests.rs +++ b/vendor/codex/codex-rs/features/src/tests.rs @@ -260,27 +260,6 @@ fn multi_agent_is_stable_and_enabled_by_default() { assert_eq!(Feature::Collab.default_enabled(), true); } -#[test] -fn enable_fanout_is_under_development() { - assert_eq!(Feature::SpawnCsv.stage(), Stage::UnderDevelopment); - assert_eq!(Feature::SpawnCsv.default_enabled(), false); -} - -#[test] -fn enable_fanout_normalization_enables_multi_agent_one_way() { - let mut enable_fanout_features = Features::with_defaults(); - enable_fanout_features.enable(Feature::SpawnCsv); - enable_fanout_features.normalize_dependencies(); - assert_eq!(enable_fanout_features.enabled(Feature::SpawnCsv), true); - assert_eq!(enable_fanout_features.enabled(Feature::Collab), true); - - let mut collab_features = Features::with_defaults(); - collab_features.enable(Feature::Collab); - collab_features.normalize_dependencies(); - assert_eq!(collab_features.enabled(Feature::Collab), true); - assert_eq!(collab_features.enabled(Feature::SpawnCsv), false); -} - #[test] fn apps_require_feature_flag_and_chatgpt_auth() { let mut features = Features::with_defaults(); diff --git a/vendor/codex/codex-rs/state/migrations/0014_agent_jobs.sql b/vendor/codex/codex-rs/state/migrations/0014_agent_jobs.sql deleted file mode 100644 index d8968c40..00000000 --- a/vendor/codex/codex-rs/state/migrations/0014_agent_jobs.sql +++ /dev/null @@ -1,38 +0,0 @@ -CREATE TABLE agent_jobs ( - id TEXT PRIMARY KEY, - name TEXT NOT NULL, - status TEXT NOT NULL, - instruction TEXT NOT NULL, - output_schema_json TEXT, - input_headers_json TEXT NOT NULL, - input_csv_path TEXT NOT NULL, - output_csv_path TEXT NOT NULL, - auto_export INTEGER NOT NULL DEFAULT 1, - created_at INTEGER NOT NULL, - updated_at INTEGER NOT NULL, - started_at INTEGER, - completed_at INTEGER, - last_error TEXT -); - -CREATE TABLE agent_job_items ( - job_id TEXT NOT NULL, - item_id TEXT NOT NULL, - row_index INTEGER NOT NULL, - source_id TEXT, - row_json TEXT NOT NULL, - status TEXT NOT NULL, - assigned_thread_id TEXT, - attempt_count INTEGER NOT NULL DEFAULT 0, - result_json TEXT, - last_error TEXT, - created_at INTEGER NOT NULL, - updated_at INTEGER NOT NULL, - completed_at INTEGER, - reported_at INTEGER, - PRIMARY KEY (job_id, item_id), - FOREIGN KEY(job_id) REFERENCES agent_jobs(id) ON DELETE CASCADE -); - -CREATE INDEX idx_agent_jobs_status ON agent_jobs(status, updated_at DESC); -CREATE INDEX idx_agent_job_items_status ON agent_job_items(job_id, status, row_index ASC); diff --git a/vendor/codex/codex-rs/state/migrations/0015_agent_jobs_max_runtime_seconds.sql b/vendor/codex/codex-rs/state/migrations/0015_agent_jobs_max_runtime_seconds.sql deleted file mode 100644 index ab1006d4..00000000 --- a/vendor/codex/codex-rs/state/migrations/0015_agent_jobs_max_runtime_seconds.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE agent_jobs -ADD COLUMN max_runtime_seconds INTEGER; diff --git a/vendor/codex/codex-rs/state/src/lib.rs b/vendor/codex/codex-rs/state/src/lib.rs index 36676d5a..88ca5a9f 100644 --- a/vendor/codex/codex-rs/state/src/lib.rs +++ b/vendor/codex/codex-rs/state/src/lib.rs @@ -24,13 +24,6 @@ pub use runtime::StateRuntime; /// Most consumers should prefer [`StateRuntime`]. pub use extract::apply_rollout_item; pub use extract::rollout_item_affects_thread_metadata; -pub use model::AgentJob; -pub use model::AgentJobCreateParams; -pub use model::AgentJobItem; -pub use model::AgentJobItemCreateParams; -pub use model::AgentJobItemStatus; -pub use model::AgentJobProgress; -pub use model::AgentJobStatus; pub use model::Anchor; pub use model::BackfillState; pub use model::BackfillStats; diff --git a/vendor/codex/codex-rs/state/src/model/agent_job.rs b/vendor/codex/codex-rs/state/src/model/agent_job.rs deleted file mode 100644 index 36f9ff12..00000000 --- a/vendor/codex/codex-rs/state/src/model/agent_job.rs +++ /dev/null @@ -1,256 +0,0 @@ -use anyhow::Result; -use chrono::DateTime; -use chrono::Utc; -use serde_json::Value; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum AgentJobStatus { - Pending, - Running, - Completed, - Failed, - Cancelled, -} - -impl AgentJobStatus { - pub const fn as_str(self) -> &'static str { - match self { - AgentJobStatus::Pending => "pending", - AgentJobStatus::Running => "running", - AgentJobStatus::Completed => "completed", - AgentJobStatus::Failed => "failed", - AgentJobStatus::Cancelled => "cancelled", - } - } - - pub fn parse(value: &str) -> Result { - match value { - "pending" => Ok(Self::Pending), - "running" => Ok(Self::Running), - "completed" => Ok(Self::Completed), - "failed" => Ok(Self::Failed), - "cancelled" => Ok(Self::Cancelled), - _ => Err(anyhow::anyhow!("invalid agent job status: {value}")), - } - } - - pub fn is_final(self) -> bool { - matches!( - self, - AgentJobStatus::Completed | AgentJobStatus::Failed | AgentJobStatus::Cancelled - ) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum AgentJobItemStatus { - Pending, - Running, - Completed, - Failed, -} - -impl AgentJobItemStatus { - pub const fn as_str(self) -> &'static str { - match self { - AgentJobItemStatus::Pending => "pending", - AgentJobItemStatus::Running => "running", - AgentJobItemStatus::Completed => "completed", - AgentJobItemStatus::Failed => "failed", - } - } - - pub fn parse(value: &str) -> Result { - match value { - "pending" => Ok(Self::Pending), - "running" => Ok(Self::Running), - "completed" => Ok(Self::Completed), - "failed" => Ok(Self::Failed), - _ => Err(anyhow::anyhow!("invalid agent job item status: {value}")), - } - } -} - -#[derive(Debug, Clone, PartialEq)] -pub struct AgentJob { - pub id: String, - pub name: String, - pub status: AgentJobStatus, - pub instruction: String, - pub auto_export: bool, - pub max_runtime_seconds: Option, - // TODO(jif-oai): Convert to JSON Schema and enforce structured outputs. - pub output_schema_json: Option, - pub input_headers: Vec, - pub input_csv_path: String, - pub output_csv_path: String, - pub created_at: DateTime, - pub updated_at: DateTime, - pub started_at: Option>, - pub completed_at: Option>, - pub last_error: Option, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct AgentJobItem { - pub job_id: String, - pub item_id: String, - pub row_index: i64, - pub source_id: Option, - pub row_json: Value, - pub status: AgentJobItemStatus, - pub assigned_thread_id: Option, - pub attempt_count: i64, - pub result_json: Option, - pub last_error: Option, - pub created_at: DateTime, - pub updated_at: DateTime, - pub completed_at: Option>, - pub reported_at: Option>, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct AgentJobProgress { - pub total_items: usize, - pub pending_items: usize, - pub running_items: usize, - pub completed_items: usize, - pub failed_items: usize, -} - -#[derive(Debug, Clone)] -pub struct AgentJobCreateParams { - pub id: String, - pub name: String, - pub instruction: String, - pub auto_export: bool, - pub max_runtime_seconds: Option, - pub output_schema_json: Option, - pub input_headers: Vec, - pub input_csv_path: String, - pub output_csv_path: String, -} - -#[derive(Debug, Clone)] -pub struct AgentJobItemCreateParams { - pub item_id: String, - pub row_index: i64, - pub source_id: Option, - pub row_json: Value, -} - -#[derive(Debug, sqlx::FromRow)] -pub(crate) struct AgentJobRow { - pub(crate) id: String, - pub(crate) name: String, - pub(crate) status: String, - pub(crate) instruction: String, - pub(crate) auto_export: i64, - pub(crate) max_runtime_seconds: Option, - pub(crate) output_schema_json: Option, - pub(crate) input_headers_json: String, - pub(crate) input_csv_path: String, - pub(crate) output_csv_path: String, - pub(crate) created_at: i64, - pub(crate) updated_at: i64, - pub(crate) started_at: Option, - pub(crate) completed_at: Option, - pub(crate) last_error: Option, -} - -impl TryFrom for AgentJob { - type Error = anyhow::Error; - - fn try_from(value: AgentJobRow) -> Result { - let output_schema_json = value - .output_schema_json - .as_deref() - .map(serde_json::from_str) - .transpose()?; - let input_headers = serde_json::from_str(value.input_headers_json.as_str())?; - let max_runtime_seconds = value - .max_runtime_seconds - .map(u64::try_from) - .transpose() - .map_err(|_| anyhow::anyhow!("invalid max_runtime_seconds value"))?; - Ok(Self { - id: value.id, - name: value.name, - status: AgentJobStatus::parse(value.status.as_str())?, - instruction: value.instruction, - auto_export: value.auto_export != 0, - max_runtime_seconds, - output_schema_json, - input_headers, - input_csv_path: value.input_csv_path, - output_csv_path: value.output_csv_path, - created_at: epoch_seconds_to_datetime(value.created_at)?, - updated_at: epoch_seconds_to_datetime(value.updated_at)?, - started_at: value - .started_at - .map(epoch_seconds_to_datetime) - .transpose()?, - completed_at: value - .completed_at - .map(epoch_seconds_to_datetime) - .transpose()?, - last_error: value.last_error, - }) - } -} - -#[derive(Debug, sqlx::FromRow)] -pub(crate) struct AgentJobItemRow { - pub(crate) job_id: String, - pub(crate) item_id: String, - pub(crate) row_index: i64, - pub(crate) source_id: Option, - pub(crate) row_json: String, - pub(crate) status: String, - pub(crate) assigned_thread_id: Option, - pub(crate) attempt_count: i64, - pub(crate) result_json: Option, - pub(crate) last_error: Option, - pub(crate) created_at: i64, - pub(crate) updated_at: i64, - pub(crate) completed_at: Option, - pub(crate) reported_at: Option, -} - -impl TryFrom for AgentJobItem { - type Error = anyhow::Error; - - fn try_from(value: AgentJobItemRow) -> Result { - Ok(Self { - job_id: value.job_id, - item_id: value.item_id, - row_index: value.row_index, - source_id: value.source_id, - row_json: serde_json::from_str(value.row_json.as_str())?, - status: AgentJobItemStatus::parse(value.status.as_str())?, - assigned_thread_id: value.assigned_thread_id, - attempt_count: value.attempt_count, - result_json: value - .result_json - .as_deref() - .map(serde_json::from_str) - .transpose()?, - last_error: value.last_error, - created_at: epoch_seconds_to_datetime(value.created_at)?, - updated_at: epoch_seconds_to_datetime(value.updated_at)?, - completed_at: value - .completed_at - .map(epoch_seconds_to_datetime) - .transpose()?, - reported_at: value - .reported_at - .map(epoch_seconds_to_datetime) - .transpose()?, - }) - } -} - -fn epoch_seconds_to_datetime(secs: i64) -> Result> { - DateTime::::from_timestamp(secs, 0) - .ok_or_else(|| anyhow::anyhow!("invalid unix timestamp: {secs}")) -} diff --git a/vendor/codex/codex-rs/state/src/model/mod.rs b/vendor/codex/codex-rs/state/src/model/mod.rs index a5f9531a..d9a60b75 100644 --- a/vendor/codex/codex-rs/state/src/model/mod.rs +++ b/vendor/codex/codex-rs/state/src/model/mod.rs @@ -1,17 +1,9 @@ -mod agent_job; mod backfill_state; mod graph; mod log; mod memories; mod thread_metadata; -pub use agent_job::AgentJob; -pub use agent_job::AgentJobCreateParams; -pub use agent_job::AgentJobItem; -pub use agent_job::AgentJobItemCreateParams; -pub use agent_job::AgentJobItemStatus; -pub use agent_job::AgentJobProgress; -pub use agent_job::AgentJobStatus; pub use backfill_state::BackfillState; pub use backfill_state::BackfillStatus; pub use graph::DirectionalThreadSpawnEdgeStatus; @@ -34,8 +26,6 @@ pub use thread_metadata::ThreadMetadata; pub use thread_metadata::ThreadMetadataBuilder; pub use thread_metadata::ThreadsPage; -pub(crate) use agent_job::AgentJobItemRow; -pub(crate) use agent_job::AgentJobRow; pub(crate) use memories::Stage1OutputRow; pub(crate) use memories::stage1_output_ref_from_parts; pub(crate) use thread_metadata::ThreadRow; diff --git a/vendor/codex/codex-rs/state/src/runtime.rs b/vendor/codex/codex-rs/state/src/runtime.rs index 67eb5377..025d0d7a 100644 --- a/vendor/codex/codex-rs/state/src/runtime.rs +++ b/vendor/codex/codex-rs/state/src/runtime.rs @@ -1,10 +1,3 @@ -use crate::AgentJob; -use crate::AgentJobCreateParams; -use crate::AgentJobItem; -use crate::AgentJobItemCreateParams; -use crate::AgentJobItemStatus; -use crate::AgentJobProgress; -use crate::AgentJobStatus; use crate::LOGS_DB_FILENAME; use crate::LOGS_DB_VERSION; use crate::LogEntry; @@ -19,7 +12,6 @@ use crate::ThreadsPage; use crate::apply_rollout_item; use crate::migrations::runtime_logs_migrator; use crate::migrations::runtime_state_migrator; -use crate::model::AgentJobRow; use crate::model::ThreadRow; use crate::model::anchor_from_item; use crate::model::datetime_to_epoch_millis; @@ -53,7 +45,6 @@ use std::sync::atomic::AtomicI64; use std::time::Duration; use tracing::warn; -mod agent_jobs; mod backfill; mod logs; mod memories; diff --git a/vendor/codex/codex-rs/state/src/runtime/agent_jobs.rs b/vendor/codex/codex-rs/state/src/runtime/agent_jobs.rs deleted file mode 100644 index 433eb5fe..00000000 --- a/vendor/codex/codex-rs/state/src/runtime/agent_jobs.rs +++ /dev/null @@ -1,796 +0,0 @@ -use super::*; -use crate::model::AgentJobItemRow; - -impl StateRuntime { - pub async fn create_agent_job( - &self, - params: &AgentJobCreateParams, - items: &[AgentJobItemCreateParams], - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let input_headers_json = serde_json::to_string(¶ms.input_headers)?; - let output_schema_json = params - .output_schema_json - .as_ref() - .map(serde_json::to_string) - .transpose()?; - let max_runtime_seconds = params - .max_runtime_seconds - .map(i64::try_from) - .transpose() - .map_err(|_| anyhow::anyhow!("invalid max_runtime_seconds value"))?; - let mut tx = self.pool.begin().await?; - sqlx::query( - r#" -INSERT INTO agent_jobs ( - id, - name, - status, - instruction, - auto_export, - max_runtime_seconds, - output_schema_json, - input_headers_json, - input_csv_path, - output_csv_path, - created_at, - updated_at, - started_at, - completed_at, - last_error -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, NULL) - "#, - ) - .bind(params.id.as_str()) - .bind(params.name.as_str()) - .bind(AgentJobStatus::Pending.as_str()) - .bind(params.instruction.as_str()) - .bind(i64::from(params.auto_export)) - .bind(max_runtime_seconds) - .bind(output_schema_json) - .bind(input_headers_json) - .bind(params.input_csv_path.as_str()) - .bind(params.output_csv_path.as_str()) - .bind(now) - .bind(now) - .execute(&mut *tx) - .await?; - - for item in items { - let row_json = serde_json::to_string(&item.row_json)?; - sqlx::query( - r#" -INSERT INTO agent_job_items ( - job_id, - item_id, - row_index, - source_id, - row_json, - status, - assigned_thread_id, - attempt_count, - result_json, - last_error, - created_at, - updated_at, - completed_at, - reported_at -) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, NULL, NULL, ?, ?, NULL, NULL) - "#, - ) - .bind(params.id.as_str()) - .bind(item.item_id.as_str()) - .bind(item.row_index) - .bind(item.source_id.as_deref()) - .bind(row_json) - .bind(AgentJobItemStatus::Pending.as_str()) - .bind(now) - .bind(now) - .execute(&mut *tx) - .await?; - } - - tx.commit().await?; - - let job_id = params.id.as_str(); - self.get_agent_job(job_id) - .await? - .ok_or_else(|| anyhow::anyhow!("failed to load created agent job {job_id}")) - } - - pub async fn get_agent_job(&self, job_id: &str) -> anyhow::Result> { - let row = sqlx::query_as::<_, AgentJobRow>( - r#" -SELECT - id, - name, - status, - instruction, - auto_export, - max_runtime_seconds, - output_schema_json, - input_headers_json, - input_csv_path, - output_csv_path, - created_at, - updated_at, - started_at, - completed_at, - last_error -FROM agent_jobs -WHERE id = ? - "#, - ) - .bind(job_id) - .fetch_optional(self.pool.as_ref()) - .await?; - row.map(AgentJob::try_from).transpose() - } - - pub async fn list_agent_job_items( - &self, - job_id: &str, - status: Option, - limit: Option, - ) -> anyhow::Result> { - let mut builder = QueryBuilder::::new( - r#" -SELECT - job_id, - item_id, - row_index, - source_id, - row_json, - status, - assigned_thread_id, - attempt_count, - result_json, - last_error, - created_at, - updated_at, - completed_at, - reported_at -FROM agent_job_items -WHERE job_id = - "#, - ); - builder.push_bind(job_id); - if let Some(status) = status { - builder.push(" AND status = "); - builder.push_bind(status.as_str()); - } - builder.push(" ORDER BY row_index ASC"); - if let Some(limit) = limit { - builder.push(" LIMIT "); - builder.push_bind(limit as i64); - } - let rows: Vec = builder - .build_query_as::() - .fetch_all(self.pool.as_ref()) - .await?; - rows.into_iter().map(AgentJobItem::try_from).collect() - } - - pub async fn get_agent_job_item( - &self, - job_id: &str, - item_id: &str, - ) -> anyhow::Result> { - let row: Option = sqlx::query_as::<_, AgentJobItemRow>( - r#" -SELECT - job_id, - item_id, - row_index, - source_id, - row_json, - status, - assigned_thread_id, - attempt_count, - result_json, - last_error, - created_at, - updated_at, - completed_at, - reported_at -FROM agent_job_items -WHERE job_id = ? AND item_id = ? - "#, - ) - .bind(job_id) - .bind(item_id) - .fetch_optional(self.pool.as_ref()) - .await?; - row.map(AgentJobItem::try_from).transpose() - } - - pub async fn latest_agent_job_item_by_source_id( - &self, - source_id: &str, - ) -> anyhow::Result> { - let row: Option = sqlx::query_as::<_, AgentJobItemRow>( - r#" -SELECT - job_id, - item_id, - row_index, - source_id, - row_json, - status, - assigned_thread_id, - attempt_count, - result_json, - last_error, - created_at, - updated_at, - completed_at, - reported_at -FROM agent_job_items -WHERE source_id = ? OR item_id = ? -ORDER BY updated_at DESC, created_at DESC -LIMIT 1 - "#, - ) - .bind(source_id) - .bind(source_id) - .fetch_optional(self.pool.as_ref()) - .await?; - let Some(row) = row else { - return Ok(None); - }; - let item = AgentJobItem::try_from(row)?; - let job = self - .get_agent_job(item.job_id.as_str()) - .await? - .ok_or_else(|| anyhow::anyhow!("agent job {} was missing", item.job_id))?; - Ok(Some((job, item))) - } - - pub async fn mark_agent_job_running(&self, job_id: &str) -> anyhow::Result<()> { - let now = Utc::now().timestamp(); - sqlx::query( - r#" -UPDATE agent_jobs -SET - status = ?, - updated_at = ?, - started_at = COALESCE(started_at, ?), - completed_at = NULL, - last_error = NULL -WHERE id = ? - "#, - ) - .bind(AgentJobStatus::Running.as_str()) - .bind(now) - .bind(now) - .bind(job_id) - .execute(self.pool.as_ref()) - .await?; - Ok(()) - } - - pub async fn mark_agent_job_completed(&self, job_id: &str) -> anyhow::Result<()> { - let now = Utc::now().timestamp(); - sqlx::query( - r#" -UPDATE agent_jobs -SET status = ?, updated_at = ?, completed_at = ?, last_error = NULL -WHERE id = ? - "#, - ) - .bind(AgentJobStatus::Completed.as_str()) - .bind(now) - .bind(now) - .bind(job_id) - .execute(self.pool.as_ref()) - .await?; - Ok(()) - } - - pub async fn mark_agent_job_failed( - &self, - job_id: &str, - error_message: &str, - ) -> anyhow::Result<()> { - let now = Utc::now().timestamp(); - sqlx::query( - r#" -UPDATE agent_jobs -SET status = ?, updated_at = ?, completed_at = ?, last_error = ? -WHERE id = ? - "#, - ) - .bind(AgentJobStatus::Failed.as_str()) - .bind(now) - .bind(now) - .bind(error_message) - .bind(job_id) - .execute(self.pool.as_ref()) - .await?; - Ok(()) - } - - pub async fn mark_agent_job_cancelled( - &self, - job_id: &str, - reason: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let mut tx = self.pool.begin().await?; - let result = sqlx::query( - r#" -UPDATE agent_jobs -SET status = ?, updated_at = ?, completed_at = ?, last_error = ? -WHERE id = ? AND status IN (?, ?) - "#, - ) - .bind(AgentJobStatus::Cancelled.as_str()) - .bind(now) - .bind(now) - .bind(reason) - .bind(job_id) - .bind(AgentJobStatus::Pending.as_str()) - .bind(AgentJobStatus::Running.as_str()) - .execute(&mut *tx) - .await?; - let cancelled = result.rows_affected() > 0; - if cancelled { - sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - completed_at = ?, - updated_at = ?, - last_error = ?, - assigned_thread_id = NULL -WHERE job_id = ? AND status = ? - "#, - ) - .bind(AgentJobItemStatus::Failed.as_str()) - .bind(now) - .bind(now) - .bind(reason) - .bind(job_id) - .bind(AgentJobItemStatus::Running.as_str()) - .execute(&mut *tx) - .await?; - } - tx.commit().await?; - Ok(cancelled) - } - - pub async fn is_agent_job_cancelled(&self, job_id: &str) -> anyhow::Result { - let row = sqlx::query( - r#" -SELECT status -FROM agent_jobs -WHERE id = ? - "#, - ) - .bind(job_id) - .fetch_optional(self.pool.as_ref()) - .await?; - let Some(row) = row else { - return Ok(false); - }; - let status: String = row.try_get("status")?; - Ok(AgentJobStatus::parse(status.as_str())? == AgentJobStatus::Cancelled) - } - - pub async fn mark_agent_job_item_running( - &self, - job_id: &str, - item_id: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - assigned_thread_id = NULL, - attempt_count = attempt_count + 1, - updated_at = ?, - last_error = NULL -WHERE job_id = ? AND item_id = ? AND status = ? - "#, - ) - .bind(AgentJobItemStatus::Running.as_str()) - .bind(now) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Pending.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn mark_agent_job_item_running_with_thread( - &self, - job_id: &str, - item_id: &str, - thread_id: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - assigned_thread_id = ?, - attempt_count = attempt_count + 1, - updated_at = ?, - last_error = NULL -WHERE job_id = ? AND item_id = ? AND status = ? - "#, - ) - .bind(AgentJobItemStatus::Running.as_str()) - .bind(thread_id) - .bind(now) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Pending.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn mark_agent_job_item_pending( - &self, - job_id: &str, - item_id: &str, - error_message: Option<&str>, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - assigned_thread_id = NULL, - updated_at = ?, - last_error = ? -WHERE job_id = ? AND item_id = ? AND status = ? - "#, - ) - .bind(AgentJobItemStatus::Pending.as_str()) - .bind(now) - .bind(error_message) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Running.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn set_agent_job_item_thread( - &self, - job_id: &str, - item_id: &str, - thread_id: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET assigned_thread_id = ?, updated_at = ? -WHERE job_id = ? AND item_id = ? AND status = ? - "#, - ) - .bind(thread_id) - .bind(now) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Running.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn report_agent_job_item_result( - &self, - job_id: &str, - item_id: &str, - reporting_thread_id: &str, - result_json: &Value, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let serialized = serde_json::to_string(result_json)?; - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - result_json = ?, - reported_at = ?, - completed_at = ?, - updated_at = ?, - last_error = NULL, - assigned_thread_id = NULL -WHERE - job_id = ? - AND item_id = ? - AND status = ? - AND assigned_thread_id = ? - "#, - ) - .bind(AgentJobItemStatus::Completed.as_str()) - .bind(serialized) - .bind(now) - .bind(now) - .bind(now) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Running.as_str()) - .bind(reporting_thread_id) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn mark_agent_job_item_completed( - &self, - job_id: &str, - item_id: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - completed_at = ?, - updated_at = ?, - assigned_thread_id = NULL -WHERE - job_id = ? - AND item_id = ? - AND status = ? - AND result_json IS NOT NULL - "#, - ) - .bind(AgentJobItemStatus::Completed.as_str()) - .bind(now) - .bind(now) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Running.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn mark_agent_job_item_failed( - &self, - job_id: &str, - item_id: &str, - error_message: &str, - ) -> anyhow::Result { - let now = Utc::now().timestamp(); - let result = sqlx::query( - r#" -UPDATE agent_job_items -SET - status = ?, - completed_at = ?, - updated_at = ?, - last_error = ?, - assigned_thread_id = NULL -WHERE - job_id = ? - AND item_id = ? - AND status = ? - "#, - ) - .bind(AgentJobItemStatus::Failed.as_str()) - .bind(now) - .bind(now) - .bind(error_message) - .bind(job_id) - .bind(item_id) - .bind(AgentJobItemStatus::Running.as_str()) - .execute(self.pool.as_ref()) - .await?; - Ok(result.rows_affected() > 0) - } - - pub async fn get_agent_job_progress(&self, job_id: &str) -> anyhow::Result { - let row = sqlx::query( - r#" -SELECT - COUNT(*) AS total_items, - SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) AS pending_items, - SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) AS running_items, - SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) AS completed_items, - SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) AS failed_items -FROM agent_job_items -WHERE job_id = ? - "#, - ) - .bind(AgentJobItemStatus::Pending.as_str()) - .bind(AgentJobItemStatus::Running.as_str()) - .bind(AgentJobItemStatus::Completed.as_str()) - .bind(AgentJobItemStatus::Failed.as_str()) - .bind(job_id) - .fetch_one(self.pool.as_ref()) - .await?; - - let total_items: i64 = row.try_get("total_items")?; - let pending_items: Option = row.try_get("pending_items")?; - let running_items: Option = row.try_get("running_items")?; - let completed_items: Option = row.try_get("completed_items")?; - let failed_items: Option = row.try_get("failed_items")?; - Ok(AgentJobProgress { - total_items: usize::try_from(total_items).unwrap_or_default(), - pending_items: usize::try_from(pending_items.unwrap_or_default()).unwrap_or_default(), - running_items: usize::try_from(running_items.unwrap_or_default()).unwrap_or_default(), - completed_items: usize::try_from(completed_items.unwrap_or_default()) - .unwrap_or_default(), - failed_items: usize::try_from(failed_items.unwrap_or_default()).unwrap_or_default(), - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::runtime::test_support::unique_temp_dir; - use pretty_assertions::assert_eq; - use serde_json::json; - - async fn create_running_single_item_job( - runtime: &StateRuntime, - ) -> anyhow::Result<(String, String, String)> { - let job_id = "job-1".to_string(); - let item_id = "item-1".to_string(); - let thread_id = "thread-1".to_string(); - runtime - .create_agent_job( - &AgentJobCreateParams { - id: job_id.clone(), - name: "test-job".to_string(), - instruction: "Return a result".to_string(), - auto_export: true, - max_runtime_seconds: None, - output_schema_json: None, - input_headers: vec!["path".to_string()], - input_csv_path: "/tmp/in.csv".to_string(), - output_csv_path: "/tmp/out.csv".to_string(), - }, - &[AgentJobItemCreateParams { - item_id: item_id.clone(), - row_index: 0, - source_id: None, - row_json: json!({"path":"file-1"}), - }], - ) - .await?; - runtime.mark_agent_job_running(job_id.as_str()).await?; - let marked_running = runtime - .mark_agent_job_item_running_with_thread( - job_id.as_str(), - item_id.as_str(), - thread_id.as_str(), - ) - .await?; - assert!(marked_running); - Ok((job_id, item_id, thread_id)) - } - - #[tokio::test] - async fn report_agent_job_item_result_completes_item_atomically() -> anyhow::Result<()> { - let codex_home = unique_temp_dir(); - let runtime = StateRuntime::init(codex_home, "test-provider".to_string()).await?; - let (job_id, item_id, thread_id) = create_running_single_item_job(runtime.as_ref()).await?; - - let accepted = runtime - .report_agent_job_item_result( - job_id.as_str(), - item_id.as_str(), - thread_id.as_str(), - &json!({"ok": true}), - ) - .await?; - assert!(accepted); - - let item = runtime - .get_agent_job_item(job_id.as_str(), item_id.as_str()) - .await? - .expect("job item should exist"); - assert_eq!(item.status, AgentJobItemStatus::Completed); - assert_eq!(item.result_json, Some(json!({"ok": true}))); - assert_eq!(item.assigned_thread_id, None); - assert_eq!(item.last_error, None); - assert!(item.reported_at.is_some()); - assert!(item.completed_at.is_some()); - let progress = runtime.get_agent_job_progress(job_id.as_str()).await?; - assert_eq!( - progress, - AgentJobProgress { - total_items: 1, - pending_items: 0, - running_items: 0, - completed_items: 1, - failed_items: 0, - } - ); - Ok(()) - } - - #[tokio::test] - async fn report_agent_job_item_result_rejects_late_reports() -> anyhow::Result<()> { - let codex_home = unique_temp_dir(); - let runtime = StateRuntime::init(codex_home, "test-provider".to_string()).await?; - let (job_id, item_id, thread_id) = create_running_single_item_job(runtime.as_ref()).await?; - - let marked_failed = runtime - .mark_agent_job_item_failed(job_id.as_str(), item_id.as_str(), "missing report") - .await?; - assert!(marked_failed); - let accepted = runtime - .report_agent_job_item_result( - job_id.as_str(), - item_id.as_str(), - thread_id.as_str(), - &json!({"late": true}), - ) - .await?; - assert!(!accepted); - - let item = runtime - .get_agent_job_item(job_id.as_str(), item_id.as_str()) - .await? - .expect("job item should exist"); - assert_eq!(item.status, AgentJobItemStatus::Failed); - assert_eq!(item.result_json, None); - assert_eq!(item.last_error, Some("missing report".to_string())); - Ok(()) - } - - #[tokio::test] - async fn mark_agent_job_cancelled_fails_running_items() -> anyhow::Result<()> { - let codex_home = unique_temp_dir(); - let runtime = StateRuntime::init(codex_home, "test-provider".to_string()).await?; - let (job_id, item_id, _thread_id) = - create_running_single_item_job(runtime.as_ref()).await?; - - let cancelled = runtime - .mark_agent_job_cancelled(job_id.as_str(), "operator interrupted job") - .await?; - assert!(cancelled); - - let job = runtime - .get_agent_job(job_id.as_str()) - .await? - .expect("job should exist"); - assert_eq!(job.status, AgentJobStatus::Cancelled); - assert_eq!(job.last_error, Some("operator interrupted job".to_string())); - - let item = runtime - .get_agent_job_item(job_id.as_str(), item_id.as_str()) - .await? - .expect("job item should exist"); - assert_eq!(item.status, AgentJobItemStatus::Failed); - assert_eq!(item.assigned_thread_id, None); - assert_eq!( - item.last_error, - Some("operator interrupted job".to_string()) - ); - assert!(item.completed_at.is_some()); - - let progress = runtime.get_agent_job_progress(job_id.as_str()).await?; - assert_eq!( - progress, - AgentJobProgress { - total_items: 1, - pending_items: 0, - running_items: 0, - completed_items: 0, - failed_items: 1, - } - ); - Ok(()) - } -} diff --git a/vendor/codex/codex-rs/tools/src/agent_job_tool.rs b/vendor/codex/codex-rs/tools/src/agent_job_tool.rs deleted file mode 100644 index bcdec5dd..00000000 --- a/vendor/codex/codex-rs/tools/src/agent_job_tool.rs +++ /dev/null @@ -1,107 +0,0 @@ -use crate::JsonSchema; -use crate::ResponsesApiTool; -use crate::ToolSpec; -use std::collections::BTreeMap; - -pub fn create_spawn_agents_on_csv_tool() -> ToolSpec { - let properties = BTreeMap::from([ - ( - "csv_path".to_string(), - JsonSchema::string(Some("Path to the CSV file containing input rows.".to_string())), - ), - ( - "instruction".to_string(), - JsonSchema::string(Some( - "Instruction template to apply to each CSV row. Use {column_name} placeholders to inject values from the row." - .to_string(), - )), - ), - ( - "id_column".to_string(), - JsonSchema::string(Some( - "Optional column name to use as stable item id.".to_string(), - )), - ), - ( - "output_csv_path".to_string(), - JsonSchema::string(Some("Optional output CSV path for exported results.".to_string())), - ), - ( - "max_concurrency".to_string(), - JsonSchema::number(Some( - "Maximum concurrent workers for this job. Defaults to 16 and is capped by config." - .to_string(), - )), - ), - ( - "max_workers".to_string(), - JsonSchema::number(Some( - "Alias for max_concurrency. Set to 1 to run sequentially.".to_string(), - )), - ), - ( - "max_runtime_seconds".to_string(), - JsonSchema::number(Some( - "Maximum runtime per worker before it is failed. Defaults to 1800 seconds." - .to_string(), - )), - ), - ( - "output_schema".to_string(), - JsonSchema::object(BTreeMap::new(), /*required*/ None, /*additional_properties*/ None), - ), - ]); - - ToolSpec::Function(ResponsesApiTool { - name: "spawn_agents_on_csv".to_string(), - description: "Process a CSV by spawning one worker sub-agent per row. The instruction string is a template where `{column}` placeholders are replaced with row values. Each worker must call `report_agent_job_result` with a JSON object (matching `output_schema` when provided); missing reports are treated as failures. This call blocks until all rows finish and automatically exports results to `output_csv_path` (or a default path)." - .to_string(), - strict: false, - defer_loading: None, - parameters: JsonSchema::object(properties, Some(vec!["csv_path".to_string(), "instruction".to_string()]), Some(false.into())), - output_schema: None, - }) -} - -pub fn create_report_agent_job_result_tool() -> ToolSpec { - let properties = BTreeMap::from([ - ( - "job_id".to_string(), - JsonSchema::string(Some("Identifier of the job.".to_string())), - ), - ( - "item_id".to_string(), - JsonSchema::string(Some("Identifier of the job item.".to_string())), - ), - ( - "result".to_string(), - JsonSchema::object(BTreeMap::new(), /*required*/ None, /*additional_properties*/ None), - ), - ( - "stop".to_string(), - JsonSchema::boolean(Some( - "Optional. When true, cancels the remaining job items after this result is recorded." - .to_string(), - )), - ), - ]); - - ToolSpec::Function(ResponsesApiTool { - name: "report_agent_job_result".to_string(), - description: - "Worker-only tool to report a result for an agent job item. Main agents should not call this." - .to_string(), - strict: false, - defer_loading: None, - parameters: JsonSchema::object(properties, Some(vec![ - "job_id".to_string(), - "item_id".to_string(), - "result".to_string(), - ]), Some(false.into())), - output_schema: None, - }) -} - -#[cfg(test)] -#[path = "agent_job_tool_tests.rs"] -mod tests; diff --git a/vendor/codex/codex-rs/tools/src/agent_job_tool_tests.rs b/vendor/codex/codex-rs/tools/src/agent_job_tool_tests.rs deleted file mode 100644 index 95f86597..00000000 --- a/vendor/codex/codex-rs/tools/src/agent_job_tool_tests.rs +++ /dev/null @@ -1,119 +0,0 @@ -use super::*; -use crate::JsonSchema; -use pretty_assertions::assert_eq; -use std::collections::BTreeMap; - -#[test] -fn spawn_agents_on_csv_tool_requires_csv_and_instruction() { - assert_eq!( - create_spawn_agents_on_csv_tool(), - ToolSpec::Function(ResponsesApiTool { - name: "spawn_agents_on_csv".to_string(), - description: "Process a CSV by spawning one worker sub-agent per row. The instruction string is a template where `{column}` placeholders are replaced with row values. Each worker must call `report_agent_job_result` with a JSON object (matching `output_schema` when provided); missing reports are treated as failures. This call blocks until all rows finish and automatically exports results to `output_csv_path` (or a default path)." - .to_string(), - strict: false, - defer_loading: None, - parameters: JsonSchema::object(BTreeMap::from([ - ( - "csv_path".to_string(), - JsonSchema::string(Some( - "Path to the CSV file containing input rows.".to_string(), - )), - ), - ( - "instruction".to_string(), - JsonSchema::string(Some( - "Instruction template to apply to each CSV row. Use {column_name} placeholders to inject values from the row." - .to_string(), - )), - ), - ( - "id_column".to_string(), - JsonSchema::string(Some( - "Optional column name to use as stable item id.".to_string(), - )), - ), - ( - "output_csv_path".to_string(), - JsonSchema::string(Some( - "Optional output CSV path for exported results.".to_string(), - )), - ), - ( - "max_concurrency".to_string(), - JsonSchema::number(Some( - "Maximum concurrent workers for this job. Defaults to 16 and is capped by config." - .to_string(), - )), - ), - ( - "max_workers".to_string(), - JsonSchema::number(Some( - "Alias for max_concurrency. Set to 1 to run sequentially.".to_string(), - )), - ), - ( - "max_runtime_seconds".to_string(), - JsonSchema::number(Some( - "Maximum runtime per worker before it is failed. Defaults to 1800 seconds." - .to_string(), - )), - ), - ( - "output_schema".to_string(), - JsonSchema::object( - BTreeMap::new(), - /*required*/ None, - /*additional_properties*/ None, - ), - ), - ]), Some(vec!["csv_path".to_string(), "instruction".to_string()]), Some(false.into())), - output_schema: None, - }) - ); -} - -#[test] -fn report_agent_job_result_tool_requires_result_payload() { - assert_eq!( - create_report_agent_job_result_tool(), - ToolSpec::Function(ResponsesApiTool { - name: "report_agent_job_result".to_string(), - description: - "Worker-only tool to report a result for an agent job item. Main agents should not call this." - .to_string(), - strict: false, - defer_loading: None, - parameters: JsonSchema::object(BTreeMap::from([ - ( - "job_id".to_string(), - JsonSchema::string(Some("Identifier of the job.".to_string())), - ), - ( - "item_id".to_string(), - JsonSchema::string(Some("Identifier of the job item.".to_string())), - ), - ( - "result".to_string(), - JsonSchema::object( - BTreeMap::new(), - /*required*/ None, - /*additional_properties*/ None, - ), - ), - ( - "stop".to_string(), - JsonSchema::boolean(Some( - "Optional. When true, cancels the remaining job items after this result is recorded." - .to_string(), - )), - ), - ]), Some(vec![ - "job_id".to_string(), - "item_id".to_string(), - "result".to_string(), - ]), Some(false.into())), - output_schema: None, - }) - ); -} diff --git a/vendor/codex/codex-rs/tools/src/lib.rs b/vendor/codex/codex-rs/tools/src/lib.rs index 2dc7c165..f01f1c89 100644 --- a/vendor/codex/codex-rs/tools/src/lib.rs +++ b/vendor/codex/codex-rs/tools/src/lib.rs @@ -1,7 +1,6 @@ //! Shared tool definitions and Responses API tool primitives that can live //! outside `codex-core`. -mod agent_job_tool; mod agent_tool; mod apply_patch_tool; mod code_mode; @@ -25,8 +24,6 @@ mod tool_suggest; mod utility_tool; mod view_image; -pub use agent_job_tool::create_report_agent_job_result_tool; -pub use agent_job_tool::create_spawn_agents_on_csv_tool; pub use agent_tool::SpawnAgentToolOptions; pub use agent_tool::WaitAgentTimeoutOptions; pub use agent_tool::create_close_agent_tool_v1; diff --git a/vendor/codex/codex-rs/tools/src/tool_config.rs b/vendor/codex/codex-rs/tools/src/tool_config.rs index c359374e..7f68f1e9 100644 --- a/vendor/codex/codex-rs/tools/src/tool_config.rs +++ b/vendor/codex/codex-rs/tools/src/tool_config.rs @@ -12,7 +12,6 @@ use codex_protocol::openai_models::ModelPreset; use codex_protocol::openai_models::WebSearchToolType; use codex_protocol::protocol::SandboxPolicy; use codex_protocol::protocol::SessionSource; -use codex_protocol::protocol::SubAgentSource; use codex_utils_absolute_path::AbsolutePathBuf; use std::path::PathBuf; @@ -109,8 +108,6 @@ pub struct ToolsConfig { pub spawn_agent_usage_hint_text: Option, pub default_mode_request_user_input: bool, pub experimental_supported_tools: Vec, - pub agent_jobs_tools: bool, - pub agent_jobs_worker_tools: bool, pub agent_type_description: String, } @@ -133,7 +130,7 @@ impl ToolsConfig { features, image_generation_tool_auth_allowed, web_search_mode, - session_source, + session_source: _, sandbox_policy, windows_sandbox_level, } = params; @@ -145,7 +142,6 @@ impl ToolsConfig { include_js_repl && features.enabled(Feature::JsReplToolsOnly); let include_collab_tools = features.enabled(Feature::Collab); let include_multi_agent_v2 = features.enabled(Feature::MultiAgentV2); - let include_agent_jobs = features.enabled(Feature::SpawnCsv); let include_default_mode_request_user_input = features.enabled(Feature::DefaultModeRequestUserInput); let include_search_tool = @@ -195,12 +191,6 @@ impl ToolsConfig { None => include_apply_patch_tool.then_some(ApplyPatchToolType::Freeform), }; - let agent_jobs_worker_tools = matches!( - session_source, - SessionSource::SubAgent(SubAgentSource::Other(label)) - if label.starts_with("agent_job:") - ); - Self { available_models: available_models.to_vec(), shell_type, @@ -229,8 +219,6 @@ impl ToolsConfig { spawn_agent_usage_hint_text: None, default_mode_request_user_input: include_default_mode_request_user_input, experimental_supported_tools: model_info.experimental_supported_tools.clone(), - agent_jobs_tools: include_agent_jobs, - agent_jobs_worker_tools, agent_type_description: String::new(), } } diff --git a/vendor/codex/codex-rs/tools/src/tool_config_tests.rs b/vendor/codex/codex-rs/tools/src/tool_config_tests.rs index e1b9d828..e1582a22 100644 --- a/vendor/codex/codex-rs/tools/src/tool_config_tests.rs +++ b/vendor/codex/codex-rs/tools/src/tool_config_tests.rs @@ -132,11 +132,10 @@ fn shell_zsh_fork_prefers_shell_command_over_unified_exec() { } #[test] -fn subagents_keep_request_user_input_mode_config_and_agent_jobs_workers_opt_in_by_label() { +fn subagents_keep_request_user_input_mode_config_without_agent_job_tools() { let model_info = model_info(); let mut features = Features::with_defaults(); features.enable(Feature::DefaultModeRequestUserInput); - features.enable(Feature::SpawnCsv); let available_models = Vec::new(); let tools_config = ToolsConfig::new(&ToolsConfigParams { @@ -153,31 +152,6 @@ fn subagents_keep_request_user_input_mode_config_and_agent_jobs_workers_opt_in_b }); assert!(tools_config.default_mode_request_user_input); - assert!(tools_config.agent_jobs_tools); - assert!(tools_config.agent_jobs_worker_tools); -} - -#[test] -fn agent_job_workers_get_report_tool_even_when_csv_front_door_disabled() { - let model_info = model_info(); - let features = Features::with_defaults(); - - let available_models = Vec::new(); - let tools_config = ToolsConfig::new(&ToolsConfigParams { - model_info: &model_info, - available_models: &available_models, - features: &features, - image_generation_tool_auth_allowed: true, - web_search_mode: Some(WebSearchMode::Cached), - session_source: SessionSource::SubAgent(SubAgentSource::Other( - "agent_job:test".to_string(), - )), - sandbox_policy: &SandboxPolicy::DangerFullAccess, - windows_sandbox_level: WindowsSandboxLevel::Disabled, - }); - - assert!(!tools_config.agent_jobs_tools); - assert!(tools_config.agent_jobs_worker_tools); } #[test] diff --git a/vendor/codex/codex-rs/tools/src/tool_registry_plan.rs b/vendor/codex/codex-rs/tools/src/tool_registry_plan.rs index 69fd794c..985778ed 100644 --- a/vendor/codex/codex-rs/tools/src/tool_registry_plan.rs +++ b/vendor/codex/codex-rs/tools/src/tool_registry_plan.rs @@ -37,7 +37,6 @@ use crate::create_list_mcp_resource_templates_tool; use crate::create_list_mcp_resources_tool; use crate::create_local_shell_tool; use crate::create_read_mcp_resource_tool; -use crate::create_report_agent_job_result_tool; use crate::create_request_permissions_tool; use crate::create_request_user_input_tool; use crate::create_resume_agent_tool; @@ -47,7 +46,6 @@ use crate::create_shell_command_tool; use crate::create_shell_tool; use crate::create_spawn_agent_tool_v1; use crate::create_spawn_agent_tool_v2; -use crate::create_spawn_agents_on_csv_tool; use crate::create_test_sync_tool; use crate::create_tool_search_tool; use crate::create_tool_suggest_tool; @@ -477,24 +475,6 @@ pub fn build_tool_registry_plan( } } - if config.agent_jobs_tools { - plan.push_spec( - create_spawn_agents_on_csv_tool(), - /*supports_parallel_tool_calls*/ false, - config.code_mode_enabled, - ); - plan.register_handler("spawn_agents_on_csv", ToolHandlerKind::AgentJobs); - } - - if config.agent_jobs_worker_tools { - plan.push_spec( - create_report_agent_job_result_tool(), - /*supports_parallel_tool_calls*/ false, - config.code_mode_enabled, - ); - plan.register_handler("report_agent_job_result", ToolHandlerKind::AgentJobs); - } - if let Some(mcp_tools) = params.mcp_tools { let mut entries = mcp_tools.to_vec(); entries.sort_by_key(|tool| tool.name.display()); diff --git a/vendor/codex/codex-rs/tools/src/tool_registry_plan_tests.rs b/vendor/codex/codex-rs/tools/src/tool_registry_plan_tests.rs index b55e53e0..021bb35b 100644 --- a/vendor/codex/codex-rs/tools/src/tool_registry_plan_tests.rs +++ b/vendor/codex/codex-rs/tools/src/tool_registry_plan_tests.rs @@ -330,10 +330,9 @@ fn test_build_specs_multi_agent_v2_uses_task_names_and_hides_resume() { } #[test] -fn test_build_specs_enable_fanout_enables_agent_jobs_and_collab_tools() { +fn test_build_specs_multi_agent_omits_agent_jobs() { let model_info = model_info(); let mut features = Features::with_defaults(); - features.enable(Feature::SpawnCsv); features.normalize_dependencies(); let available_models = Vec::new(); let tools_config = ToolsConfig::new(&ToolsConfigParams { @@ -355,14 +354,10 @@ fn test_build_specs_enable_fanout_enables_agent_jobs_and_collab_tools() { assert_contains_tool_names( &tools, - &[ - "spawn_agent", - "send_input", - "wait_agent", - "close_agent", - "spawn_agents_on_csv", - ], + &["spawn_agent", "send_input", "wait_agent", "close_agent"], ); + assert_lacks_tool_name(&tools, "spawn_agents_on_csv"); + assert_lacks_tool_name(&tools, "report_agent_job_result"); } #[test] @@ -469,78 +464,6 @@ fn disabled_environment_omits_environment_backed_tools() { assert_lacks_tool_name(&tools, VIEW_IMAGE_TOOL_NAME); } -#[test] -fn test_build_specs_agent_job_worker_tools_enabled() { - let model_info = model_info(); - let mut features = Features::with_defaults(); - features.enable(Feature::SpawnCsv); - features.normalize_dependencies(); - features.enable(Feature::Sqlite); - let available_models = Vec::new(); - let tools_config = ToolsConfig::new(&ToolsConfigParams { - model_info: &model_info, - available_models: &available_models, - features: &features, - image_generation_tool_auth_allowed: true, - web_search_mode: Some(WebSearchMode::Cached), - session_source: SessionSource::SubAgent(SubAgentSource::Other( - "agent_job:test".to_string(), - )), - sandbox_policy: &SandboxPolicy::DangerFullAccess, - windows_sandbox_level: WindowsSandboxLevel::Disabled, - }); - let (tools, _) = build_specs( - &tools_config, - /*mcp_tools*/ None, - /*deferred_mcp_tools*/ None, - &[], - ); - - assert_contains_tool_names( - &tools, - &[ - "spawn_agent", - "send_input", - "resume_agent", - "wait_agent", - "close_agent", - "spawn_agents_on_csv", - "report_agent_job_result", - REQUEST_USER_INPUT_TOOL_NAME, - ], - ); -} - -#[test] -fn test_build_specs_agent_job_worker_report_tool_without_csv_front_door() { - let model_info = model_info(); - let mut features = Features::with_defaults(); - features.normalize_dependencies(); - features.enable(Feature::Sqlite); - let available_models = Vec::new(); - let tools_config = ToolsConfig::new(&ToolsConfigParams { - model_info: &model_info, - available_models: &available_models, - features: &features, - image_generation_tool_auth_allowed: true, - web_search_mode: Some(WebSearchMode::Cached), - session_source: SessionSource::SubAgent(SubAgentSource::Other( - "agent_job:test".to_string(), - )), - sandbox_policy: &SandboxPolicy::DangerFullAccess, - windows_sandbox_level: WindowsSandboxLevel::Disabled, - }); - let (tools, _) = build_specs( - &tools_config, - /*mcp_tools*/ None, - /*deferred_mcp_tools*/ None, - &[], - ); - - assert_contains_tool_names(&tools, &["report_agent_job_result"]); - assert_lacks_tool_name(&tools, "spawn_agents_on_csv"); -} - #[test] fn request_user_input_description_reflects_default_mode_feature_flag() { let model_info = model_info(); diff --git a/vendor/codex/codex-rs/tools/src/tool_registry_plan_types.rs b/vendor/codex/codex-rs/tools/src/tool_registry_plan_types.rs index b9d66a0c..ef168bb5 100644 --- a/vendor/codex/codex-rs/tools/src/tool_registry_plan_types.rs +++ b/vendor/codex/codex-rs/tools/src/tool_registry_plan_types.rs @@ -10,7 +10,6 @@ use std::collections::HashMap; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ToolHandlerKind { - AgentJobs, ApplyPatch, CloseAgentV1, CloseAgentV2,