{"record":{"id":"99d3fbcc831416c3","repo":"different-ai/openwork","slug":"request-timed-out","errorCode":null,"errorMessage":"Request timed out.","messagePattern":"Request timed out\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/opencode.ts","lineNumber":169,"sourceCode":"\n  let timeoutId: ReturnType<typeof setTimeout> | null = null;\n  const timeoutPromise = new Promise<never>((_, reject) => {\n    timeoutId = setTimeout(() => {\n      try {\n        controller?.abort();\n      } catch {\n        // ignore\n      }\n      reject(new Error(\"Request timed out.\"));\n    }, effectiveTimeoutMs);\n  });\n\n  try {\n    return await Promise.race([fetchImpl(input, initWithSignal), timeoutPromise]);\n  } catch (error) {\n    const name = (error && typeof error === \"object\" && \"name\" in error ? (error as any).name : \"\") as string;\n    if (name === \"AbortError\") {\n      throw new Error(\"Request timed out.\");\n    }\n    throw error;\n  } finally {\n    if (timeoutId) clearTimeout(timeoutId);\n  }\n}\n\nconst encodeBasicAuth = (auth?: OpencodeAuth) => {\n  if (!auth?.username || !auth?.password) return null;\n  const token = `${auth.username}:${auth.password}`;\n  if (typeof btoa === \"function\") return btoa(token);\n  const buffer = (globalThis as { Buffer?: { from: (input: string, encoding: string) => { toString: (encoding: string) => string } } })\n    .Buffer;\n  return buffer ? buffer.from(token, \"utf8\").toString(\"base64\") : null;\n};\n\nconst resolveAuthHeader = (auth?: OpencodeAuth) => {\n  if (auth?.mode === \"openwork\" && auth.token) {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/opencode.ts#L151-L187","documentation":"fetchWithTimeout races the fetch against a timeout promise; if the loser is an AbortError (raised by the abort controller when the deadline elapses), it is rethrown as \"Request timed out.\" This distinguishes deadline aborts from other failures. Used by createDesktopFetch and fetchImpl.","triggerScenarios":"Any fetch routed through fetchWithTimeout that exceeds its configured timeout: slow network, hung server, large body with no streaming, DNS stall. The abort signal fires and the race rejects with AbortError.","commonSituations":"First-run server health checks against a slow-to-boot local server, remote API latency spikes, VPN/proxy slowness, or a timeout value set too aggressively for the endpoint.","solutions":["Retry the request; transient timeouts often succeed on a second attempt.","Increase the timeout passed to fetchWithTimeout for slow endpoints (e.g. server startup polling).","Verify the target host is reachable (curl) to rule out network/proxy issues.","Check whether the server is hung and needs restart rather than the client needing more time."],"exampleFix":"// before: single attempt\nconst res = await fetchWithTimeout(url, { timeoutMs: 5000 });\n// after: bounded retry for timeout\nlet res;\nfor (let i = 0; i < 3; i++) {\n  try { res = await fetchWithTimeout(url, { timeoutMs: 5000 }); break; }\n  catch (e) { if (i === 2 || String(e.message).includes(\"timed out\") === false) throw e; }\n}","handlingStrategy":"retry","validationCode":"// can only be detected at runtime; ensure timeout exceeds worst-case latency\nconst timeoutMs = endpoint.slow ? 30000 : 5000;\nawait fetchWithTimeout(url, { timeoutMs });","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetchWithTimeout(url, init);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Request timed out.\") {\n    // deadline hit: retry with backoff or enlarge timeout\n    return retryWithBackoff(() => fetchWithTimeout(url, { ...init, timeoutMs: init.timeoutMs * 2 }), 2);\n  }\n  throw err;\n}","preventionTips":["Set per-endpoint timeouts sized to realistic worst-case latency.","Retry idempotent GETs automatically on timeout.","Use health polling with generous budgets during server cold starts.","Monitor network paths (VPN/proxy) known to add latency."],"tags":["network","timeout","fetch","abort"],"backgroundTag":"request-timeout","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}