Skip to content

Commit 092bd17

Browse files
authored
feat: Add delay information when retrying requests (RooCodeInc#3817)
* Add delay information when retrying requests * Display delays * refactor and add countdown
1 parent 079d05c commit 092bd17

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Display delay information when retrying API calls

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ interface CopyButtonProps {
4141
textToCopy: string | undefined
4242
}
4343

44+
const normalColor = "var(--vscode-foreground)"
45+
const errorColor = "var(--vscode-errorForeground)"
46+
const successColor = "var(--vscode-charts-green)"
47+
const cancelledColor = "var(--vscode-descriptionForeground)"
48+
4449
const CopyButtonStyled = styled(VSCodeButton)`
4550
position: absolute;
4651
bottom: 2px;
@@ -153,6 +158,40 @@ const Markdown = memo(({ markdown }: { markdown?: string }) => {
153158
)
154159
})
155160

161+
const RetryMessage = ({ seconds, attempt, retryOperations }: { retryOperations: number; attempt: number; seconds?: number }) => {
162+
const [remainingSeconds, setRemainingSeconds] = useState(seconds || 0)
163+
164+
useEffect(() => {
165+
if (seconds && seconds > 0) {
166+
setRemainingSeconds(seconds)
167+
168+
const interval = setInterval(() => {
169+
setRemainingSeconds((prev) => {
170+
if (prev <= 1) {
171+
clearInterval(interval)
172+
return 0
173+
}
174+
return prev - 1
175+
})
176+
}, 1000)
177+
178+
return () => clearInterval(interval)
179+
}
180+
}, [seconds])
181+
182+
return (
183+
<span
184+
style={{
185+
color: normalColor,
186+
fontWeight: "bold",
187+
}}>
188+
{`API Request (Retrying failed attempt ${attempt}/${retryOperations}`}
189+
{remainingSeconds > 0 && ` in ${remainingSeconds} seconds`}
190+
)...
191+
</span>
192+
)
193+
}
194+
156195
const ChatRow = memo(
157196
(props: ChatRowProps) => {
158197
const { isLast, onHeightChange, message, lastModifiedMessage, inputValue } = props
@@ -230,11 +269,6 @@ export const ChatRowContent = ({
230269

231270
const type = message.type === "ask" ? message.ask : message.say
232271

233-
const normalColor = "var(--vscode-foreground)"
234-
const errorColor = "var(--vscode-errorForeground)"
235-
const successColor = "var(--vscode-charts-green)"
236-
const cancelledColor = "var(--vscode-descriptionForeground)"
237-
238272
const handleMessage = useCallback((event: MessageEvent) => {
239273
const message: ExtensionMessage = event.data
240274
switch (message.type) {
@@ -448,11 +482,11 @@ export const ChatRowContent = ({
448482
if (retryStatus && cost == null && !apiReqCancelReason) {
449483
const retryOperations = retryStatus.maxAttempts > 0 ? retryStatus.maxAttempts - 1 : 0
450484
return (
451-
<span
452-
style={{
453-
color: normalColor,
454-
fontWeight: "bold",
455-
}}>{`API Request (Retrying failed attempt ${retryStatus.attempt}/${retryOperations})...`}</span>
485+
<RetryMessage
486+
seconds={retryStatus.delaySec}
487+
attempt={retryStatus.attempt}
488+
retryOperations={retryOperations}
489+
/>
456490
)
457491
}
458492

0 commit comments

Comments
 (0)