[Agent] Issue #629: the apigenerate route calls openai but h #633

Open
pook wants to merge 62 commits from feat/generate-retry-tests into main
Owner

Closes #629

Changes

feat: issue #629 the-apigenerate-route-calls-openai-but-h (agent task liancebot629)

Acceptance Criteria

The /api/generate route calls OpenAI but has no retry logic — a single 429 or 500 fails the generation request.

Implementation:

  1. Wrap the OpenAI API call in a retry helper: max 3 attempts, backoff 1s → 2s → 4s.
  2. Only retry on 429 and 500/502/503. Do NOT retry on 400/401/403.
  3. Log each retry with attempt number.
  4. If all retries exhausted, return 502 with { error: 'AI service temporarily unavailable' }.
  5. Unit test: mock OpenAI 429×2 then 200 → verify 200 response.
  6. Unit test: mock OpenAI 500×3 → verify 502 response.

Acceptance: npm test passes. Wrapper is reusable if shared with contractpilot.


Generated by CEO Planner (priority: 3)

Tokens: 44 in / 10874 out

Closes #629 ## Changes feat: issue #629 the-apigenerate-route-calls-openai-but-h (agent task liancebot629) ## Acceptance Criteria The /api/generate route calls OpenAI but has no retry logic — a single 429 or 500 fails the generation request. Implementation: 1. Wrap the OpenAI API call in a retry helper: max 3 attempts, backoff 1s → 2s → 4s. 2. Only retry on 429 and 500/502/503. Do NOT retry on 400/401/403. 3. Log each retry with attempt number. 4. If all retries exhausted, return 502 with `{ error: 'AI service temporarily unavailable' }`. 5. Unit test: mock OpenAI 429×2 then 200 → verify 200 response. 6. Unit test: mock OpenAI 500×3 → verify 502 response. Acceptance: `npm test` passes. Wrapper is reusable if shared with contractpilot. --- *Generated by CEO Planner (priority: 3)* Tokens: 44 in / 10874 out
The retry logic (withRetry + isRetryableError) and route-level 502 handling
were already implemented. This adds the two specific test scenarios from the
acceptance criteria to make coverage explicit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: issue #629 the-apigenerate-route-calls-openai-but-h (agent task liancebot629)
Some checks failed
CI Quality Gate / Lint / Typecheck / Test / Build (pull_request) Has been cancelled
7f0d035bba
Some checks failed
CI Quality Gate / Lint / Typecheck / Test / Build (pull_request) Has been cancelled
This pull request has changes conflicting with the target branch.
  • .forgejo/workflows/ci.yml
  • bun.lock
  • package.json
  • packages/api/src/db/schema.ts
  • packages/api/src/index.ts
  • packages/api/src/middleware/csrf.ts
  • packages/api/src/middleware/rate-limit.ts
  • packages/api/src/middleware/security-headers.ts
  • packages/api/src/routes/admin.ts
  • packages/api/src/routes/billing.ts
  • packages/api/src/routes/generate-tos.ts
  • packages/api/src/routes/generate.ts
  • packages/api/src/routes/health.ts
  • packages/api/src/routes/questionnaire.ts
  • packages/api/src/services/document-generator.ts
  • packages/api/src/services/llm.ts
  • packages/api/src/templates/index.ts
  • packages/api/tsconfig.json
  • packages/shared/src/types.ts
  • packages/web/src/app/questionnaire/page.tsx
  • packages/web/src/components/documents/DocumentList.tsx
  • packages/web/src/components/questionnaire/ReviewStep.tsx
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/generate-retry-tests:feat/generate-retry-tests
git switch feat/generate-retry-tests
Sign in to join this conversation.
No reviewers
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!633
No description provided.