Skip to content

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

fix(observability): scrub expected-error log lines like reported ones

M3gA-Mind7b01c9d86299
diff --git a/crates/openhuman-core/src/core/observability_reporting.rs b/crates/openhuman-core/src/core/observability_reporting.rs
index b3f966a370..b41e587634 100644
--- a/crates/openhuman-core/src/core/observability_reporting.rs
+++ b/crates/openhuman-core/src/core/observability_reporting.rs
@@ -46,6 +46,10 @@ pub fn report_error_or_expected<E: Display + ?Sized>(
}
fn report_expected_message(kind: ExpectedErrorKind, message: &str, domain: &str, operation: &str) {
+ // Same redaction as `report_error_message`: these lines reach the log
+ // sinks (and Sentry breadcrumbs) too. Classification ran on the raw text.
+ let scrubbed = crate::core::log_redaction::scrub_secrets(message);
+ let message = scrubbed.as_str();
match kind {
ExpectedErrorKind::LocalAiDisabled => {
tracing::info!(
diff --git a/crates/openhuman-core/src/core/observability_tests.rs b/crates/openhuman-core/src/core/observability_tests.rs
index e5c667166b..1d36f9609a 100644
--- a/crates/openhuman-core/src/core/observability_tests.rs
+++ b/crates/openhuman-core/src/core/observability_tests.rs
@@ -132,3 +132,51 @@ mod error_classification_provider;
mod error_classification_session;
#[path = "observability_error_classification_user_state_tests.rs"]
mod error_classification_user_state;
+
+/// Log output of `f` under a plain fmt subscriber.
+fn captured_logs(f: impl FnOnce()) -> String {
+ #[derive(Clone, Default)]
+ struct Capture(Arc<Mutex<Vec<u8>>>);
+ impl std::io::Write for Capture {
+ 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 Capture {
+ type Writer = Self;
+ fn make_writer(&'a self) -> Self::Writer {
+ self.clone()
+ }
+ }
+ let capture = Capture::default();
+ let subscriber = tracing_subscriber::fmt()
+ .with_writer(capture.clone())
+ .with_ansi(false)
+ .with_max_level(tracing::Level::TRACE)
+ .finish();
+ tracing::subscriber::with_default(subscriber, f);
+ let out = String::from_utf8(capture.0.lock().unwrap().clone()).unwrap();
+ out
+}
+
+#[test]
+fn expected_and_reported_errors_are_logged_scrubbed() {
+ let msg = "Embedding API error (429 Too Many Requests): Bearer sekrit-value rejected";
+ assert!(
+ expected_error_kind(msg).is_some(),
+ "fixture must take the expected-error path"
+ );
+ let expected = captured_logs(|| report_error_or_expected(&msg, "d", "o", &[]));
+ assert!(expected.contains("[REDACTED]"), "{expected}");
+ assert!(!expected.contains("sekrit"), "{expected}");
+
+ let reported = captured_logs(|| report_error(&"boom Bearer sekrit-value", "d", "o", &[]));
+ assert!(
+ !reported.is_empty() && !reported.contains("sekrit"),
+ "{reported}"
+ );
+}