{"record":{"id":"90faf2df75e217aa","repo":"mastra-ai/mastra","slug":"cursor-run-result-id-ended-with-status-result","errorCode":null,"errorMessage":"Cursor run ${result.id} ended with status ${result.status}","messagePattern":"Cursor run (.+?) ended with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent-sdks/cursor/src/index.ts","lineNumber":320,"sourceCode":"  if (structuredOutput && 'schema' in structuredOutput) {\n    throw new Error(\n      'CursorSDKAgent does not support structuredOutput because the Cursor TypeScript SDK does not expose a schema-constrained output API.',\n    );\n  }\n}\n\nasync function runCursorGenerate(\n  prompt: string,\n  options: CursorAgentOptions,\n  agent: SDKAgent,\n  telemetry: CursorToolTelemetry,\n): Promise<SDKModelGenerateResult> {\n  const usage = createCursorUsageCollector();\n  const run = await agent.send(prompt, createCursorSendOptions(options, usage, telemetry));\n  const result = await run.wait();\n\n  if (result.status === 'error' || result.status === 'cancelled') {\n    throw new Error(`Cursor run ${result.id} ended with status ${result.status}`);\n  }\n\n  const responseModel = getModelId(result.model ?? run.model ?? getRequestedModel(options) ?? agent.model);\n  const providerMetadata = getCursorProviderMetadata(\n    options,\n    agent.agentId,\n    result.id,\n    result.status,\n    result.durationMs,\n    usage.totals(),\n    responseModel,\n  );\n\n  return {\n    content: [{ type: 'text', text: result.result ?? '' }],\n    finishReason: { unified: 'stop', raw: 'stop' },\n    usage: usage.toV3Usage(),\n    response: {","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/agent-sdks/cursor/src/index.ts#L302-L338","documentation":"runCursorGenerate sends the prompt via agent.send, waits for the run to finish with run.wait(), and throws if the finished run's status is 'error' or 'cancelled' — i.e. the Cursor agent run did not complete successfully.","triggerScenarios":"cursorAgent.generate(prompt) where the awaited Cursor run ends with result.status === 'error' or 'cancelled'.","commonSituations":"Cursor API authentication failure; run cancelled by the user or a timeout; the remote agent crashing server-side; hitting Cursor usage limits.","solutions":["Check Cursor API credentials and account status/limits.","Determine whether the run was cancelled externally (user action, abort signal) and avoid aborting.","Retry the generate call if the error was transient.","Log result.status (included in the message) and any Cursor-side run details for diagnosis."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate Cursor credentials/config before sending\nif (!process.env.CURSOR_API_KEY) throw new Error('CURSOR_API_KEY missing before Cursor generate');","typeGuard":"function isFinishedOk(result: { status: string }): boolean {\n  return result.status !== 'error' && result.status !== 'cancelled';\n}","tryCatchPattern":"try {\n  const res = await cursorAgent.generate(prompt);\n} catch (e) {\n  if (e instanceof Error && /ended with status (error|cancelled)/.test(e.message)) {\n    if (e.message.includes('status error')) await retryWithBackoff(() => cursorAgent.generate(prompt));\n    // cancelled: do not retry, handle cancellation\n  } else throw e;\n}","preventionTips":["Check Cursor API key validity and account limits before long runs.","Distinguish cancelled (no retry) from error (transient retry with backoff).","Log result.id from the message for Cursor-side debugging."],"tags":["cursor","agent-sdk","runtime-failure","generate"],"backgroundTag":"agent-run-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}