From 3b958a83bc7284aef798fec7de6c94358f30ce52 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 22 Aug 2026 21:40:34 +0200 Subject: [PATCH] Give Persona one explicit turn deadline --- epiphany-openai-codex-spine/src/lib.rs | 2 +- .../src/bin/epiphany-persona-service.rs | 10 ++++++ .../src/persona_executor.rs | 32 +++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/epiphany-openai-codex-spine/src/lib.rs b/epiphany-openai-codex-spine/src/lib.rs index 2be165c7..0a7bdf6a 100644 --- a/epiphany-openai-codex-spine/src/lib.rs +++ b/epiphany-openai-codex-spine/src/lib.rs @@ -1473,7 +1473,7 @@ fn response_error_message(response: Option<&Value>) -> String { } fn transport_error_to_anyhow(err: TransportError) -> anyhow::Error { - anyhow::anyhow!("failed to open direct Responses stream: {err}") + anyhow::anyhow!("failed to open provider transport: {err}") } fn auth_mode_from_manager( diff --git a/epiphany-openai-runtime/src/bin/epiphany-persona-service.rs b/epiphany-openai-runtime/src/bin/epiphany-persona-service.rs index e22f040f..e6e515ba 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-persona-service.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-persona-service.rs @@ -105,6 +105,7 @@ async fn poll_once(options: &Options) -> Result { provider_credential_path: options.provider_credential_path.clone(), provider: options.provider.clone(), model: options.model.clone(), + turn_timeout: Duration::from_secs(options.turn_timeout_seconds), }; let model_terminal = match execute_persona_model_turn(&plan, &mut runner).await { Ok(receipt) => receipt, @@ -321,6 +322,7 @@ struct Options { mouth_rudp: SocketAddr, mouth_timeout_ms: u64, retained_terminal_conversations: usize, + turn_timeout_seconds: u64, poll_ms: u64, once: bool, } @@ -369,6 +371,13 @@ impl Options { "256", ) .parse()?, + turn_timeout_seconds: { + let seconds = value(&values, "--turn-timeout-seconds", "600").parse()?; + if seconds == 0 { + return Err(anyhow!("--turn-timeout-seconds must be greater than zero")); + } + seconds + }, runtime_id: value(&values, "--runtime-id", "epiphany-local"), provider: value(&values, "--provider", "openai-codex"), model: value(&values, "--model", "gpt-5.4"), @@ -462,6 +471,7 @@ mod tests { mouth_rudp: "127.0.0.1:1".parse()?, mouth_timeout_ms: 1, retained_terminal_conversations: 1, + turn_timeout_seconds: 600, poll_ms: 1, once: true, }; diff --git a/epiphany-openai-runtime/src/persona_executor.rs b/epiphany-openai-runtime/src/persona_executor.rs index 8d007d3c..226443ec 100644 --- a/epiphany-openai-runtime/src/persona_executor.rs +++ b/epiphany-openai-runtime/src/persona_executor.rs @@ -1,6 +1,7 @@ use std::future::Future; use std::path::{Path, PathBuf}; use std::pin::Pin; +use std::time::Duration; use anyhow::{Context, Result, anyhow}; use chrono::SecondsFormat; @@ -70,6 +71,7 @@ pub struct NativePersonaModelRunner { pub provider_credential_path: Option, pub provider: String, pub model: String, + pub turn_timeout: Duration, } pub trait PersonaModelRunner { @@ -106,9 +108,21 @@ impl PersonaModelRunner for NativePersonaModelRunner { coordinator_note: "Native Persona model executor; transport owns inference only." .to_string(), default_model: Some(self.model.clone()), - request_timeout: Some(crate::DEFAULT_PROVIDER_REQUEST_TIMEOUT), + // Persona owns one outer typed turn budget. A second transport + // timer would give timeout policy two conflicting owners. + request_timeout: None, }; - let summary = run_model_turn(&self.provider, options.clone(), request.clone()).await?; + let summary = tokio::time::timeout( + self.turn_timeout, + run_model_turn(&self.provider, options.clone(), request.clone()), + ) + .await + .map_err(|_| { + anyhow!( + "Persona {stage} stage exceeded its {} second outer turn budget", + self.turn_timeout.as_secs() + ) + })??; let output = assistant_text_from_model_events(&self.store_path, &request.request_id)?; if summary.verdict != "pass" || output.trim().is_empty() { let failure_summary = if summary.verdict != "pass" { @@ -666,6 +680,20 @@ mod tests { use epiphany_core::PersonaIdentity; use tempfile::tempdir; + #[test] + fn native_persona_runner_has_one_outer_turn_deadline() { + let source = include_str!("persona_executor.rs"); + let production = source + .split("#[cfg(test)]") + .next() + .expect("production code"); + assert!(production.contains("tokio::time::timeout(")); + assert!(production.contains("request_timeout: None")); + assert!( + !production.contains("request_timeout: Some(crate::DEFAULT_PROVIDER_REQUEST_TIMEOUT)") + ); + } + struct FakeRunner { calls: Vec, }