Add retry with exponential backoff for OpenAI API failures in policy generation #482

Open
opened 2026-04-10 19:45:15 -04:00 by pook · 0 comments
Owner

The /api/generate endpoints call OpenAI API for policy document generation. Currently, any OpenAI 429 or 5xx error fails immediately, producing a broken document or error page for the user. Add retry logic: wrap OpenAI API calls with a retry utility that retries up to 3 times with exponential backoff (1s, 2s, 4s) on 429 and 5xx errors. Log retry attempts with attempt number and status code. If all retries fail, return 502 with 'AI service temporarily unavailable'. Do NOT retry on 4xx errors. Acceptance: add retry wrapper function, integrate into /api/generate route, add unit test with mocked OpenAI failures to verify retry behavior.


Generated by CEO Planner (priority: 3)

The /api/generate endpoints call OpenAI API for policy document generation. Currently, any OpenAI 429 or 5xx error fails immediately, producing a broken document or error page for the user. Add retry logic: wrap OpenAI API calls with a retry utility that retries up to 3 times with exponential backoff (1s, 2s, 4s) on 429 and 5xx errors. Log retry attempts with attempt number and status code. If all retries fail, return 502 with 'AI service temporarily unavailable'. Do NOT retry on 4xx errors. Acceptance: add retry wrapper function, integrate into /api/generate route, add unit test with mocked OpenAI failures to verify retry behavior. --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#482
No description provided.