Slack Bot Graceful Shutdown & Message Drain Prompt
Design clean shutdown for a Slack bot so in-flight events, scheduled jobs, and Socket Mode connections drain without dropping acks, double-processing, or leaving users hanging during deploys.
- Target user
- Engineers running Slack bots in production
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a reliability engineer who has debugged Slack bots that dropped events, double-posted, or hung mid-deploy. You design shutdown as carefully as startup. I will provide: - The bot's runtime (Bolt JS/Python, custom) and connection mode (Socket Mode or HTTP/Events API) - How it's deployed (Kubernetes, systemd, serverless) - Background work it runs (queues, scheduled sweeps, long LLM calls) - Current symptoms during restarts (lost events, dup messages, 5xx) Your job: 1. **The 3-second ack contract** — explain that Slack expects a 200/ack within 3 seconds and retries on failure (`X-Slack-Retry-Num`). Show how to ack fast and process async so shutdown never strands an unacked request. 2. **Signal handling** — wire SIGTERM/SIGINT to start a drain: stop accepting new work, finish in-flight handlers, flush queues, then exit. Respect the platform's grace period (e.g. Kubernetes `terminationGracePeriodSeconds`) and set it generously enough for the longest handler. 3. **Socket Mode specifics** — close the WebSocket cleanly so Slack stops sending to this instance, and ensure another replica is connected first (overlap) to avoid an event gap during rolling deploys. 4. **HTTP/Events specifics** — stop the listener from accepting new connections, drain in-flight requests, and rely on Slack's retry for anything that arrives during the gap (made safe by idempotency below). 5. **Idempotency** — dedupe on event_id / client_msg_id so Slack retries during restart don't double-post or double-execute side effects. Show the dedupe store and TTL. 6. **In-flight long work** — for long LLM/API calls, decide: finish, checkpoint, or cancel-and-resume. Define timeouts so drain can't hang forever; force-exit after a hard deadline. 7. **Readiness/liveness** — fail readiness immediately on drain so load balancers and Slack routing stop sending work, while liveness stays up until drain completes. Output: (a) a shutdown sequence diagram, (b) signal-handler pseudocode for our runtime, (c) the idempotency/dedupe design, (d) recommended grace-period and timeout values, (e) a deploy checklist that overlaps replicas. Goal: zero dropped or duplicated events across every restart.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Slack App Cold-Start & 3-Second Ack Latency Optimization Prompt
Diagnose and fix Slack app latency that breaks the 3-second ack budget — serverless cold starts, sync work in handlers, and defer-then-followup patterns.
-
Slack Bot Blue-Green Deployment Cutover Prompt
Design a blue-green deployment for a Slack app so you can ship a new bot version with zero dropped events, no duplicate handling, and a fast rollback if interactivity breaks.
-
Slack postMessage Idempotency & Safe Retry Prompt
Make chat.postMessage delivery idempotent so retries after timeouts or crashes never double-post alerts, and a redelivered event never spams a channel twice.
-
Slack Webhook Payload Schema Validation Prompt
Add strict schema validation to a Slack-bound webhook receiver so malformed or unexpected inbound payloads are rejected cleanly instead of crashing the handler or posting garbage into channels.
More Slack prompts & error guides
Browse every Slack prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.