Schedule icon
Webhook icon
Script icon
Docker icon
Set icon
If icon
SlackIncomingWebhook icon
Log icon
Fail icon

Temporal Activity Retry Exhaustion & Workflow Dead-Letter Guard

Detect Temporal workflows stuck in infinite activity retries, quarantine failing executions, log state to Kestra KV, and alert on-call teams via Slack.

Categories
CoreInfrastructure

Surveillance flow for Temporal Server and Temporal Cloud namespaces to detect workflow executions caught in infinite activity retry loops, quarantine stuck executions, extract failure stack traces into Kestra Key-Value store, and dispatch high-priority incident notifications to Slack.

Temporal activities default to infinite retries with exponential backoff when unhandled errors occur. If a downstream dependency fails permanently or returns non-retryable errors disguised as generic exceptions, activities loop continuously, consuming task queue slots and worker thread capacity. This blueprint continuously scans workflow executions, identifies activity attempt counters exceeding safety thresholds, executes quarantine terminations, persists detailed dead-letter diagnostics in Kestra KV store, and alerts site reliability engineering (SRE) teams.

How it works

  1. Visibility Scanning: Queries the Temporal Server HTTP visibility API (/api/v1/namespaces/{namespace}/workflow-executions) using SQL-like visibility filters to retrieve open, timed out, and failed workflow executions.
  2. Activity Inspection & Failure Extraction: For running workflows, probes the workflow execution describe endpoint to inspect pendingActivities. Evaluates the attempt counter against max_activity_retry_threshold and extracts activity type, error messages, stack traces, and worker identity.
  3. Automated Quarantine: When an activity exceeds the retry threshold, automatically executes the configured quarantine action (TERMINATE or CANCEL) via Temporal API to stop worker thread exhaustion.
  4. Dead-Letter KV Store Persistence: Encodes all quarantined, timed-out, and failed workflow details into a structured JSON manifest and records it in Kestra's Key-Value store under temporal_dlq_{namespace} for automated replay and auditing.
  5. Slack Incident Alerting: Formats diagnostic failure overviews with direct links to the Temporal Web UI history and sends high-priority notifications to the designated Slack channel.
  6. Pipeline Gating: Optionally fails the Kestra execution when fail_on_quarantine is enabled to halt dependent deployment or data synchronization workflows.

Architecture diagram

flowchart TD
    A[Schedule or Webhook Trigger] --> B[audit_and_quarantine_workflows Python Script]
    B --> C[record_dead_letter_state_kv KV Set]
    C --> D{Dead-Letters Detected?}
    D -- Yes --> E[dispatch_slack_dead_letter_alert Slack]
    D -- No --> F[log_nominal_health Log]
    E --> G{fail_on_quarantine?}
    F --> H[Pipeline Complete]
    G -- True --> I[halt_pipeline Fail]
    G -- False --> H

Architecture components

  • Schedule & Webhook Triggers: Enables recurring automated audits (every 10 minutes) or event-driven triage triggered by external alerts.
  • Audit Task (audit_and_quarantine_workflows): Isolated Python container that queries Temporal Server, evaluates retry attempt counts, triggers quarantine terminations, and formats error diagnostics.
  • Dead-Letter State Store (record_dead_letter_state_kv): Persists structured incident records in Kestra KV store for downstream analysis, historical auditability, and automated replay workflows.
  • Alert Notification (dispatch_slack_dead_letter_alert): Delivers rich Slack incident summaries including workflow IDs, activity names, retry attempt metrics, and root cause stack traces.
  • Deployment Gate (gate_on_quarantine_policy): Circuit-breaker gate preventing upstream CI/CD or data pipelines from executing against compromised task queues.

Key capabilities

  • Infinite Retry Loop Detection: Detects hidden activity retry storms before workers exhaust local memory and CPU capacity.
  • Automated Quarantine & Remediation: Halts stuck workflow executions via Temporal HTTP API with contextual reason strings visible in Temporal Web UI event histories.
  • Root-Cause Failure Extraction: Extracts complete Python, Go, Java, or TypeScript stack traces and error messages directly from Temporal pending activity metadata.
  • Centralized Dead-Letter Queue (DLQ): Converts volatile Temporal activity failures into durable, queryable state stored in Kestra Key-Value storage.
  • Zero External Dependencies: Operates directly over standard Temporal Server HTTP/gRPC gateway endpoints with native Python standard library networking.

What you get

  • Immediate detection and quarantine of Temporal workflows caught in runaway activity retry loops.
  • Protection of Temporal task queue throughput against worker thread starvation.
  • Structured dead-letter queue manifests stored in Kestra Key-Value storage for auditing and replay.
  • Rich Slack notifications with direct deep-links to Temporal Web UI execution histories.
  • Automated circuit-breaking for downstream deployment and data orchestration pipelines.

Who it's for

  • Site Reliability Engineers (SREs) operating production Temporal clusters and Temporal Cloud namespaces.
  • Platform Engineering Teams managing shared worker pools and task queue SLAs.
  • Backend Developers maintaining distributed microservices and workflow-driven architectures.

Why orchestrate this with Kestra

  • Decoupled Incident Management: Decouples dead-letter detection and quarantine logic from worker codebases.
  • Stateful DLQ Persistence: Native Kestra Key-Value store preserves structured dead-letter manifests without provisioning auxiliary databases.
  • Multi-Tenant Auditability: Full execution history, timing benchmarks, and audit logs recorded per namespace in Kestra.
  • Secure Credential Handling: Encrypted secrets for Temporal Cloud authentication tokens, Slack webhooks, and audit keys.

Use cases

  • Payment Settlement Guard: Intercept payment processing workflows stuck retrying against offline third-party payment gateways.
  • Worker Queue Health SRE Sentinel: Continuously audit task queue capacity to prevent runaway activity retry storms from degrading cluster performance.
  • CI/CD Deployment Gate: Verify zero dead-lettered or failing workflows in staging environments before promoting worker container images to production.

Inputs

Name Type Default Description
temporal_api_url STRING http://localhost:7233 Base HTTP endpoint of Temporal Frontend or Web UI proxy.
temporal_namespace STRING default Target Temporal namespace containing workflows under audit.
visibility_query STRING ExecutionStatus = 'Running' OR ExecutionStatus = 'TimedOut' OR ExecutionStatus = 'Failed' SQL-like query filter for workflow discovery.
max_activity_retry_threshold INT 10 Maximum allowable retry attempts before flagging retry exhaustion.
quarantine_action SELECT TERMINATE Remediation action applied against stuck workflows (TERMINATE, CANCEL, OBSERVE_ONLY).
max_executions_to_scan INT 50 Maximum workflow executions inspected per audit batch.
alert_on_quarantine BOOL true Toggle whether Slack incident notifications are sent.
fail_on_quarantine BOOL false Halt Kestra execution with failure if dead letters are discovered.
temporal_web_url STRING http://localhost:8233 Base URL of Temporal Web UI for triage links.
slack_channel STRING #temporal-incidents Slack channel destination for alerts.

Expected outputs

  • {{ outputs.audit_and_quarantine_workflows.vars.status }}: Operational status (NOMINAL_HEALTHY or DEAD_LETTER_INCIDENT_DETECTED).
  • {{ outputs.audit_and_quarantine_workflows.vars.has_dead_letters }}: Boolean flag indicating if dead letters or stuck retries were found.
  • {{ outputs.audit_and_quarantine_workflows.vars.scanned_count }}: Number of workflow executions inspected during the audit.
  • {{ outputs.audit_and_quarantine_workflows.vars.dead_letter_count }}: Total number of dead-lettered, timed out, and failed executions.
  • {{ outputs.audit_and_quarantine_workflows.vars.quarantined_count }}: Number of stuck executions terminated or cancelled.
  • {{ outputs.audit_and_quarantine_workflows.vars.stuck_retry_count }}: Number of workflows caught in activity retry loops.
  • {{ outputs.audit_and_quarantine_workflows.vars.diagnostic_summary }}: Formatted text overview of failing workflows and errors.
  • {{ outputs.audit_and_quarantine_workflows.vars.dead_letter_summary }}: Full JSON manifest stored in Kestra Key-Value store.

Prerequisites

  • Temporal Server v1.20+ with HTTP API enabled, or Temporal Cloud namespace with API credentials.
  • Docker daemon available to Kestra workers for container execution.
  • Slack Incoming Webhook URL configured in Kestra secrets.

Secrets

  • TEMPORAL_AUTH_TOKEN: Optional Bearer authentication token for Temporal Cloud or authenticated cluster access.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for incident notifications.
  • TEMPORAL_AUDIT_WEBHOOK_KEY: Secret authentication key for inbound audit webhook triggers.

Quick start

  1. Configure SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. For authenticated Temporal clusters or Temporal Cloud, register TEMPORAL_AUTH_TOKEN.
  3. Import this blueprint into your Kestra instance.
  4. Execute the flow against your Temporal namespace to verify connectivity and audit active workflows.
  5. Enable periodic_audit_schedule to enforce continuous 24/7 dead-letter surveillance.

Common pitfalls and troubleshooting

  • Temporal Port Configuration: Temporal Frontend defaults to port 7233 for gRPC and HTTP gateway. Ensure your firewall allows HTTP traffic from Kestra workers to the target host and port.
  • Visibility Store Latency: On clusters using Standard SQL visibility rather than Advanced Visibility (Elasticsearch/OpenSearch), complex query filters may exhibit slight indexing delay.
  • Quarantine Permissions: Verify that the authentication credentials associated with TEMPORAL_AUTH_TOKEN have WorkflowExecutionWrite permissions to terminate workflows.

How to extend

  • Automated Workflow Replay: Add a downstream task using io.kestra.plugin.temporal.workflow.Trigger to automatically restart quarantined workflows with adjusted retry policies or updated input payloads once upstream outages resolve.
  • Jira or ServiceNow Incident Creation: Integrate io.kestra.plugin.jira.issues.Create or ServiceNow plugins to automatically generate severity tickets containing the extracted stack traces.
  • Dead-Letter S3 Archive: Add an io.kestra.plugin.aws.s3.Upload task to archive historical dead-letter JSON manifests into AWS S3 or Google Cloud Storage for compliance retention.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.