CORS OPTIONS Preflight Fix - Deployment Summary
Date: 2026-01-18Issue: OPTIONS preflight requests returning 404 on
payroll-backend-prod for hierarchy endpointsCommit:
7cd7f2848f6077e3abcf4ca7a5c4f451a94d2144
Problem
CORS preflight (OPTIONS) requests were failing with 404:OPTIONS /api/v1/admin/agents/resolver→ 404OPTIONS /api/v1/admin/hierarchy/*→ 404
- Agent Mapping resolver cache
- Export Agent IDs (CSV)
- Hierarchy tools
Root Cause
FastAPI’sCORSMiddleware should handle OPTIONS automatically, but it wasn’t working for routes with complex dependencies (like require_admin_or_ceo). The middleware might not handle OPTIONS for routes that don’t exist or routes that fail dependency checks before CORS can respond.
Solution
Added explicit OPTIONS handlers for all hierarchy endpoints:/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)
Code Changes
File:api/routes/admin_hierarchy.py
Added OPTIONS handlers (6 total):
Deployment Status
Commit:7cd7f2848f6077e3abcf4ca7a5c4f451a94d2144Status: ⚠️ Deployment failed (container startup timeout) Current Revision:
payroll-backend-prod-00161-g9n (previous revision, still serving traffic)
Deployment Error: Container failed to start and listen on port 8080 within timeout. This appears to be unrelated to the OPTIONS handler changes (code compiles, syntax is correct).
Next Steps
-
Investigate deployment failure:
- Check Cloud Run logs for startup errors
- Verify Dockerfile and startup command
- Check if there are any import errors or missing dependencies
-
Retry deployment after fixing startup issue:
-
Post-deploy verification:
Verification Checklist
After successful deployment:- OPTIONS
/api/v1/admin/agents/resolverreturns 204 (not 404) - CORS headers present:
Access-Control-Allow-Origin,Access-Control-Allow-Methods,Access-Control-Allow-Headers - Browser DevTools: No CORS errors when calling resolver endpoint
- Export Agent IDs (CSV) works in browser
- Hierarchy tools load without resolver errors
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