{"record":{"id":"7d44da9c7b825ce3","repo":"vercel/ai","slug":"opencode-prompt-failed-formaterror-prompted-err","errorCode":null,"errorMessage":"OpenCode prompt failed: ${formatError(prompted.error)}","messagePattern":"OpenCode prompt failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/harness-opencode/src/bridge/index.ts","lineNumber":769,"sourceCode":"        message.accept();\n      } catch (error) {\n        message.reject(error);\n      } finally {\n        submittingUserMessage = false;\n      }\n    }\n  })();\n  const prompted = await legacySessionPrompt({\n    client,\n    sessionId,\n    start,\n  });\n  if (prompted.error) {\n    eventsAbort.abort();\n    turn.experimental_userMessages.close(\n      new Error(`OpenCode prompt failed: ${formatError(prompted.error)}`),\n    );\n    throw new Error(`OpenCode prompt failed: ${formatError(prompted.error)}`);\n  }\n  const settlement = await turnSettled.promise;\n  eventsAbort.abort();\n  await eventLoop.catch(() => {});\n  await userMessageLoop.catch(() => {});\n  if (settlement === 'stream-ended') {\n    throw new Error('OpenCode event stream ended before the turn settled.');\n  }\n  if (terminalError) throw new Error(terminalError);\n  if (!sawFinishStep) {\n    const emittedFallback = await emitContextFallback({\n      client,\n      sessionId,\n      assistantBaseline,\n      state,\n      emit,\n      emitContent: !sawContent,\n    }).catch(() => false);","sourceCodeStart":751,"sourceCodeEnd":787,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-opencode/src/bridge/index.ts#L751-L787","documentation":"runPrompt sends the user prompt to the OpenCode session with legacySessionPrompt. If the prompt API returns an error result, the bridge aborts the event stream, closes the user-message queue with this error, and throws it. The turn fails immediately with the OpenCode server's formatted error message.","triggerScenarios":"Calling a turn (runTurn -> runPrompt) when legacySessionPrompt resolves prompted.error — server rejected the prompt request (invalid session id, session already busy, provider/model misconfigured, HTTP 4xx/5xx from OpenCode).","commonSituations":"Prompting a stale/deleted session id; a model/provider name not configured on the OpenCode server; concurrent prompts to the same session; OpenCode server returning 409/500 while processing.","solutions":["Inspect formatError output in the message for the server-side cause (invalid model, busy session, etc.).","Verify the session id is still valid and no other prompt is in flight for it.","Check the model/provider configured in start options exists on the OpenCode server.","Retry the turn if the failure was transient (e.g. 502 from the underlying LLM provider)."],"exampleFix":"// before: stale session id reused across restarts\nawait bridge.runTurn({ sessionId: oldId, prompt }); // OpenCode prompt failed: session not found\n// after: let the bridge create a fresh session\nawait bridge.runTurn({ prompt }); // new session created automatically","handlingStrategy":"try-catch","validationCode":"const session = await fetch(`${base}/session/${sessionId}`).then(r => r.ok);\nif (!session) throw new Error(`Session ${sessionId} does not exist before prompting`);","typeGuard":"function isPromptError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('OpenCode prompt failed:');\n}","tryCatchPattern":"try {\n  await bridge.runTurn({ sessionId, prompt });\n} catch (e) {\n  if (isPromptError(e)) {\n    console.error('Prompt error detail:', e.message.replace('OpenCode prompt failed: ', ''));\n    // recreate session or fix model config, then retry\n  } else throw e;\n}","preventionTips":["Never reuse session ids across OpenCode server restarts.","Serialize prompts per session — no concurrent turns.","Validate model/provider options before submitting.","Retry turns on transient 5xx with backoff."],"tags":["prompt","opencode","http","api"],"backgroundTag":"opencode-prompt-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}