Skip to content

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

test(session_host): assert credentials are redacted in trace and history

Steven Enamakele7779a1e9efa
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_trace_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_trace_tests.rs
index b8c8314648..eeecee2bbb 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_trace_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_trace_tests.rs
@@ -1,5 +1,6 @@
use std::sync::Arc;
+use crate::storage::sessions::splice_fixture_tests::{head_of, memory_locator};
use async_trait::async_trait;
use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};
@@ -7,6 +8,7 @@ struct GatedRepairModel {
calls: std::sync::atomic::AtomicUsize,
repair_started: tokio::sync::Notify,
repair_call_id: std::sync::Mutex<Option<String>>,
+ user_messages: std::sync::Mutex<Vec<String>>,
}
#[async_trait]
@@ -26,6 +28,13 @@ impl ChatModel<()> for GatedRepairModel {
_state: &(),
request: ModelRequest,
) -> tinyinference_llm::Result<ModelResponse> {
+ self.user_messages.lock().unwrap().extend(
+ request
+ .messages
+ .iter()
+ .filter(|message| matches!(message, tinyinference_llm::message::Message::User(_)))
+ .map(tinyinference_llm::message::Message::text),
+ );
let supplemental = request
.correlation
.as_ref()
@@ -69,8 +78,10 @@ async fn cancellation_during_required_output_repair_finalizes_native_run() {
calls: std::sync::atomic::AtomicUsize::new(0),
repair_started: tokio::sync::Notify::new(),
repair_call_id: std::sync::Mutex::new(None),
+ user_messages: std::sync::Mutex::new(Vec::new()),
});
let chat_model: Arc<dyn ChatModel<()>> = model.clone();
+ let locator = memory_locator();
let mut host = crate::agent::SessionHostBuilder::new()
.chat_model_with_config(chat_model, Arc::new(config.clone()))
.config(config.agent.clone())
@@ -78,9 +89,7 @@ async fn cancellation_during_required_output_repair_finalizes_native_run() {
.workspace_dir(workspace.clone())
.action_dir(scratch.path().to_path_buf())
.tool_dispatcher(Box::new(tinytools_agent::dialect::NativeDialect))
- .with_session_history_locator(
- crate::storage::sessions::splice_fixture_tests::memory_locator(),
- )
+ .with_session_history_locator(Arc::clone(&locator))
.build()
.expect("host session");
let thread_id = "trace-terminal-cancel-repair";
@@ -98,8 +107,15 @@ async fn cancellation_during_required_output_repair_finalizes_native_run() {
client_id: "trace-terminal-test".into(),
request_id: Some(request_id.clone()),
};
- let turn =
- tokio::spawn(async move { host.run_single_with_origin("hello", Some(origin)).await });
+ let secret: String = [
+ 's', 'k', '-', 'r', 'e', 'p', 'a', 'i', 'r', '-', '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+ ]
+ .into_iter()
+ .collect();
+ let input = format!("hello using this synthetic credential: {secret}");
+ let redacted = tinyinference_core::sanitize::scrub_credentials(&input);
+ let turn = tokio::spawn(async move { host.run_single_with_origin(&input, Some(origin)).await });
model.repair_started.notified().await;
let repair_call_id = model
.repair_call_id
@@ -109,6 +125,22 @@ async fn cancellation_during_required_output_repair_finalizes_native_run() {
.expect("only a post-harness supplemental call releases this barrier");
cancellation.cancel();
assert!(turn.await.expect("turn task").is_err());
+ assert!(model
+ .user_messages
+ .lock()
+ .unwrap()
+ .iter()
+ .any(|message| message.contains(&redacted)));
+ assert!(model
+ .user_messages
+ .lock()
+ .unwrap()
+ .iter()
+ .all(|message| !message.contains(&secret)));
+ let persisted = head_of(&locator, thread_id);
+ let persisted_json = serde_json::to_string(&persisted.messages).expect("serialize transcript");
+ assert!(!persisted_json.contains(&secret));
+ assert!(persisted_json.contains(&redacted));
let dispatch = crate::core::runtime::DispatchCtx::new(Arc::clone(&core));
let run_id =