[Bugfix] [Rust Frontend] Fix stop string truncation with repeated matches (#46113)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Signed-off-by: reidliu41 <reid201711@gmail.com>

Reid committed Jun 22, 2026 at 14:11 UTC 31124749d1b3fb8ac01a6cd27da2a35425bb5772
1 file changed +8 -1
rust/src/text/src/output/decoded.rs
+8 -1
@@ -309,7 +309,7 @@ fn matches_stop_string(stops: &[String], output: &str, new_bytes: usize) -> Opti
309 .find_map(|(ss_idx, (ss, len, start_off))| {
310 output[start_off..]
311 .windows(len)
312 - .rposition(|w| w == ss)
312 + .position(|w| w == ss)
313 .map(|pos| (ss_idx, start_off + pos))
314 })
315 }
@@ -562,6 +562,13 @@ mod tests {
562 assert_eq!(result, Some((0, 4)));
563 }
564
565 + #[test]
566 + fn stop_string_matches_leftmost_with_multiple_new_bytes() {
567 + let stops = vec!["\n".to_string()];
568 + let result = matches_stop_string(&stops, "Answer\n\n", 2);
569 + assert_eq!(result, Some((0, 6)));
570 + }
571 +
572 #[test]
573 fn stop_string_matches_at_beginning() {
574 let stops = vec!["say".to_string()];