feat: add configurable timeout for AI generation API calls #66

Closed
pook wants to merge 1 commit from feature/ai-generation-timeout into main
Owner

Summary

  • Wraps all OpenAI API calls with an AbortController-based timeout (default 120s, configurable via AI_GENERATION_TIMEOUT_MS env var)
  • Returns HTTP 504 with user-friendly error message and requestId when timeout is hit
  • Logs timeout events with request ID, document type, and elapsed duration
  • Adds unit tests verifying timeout behavior

Closes #63

Changes

File Change
packages/api/src/services/llm.ts Added AITimeoutError class and AbortController timeout wrapper around OpenAI call
packages/api/src/routes/generate.ts Catch AITimeoutError → 504 response with logging
packages/api/src/routes/generate-tos.ts Catch AITimeoutError → 504 response with logging
packages/api/tests/unit/ai-timeout.test.ts 5 unit tests for timeout behavior

Test plan

  • bun test packages/api/tests/unit/ai-timeout.test.ts — 5/5 pass
  • TypeScript typecheck passes (no new errors)
  • Manual: set AI_GENERATION_TIMEOUT_MS=100 and trigger generation to verify 504 response

🤖 Generated with Claude Code

## Summary - Wraps all OpenAI API calls with an `AbortController`-based timeout (default 120s, configurable via `AI_GENERATION_TIMEOUT_MS` env var) - Returns HTTP 504 with user-friendly error message and `requestId` when timeout is hit - Logs timeout events with request ID, document type, and elapsed duration - Adds unit tests verifying timeout behavior Closes #63 ## Changes | File | Change | |------|--------| | `packages/api/src/services/llm.ts` | Added `AITimeoutError` class and `AbortController` timeout wrapper around OpenAI call | | `packages/api/src/routes/generate.ts` | Catch `AITimeoutError` → 504 response with logging | | `packages/api/src/routes/generate-tos.ts` | Catch `AITimeoutError` → 504 response with logging | | `packages/api/tests/unit/ai-timeout.test.ts` | 5 unit tests for timeout behavior | ## Test plan - [x] `bun test packages/api/tests/unit/ai-timeout.test.ts` — 5/5 pass - [x] TypeScript typecheck passes (no new errors) - [ ] Manual: set `AI_GENERATION_TIMEOUT_MS=100` and trigger generation to verify 504 response 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Wraps all OpenAI API calls with an AbortController-based timeout
(default 120s, configurable via AI_GENERATION_TIMEOUT_MS env var).
When hit, returns HTTP 504 with a user-friendly retry message and
logs requestId, document type, and elapsed duration.

Closes #63

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
Owner

Closed 2026-04-10 during pipeline triage.

Merge conflicts with current main were blocking the CEO agent's backlog view. The compliancebot repo had ~60 open PRs and 141 open agent-task issues. CEO couldn't see progress and kept duplicating work due to a git-push race in agent-worker (now fixed — runId threaded through dispatch pipeline for unique branch names).

Reopen / resubmit against current main if the work is still relevant. Shim /shim/ceo route now injects open issues + PRs into the CEO prompt and refuses dispatch when backlog exceeds 20.

Closed 2026-04-10 during pipeline triage. Merge conflicts with current main were blocking the CEO agent's backlog view. The compliancebot repo had ~60 open PRs and 141 open agent-task issues. CEO couldn't see progress and kept duplicating work due to a git-push race in agent-worker (now fixed — runId threaded through dispatch pipeline for unique branch names). Reopen / resubmit against current main if the work is still relevant. Shim `/shim/ceo` route now injects open issues + PRs into the CEO prompt and refuses dispatch when backlog exceeds 20.
pook closed this pull request 2026-04-10 15:08:20 -04:00

Pull request closed

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!66
No description provided.