Skip to content

fix(qstash): pin client to US region via QSTASH_URL#3584

Merged
saddlepaddle merged 1 commit into
mainfrom
qstash-us-region
Apr 20, 2026
Merged

fix(qstash): pin client to US region via QSTASH_URL#3584
saddlepaddle merged 1 commit into
mainfrom
qstash-us-region

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Apr 20, 2026

Summary

Our prod QStash project lives in us-east-1 but Upstash's global endpoint was routing us to eu-central-1, so the first scheduler setup run 404'd with "user not found in this region." Pass an explicit baseUrl from a new `QSTASH_URL` secret.

  • `apps/api/src/env.ts` — require `QSTASH_URL`
  • `evaluate` route + `setup-automations-schedule` script — pass `baseUrl` to `new Client({...})`
  • deploy-production / deploy-preview / setup-automations-schedule workflows — plumb the secret through

Once this lands:

  1. Re-run Deploy Production so Vercel bakes in `QSTASH_URL`
  2. Re-trigger Setup Automations Schedule — should register the cron on us-east-1

Test plan

  • Deploy Production completes
  • `Setup Automations Schedule` succeeds and prints the new scheduleId
  • Evaluator cron invocation lands in QStash US dashboard within a minute

Summary by cubic

Pin @upstash/qstash to our US region by introducing QSTASH_URL and passing it as baseUrl. Fixes cross‑region routing that caused "user not found in this region" 404s for schedule setup and evaluator cron.

  • Bug Fixes

    • Require QSTASH_URL in apps/api/src/env.ts.
    • Pass baseUrl to new Client({...}) in the evaluate route and setup-automations-schedule script.
    • Plumb QSTASH_URL through deploy-production, deploy-preview, and setup-automations-schedule workflows.
  • Migration

    • Add QSTASH_URL secret pointing to the us-east-1 endpoint (e.g., https://qstash-us-east-1.upstash.io).
    • Redeploy Production, then re-run “Setup Automations Schedule” to register the cron in us-east-1.

Written for commit 78c83ca. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Added configurable QStash endpoint support through a new environment variable across deployment workflows and automation schedules, enabling the system to use custom QStash endpoint URLs.

Upstash's global endpoint routed us to eu-central-1 even though our
prod QStash project lives in us-east-1, so schedules.list() 404'd with
"user not found in this region." Pass an explicit baseUrl from a new
QSTASH_URL env var so every call hits the right region.

- apps/api/src/env.ts: add QSTASH_URL.
- evaluate route + setup script: pass baseUrl to new Client({...}).
- deploy-{preview,production} + setup-automations-schedule workflows:
  plumb the secret through.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28fae927-3fc4-4eb2-8ece-db24d8b9f614

📥 Commits

Reviewing files that changed from the base of the PR and between 444c9aa and 78c83ca.

📒 Files selected for processing (6)
  • .github/workflows/deploy-preview.yml
  • .github/workflows/deploy-production.yml
  • .github/workflows/setup-automations-schedule.yml
  • apps/api/scripts/setup-automations-schedule.ts
  • apps/api/src/app/api/automations/evaluate/route.ts
  • apps/api/src/env.ts

📝 Walkthrough

Walkthrough

This pull request introduces QSTASH_URL as a new environment variable throughout the API deployment and automation infrastructure. The variable is added to GitHub Actions workflows, environment schemas, and QStash client initialization logic to enable configurable QStash endpoint routing.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/deploy-preview.yml, .github/workflows/deploy-production.yml
Added QSTASH_URL secret/environment variable to deploy-api job configuration and passed it to Vercel deployment via --env flag.
Automation Scheduling
.github/workflows/setup-automations-schedule.yml, apps/api/scripts/setup-automations-schedule.ts
Added QSTASH_URL environment variable to workflow step and updated script to validate and use it when initializing QStash Client with explicit baseUrl.
Environment Configuration
apps/api/src/env.ts
Added required QSTASH_URL server environment variable declaration with URL validation schema.
API Route
apps/api/src/app/api/automations/evaluate/route.ts
Updated QStash Client initialization to include baseUrl sourced from env.QSTASH_URL alongside existing token configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes


🐰 A new URL hops into the queue,
Config-wise, we know just what to do,
QStash endpoints now align with care,
Through workflows and scripts, variables everywhere!
The schedule automation dances with glee,
With baseUrl routed properly. ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch qstash-us-region

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@saddlepaddle saddlepaddle merged commit 1353b20 into main Apr 20, 2026
6 of 8 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) Failed to create
Fly.io Electric (Fly.io) Failed to deploy
Vercel API (Vercel) Failed to deploy
Vercel Web (Vercel) Failed to deploy
Vercel Marketing (Vercel) Failed to deploy
Vercel Admin (Vercel) Failed to deploy
Vercel Docs (Vercel) Failed to deploy

Preview updates automatically with new commits

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 20, 2026

Greptile Summary

This PR fixes a production routing bug where Upstash's global QStash endpoint was directing traffic to eu-central-1 instead of the project's actual us-east-1 region, causing 404 "user not found in this region" errors. The fix pins all QStash client instantiations to an explicit regional base URL via a new QSTASH_URL secret, and plumbs that secret through all three relevant workflows.

  • Added QSTASH_URL: z.string().url() as a required server env var in apps/api/src/env.ts
  • Passed baseUrl: env.QSTASH_URL to the Client constructor in both the evaluate route and the setup-automations-schedule script
  • Threaded secrets.QSTASH_URL through deploy-production.yml, deploy-preview.yml, and setup-automations-schedule.yml
  • The Receiver is correctly left without a baseUrl — it only performs local HMAC verification and makes no outbound API calls
  • Note: QSTASH_URL is now required (not optional), so developers will need to add it to local .env files

Confidence Score: 5/5

Safe to merge — targeted, minimal change that correctly resolves the region-routing 404 with no logic regressions.

baseUrl is a documented @upstash/qstash Client option, all three call-sites are updated consistently, secret plumbing is complete across all workflows, and the Receiver is correctly left unchanged.

No files require special attention.

Important Files Changed

Filename Overview
apps/api/src/env.ts Adds required QSTASH_URL server env var with URL validation — correctly placed alongside other QStash secrets, no issues.
apps/api/src/app/api/automations/evaluate/route.ts Passes baseUrl: env.QSTASH_URL to the QStash Client constructor to pin to US region; Receiver intentionally left unchanged as it only does local HMAC verification.
apps/api/scripts/setup-automations-schedule.ts Reads and validates QSTASH_URL from env, then passes it as baseUrl to the Client; idempotency logic unchanged and correct.
.github/workflows/deploy-production.yml Correctly threads QSTASH_URL secret into both the job env block and the explicit --env flags of vercel deploy.
.github/workflows/deploy-preview.yml Correctly threads QSTASH_URL secret into both the job env block and the explicit --env flags of vercel deploy.
.github/workflows/setup-automations-schedule.yml Adds QSTASH_URL secret to the Create schedule step env, completing the plumbing for the one-shot setup script.

Reviews (1): Last reviewed commit: "fix(qstash): pin client to QSTASH_URL so..." | Re-trigger Greptile

@Kitenite Kitenite deleted the qstash-us-region branch May 6, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant