Skip to content

Commit 14a6c83

Browse files
Emir Corovicopenclaudeai
authored andcommitted
fix(sdk,core): prevent unrecoverable "Failed to fetch" on long sessions
The SDK client disabled request timeouts entirely (`req.timeout = false`), causing fetch to hang forever when the Go backend becomes unresponsive. Combined with only 3 retry attempts at 10s max delay, the renderer's fetchMessages call would permanently fail with TypeError: Failed to fetch, freezing the TUI display while the backend continued working in the background. Changes: - Set SDK fetch timeout to 5 minutes (300_000ms) instead of disabled - Increase retry defaults: 5 attempts (was 3), 1s initial delay (was 500ms), 30s max delay (was 10s) for better transient error recovery Fixes anomalyco#28702 Co-Authored-By: OpenClaude (GLM-5.1) <[email protected]>
1 parent d709420 commit 14a6c83

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎packages/core/src/util/retry.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function isTransientError(error: unknown): boolean {
2525
}
2626

2727
export async function retry<T>(fn: () => Promise<T>, options: RetryOptions = {}): Promise<T> {
28-
const { attempts = 3, delay = 500, factor = 2, maxDelay = 10000, retryIf = isTransientError } = options
28+
const { attempts = 5, delay = 1000, factor = 2, maxDelay = 30000, retryIf = isTransientError } = options
2929

3030
let lastError: unknown
3131
for (let attempt = 0; attempt < attempts; attempt++) {

‎packages/sdk/js/src/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ function rewrite(request: Request, directory?: string) {
3333
export function createOpencodeClient(config?: Config & { directory?: string }) {
3434
if (!config?.fetch) {
3535
const customFetch: any = (req: any) => {
36+
// Use a 5-minute timeout instead of disabling it entirely.
37+
// Disabling the timeout causes fetch to hang forever when the backend
38+
// becomes unresponsive, leading to unrecoverable "Failed to fetch" errors
39+
// in the renderer (see #28702).
3640
// @ts-ignore
37-
req.timeout = false
41+
req.timeout = 300_000
3842
return fetch(req)
3943
}
4044
config = {

‎packages/sdk/js/src/v2/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ function rewrite(request: Request, values: { directory?: string; workspace?: str
4747
export function createOpencodeClient(config?: Config & { directory?: string; experimental_workspaceID?: string }) {
4848
if (!config?.fetch) {
4949
const customFetch: any = (req: any) => {
50+
// Use a 5-minute timeout instead of disabling it entirely.
51+
// Disabling the timeout causes fetch to hang forever when the backend
52+
// becomes unresponsive, leading to unrecoverable "Failed to fetch" errors
53+
// in the renderer (see #28702).
5054
// @ts-ignore
51-
req.timeout = false
55+
req.timeout = 300_000
5256
return fetch(req)
5357
}
5458
config = {

0 commit comments

Comments
 (0)