From db609342f727c3283b9b828e6a611466367df184 Mon Sep 17 00:00:00 2001 From: xiaoski Date: Tue, 5 May 2026 00:56:42 +0800 Subject: [PATCH] fix: char-boundary-safe name truncation in cron_add tool The name fallback used byte-index slice on the prompt, which panics on multi-byte UTF-8 characters like Chinese. Use is_char_boundary() to find a safe truncation point. --- src/tools/cron.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tools/cron.rs b/src/tools/cron.rs index 792e64e..e180870 100644 --- a/src/tools/cron.rs +++ b/src/tools/cron.rs @@ -131,7 +131,19 @@ impl Tool for CronAddTool { let name = args .get("name") .and_then(|v| v.as_str()) - .unwrap_or(&prompt[..prompt.len().min(50)]) + .unwrap_or_else(|| { + // char-boundary-safe truncation to 50 bytes + let limit = 50; + if prompt.len() <= limit { + prompt.as_str() + } else { + let mut end = limit; + while !prompt.is_char_boundary(end) { + end -= 1; + } + &prompt[..end] + } + }) .to_string(); let model = args .get("model")