{"record":{"id":"6149d937c2c35d9d","repo":"paperclipai/paperclip","slug":"opencode-models-timed-out-after-models-discove","errorCode":null,"errorMessage":"`opencode models` timed out after ${MODELS_DISCOVERY_TIMEOUT_MS / 1000}s.","messagePattern":"`opencode models` timed out after (.+?)s\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapters/opencode-local/src/server/models.ts","lineNumber":149,"sourceCode":"  }\n  // Prevent OpenCode from writing an opencode.json into the working directory.\n  const runtimeEnv = normalizeEnv(ensurePathInEnv({ ...process.env, ...env, ...(resolvedHome ? { HOME: resolvedHome } : {}), OPENCODE_DISABLE_PROJECT_CONFIG: \"true\" }));\n\n  const result = await runChildProcess(\n    `opencode-models-${Date.now()}-${Math.random().toString(16).slice(2)}`,\n    command,\n    [\"models\"],\n    {\n      cwd,\n      env: runtimeEnv,\n      timeoutSec: MODELS_DISCOVERY_TIMEOUT_MS / 1000,\n      graceSec: 3,\n      onLog: async () => {},\n    },\n  );\n\n  if (result.timedOut) {\n    throw new Error(`\\`opencode models\\` timed out after ${MODELS_DISCOVERY_TIMEOUT_MS / 1000}s.`);\n  }\n  if ((result.exitCode ?? 1) !== 0) {\n    const detail = firstNonEmptyLine(result.stderr) || firstNonEmptyLine(result.stdout);\n    throw new Error(detail ? `\\`opencode models\\` failed: ${detail}` : \"`opencode models` failed.\");\n  }\n\n  return sortModels(parseOpenCodeModelsOutput(result.stdout));\n}\n\nexport async function discoverOpenCodeModelsCached(input: {\n  command?: unknown;\n  cwd?: unknown;\n  env?: unknown;\n} = {}): Promise<AdapterModel[]> {\n  const command = resolveOpenCodeCommand(input.command);\n  const cwd = asString(input.cwd, process.cwd());\n  const env = normalizeEnv(input.env);\n  const key = discoveryCacheKey(command, cwd, env);","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapters/opencode-local/src/server/models.ts#L131-L167","documentation":"Thrown by discoverOpenCodeModels (LOCAL discovery, models.ts) when the local `opencode models` child process does not finish within MODELS_DISCOVERY_TIMEOUT_MS (20s). This is the local-side sibling of the remote probe timeout (388); it uses runChildProcess with timeoutSec = 20 and graceSec = 3.","triggerScenarios":"runChildProcess for `opencode models` returns { timedOut: true } during local model discovery (not a remote target).","commonSituations":"First-run provider auth check that hangs on a network call; slow disk/antivirus scanning the opencode binary; opencode stuck on an interactive prompt in a non-TTY shell; heavily loaded host.","solutions":["Run `opencode models` manually on the host to see what it is waiting on.","Pre-authenticate the provider (opencode login or API key env) so model enumeration is fast.","If discovery is consistently slow and the model is known-good, set OPENCODE_ALLOW_ALL_MODELS to skip discovery.","Raise MODELS_DISCOVERY_TIMEOUT_MS only if the slowness is a known temporary condition."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Bypass discovery when the model is pre-validated.\nif (isTruthyEnvFlag(env.OPENCODE_ALLOW_ALL_MODELS ?? process.env.OPENCODE_ALLOW_ALL_MODELS)) {\n  return [{ id: model, label: model }]; // skip discoverOpenCodeModels\n}","typeGuard":null,"tryCatchPattern":"let attempt = 0;\nwhile (true) {\n  try {\n    return await discoverOpenCodeModels(input);\n  } catch (e) {\n    if (e instanceof Error && /`opencode models` timed out after/.test(e.message) && attempt++ < 1) continue;\n    throw e;\n  }\n}","preventionTips":["Pre-authenticate providers so `opencode models` is fast.","Set OPENCODE_ALLOW_ALL_MODELS when discovery is unreliable and the model is known-good.","Monitor host load; discovery timeout often tracks CPU/disk contention."],"tags":["opencode","models","local","timeout","discovery"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}