Webhook icon
OutputValues icon
Fail icon
Download icon
Script icon
Parallel icon
Commands icon
Docker icon
If icon
Set icon
LoopUntil icon
Log icon
Switch icon
Upload icon
Labels icon
Delete icon

Honey, I Shrunk the Incident: Bisect a Failed S3 Batch to One Record

Shrink a failed S3 batch to a one-record reproducer by bisection with LoopUntil, Docker reruns and a cross-check, then store the evidence in S3.

Categories
DataInfrastructure

A batch job crashes on 16,384 records and the stack trace says decimal.InvalidOperation, not which record caused it. This flow finds out the way you would by hand, only without the guesswork: it keeps halving the batch and rerunning the real processor until a single record is left, then proves that record is the cause before it says so. The result is a tiny reproducer, an observations file and a replay command in a private S3 bucket.

How it works

  1. The pipeline's failure handler calls the Webhook with the S3 object_key and a processor_id. The processor must be in the allowlist under variables.processors, and the key must sit under allowed_prefix, so the caller cannot pick an image, a command or another object.
  2. Evidence: aws.s3.Download fetches the batch. The flow records its SHA-256 and ETag, the SHA-256 of the processor source and the pinned image digest.
  3. Reproduce: the processor runs on the whole batch twice, each time in a fresh Docker container with no network. Both runs must exit non-zero with the same signature (exit code plus exception type). Otherwise the verdict is UNRESOLVED.
  4. Shrink: a LoopUntil runs split, execute (both halves in parallel), compare and select on every round. The failing half is kept and the window lives in the KV store between rounds. The loop stops at one record, or when neither half fails on its own, which means the records interact and the verdict is UNRESOLVED.
  5. Cross-examine: the isolated record runs twice more, and the original batch minus that record runs once. A Switch routes to ISOLATED_RECORD, MORE_FAILURES (the reproducer is real but the rest still fails) or UNRESOLVED.
  6. Preserve: aws.s3.Upload writes the reproducer, the remainder or failing slice when relevant, observations.json, processor.py and replay.sh under incidents/<flow>/<execution>/.

What you get

  • A one-record reproducer for a batch of N records in about log2(N) rounds: 14 rounds for 16,384.
  • No false diagnosis. Flaky failures, different errors and interacting records end as UNRESOLVED with the reason.
  • A replay script that checks the reproducer's SHA-256 and reruns the same pinned image offline.
  • When more than one record is bad, the batch minus the found record is uploaded so you can run the flow again on it.

Who it's for

  • Data engineers who get paged for a crashed batch job.
  • Platform teams who want failed batches triaged before a human looks at them.

Why orchestrate this with Kestra

  • Each run is a separate task with its own logs, container and outputs, so the bisection trace is visible round by round.
  • Allowlisted images, a webhook key and networkMode: none keep untrusted batch data away from everything else.
  • The verdict is an execution label, so failed batches can be searched by outcome.

Prerequisites

  • A Kestra worker that can start Docker containers.
  • An S3 bucket with the failed batches (JSON Lines, one record per line) and a private bucket for evidence. MinIO, LocalStack and other S3-compatible stores work through the s3_endpoint input.
  • IAM permissions: s3:GetObject on the source prefix and s3:PutObject on the evidence bucket.
  • Deterministic processing in which each record is handled on its own.

Secrets

  • AWS_ACCESS_KEY_ID: access key for both buckets.
  • AWS_SECRET_ACCESS_KEY: matching secret key.
  • INCIDENT_WEBHOOK_KEY: key that guards the webhook URL.

Quick start

  1. Add the three secrets and create both buckets.
  2. Upload a failing batch under batches/ and click Execute with its key.
  3. Read the round-by-round log, then run replay.sh from the evidence prefix.
  4. Point your pipeline's failure handler at /api/v1/main/executions/webhook/company.data/s3-failed-batch-bisect-to-reproducer/<key> with {"object_key": "...", "processor_id": "orders-pricing-v1"}.

How to extend

  • Add your own processors to the allowlist with their pinned image digest and entrypoint.
  • Post the verdict and the evidence URI to Slack or open a ticket in the ISOLATED_RECORD case.
  • Feed remainder.jsonl back into the flow with a Subflow until every bad record is found.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.