Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/crates/core/src/agentic/execution/round_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,11 @@ fn strip_markdown_fences(content: &str) -> String {
return content.to_string();
}

// Find the end of the opening fence line
let fence_end = trimmed.find('\n').unwrap_or(3);
// Find the end of the opening fence line. If the model emitted only an
// opening fence, there is no inner content to keep.
let Some(fence_end) = trimmed.find('\n') else {
return String::new();
};
// let _lang = &trimmed[3..fence_end].trim(); // language hint, ignored

// Check if content ends with ```
Expand Down Expand Up @@ -2067,12 +2070,10 @@ mod tests {
assert_eq!(messages[3].role, "user");
assert_eq!(messages[4].role, "assistant");
assert_eq!(messages[4].content.as_deref(), Some("<bitfun_contents>"));
assert!(
messages[4]
.content
.as_deref()
.is_some_and(|content| !content.ends_with(char::is_whitespace))
);
assert!(messages[4]
.content
.as_deref()
.is_some_and(|content| !content.ends_with(char::is_whitespace)));
}

#[test]
Expand Down Expand Up @@ -2168,6 +2169,12 @@ mod tests {
assert_eq!(extract_bitfun_contents(text), "fn main() {}");
}

#[test]
fn sanitization_handles_bare_markdown_fence() {
assert_eq!(extract_bitfun_contents("```"), "");
assert_eq!(extract_bitfun_contents("```rust"), "");
}

#[test]
fn sanitization_strips_xml_thinking_tags_with_content() {
let text = "<bitfun_contents>\n<thinking>\nI need to write a function\n</thinking>\nfn main() {}\n</bitfun_contents>";
Expand Down
Loading