Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(agent): validate agent timeout before applying chat agent id

Steven Enamakel45ba09791844
diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs
index 87fa054814..dd4159bb29 100644
--- a/crates/openhuman-core/src/config/ops/agent.rs
+++ b/crates/openhuman-core/src/config/ops/agent.rs
@@ -227,7 +227,6 @@ pub async fn apply_agent_settings(
"agent_timeout_secs must be between {MIN_TIMEOUT_SECS} and {MAX_TIMEOUT_SECS} seconds (got {timeout_secs})"
));
}
- config.agent.agent_timeout_secs = timeout_secs;
}
if let Some(chat_agent_id) = update.chat_agent_id {
@@ -239,6 +238,14 @@ pub async fn apply_agent_settings(
"chat_agent_id '{trimmed}' is not a runnable agent definition"
));
}
+ }
+
+ if let Some(timeout_secs) = update.agent_timeout_secs {
+ config.agent.agent_timeout_secs = timeout_secs;
+ }
+
+ if let Some(chat_agent_id) = update.chat_agent_id {
+ let trimmed = chat_agent_id.trim();
config.agent.chat_agent_id = (!trimmed.is_empty()).then(|| trimmed.to_string());
log::debug!(
"[config][agent] chat_agent_id -> {:?}",
diff --git a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs
index ad4ef8dd80..5fdffdb0d7 100644
--- a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs
+++ b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs
@@ -69,6 +69,28 @@ async fn apply_agent_settings_rejects_unknown_chat_agent_id() {
assert!(cfg.agent.chat_agent_id.is_none());
}
+#[tokio::test]
+async fn apply_agent_settings_rejects_a_mixed_patch_without_mutating_config() {
+ let _g = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let tmp = tempdir().unwrap();
+ let mut cfg = tmp_config(&tmp);
+ let original_timeout = cfg.agent.agent_timeout_secs;
+
+ let err = apply_agent_settings(
+ &mut cfg,
+ AgentSettingsPatch {
+ agent_timeout_secs: Some(300),
+ chat_agent_id: Some("typoed_agent".into()),
+ },
+ )
+ .await
+ .expect_err("unknown agent must reject the entire patch");
+
+ assert!(err.contains("not a runnable agent definition"), "{err}");
+ assert_eq!(cfg.agent.agent_timeout_secs, original_timeout);
+ assert!(cfg.agent.chat_agent_id.is_none());
+}
+
// ── apply_agent_paths_settings (action_dir editable, issue #3240) ──────────────
#[tokio::test]
diff --git a/scripts/life-scenarios/run.mjs b/scripts/life-scenarios/run.mjs
index 5451df895c..dc79fe02a0 100644
--- a/scripts/life-scenarios/run.mjs
+++ b/scripts/life-scenarios/run.mjs
@@ -49,6 +49,7 @@ import { startMockSearch, DEFAULT_INDEX_PATH } from "./mock-search.mjs";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const REPO = path.resolve(HERE, "..", "..");
const FIXTURES = path.join(HERE, "fixtures");
+const SUPPORTED_AGENT_IDS = new Set(["life_scenarios", "orchestrator"]);
// ---------------------------------------------------------------------------
// args
@@ -104,11 +105,16 @@ function parseArgs(argv) {
else if (a === "--driver") o.driver = next();
else if (a === "--agent") {
const agentId = next();
- if (agentId && !/^[A-Za-z0-9_-]+$/.test(agentId)) {
+ if (!/^[A-Za-z0-9_-]+$/.test(agentId)) {
throw new Error(
"--agent must contain only ASCII letters, digits, '_' or '-'",
);
}
+ if (!SUPPORTED_AGENT_IDS.has(agentId)) {
+ throw new Error(
+ `--agent must be one of: ${[...SUPPORTED_AGENT_IDS].join(", ")}`,
+ );
+ }
o.agentId = agentId;
}
else if (a === "--model") o.model = next();