Skip to content

fix(billing): unify Upstash and Vercel KV credential resolution - #2686

Merged
groupthinking merged 2 commits into
mainfrom
fix/upstash-kv-credential-parity
Nov 16, 2026
Merged

groupthinking merged 2 commits into
mainfrom
fix/upstash-kv-credential-parity

Conversation

@groupthinking

Copy link
Copy Markdown
Owner

Canonical issue

Closes #2685

Outcome

Ensures apps/web/src/proxy.ts (edge rate limiting) and the remaining billing/telemetry stores (chat-quota.ts, checkout-session-store.ts, kaizen-trace.ts) resolve both UPSTASH_REDIS_REST_* and Vercel Marketplace KV_REST_API_* credentials identically to video-pack-store.ts, video-pack-admission.ts, entitlement-store.ts, and origin-gate-store.ts.

Scope

  • Included:
    • Added shared helper apps/web/src/lib/billing/upstash-client.ts (createUpstashRedisClient()) backed by resolveUpstashRedisCredentials()
    • Updated apps/web/src/proxy.ts, chat-quota.ts, checkout-session-store.ts, kaizen-trace.ts, and entitlement-store.ts to reuse createUpstashRedisClient() / resolveUpstashRedisCredentials()
    • Added apps/web/src/lib/billing/__tests__/upstash-kv-parity.test.ts and added KV_REST_API_* isolation + coverage in apps/web/src/__tests__/proxy-auth-gate.test.ts
  • Explicitly excluded:
    • No changes to 402 billing/quota gates, TEMP_PAYWALL_OFF, pricing, or production secrets/env vars

Risk

  • Risk level: low
  • Failure mode: If KV_REST_API_* variables are misconfigured in production, Upstash REST client calls will fail the same way UPSTASH_REDIS_REST_* would (paid AI routes in proxy.ts remain fail-closed 503).
  • Rollback: Revert commit b1110c7a5 (git revert b1110c7a5).

Verification

Verified on commit b1110c7a5 in clean worktree:

  • npx vitest run src/__tests__/proxy-auth-gate.test.ts src/lib/billing/__tests__/upstash-kv-parity.test.ts src/lib/billing/__tests__/entitlement-store.test.ts src/lib/billing/__tests__/checkout-session-store.test.ts src/lib/__tests__/video-pack-store.test.ts src/lib/__tests__/video-pack-admission.test.ts src/__tests__/test-env-isolation.test.ts: 7 test files passed (62 passed, 1 skipped in video-pack-store.test.ts)

  • npx tsc --noEmit: passed (0 errors)

  • npx eslint ... on all 8 touched files: passed (0 errors/warnings)

  • Focused tests

  • Required CI

  • Review threads resolved

Production evidence

Not yet deployed; awaiting CI and Vercel preview on this PR.

Agent handoff

Copilot AI max review requested due to automatic review settings November 16, 2026 22:46
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
v0-uvai Ready Ready Preview, v0 Nov 16, 2026 11:11pm UTC

@github-actions github-actions Bot added javascript Pull requests that update javascript code tests labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ E2E Test Results: ALL TESTS PASSED

Metric Value
Status 🟢 GREEN
Total Tests
Passed 16
Failed
Deployment https://v0-uvai-oyl04r8fv-garv1.vercel.app
Test Output
very request without persisting it�[32m 1�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mhomepage returns 200 with HTML�[32m 197�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page contains template/workflow markup�[32m 219�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page surfaces at least 5 workflow/template indicators�[32m 181�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mPOST /api/video/pack accepts a YouTube URL without hanging�[33m 2047�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mGET /api/video/pack resolves to a ready pack with evidence lineage�[33m 1171�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mmissing URL returns 400, not a hang�[32m 225�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22minvalid URL returns 400 quickly, not a hang�[32m 181�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mPOST /api/video/pack with no body returns 400�[32m 171�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard returns 200�[32m 195�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard contains agent or pipeline visualization markup�[32m 155�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mGET /api returns a response (not 404)�[32m 264�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mretired /api/pipeline routes are gone (no pipeline served)�[32m 76�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22mhomepage has proper meta tags�[32m 121�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22m/features page returns 200�[32m 182�[2mms�[22m�[39m

�[2m Test Files �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m
�[2m      Tests �[22m �[1m�[32m16 passed�[39m�[22m�[90m (16)�[39m
�[2m   Start at �[22m 22:47:44
�[2m   Duration �[22m 7.05s�[2m (transform 42ms, setup 0ms, import 54ms, tests 6.87s, environment 0ms)�[22m


Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The KV credential test does not verify the constructor URL and token, so it could miss a regression that enables the client with unset credentials.

1 open issue
What changed in this PR

Unifies Upstash REST credential handling in UVAI’s web app so rate limiting and billing/telemetry stores accept Vercel Marketplace KV_REST_API_* credentials, addressing #2685.

Changes:

  • Adds a shared Redis client factory backed by the existing credential resolver.
  • Migrates the proxy and four stores without changing billing or quota policies.
  • Adds KV-only regression coverage and test environment isolation.
File Description
apps/​web/​src/​proxy.ts Uses shared credential resolution for distributed rate limiting.
apps/​web/​src/​lib/​billing/​upstash-client.ts Adds the shared Upstash REST client factory.
apps/​web/​src/​lib/​billing/​kaizen-trace.ts Uses the shared factory for trace storage.
apps/​web/​src/​lib/​billing/​entitlement-store.ts Replaces duplicate client construction with the factory.
apps/​web/​src/​lib/​billing/​checkout-session-store.ts Enables KV credentials for checkout activation storage.
apps/​web/​src/​lib/​billing/​chat-quota.ts Enables KV credentials for distributed quota counting.
apps/​web/​src/​lib/​billing/​__tests__/​upstash-kv-parity.test.ts Tests KV credential use across billing and telemetry stores.
apps/​web/​src/​__tests__/​proxy-auth-gate.test.ts Adds KV-only proxy coverage and environment isolation.

Review effort: Max

@github-actions

Copy link
Copy Markdown
Contributor

✅ E2E Test Results: ALL TESTS PASSED

Metric Value
Status 🟢 GREEN
Total Tests
Passed 16
Failed
Deployment https://v0-uvai-qka8k6xno-garv1.vercel.app
Test Output
every request without persisting it�[32m 1�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mhomepage returns 200 with HTML�[32m 156�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page contains template/workflow markup�[32m 224�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page surfaces at least 5 workflow/template indicators�[32m 131�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mPOST /api/video/pack accepts a YouTube URL without hanging�[33m 1983�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mGET /api/video/pack resolves to a ready pack with evidence lineage�[33m 911�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mmissing URL returns 400, not a hang�[32m 177�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22minvalid URL returns 400 quickly, not a hang�[32m 166�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mPOST /api/video/pack with no body returns 400�[32m 162�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard returns 200�[32m 167�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard contains agent or pipeline visualization markup�[32m 185�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mGET /api returns a response (not 404)�[32m 272�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mretired /api/pipeline routes are gone (no pipeline served)�[32m 66�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22mhomepage has proper meta tags�[32m 103�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22m/features page returns 200�[32m 114�[2mms�[22m�[39m

�[2m Test Files �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m
�[2m      Tests �[22m �[1m�[32m16 passed�[39m�[22m�[90m (16)�[39m
�[2m   Start at �[22m 23:12:45
�[2m   Duration �[22m 6.45s�[2m (transform 32ms, setup 0ms, import 43ms, tests 6.31s, environment 0ms)�[22m


@groupthinking

Copy link
Copy Markdown
Owner Author

Updated apps/web/src/__tests__/proxy-auth-gate.test.ts in dfc369772 to record Redis constructor arguments and assert { url: 'https://kv.example.upstash.io', token: 'kv-token' }.

@groupthinking
groupthinking merged commit aaea6e1 into main Nov 16, 2026
30 checks passed
@groupthinking
groupthinking deleted the fix/upstash-kv-credential-parity branch November 16, 2026 23:18

This branch was successfully deployed

1 active deployment
Preview — dfc36977 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(billing): unify Upstash and Vercel KV credential resolution across edge proxy and billing stores

3 participants