{"record":{"id":"917fdaeae2a7820c","repo":"vercel/ai","slug":"opencode-session-create-failed-formaterror-crea","errorCode":null,"errorMessage":"OpenCode session create failed: ${formatError(created.error)}","messagePattern":"OpenCode session create failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/harness-opencode/src/bridge/index.ts","lineNumber":590,"sourceCode":"  client: OpenCodeClient;\n  start: StartMessage;\n  emit: Emit;\n}): Promise<string> {\n  if (runtime.sessionId) return runtime.sessionId;\n  if (start.resumeSessionId) {\n    const existing = await legacySessionGet({\n      client,\n      sessionId: start.resumeSessionId,\n    }).catch(() => undefined);\n    if (existing && !existing.error) {\n      runtime.sessionId = start.resumeSessionId;\n      emit({ type: 'bridge-thread', threadId: runtime.sessionId });\n      return runtime.sessionId;\n    }\n  }\n  const created = await legacySessionCreate({ client });\n  if (created.error) {\n    throw new Error(\n      `OpenCode session create failed: ${formatError(created.error)}`,\n    );\n  }\n  const id = readSessionId(created.data);\n  if (!id) throw new Error('OpenCode session create returned no id.');\n  runtime.sessionId = id;\n  emit({ type: 'bridge-thread', threadId: id });\n  return id;\n}\n\nasync function runPrompt({\n  client,\n  sessionId,\n  start,\n  turn,\n  emit,\n}: {\n  client: OpenCodeClient;","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-opencode/src/bridge/index.ts#L572-L608","documentation":"ensureSession creates an OpenCode session via the legacy session-create API before a turn can run. If that API call returns an error result, the bridge throws with the formatted OpenCode error. This means the OpenCode server refused or failed the session creation request.","triggerScenarios":"Calling a harness run (which calls sessionId -> ensureSession) when legacySessionCreate returns created.error — typically because the OpenCode server is unreachable, its HTTP API version changed, or the server rejects the create request (bad config, auth, unsupported API).","commonSituations":"OpenCode server not running or wrong baseURL configured; OpenCode upgraded and the session-create endpoint/response shape changed; missing or invalid API credentials; server-side model/provider configuration invalid.","solutions":["Read the formatted OpenCode error in the message for the server's own reason and address it.","Confirm the OpenCode server is running and reachable at the configured base URL.","Check that your OpenCode version matches what the harness bridge expects (update either side if the API changed).","Verify server configuration/auth (API keys, provider config) that session creation depends on."],"exampleFix":"// before: server not started\nconst agent = createOpenCodeHarness();\nawait agent.run(...); // throws\n// after: ensure the server is up first\nawait spawnOrVerifyOpenCodeServer({ port: 4096 });\nconst agent = createOpenCodeHarness({ baseURL: 'http://localhost:4096' });\nawait agent.run(...);","handlingStrategy":"try-catch","validationCode":"const base = process.env.OPENCODE_BASE_URL ?? 'http://localhost:4096';\nawait fetch(`${base}/session`, { method: 'GET' }).then(r => { if (!r.ok) throw new Error('OpenCode server not healthy'); });","typeGuard":"function isSessionCreateError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('OpenCode session create failed:');\n}","tryCatchPattern":"try {\n  await agent.run(...);\n} catch (e) {\n  if (isSessionCreateError(e)) {\n    console.error('OpenCode create error detail:', e.message.replace('OpenCode session create failed: ', ''));\n    // verify server is running / version-compatible, then retry\n  } else throw e;\n}","preventionTips":["Verify the OpenCode server is up and healthy before launching harness runs.","Keep OpenCode server and @ai-sdk/harness-opencode versions aligned.","Confirm auth/provider configuration before first use.","Wrap session bootstrap in a startup check rather than discovering failures mid-run."],"tags":["session","opencode","http","api"],"backgroundTag":"opencode-session-create-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}