Skip to content

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

fix(web_chat): handle missing chat session on start

Steven Enamakele3fe1eaecfe5
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
index 40089d7e43..09a94acdde 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
@@ -49,17 +49,31 @@ pub enum StartChatError {
impl std::fmt::Display for StartChatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- StartChatError::Guardrail {
- verdict, score, ..
- } => write!(
- f,
- "blocked by guardrail (verdict={verdict} score={score:.2})"
- ),
+ // The same user-facing copy `prompt_guard_user_message` gives a
+ // fresh rejection — a caller that only has `.to_string()` (a
+ // plain-string RPC error, a `{err}` log line) still gets an
+ // actionable message, not a bare verdict/score dump.
+ StartChatError::Guardrail { verdict, .. } => {
+ f.write_str(guardrail_verdict_user_message(verdict))
+ }
StartChatError::Other(message) => write!(f, "{message}"),
}
}
}
+/// User-facing copy for a guardrail verdict string (`"block"` /
+/// `"review_blocked"` / `"allow"` — see the `match` in [`start_chat`] that
+/// builds [`StartChatError::Guardrail`]). Shared by `Display` above so a
+/// plain-string consumer of the error still reads the same rejection copy
+/// [`prompt_guard_user_message`] gives a fresh (non-error-wrapped) decision.
+fn guardrail_verdict_user_message(verdict: &str) -> &'static str {
+ match verdict {
+ "block" => prompt_guard_user_message(PromptEnforcementAction::Blocked),
+ "review_blocked" => prompt_guard_user_message(PromptEnforcementAction::ReviewBlocked),
+ _ => prompt_guard_user_message(PromptEnforcementAction::Allow),
+ }
+}
+
impl std::error::Error for StartChatError {}
impl From<String> for StartChatError {