#892

Misconfigured REDIS_URL (Upstash URL) crashes session creation with empty 500

Openmlekhiopened 5mo ago

Summary

If REDIS_URL/KV_URL is set to an Upstash REST URL (https://...) instead of a TCP connection string (rediss://...), every POST /api/sessions fails with a naked empty-body 500 and no useful client error. The Upstash console displays the REST endpoint, so this is an easy mistake for anyone wiring redis by hand instead of through the Vercel integration.

Error: Unsupported Redis URL protocol: https:
    at getRedisConnectionOptions (lib/redis.ts)

Issue

getSharedRedisClient() is called outside the try/catch in checkRateLimit (lib/rate-limit.ts), and the rate-limit check in app/api/sessions/route.ts runs before the route's own try block, so the throw escapes both and surfaces as a 500 with an empty body ("Unexpected end of JSON input" client-side). Nothing tells the user the redis URL format is wrong.

Suggestions

  1. Validate the URL protocol where the env is read (e.g. REDIS_URL must be redis:// or rediss://, not https://. Use the TCP connection string instead)
  2. Document redis requirements in the README:
    • the URL must be redis:///rediss:// (TCP), not the Upstash REST endpoint
    • in production, rate limiting requires redis and fails closed with 503 "Rate limit unavailable" when unset. The current line "optional skills metadata cache (falls back to in-memory when not configured)" reads misleading.

Repro

  1. Set REDIS_URL=https://<anything>.upstash.io on a production deployment (or any env where it's read)
  2. Sign in and create a session
  3. POST /api/sessions → 500 with empty body; logs show Unsupported Redis URL protocol: https:

Activity

1
sushanshakya771mo ago

I have a fix for this on a branch (the repo only accepts PRs from collaborators, so I can't open one): https://github.com/vercel-labs/open-agents/compare/main...sushanshakya77:open-agents:fix/redis-url-rate-limit-500

It creates the Redis client inside checkRateLimit's try, so a bad URL returns 503 instead of an empty 500 on every rate-limited route. It also makes the protocol error say what to use and fixes the README. Includes a test. Happy to adjust.