Skip to content

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

fix(claude-code): report the shape of an unparsable line, not its content

Nguyen Thanh Dat38a0336a6dc4
diff --git a/src/openhuman/inference/provider/claude_code/driver.rs b/src/openhuman/inference/provider/claude_code/driver.rs
index ce016d5bd4..fa2bc8dfb7 100644
--- a/src/openhuman/inference/provider/claude_code/driver.rs
+++ b/src/openhuman/inference/provider/claude_code/driver.rs
@@ -18,27 +18,40 @@ use tokio::sync::mpsc;
/// infinite loop, MCP deadlock) we kill the child and surface a timeout.
const TURN_TIMEOUT: Duration = Duration::from_secs(300);
-/// Characters of an unparsable stream line kept in the log: enough to recognise
-/// the shape of the line, not so much that a whole model reply lands in the log.
-const PARSE_ERROR_PREVIEW_CHARS: usize = 200;
+/// Classify the shape of an unparsable stream line without quoting it.
+///
+/// This says whether Claude spoke JSON at all - the one thing that tells a
+/// crashed CLI apart from a protocol change - and nothing about what the line
+/// said.
+fn parse_error_line_shape(line: &str) -> &'static str {
+ match line.trim_start().chars().next() {
+ Some('{') => "json object",
+ Some('[') => "json array",
+ Some('"') => "json string",
+ Some(_) => "non-json",
+ None => "blank",
+ }
+}
/// Render the log line for a `ParseError` event, or `None` for anything else.
///
/// The parser keeps `ParseError` precisely so an unparsable line is reported
/// instead of vanishing, but the event mapper turns it into no deltas - so the
/// driver loop is the only place left that can say anything about it.
+///
+/// The line itself is never quoted. It is whatever Claude Code wrote to stdout
+/// - a malformed event, or a well-formed one of an unknown type - so it can
+/// carry the user's prompt, the model's reply, or a credential, and the desktop
+/// build routes `log` into rotating support logs and Sentry breadcrumbs. Shape,
+/// size, and the parser's own reason are enough to act on; content is not.
fn parse_error_log_line(ev: &ClaudeCodeEvent) -> Option<String> {
let ClaudeCodeEvent::ParseError { line, reason } = ev else {
return None;
};
- let preview: String = line.chars().take(PARSE_ERROR_PREVIEW_CHARS).collect();
- let ellipsis = if preview.chars().count() < line.chars().count() {
- "..."
- } else {
- ""
- };
Some(format!(
- "[claude-code][driver] dropping unparsable stream line ({reason}): {preview}{ellipsis}"
+ "[claude-code][driver] dropping unparsable stream line ({reason}): {} of {} bytes",
+ parse_error_line_shape(line),
+ line.len()
))
}
diff --git a/src/openhuman/inference/provider/claude_code/driver_tests.rs b/src/openhuman/inference/provider/claude_code/driver_tests.rs
index e86d633069..5a63bb8df6 100644
--- a/src/openhuman/inference/provider/claude_code/driver_tests.rs
+++ b/src/openhuman/inference/provider/claude_code/driver_tests.rs
@@ -186,8 +186,8 @@ fn parse_error_events_produce_a_log_line() {
reason: "expected value at line 1 column 2".to_string(),
};
let msg = parse_error_log_line(&ev).expect("a ParseError must be reported");
- assert!(msg.contains("{not json"), "{msg}");
assert!(msg.contains("expected value at line 1 column 2"), "{msg}");
+ assert!(msg.contains("9 bytes"), "{msg}");
}
#[test]
@@ -198,36 +198,43 @@ fn other_events_produce_nothing() {
assert!(parse_error_log_line(&ev).is_none());
}
+/// An unparsable line can be a well-formed event of an unknown type, so it
+/// can hold the prompt, the reply, or a credential. None of it is quoted.
#[test]
-fn a_long_line_is_previewed_not_dumped() {
+fn the_line_itself_is_never_quoted() {
let ev = ClaudeCodeEvent::ParseError {
- line: "x".repeat(5_000),
- reason: "trailing characters".to_string(),
+ line: r#"{"type":"secret_leak","api_key":"sk-ant-not-in-the-log"}"#.to_string(),
+ reason: "unknown event type `secret_leak`".to_string(),
};
let msg = parse_error_log_line(&ev).unwrap();
- assert!(msg.ends_with("..."), "a truncated line must say so: {msg}");
- assert_eq!(msg.matches('x').count(), PARSE_ERROR_PREVIEW_CHARS);
+ assert!(!msg.contains("sk-ant-not-in-the-log"), "{msg}");
+ assert!(!msg.contains("api_key"), "{msg}");
}
+/// Size is reported instead of content, so a truncated stream still reads
+/// differently from a chatty one.
#[test]
-fn a_short_line_is_not_marked_as_truncated() {
+fn the_size_of_the_line_is_reported() {
let ev = ClaudeCodeEvent::ParseError {
- line: "oops".to_string(),
- reason: "r".to_string(),
+ line: "x".repeat(5_000),
+ reason: "trailing characters".to_string(),
};
- assert!(!parse_error_log_line(&ev).unwrap().ends_with("..."));
+ assert!(parse_error_log_line(&ev).unwrap().contains("5000 bytes"));
}
-/// The preview counts characters, so a multi-byte line is not split
-/// mid-character the way byte slicing would split it.
#[test]
-fn a_multibyte_line_is_previewed_on_character_boundaries() {
- let ev = ClaudeCodeEvent::ParseError {
- line: "\u{65e5}".repeat(5_000),
- reason: "r".to_string(),
+fn the_shape_of_the_line_is_reported() {
+ let shape = |line: &str| {
+ parse_error_log_line(&ClaudeCodeEvent::ParseError {
+ line: line.to_string(),
+ reason: "r".to_string(),
+ })
+ .unwrap()
};
- let msg = parse_error_log_line(&ev).unwrap();
- assert_eq!(msg.matches('\u{65e5}').count(), PARSE_ERROR_PREVIEW_CHARS);
+ assert!(shape(r#" {"type":"x"}"#).contains("json object"));
+ assert!(shape("[1,2]").contains("json array"));
+ assert!(shape("panic: claude-code crashed").contains("non-json"));
+ assert!(shape(" ").contains("blank"));
}
use super::*;