From 2d1d7e7b9579155d9648b2fae85dac7ea8d33e89 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sun, 12 Apr 2026 10:11:41 +0530 Subject: [PATCH] Fix off-by-one in is_partial_stop causing false positives The range started at 0, so on the first iteration output[-0:] evaluates to the entire string (Python treats -0 as 0). This made stop_str.startswith(output) return True whenever the full output happened to be a prefix of the stop string, incorrectly suppressing streaming chunks. The exclusive upper bound also skipped the longest valid suffix check. Fix: start the range at 1 and add 1 to the upper bound. Co-Authored-By: Claude Opus 4.6 (1M context) --- fastchat/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastchat/utils.py b/fastchat/utils.py index d3531928f..13c9f1453 100644 --- a/fastchat/utils.py +++ b/fastchat/utils.py @@ -330,7 +330,7 @@ def parse_gradio_auth_creds(filename: str): def is_partial_stop(output: str, stop_str: str): """Check whether the output contains a partial stop str.""" - for i in range(0, min(len(output), len(stop_str))): + for i in range(1, min(len(output), len(stop_str)) + 1): if stop_str.startswith(output[-i:]): return True return False