{"record":{"id":"97f225be8be20630","repo":"thedotmack/claude-mem","slug":"worker-request-timed-out-after-worker-fetch-time","errorCode":null,"errorMessage":"Worker request timed out after ${WORKER_FETCH_TIMEOUT_MS}ms: ${url}","messagePattern":"Worker request timed out after (.+?)ms: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/export-memories.ts","lineNumber":42,"sourceCode":"  const port = Number.parseInt(normalized, 10);\n  if (!Number.isInteger(port) || port < 1 || port > 65535 || String(port) !== normalized) {\n    throw new Error(`Invalid CLAUDE_MEM_WORKER_PORT in settings.json: ${rawPort}`);\n  }\n  return port;\n}\n\nasync function fetchWithTimeout(url: string, init?: RequestInit): Promise<Response> {\n  const controller = new AbortController();\n  const timeout = setTimeout(() => controller.abort(), WORKER_FETCH_TIMEOUT_MS);\n\n  try {\n    return await fetch(url, {\n      ...init,\n      signal: controller.signal,\n    });\n  } catch (error) {\n    if (error instanceof Error && error.name === 'AbortError') {\n      throw new Error(`Worker request timed out after ${WORKER_FETCH_TIMEOUT_MS}ms: ${url}`);\n    }\n    throw error;\n  } finally {\n    clearTimeout(timeout);\n  }\n}\n\nexport async function exportMemories(query: string, outputFile: string, project?: string) {\n  const settings = SettingsDefaultsManager.loadFromFile(join(resolveDataDir(), 'settings.json'));\n  const port = parseWorkerPort(settings.CLAUDE_MEM_WORKER_PORT);\n  const baseUrl = `http://localhost:${port}`;\n\n  console.log(`🔍 Searching for: \"${query}\"${project ? ` (project: ${project})` : ' (all projects)'}`);\n\n  const params = new URLSearchParams({\n    query,\n    format: 'json',\n    limit: '999999'","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/scripts/export-memories.ts#L24-L60","documentation":"Thrown by fetchWithTimeout() when the AbortController fires after WORKER_FETCH_TIMEOUT_MS (30000ms) and the resulting AbortError is re-interpreted as a worker timeout. The export script wraps every worker HTTP call in this 30-second bound, so any single request exceeding it produces this error rather than hanging indefinitely. Non-abort fetch errors are re-thrown unchanged.","triggerScenarios":"Any fetchWithTimeout() call (search, sdk-sessions/batch) where the worker does not respond within 30s. Concretely: exporting a huge result set against /api/search with limit=999999, the worker blocked on a slow Postgres/Chroma query, the worker process wedged, or localhost loopback stalled.","commonSituations":"Large memory database where the hybrid search query plan is slow. Worker contending with the daemon for DB connections. A degenerate query that matches nearly every observation. Resource-constrained machine where the worker is swapping.","solutions":["Narrow the export: pass a more specific query and/or --project to reduce the result set so /api/search returns within 30s.","Check worker health (logs, CPU, DB connection pool) and restart it if wedged.","Confirm the worker port is correct so the request isn't hitting a dead listener that never RSTs.","If large exports are expected, raise WORKER_FETCH_TIMEOUT_MS in the script and rebuild, or paginate the export in smaller batches."],"exampleFix":"// before — single huge export\nexportMemories('\"\"', 'all.json')\n// after — scoped, returns fast\nexportMemories('auth', 'auth.json', 'claude-mem')","handlingStrategy":"retry","validationCode":"import { createConnection } from 'net';\nconst sock = createConnection({ host: '127.0.0.1', port }, () => { sock.end(); });\nsock.on('error', () => { /* worker not listening */ });","typeGuard":null,"tryCatchPattern":"try {\n  return await fetchWithTimeout(url, init);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Worker request timed out')) {\n    // narrow the query and retry once, or surface a 'reduce scope' message\n  }\n  throw e;\n}","preventionTips":["Scope exports with a specific query and --project to keep /api/search responses well under 30s.","Monitor worker DB/Chroma latency so slow queries are caught before they hit the export timeout.","If large exports are routine, raise WORKER_FETCH_TIMEOUT_MS or paginate in batches."],"tags":["network","timeout","worker","export","fetch"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}