Skip to content

Commit 367301c

Browse files
committed
fix: address CodeRabbit review feedback
Backend (indexing_events.py): - Add explicit guard for files_total <= 0 (division by zero) - Remove channel truncation in logs for better debugging Backend (repos.py): - Add TODO comment for Redis Streams alternative Frontend (IndexingProgressModal.tsx): - Use composite key for recentFiles list (file + index) - Add aria-label to close button - Add Escape key handler to close modal
1 parent ef5fc8f commit 367301c

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

backend/routes/repos.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ async def _run_async_indexing(
257257
try:
258258
# Wait for WebSocket client to connect and subscribe
259259
# Redis pub/sub doesn't buffer - events sent before subscription are lost
260+
# TODO: Consider Redis Streams or initial state fetch to avoid timing dependency
260261
await asyncio.sleep(1.5)
261262

262263
repo_manager.update_status(repo_id, "indexing")

backend/services/indexing_events.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ class IndexingProgress:
3636
functions_total: int = 0 # Total functions to embed (set during embedding phase)
3737

3838
def __post_init__(self):
39+
# Guard against division by zero
40+
if self.files_total <= 0:
41+
self.percent = 0
42+
return
43+
3944
# If we have functions_total, we're in embedding phase (slow) - weight it 80%
4045
# File extraction is fast, weight it 20%
41-
if self.functions_total > 0 and self.files_total > 0:
46+
if self.functions_total > 0:
4247
file_progress = (self.files_processed / self.files_total) * 20 # 0-20%
4348
embed_progress = (self.functions_found / self.functions_total) * 80 # 0-80%
4449
self.percent = int(file_progress + embed_progress)
45-
elif self.files_total > 0:
50+
else:
4651
# Still in file extraction phase (0-20%)
4752
self.percent = int((self.files_processed / self.files_total) * 20)
4853

@@ -85,7 +90,7 @@ def _publish(self, entity_id: str, event: dict) -> bool:
8590
result = self.redis.publish(channel, json.dumps(event))
8691
logger.info(
8792
"Published event to Redis",
88-
channel=channel[:40],
93+
channel=channel,
8994
event_type=event.get("type"),
9095
subscribers=result
9196
)

frontend/src/components/IndexingProgressModal.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ export function IndexingProgressModal({
8282
}
8383
}, [isOpen])
8484

85+
// Handle Escape key to close modal
86+
useEffect(() => {
87+
if (!isOpen) return
88+
89+
const handleKeyDown = (e: KeyboardEvent) => {
90+
if (e.key === 'Escape') {
91+
if (closeTimeoutRef.current) {
92+
clearTimeout(closeTimeoutRef.current)
93+
closeTimeoutRef.current = null
94+
}
95+
reset()
96+
onClose()
97+
}
98+
}
99+
100+
document.addEventListener('keydown', handleKeyDown)
101+
return () => document.removeEventListener('keydown', handleKeyDown)
102+
}, [isOpen, onClose, reset])
103+
85104
const handleClose = () => {
86105
if (closeTimeoutRef.current) {
87106
clearTimeout(closeTimeoutRef.current)
@@ -128,6 +147,7 @@ export function IndexingProgressModal({
128147
</h3>
129148
<button
130149
onClick={handleClose}
150+
aria-label="Close dialog"
131151
className="p-1 text-zinc-400 hover:text-white transition-colors rounded-lg hover:bg-zinc-800"
132152
>
133153
<X className="w-5 h-5" />
@@ -171,7 +191,7 @@ export function IndexingProgressModal({
171191
<div className="space-y-1 max-h-32 overflow-y-auto">
172192
{recentFiles.slice(0, 5).map((file, i) => (
173193
<motion.div
174-
key={file}
194+
key={`${file}-${i}`}
175195
initial={{ opacity: 0, x: -10 }}
176196
animate={{ opacity: 1 - i * 0.15, x: 0 }}
177197
className="flex items-center gap-2 text-sm"

0 commit comments

Comments
 (0)