Skip to content

Commit 1f845e4

Browse files
committed
fix(progress): clamp percent to 0-100 range
Defensive programming to prevent UI showing values like '107%' if counts ever overshoot due to race conditions or off-by-one bugs.
1 parent 367301c commit 1f845e4

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

backend/services/indexing_events.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ def __post_init__(self):
4646
if self.functions_total > 0:
4747
file_progress = (self.files_processed / self.files_total) * 20 # 0-20%
4848
embed_progress = (self.functions_found / self.functions_total) * 80 # 0-80%
49-
self.percent = int(file_progress + embed_progress)
49+
raw_percent = file_progress + embed_progress
5050
else:
5151
# Still in file extraction phase (0-20%)
52-
self.percent = int((self.files_processed / self.files_total) * 20)
52+
raw_percent = (self.files_processed / self.files_total) * 20
53+
54+
# Clamp to 0-100 range defensively
55+
self.percent = max(0, min(100, int(raw_percent)))
5356

5457

5558
@dataclass

0 commit comments

Comments
 (0)