mastra-ai/mastra · error

Cursor run ${result.id} ended with status ${result.status}

Error message

Cursor run ${result.id} ended with status ${result.status}

What it means

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.

Source

Thrown at agent-sdks/cursor/src/index.ts:320

  if (structuredOutput && 'schema' in structuredOutput) {
    throw new Error(
      'CursorSDKAgent does not support structuredOutput because the Cursor TypeScript SDK does not expose a schema-constrained output API.',
    );
  }
}

async function runCursorGenerate(
  prompt: string,
  options: CursorAgentOptions,
  agent: SDKAgent,
  telemetry: CursorToolTelemetry,
): Promise<SDKModelGenerateResult> {
  const usage = createCursorUsageCollector();
  const run = await agent.send(prompt, createCursorSendOptions(options, usage, telemetry));
  const result = await run.wait();

  if (result.status === 'error' || result.status === 'cancelled') {
    throw new Error(`Cursor run ${result.id} ended with status ${result.status}`);
  }

  const responseModel = getModelId(result.model ?? run.model ?? getRequestedModel(options) ?? agent.model);
  const providerMetadata = getCursorProviderMetadata(
    options,
    agent.agentId,
    result.id,
    result.status,
    result.durationMs,
    usage.totals(),
    responseModel,
  );

  return {
    content: [{ type: 'text', text: result.result ?? '' }],
    finishReason: { unified: 'stop', raw: 'stop' },
    usage: usage.toV3Usage(),
    response: {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Check Cursor API credentials and account status/limits.
  2. Determine whether the run was cancelled externally (user action, abort signal) and avoid aborting.
  3. Retry the generate call if the error was transient.
  4. Log result.status (included in the message) and any Cursor-side run details for diagnosis.
Defensive patterns

Strategy: retry

Validate before calling

// Validate Cursor credentials/config before sending
if (!process.env.CURSOR_API_KEY) throw new Error('CURSOR_API_KEY missing before Cursor generate');

Type guard

function isFinishedOk(result: { status: string }): boolean {
  return result.status !== 'error' && result.status !== 'cancelled';
}

Try / catch

try {
  const res = await cursorAgent.generate(prompt);
} catch (e) {
  if (e instanceof Error && /ended with status (error|cancelled)/.test(e.message)) {
    if (e.message.includes('status error')) await retryWithBackoff(() => cursorAgent.generate(prompt));
    // cancelled: do not retry, handle cancellation
  } else throw e;
}

Prevention

When it happens

Trigger: cursorAgent.generate(prompt) where the awaited Cursor run ends with result.status === 'error' or 'cancelled'.

Common situations: Cursor API authentication failure; run cancelled by the user or a timeout; the remote agent crashing server-side; hitting Cursor usage limits.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/90faf2df75e217aa. Report an issue: GitHub.