Skip to content

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

fix(session_host): gate prompt refresh on dynamic prompts only

Steven Enamakel145c9edc84e3
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.rs
index 13096196e1..f22db9f9a4 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
@@ -82,15 +82,19 @@ impl OpenHumanTurnPrelude {
if changed {
tracing::info!(
thread_id = ?self.thread_id,
+ prefix_in_use = "refreshed",
+ reason = "prompt_changed",
recorded_segments = view.prefix.messages().len(),
- "[session] refresh_prompt_on_resume: the resumed thread's prompt is out of date; it continues under the current one"
+ "[session] refresh_prompt_on_resume"
);
let text = user_text_with_markers(&request.input);
request.input = user_message_from_text(&format!("{PROMPT_UPDATE_NOTE}\n\n{text}"));
} else {
- tracing::debug!(
+ tracing::info!(
thread_id = ?self.thread_id,
- "[session] refresh_prompt_on_resume: the resumed thread keeps its prompt"
+ prefix_in_use = "kept",
+ reason = "unchanged",
+ "[session] refresh_prompt_on_resume"
);
}
}
@@ -115,9 +119,9 @@ impl OpenHumanTurnPrelude {
/// the extent of the recorded prompt could not be recovered (a
/// compacted legacy head), so its old instructions are still part of
/// the history, and a new prompt beside them would leave them in place;
- /// - the prompt renders live state (anything but a verbatim prompt) and
- /// the connected integrations have not been read this session: a prompt
- /// rendered without them would replace a complete one;
+ /// - a dynamic prompt can render connected integrations and they have not
+ /// been read this session: a prompt rendered without them could replace
+ /// a complete one;
/// - the prompt cannot be rendered: the thread goes on under the one it
/// has rather than failing its turn.
///
@@ -130,22 +134,26 @@ impl OpenHumanTurnPrelude {
if unknown_extent {
tracing::warn!(
thread_id = ?self.thread_id,
- "[session] refresh_prompt_on_resume: the resumed thread's recorded prompt has no known extent; keeping it"
+ prefix_in_use = "kept",
+ reason = "unknown_extent",
+ "[session] refresh_prompt_on_resume"
);
return None;
}
- let verbatim = self.definition.as_ref().is_some_and(|definition| {
- matches!(definition.system_prompt, PromptSource::Verbatim(_))
+ let uses_live_integrations = self.definition.as_ref().is_some_and(|definition| {
+ matches!(definition.system_prompt, PromptSource::Dynamic(()))
});
let hydrated = {
let mutable = self.mutable.lock().unwrap_or_else(PoisonError::into_inner);
mutable.connected_integrations_initialized
&& mutable.connected_integrations_authoritative
};
- if !verbatim && !hydrated {
- tracing::debug!(
+ if uses_live_integrations && !hydrated {
+ tracing::info!(
thread_id = ?self.thread_id,
- "[session] refresh_prompt_on_resume: integrations not read yet; keeping the recorded prompt"
+ prefix_in_use = "kept",
+ reason = "integrations_not_read",
+ "[session] refresh_prompt_on_resume"
);
return None;
}
@@ -154,8 +162,10 @@ impl OpenHumanTurnPrelude {
Err(error) => {
tracing::warn!(
thread_id = ?self.thread_id,
+ prefix_in_use = "kept",
+ reason = "render_failed",
%error,
- "[session] refresh_prompt_on_resume: the current prompt did not render; keeping the recorded one"
+ "[session] refresh_prompt_on_resume"
);
None
}
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.rs
index 3d0eaff075..5937e356a3 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,6 +12,28 @@ 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
@@ -230,7 +252,10 @@ async fn resume_refreshes_the_prompt_without_an_integrations_backend() {
// Inline prompts do not render connected integrations, so that absence
// must not keep the resumed thread on its recorded prompt.
let mut resumed = inline_host(&locator, &model, root.path(), "You are release two.");
- assert_eq!(resumed.turn("second message").await.unwrap(), "second reply");
+ assert_eq!(
+ resumed.turn("second message").await.unwrap(),
+ "second reply"
+ );
assert!(
sent_prompt(&model)
.iter()
@@ -513,6 +538,37 @@ async fn a_composed_prompt_waits_for_the_integrations_to_be_read() {
assert_eq!(prepared.prefix, Some(current().refreshing()));
}
+#[tokio::test]
+async fn refresh_log_names_the_prefix_in_use() {
+ 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);
+
+ 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}"
+ );
+}
+
fn failing_prompt(_: &PromptContext<'_>) -> anyhow::Result<String> {
anyhow::bail!("the prompt source is unavailable")
}