{"record":{"id":"14bd12d8caa1fee6","repo":"mastra-ai/mastra","slug":"failed-to-execute-upstash-command-response-stat","errorCode":null,"errorMessage":"Failed to execute Upstash command: ${response.statusText}","messagePattern":"Failed to execute Upstash command: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/loggers/src/upstash/index.ts","lineNumber":58,"sourceCode":"    this.flushIntervalId = setInterval(() => {\n      this._flush().catch(err => {\n        console.error('Error flushing logs to Upstash:', err);\n      });\n    }, this.flushInterval);\n  }\n\n  private async executeUpstashCommand(command: any[]): Promise<any> {\n    const response = await fetch(`${this.upstashUrl}/pipeline`, {\n      method: 'POST',\n      headers: {\n        Authorization: `Bearer ${this.upstashToken}`,\n        'Content-Type': 'application/json',\n      },\n      body: JSON.stringify([command]),\n    });\n\n    if (!response.ok) {\n      throw new Error(`Failed to execute Upstash command: ${response.statusText}`);\n    }\n\n    return response.json();\n  }\n\n  async _flush() {\n    if (this.logBuffer.length === 0) {\n      return;\n    }\n\n    const now = Date.now();\n    const logs = this.logBuffer.splice(0, this.batchSize);\n\n    try {\n      // Prepare the Upstash Redis command\n      const command = ['LPUSH', this.listName, ...logs.map(log => JSON.stringify(log))];\n\n      // Trim the list if it exceeds maxListLength","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/loggers/src/upstash/index.ts#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Check the token: re-copy the current REST token from the Upstash console and update upstashToken (401/403 means auth).","Inspect response details and retry 429/5xx with backoff; reduce flush batch size if payloads are too large.","Verify the Redis key (listName) holds a list and the command shape matches the Upstash REST API ([\"RPUSH\", key, ...values])."],"exampleFix":"// before: silent hard failure on rate limit\nawait logger.flush();\n// after\ntry {\n  await logger.flush();\n} catch (e) {\n  if (String(e.message).includes('Too Many Requests')) {\n    await new Promise(r => setTimeout(r, 5000));\n    await logger.flush();\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":"function assertUpstashEndpoint(url, token) {\n  if (!/^https:\\/\\/.+\\.upstash\\.io/.test(url)) console.warn('Unexpected Upstash REST URL format');\n  if (typeof token !== 'string' || token.length < 10) throw new Error('Upstash token looks invalid');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await logger.flush();\n} catch (e) {\n  if (String(e.message).startsWith('Failed to execute Upstash command')) {\n    // log the failure locally so entries are not lost, then retry later\n    console.error('Upstash push failed:', e.message);\n    scheduleRetry(() => logger.flush());\n  } else throw e;\n}","preventionTips":["Rotate Upstash REST tokens on a schedule and update deployments before old ones expire.","Keep flush batches small to avoid oversized REST payloads.","Add a local fallback buffer so logs survive transient Upstash outages."],"tags":["network","redis","logging","upstash","retry"],"backgroundTag":"upstash-rest-command-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}