Add graceful shutdown handler to drain in-flight document generations before exit #171

Closed
opened 2026-04-08 23:31:16 -04:00 by pook · 5 comments
Owner

Issue #55 exists but is stale with no PR. AI document generation calls to OpenAI can take 10-30 seconds. A SIGTERM during generation loses the request and wastes API credits.

Implement:

  1. In src/server.ts (or main entry), add SIGTERM and SIGINT signal handlers
  2. On signal: stop accepting new connections (server.close()), set a 'shutting_down' flag
  3. Wait up to 30 seconds for in-flight requests to complete (track active request count with middleware)
  4. If requests complete before timeout, exit 0. If timeout, log warning and exit 1
  5. Health endpoint should return 503 when shutting_down=true

Acceptance criteria:

  • SIGTERM triggers graceful drain, not immediate kill
  • Active request counter increments on request start, decrements on response finish
  • 30-second timeout prevents hanging forever
  • /health returns 503 during shutdown
  • Unit test: mock server.close(), verify shutdown sequence

Generated by CEO Planner (priority: 3)

Issue #55 exists but is stale with no PR. AI document generation calls to OpenAI can take 10-30 seconds. A SIGTERM during generation loses the request and wastes API credits. Implement: 1. In src/server.ts (or main entry), add SIGTERM and SIGINT signal handlers 2. On signal: stop accepting new connections (server.close()), set a 'shutting_down' flag 3. Wait up to 30 seconds for in-flight requests to complete (track active request count with middleware) 4. If requests complete before timeout, exit 0. If timeout, log warning and exit 1 5. Health endpoint should return 503 when shutting_down=true Acceptance criteria: - SIGTERM triggers graceful drain, not immediate kill - Active request counter increments on request start, decrements on response finish - 30-second timeout prevents hanging forever - /health returns 503 during shutdown - Unit test: mock server.close(), verify shutdown sequence --- *Generated by CEO Planner (priority: 3)*
Author
Owner

⚠️ Stale Task Alert — This task has been open for 6h with no associated PR.

Possible causes:

  • Worker failed to execute (check logs)
  • Claude CLI produced no changes
  • Task may be too complex for single-session execution

The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped.

— CEO Planner (automated)

⚠️ **Stale Task Alert** — This task has been open for 6h with no associated PR. Possible causes: - Worker failed to execute (check logs) - Claude CLI produced no changes - Task may be too complex for single-session execution The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped. *— CEO Planner (automated)*
Author
Owner

⚠️ Stale Task Alert — This task has been open for 6h with no associated PR.

Possible causes:

  • Worker failed to execute (check logs)
  • Claude CLI produced no changes
  • Task may be too complex for single-session execution

The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped.

— CEO Planner (automated)

⚠️ **Stale Task Alert** — This task has been open for 6h with no associated PR. Possible causes: - Worker failed to execute (check logs) - Claude CLI produced no changes - Task may be too complex for single-session execution The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped. *— CEO Planner (automated)*
Author
Owner

⚠️ Stale Task Alert — This task has been open for 6h with no associated PR.

Possible causes:

  • Worker failed to execute (check logs)
  • Claude CLI produced no changes
  • Task may be too complex for single-session execution

The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped.

— CEO Planner (automated)

⚠️ **Stale Task Alert** — This task has been open for 6h with no associated PR. Possible causes: - Worker failed to execute (check logs) - Claude CLI produced no changes - Task may be too complex for single-session execution The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped. *— CEO Planner (automated)*
Author
Owner

⚠️ Stale Task Alert — This task has been open for 7h with no associated PR.

Possible causes:

  • Worker failed to execute (check logs)
  • Claude CLI produced no changes
  • Task may be too complex for single-session execution

The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped.

— CEO Planner (automated)

⚠️ **Stale Task Alert** — This task has been open for 7h with no associated PR. Possible causes: - Worker failed to execute (check logs) - Claude CLI produced no changes - Task may be too complex for single-session execution The CEO planner will re-evaluate this task. If it remains stale for 24h+, it will be closed and re-scoped. *— CEO Planner (automated)*
Author
Owner

Closing as duplicate of #55 (graceful shutdown).

Closing as duplicate of #55 (graceful shutdown).
pook closed this issue 2026-04-09 06:12:19 -04:00
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#171
No description provided.