The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(session-host): extract prompt refresh log fields helper
Steven Enamakel472283f726e3
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rsindex f22db9f9a4..1e2514fa88 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs@@ -33,6 +33,14 @@ use super::OpenHumanTurnPrelude;use crate::agent::message_convert::{user_message_from_text, user_text_with_markers};use crate::agent::tinyagents::middleware::turn_context::TranscriptSnapshotSink;+fn prompt_refresh_log_fields(prompt_changed: bool) -> (&'static str, &'static str) {+ if prompt_changed {+ ("refreshed", "prompt_changed")+ } else {+ ("kept", "unchanged")+ }+}+/// Prepended to the user's message on the turn a resumed thread's prompt is/// replaced; the turn's record keeps it, so later turns see where the change/// happened.@@ -79,11 +87,12 @@ impl OpenHumanTurnPrelude {.prefix.as_ref().is_some_and(|prefix| prefix.messages() != view.prefix.messages());+ let (prefix_in_use, reason) = prompt_refresh_log_fields(changed);if changed {tracing::info!(thread_id = ?self.thread_id,- prefix_in_use = "refreshed",- reason = "prompt_changed",+ prefix_in_use,+ reason,recorded_segments = view.prefix.messages().len(),"[session] refresh_prompt_on_resume");@@ -92,8 +101,8 @@ impl OpenHumanTurnPrelude {} else {tracing::info!(thread_id = ?self.thread_id,- prefix_in_use = "kept",- reason = "unchanged",+ prefix_in_use,+ reason,"[session] refresh_prompt_on_resume");}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rsindex ab48893093..33ac9e614b 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs@@ -12,28 +12,6 @@ use tinyagents_session::transcript::TranscriptLocator;const THREAD: &str = "thread-prompt-refresh";-#[derive(Clone, Default)]-struct LogCapture(Arc<std::sync::Mutex<Vec<u8>>>);--impl std::io::Write for LogCapture {- fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {- self.0.lock().unwrap().extend_from_slice(bytes);- Ok(bytes.len())- }-- fn flush(&mut self) -> std::io::Result<()> {- Ok(())- }-}--impl<'a> tracing_subscriber::fmt::MakeWriter<'a> for LogCapture {- type Writer = Self;-- fn make_writer(&'a self) -> Self::Writer {- self.clone()- }-}-/// A thread-bound session over `locator` that renders its prompt with/// `prompt` and answers from `model`, under the registry's definition as/// `define` edits it: the definition the embed factory stamps on its@@ -543,46 +521,11 @@ async fn a_composed_prompt_waits_for_the_integrations_to_be_read() {#[test]fn refresh_log_names_the_prefix_in_use() {- std::thread::Builder::new()- .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)- .spawn(|| {- let root = tempfile::tempdir().expect("tempdir");- let prelude = prelude(root.path(), "current", true);- let recorded = PrefixSnapshot::new(vec![Message::system("recorded")]);- let history = [Message::system("recorded"), Message::user("hi")];- let capture = LogCapture::default();- let subscriber = tracing_subscriber::fmt()- .with_writer(capture.clone())- .with_ansi(false)- .with_max_level(tracing::Level::INFO)- .finish();- let _subscriber_guard = tracing::subscriber::set_default(subscriber);- tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .expect("test runtime")- .block_on(async {- prelude- .prepare_turn(- false,- &resumed(&recorded, &history),- &snapshot(3),- &mut request(),- )- .await- .expect("prepared turn");- });-- let logs = String::from_utf8(capture.0.lock().unwrap().clone()).expect("UTF-8 logs");- assert!(- logs.contains("prefix_in_use=\"refreshed\"")- && logs.contains("reason=\"prompt_changed\""),- "refresh log should identify the prefix and why it is used: {logs}"- );- })- .expect("test thread")- .join()- .expect("test thread panicked");+ assert_eq!(+ prompt_refresh_log_fields(true),+ ("refreshed", "prompt_changed")+ );+ assert_eq!(prompt_refresh_log_fields(false), ("kept", "unchanged"));}fn failing_prompt(_: &PromptContext<'_>) -> anyhow::Result<String> {