mastra-ai/mastra · error · Error

Failed to execute Upstash command: ${response.statusText}

Error message

Failed to execute Upstash command: ${response.statusText}

What it means

executeUpstashCommand() POSTs a Redis command to the Upstash REST API and throws 'Failed to execute Upstash command: <statusText>' when response.ok is false. This means Upstash rejected the request — auth failure, malformed command, rate limit, or server error.

Source

Thrown at packages/loggers/src/upstash/index.ts:58

    this.flushIntervalId = setInterval(() => {
      this._flush().catch(err => {
        console.error('Error flushing logs to Upstash:', err);
      });
    }, this.flushInterval);
  }

  private async executeUpstashCommand(command: any[]): Promise<any> {
    const response = await fetch(`${this.upstashUrl}/pipeline`, {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${this.upstashToken}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify([command]),
    });

    if (!response.ok) {
      throw new Error(`Failed to execute Upstash command: ${response.statusText}`);
    }

    return response.json();
  }

  async _flush() {
    if (this.logBuffer.length === 0) {
      return;
    }

    const now = Date.now();
    const logs = this.logBuffer.splice(0, this.batchSize);

    try {
      // Prepare the Upstash Redis command
      const command = ['LPUSH', this.listName, ...logs.map(log => JSON.stringify(log))];

      // Trim the list if it exceeds maxListLength

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Check the token: re-copy the current REST token from the Upstash console and update upstashToken (401/403 means auth).
  2. Inspect response details and retry 429/5xx with backoff; reduce flush batch size if payloads are too large.
  3. Verify the Redis key (listName) holds a list and the command shape matches the Upstash REST API (["RPUSH", key, ...values]).

Example fix

// before: silent hard failure on rate limit
await logger.flush();
// after
try {
  await logger.flush();
} catch (e) {
  if (String(e.message).includes('Too Many Requests')) {
    await new Promise(r => setTimeout(r, 5000));
    await logger.flush();
  } else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

function assertUpstashEndpoint(url, token) {
  if (!/^https:\/\/.+\.upstash\.io/.test(url)) console.warn('Unexpected Upstash REST URL format');
  if (typeof token !== 'string' || token.length < 10) throw new Error('Upstash token looks invalid');
}

Try / catch

try {
  await logger.flush();
} catch (e) {
  if (String(e.message).startsWith('Failed to execute Upstash command')) {
    // log the failure locally so entries are not lost, then retry later
    console.error('Upstash push failed:', e.message);
    scheduleRetry(() => logger.flush());
  } else throw e;
}

Prevention

When it happens

Trigger: UpstashTransport _flush calling executeUpstashCommand (e.g. RPUSH of log entries) when the API returns non-2xx: 401 for an invalid token, 400 for a malformed command/payload exceeding limits, 429 when rate-limited.

Common situations: Rotated or revoked Upstash REST token; oversized batch pushing past payload limits; exceeding Upstash request quota; network/proxy returning an error page; listName collisions with wrong data types in Redis (e.g. key holding a non-list).

Related errors


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