GeezerVison is showing github.com — fix(sdk,core): prevent unrecoverable "Failed to fetch" on long sessions · Krypto-Whitehat/opencode@14a6c83
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/core/src/util/retry.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ function isTransientError(error: unknown): boolean { |
25 | 25 | } |
26 | 26 |
|
27 | 27 | 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 |
29 | 29 |
|
30 | 30 | let lastError: unknown |
31 | 31 | for (let attempt = 0; attempt < attempts; attempt++) { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/sdk/js/src/client.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,8 +33,12 @@ function rewrite(request: Request, directory?: string) { |
33 | 33 | export function createOpencodeClient(config?: Config & { directory?: string }) { |
34 | 34 | if (!config?.fetch) { |
35 | 35 | 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). |
36 | 40 | // @ts-ignore |
37 | | - req.timeout = false |
| 41 | + req.timeout = 300_000 |
38 | 42 | return fetch(req) |
39 | 43 | } |
40 | 44 | config = { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/sdk/js/src/v2/client.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,8 +47,12 @@ function rewrite(request: Request, values: { directory?: string; workspace?: str |
47 | 47 | export function createOpencodeClient(config?: Config & { directory?: string; experimental_workspaceID?: string }) { |
48 | 48 | if (!config?.fetch) { |
49 | 49 | 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). |
50 | 54 | // @ts-ignore |
51 | | - req.timeout = false |
| 55 | + req.timeout = 300_000 |
52 | 56 | return fetch(req) |
53 | 57 | } |
54 | 58 | config = { |
|