feat: graceful shutdown to prevent lost LLM API calls #173

Closed
pook wants to merge 2 commits from feat/graceful-shutdown into main
Owner

Summary

  • SIGTERM/SIGINT triggers graceful drain instead of immediate kill
  • Active request counter tracks in-flight requests via middleware
  • 30-second timeout prevents hanging forever, exits 1 if exceeded
  • /health and /health/ready return 503 during shutdown
  • New requests rejected with 503 once shutdown begins

Files changed

  • packages/api/src/middleware/graceful-shutdown.ts - new module
  • packages/api/src/index.ts - switch to Bun.serve(), wire signal handlers
  • packages/api/src/routes/health.ts - 503 during shutdown
  • packages/api/tests/unit/graceful-shutdown.test.ts - 8 unit tests

Closes #55

## Summary - SIGTERM/SIGINT triggers graceful drain instead of immediate kill - Active request counter tracks in-flight requests via middleware - 30-second timeout prevents hanging forever, exits 1 if exceeded - /health and /health/ready return 503 during shutdown - New requests rejected with 503 once shutdown begins ## Files changed - packages/api/src/middleware/graceful-shutdown.ts - new module - packages/api/src/index.ts - switch to Bun.serve(), wire signal handlers - packages/api/src/routes/health.ts - 503 during shutdown - packages/api/tests/unit/graceful-shutdown.test.ts - 8 unit tests Closes #55
SIGTERM/SIGINT now triggers a drain sequence: stop accepting new connections,
wait up to 30s for in-flight requests (e.g. LLM generation) to complete,
then exit. Health endpoint returns 503 during shutdown for load balancer awareness.

Closes #55

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:10 -04:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!173
No description provided.