Give Persona one explicit turn deadline
This commit is contained in:
parent
850611291b
commit
3b958a83bc
3 changed files with 41 additions and 3 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ async fn poll_once(options: &Options) -> Result<bool> {
|
|||
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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<PathBuf>,
|
||||
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<String>,
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue