CORS OPTIONS Preflight Fix - COMPLETE
Date: 2026-01-18Issue: OPTIONS preflight requests returning 404 on
payroll-backend-prod for hierarchy endpointsRoot Cause: Environment variable parsing error in deployment command
Commit:
7cd7f2848f6077e3abcf4ca7a5c4f451a94d2144Deployed Revision:
payroll-backend-prod-00164-khb
Root Cause Analysis
Initial Problem
CORS preflight (OPTIONS) requests were failing with 404:OPTIONS /api/v1/admin/agents/resolver→ 404OPTIONS /api/v1/admin/hierarchy/*→ 404
Deployment Failure
First deployment attempt failed with:gcloud run deploy command:
- Incorrect:
--set-env-vars GCP_PROJECT_ID=payroll-bi-gauntlet,GIT_COMMIT_SHA=... - Problem: PowerShell interpreted comma as part of the value, setting
GCP_PROJECT_IDto entire string - Fix: Used PowerShell variable to properly quote the comma-separated list
Solution Implemented
Code Changes
Added explicit OPTIONS handlers for all hierarchy endpoints inapi/routes/admin_hierarchy.py:
/api/v1/admin/agents/resolver→options_agent_resolver()/api/v1/admin/hierarchy/reparent→options_hierarchy_reparent()/api/v1/admin/hierarchy/batch_reparent→options_hierarchy_batch_reparent()/api/v1/admin/hierarchy/bootstrap→options_hierarchy_bootstrap()/api/v1/admin/hierarchy/tree→options_hierarchy_tree()/api/v1/admin/hierarchy/history→options_hierarchy_history()
- Returns
204 No Content(standard for OPTIONS) CORSMiddlewareautomatically adds CORS headers- No auth dependencies (OPTIONS requests don’t include auth headers)
Deployment Fix
Corrected Command:Deployment Status
Status: ✅ SUCCESSFULLY DEPLOYED- Revision:
payroll-backend-prod-00164-khb - Service URL:
https://payroll-backend-prod-238826317621.us-central1.run.app - Deployment Time: ~3 minutes
- Status: Serving 100% of traffic
Post-Deploy Verification
OPTIONS Preflight Test
Access-Control-Allow-Origin: https://payroll-pipeline-cbs.vercel.appAccess-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, PATCHAccess-Control-Allow-Headers: *Access-Control-Allow-Credentials: true
Verification Checklist
- OPTIONS
/api/v1/admin/agents/resolverreturns 200 (not 404) - CORS headers present:
Access-Control-Allow-Origin,Access-Control-Allow-Methods,Access-Control-Allow-Headers - Deployment successful: revision
payroll-backend-prod-00164-khbis healthy - Browser DevTools: No CORS errors when calling resolver endpoint (manual verification needed)
- Export Agent IDs (CSV) works in browser (manual verification needed)
- Hierarchy tools load without resolver errors (manual verification needed)
Files Modified
api/routes/admin_hierarchy.py- Added 6 OPTIONS handlers (46 lines)docs/CORS_OPTIONS_FIX.md- Initial deployment summarydocs/CORS_OPTIONS_FIX_COMPLETE.md- This file
Notes
- OPTIONS handlers are minimal and safe - they don’t change business logic
CORSMiddlewareconfiguration remains unchanged (already correct)- This fix is compatible with existing CORS setup
- No RBAC/auth changes - OPTIONS handlers have no dependencies
- Environment variable parsing issue was deployment-specific, not code-related
Next Steps
-
Manual Browser Verification:
- Navigate to
/admin/identity-overrides?tab=hierarchy - Click “Export Agent IDs”
- Verify no CORS errors in DevTools
- Confirm CSV downloads successfully
- Navigate to
-
Monitor Production:
- Check Cloud Run logs for any OPTIONS-related errors
- Verify resolver endpoint calls succeed from frontend