feat: runtime-toggleable ENABLE_UNIVERSAL_VERCEL_ROUTING via Edge Config#379
feat: runtime-toggleable ENABLE_UNIVERSAL_VERCEL_ROUTING via Edge Config#379kiloconnect[bot] wants to merge 2 commits intomainfrom
Conversation
…Edge Config flag Replace the hardcoded boolean constant with a runtime-toggleable flag backed by Vercel Edge Config. This allows admins to flip the universal Vercel routing switch without redeploying. Changes: - Add @vercel/edge-config dependency - Create src/lib/edge-config.ts with TTL-cached reader (15s) and writer - Update src/lib/providers/vercel.ts to use async isUniversalVercelRoutingEnabled() - Add admin.routingSwitch tRPC router (getStatus/setStatus) - Add unit tests for the edge-config module
| expect(await isUniversalVercelRoutingEnabled()).toBe(false); | ||
| }); | ||
|
|
||
| test('returns stale cached value when Edge Config read fails after a successful read', async () => { |
There was a problem hiding this comment.
WARNING: This test doesn't actually verify stale-cache fallback.
_resetCacheForTesting() on line 60 sets cached = null, so when mockGet rejects on line 61, the catch branch in isUniversalVercelRoutingEnabled finds cached === null and returns false — it never exercises the if (cached) return cached.value stale-cache path.
To truly test stale-cache fallback you'd need to let the TTL expire without clearing the cache (e.g. by advancing Date.now() past the TTL via jest.useFakeTimers()) so that cached is still populated but stale when the fetch fails.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge This PR replaces the hardcoded
Files Reviewed (9 files)
|
Add /admin/routing-switch page with: - Big visual status indicator (Jurassic Park energy) - Toggle button to enable/disable universal Vercel routing - Confirmation dialog before toggling (affects all traffic) - Success/error toasts via sonner - Auto-refresh every 15 seconds (matches Edge Config TTL) - Warning card explaining the impact - Sidebar navigation entry under Product & Engineering
Summary
Replace the hardcoded
ENABLE_UNIVERSAL_VERCEL_ROUTINGboolean constant insrc/lib/providers/vercel.tswith a dynamic, runtime-toggleable flag backed by Vercel Edge Config. This enables admins to flip the universal Vercel routing "emergency switch" without redeploying.What changed
New:
src/lib/edge-config.tsisUniversalVercelRoutingEnabled()— reads the flag from Edge Config with a 15-second in-memory TTL cache, so the hot path almost never hits Edge ConfigsetUniversalVercelRouting(enabled)— writes the flag via the Vercel REST API (the SDK is read-only)falseon any error (safe default = normal routing, not universal Vercel)Modified:
src/lib/providers/vercel.tsconst ENABLE_UNIVERSAL_VERCEL_ROUTING = falseshouldRouteToVercel()now callsawait isUniversalVercelRoutingEnabled()(was already async)New:
src/routers/admin-routing-switch-router.tsadmin.routingSwitch.getStatus— query to read current flag stateadmin.routingSwitch.setStatus— mutation to toggle the flag on/offadminProcedureModified:
src/routers/admin-router.tsadminRoutingSwitchRouterasroutingSwitchNew:
src/app/admin/routing-switch/page.tsx/admin/routing-switchfor toggling universal Vercel routingModified:
src/app/admin/components/AppSidebar.tsxNew:
src/lib/edge-config.test.tsNew dependency:
@vercel/edge-configEnvironment variables needed
EDGE_CONFIGEDGE_CONFIG_IDVERCEL_API_TOKENVERCEL_TEAM_IDHow to use
Navigate to Admin → Product & Engineering → Routing Switch or go directly to
/admin/routing-switch.The page shows the current state and provides a big toggle button with a confirmation dialog.
Programmatically via tRPC:
The flag propagates to all instances within ~15 seconds (the TTL cache window).
Safety
false(normal routing) if Edge Config is unavailable or the key doesn't existBuilt for Mark by Kilo for Slack
Built for Mark by Kilo for Slack