From 185c490967b71166a386005ba4edb5b1a67088d6 Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Sat, 30 May 2026 14:34:21 +0800 Subject: [PATCH] fix(agentic): handle bare markdown fence writes --- .../src/agentic/execution/round_executor.rs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/crates/core/src/agentic/execution/round_executor.rs b/src/crates/core/src/agentic/execution/round_executor.rs index a2550872c..55a52ef49 100644 --- a/src/crates/core/src/agentic/execution/round_executor.rs +++ b/src/crates/core/src/agentic/execution/round_executor.rs @@ -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 ``` @@ -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("")); - 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] @@ -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 = "\n\nI need to write a function\n\nfn main() {}\n";