Pulsar Topic Activity Sentinel
Non-destructively sample a Pulsar topic on a schedule with a non-durable reader and page Slack when it goes silent, floods, or the broker is unreachable.
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.
id: s3-failed-batch-bisect-to-reproducer
namespace: company.data
inputs:
- id: object_key
type: STRING
displayName: S3 key of the failed batch
description: JSON Lines file, one record per line. A webhook body field
`object_key` overrides this input.
defaults: batches/orders/2026-10-19/batch-0042.jsonl
- id: processor_id
type: STRING
displayName: Processor id
description: Must be a key of the `processors` allowlist in the flow variables.
A webhook body field `processor_id` overrides this input.
defaults: orders-pricing-v1
- id: source_bucket
type: STRING
displayName: Bucket holding failed batches
defaults: acme-orders-landing
- id: allowed_prefix
type: STRING
displayName: Allowed key prefix
description: The object key must start with this prefix, so a webhook caller
cannot point the flow at arbitrary objects in the bucket.
defaults: batches/
- id: evidence_bucket
type: STRING
displayName: Private evidence bucket
description: Bucket where the reproducer, observations and replay script are
written. Keep it private; failed records often contain customer data.
defaults: acme-incident-evidence
- id: aws_region
type: STRING
displayName: AWS region
defaults: eu-west-1
- id: s3_endpoint
type: STRING
displayName: S3 endpoint override
description: Leave empty for AWS. Set it for S3-compatible storage such as MinIO
or LocalStack, for example http://localhost:9000; path-style addressing is
switched on automatically.
required: false
variables:
helper_image: python:3.13.1-slim@sha256:031ebf3cde9f3719d2db385233bcb18df5162038e9cda20e64e08f49f4b47a2f
# Harness shared by every processor run: run the allowlisted command on
# batch.jsonl and reduce the outcome to a signature made of the exit code and
# the exception type on the last stderr line.
harness: |
set +e
{{ outputs.processor.values.command }} batch.jsonl > stdout.log 2> stderr.log
code=$?
printf 'exit=%s %s\n' "$code" "$(tail -n 1 stderr.log | cut -d: -f1 | cut -c1-200)" > signature.txt
echo "::{\"outputs\":{\"processor_exit\":$code,\"records\":$(grep -c '' batch.jsonl)}}::"
# Allowlist of processors the flow may run. Each entry pins the exact image
# and command your pipeline runs; the batch path is appended to the command.
# `source` is optional and is mounted as processor.py, which keeps this
# example self-contained. With your own image, drop `source` and point
# `command` at the entrypoint baked into it.
processors:
orders-pricing-v1:
image: python:3.13.1-slim@sha256:031ebf3cde9f3719d2db385233bcb18df5162038e9cda20e64e08f49f4b47a2f
command: python processor.py
source: |
import json
import sys
from decimal import Context, Decimal, InvalidOperation
# Strict context: anything that is not a plain decimal raises.
STRICT = Context(prec=28, traps=[InvalidOperation])
CENT = Decimal("0.01")
def to_price(raw):
value = STRICT.create_decimal(str(raw))
if not value.is_finite() or value < 0:
raise ValueError("price must be a finite, non-negative decimal")
return value.quantize(CENT, context=STRICT)
orders = 0
revenue = Decimal(0)
with open(sys.argv[1]) as batch:
for line in batch:
if not line.strip():
continue
order = json.loads(line)
revenue += to_price(order["price"]) * int(order["quantity"])
orders += 1
print(json.dumps({"orders": orders, "revenue": str(revenue)}))
triggers:
- id: on_failed_batch
type: io.kestra.plugin.core.trigger.Webhook
description: The pipeline's failure handler POSTs {"object_key", "processor_id"}
here when a batch crashes. Both fields are validated before anything runs.
key: "{{ secret('INCIDENT_WEBHOOK_KEY') }}"
tasks:
- id: incident
type: io.kestra.plugin.core.output.OutputValues
description: Resolve the request once. Webhook body fields win over manual inputs.
values:
object_key: "{{ trigger.body.object_key ?? inputs.object_key }}"
processor_id: "{{ trigger.body.processor_id ?? inputs.processor_id }}"
evidence_prefix: "incidents/{{ flow.id }}/{{ execution.id }}"
- id: reject_unknown_processor
type: io.kestra.plugin.core.execution.Fail
description: Only processors in the allowlist can run, so a webhook caller
cannot choose an arbitrary image or command.
condition: "{{ vars.processors[outputs.incident.values.processor_id] is not
defined }}"
errorMessage: "Processor '{{ outputs.incident.values.processor_id }}' is not in
the allowlist ({{ vars.processors | keys | join(', ') }})."
- id: reject_bad_key
type: io.kestra.plugin.core.execution.Fail
description: The key must sit under the allowed prefix, contain no '..' and use
only [A-Za-z0-9._/=-].
condition: "{{ not (outputs.incident.values.object_key |
startsWith(inputs.allowed_prefix)) or (outputs.incident.values.object_key
contains '..') or ((outputs.incident.values.object_key |
replace({'[A-Za-z0-9._/=-]': ''}, regexp=true)) is not empty) }}"
errorMessage: "Object key '{{ outputs.incident.values.object_key }}' is outside
'{{ inputs.allowed_prefix }}' or has unsafe characters."
- id: processor
type: io.kestra.plugin.core.output.OutputValues
description: The allowlisted processor definition. Every run below uses exactly
this image and command.
values:
image: "{{ vars.processors[outputs.incident.values.processor_id].image }}"
command: "{{ vars.processors[outputs.incident.values.processor_id].command }}"
source: "{{ vars.processors[outputs.incident.values.processor_id].source ?? ''
}}"
- id: download
type: io.kestra.plugin.aws.s3.Download
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
description: Pull the exact failed batch. The ETag and version id go into the
observations.
bucket: "{{ inputs.source_bucket }}"
key: "{{ outputs.incident.values.object_key }}"
- id: fingerprint
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ vars.helper_image }}"
description: Evidence before anything else runs. SHA-256 of the batch and of the
processor source, record count, and the pinned image reference.
inputFiles:
batch.jsonl: "{{ outputs.download.uri }}"
processor.py: "{{ outputs.processor.values.source }}"
script: |
import hashlib, json
def sha256(path):
digest = hashlib.sha256()
with open(path, "rb") as fh:
for chunk in iter(lambda: fh.read(1 << 20), b""):
digest.update(chunk)
return digest.hexdigest()
with open("batch.jsonl", "rb") as fh:
records = sum(1 for _ in fh)
if records == 0:
raise SystemExit("The batch is empty, nothing to shrink.")
out = {
"batch_sha256": sha256("batch.jsonl"),
"processor_source_sha256": sha256("processor.py"),
"records": records,
"processor_image": "{{ outputs.processor.values.image }}",
}
print(json.dumps(out))
print("::" + json.dumps({"outputs": out}) + "::")
- id: reproduce
type: io.kestra.plugin.core.flow.Parallel
description: Run the real processor on the whole batch twice, each time in a
fresh container.
tasks:
- id: reproduce_1
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.download.uri }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: reproduce_2
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.download.uri }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: baseline
type: io.kestra.plugin.core.output.OutputValues
description: The failure counts as reproduced only when both runs exit non-zero
with the same signature. That signature is what every later run is
compared to.
values:
signature: "{{ read(outputs.reproduce_1.outputFiles['signature.txt']) | trim }}"
status: "{{ (outputs.reproduce_1.vars.processor_exit != 0 and
(read(outputs.reproduce_1.outputFiles['signature.txt']) | trim) ==
(read(outputs.reproduce_2.outputFiles['signature.txt']) | trim)) ?
'REPRODUCED' : 'NOT_REPRODUCED' }}"
second_signature: "{{ read(outputs.reproduce_2.outputFiles['signature.txt']) | trim }}"
- id: if_reproduced
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.baseline.values.status == 'REPRODUCED' }}"
then:
- id: init_state
type: io.kestra.plugin.core.kv.Set
description: The search window [lo, hi) over record positions. LoopUntil
iterations hand it to each other through the KV store.
key: "shrink_{{ execution.id }}"
kvType: JSON
ttl: P1D
value: "{{ {'lo': 0, 'hi': outputs.fingerprint.vars.records, 'n':
outputs.fingerprint.vars.records, 'round': 0, 'status': 'SHRINKING',
'trace': '' ~ outputs.fingerprint.vars.records} | toJson }}"
- id: shrink
type: io.kestra.plugin.core.flow.LoopUntil
description: Halve the window until one record is left, or until neither half
fails on its own.
condition: "{{ kv('shrink_' ~ execution.id).status != 'SHRINKING' }}"
failOnMaxReached: true
checkFrequency:
interval: PT1S
maxIterations: 64
tasks:
- id: split
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ vars.helper_image }}"
description: Cut the current window in two, keeping record order.
inputFiles:
batch.jsonl: "{{ outputs.download.uri }}"
state.json: "{{ kv('shrink_' ~ execution.id) | toJson }}"
outputFiles:
- left.jsonl
- right.jsonl
script: |
import json
state = json.load(open("state.json"))
lo, hi = state["lo"], state["hi"]
mid = lo + (hi - lo) // 2
with open("batch.jsonl") as src, open("left.jsonl", "w") as left, open("right.jsonl", "w") as right:
for position, line in enumerate(src):
if position >= hi:
break
if position >= mid:
right.write(line)
elif position >= lo:
left.write(line)
out = {"lo": lo, "mid": mid, "hi": hi, "n": hi - lo, "left_n": mid - lo, "right_n": hi - mid, "round": state["round"] + 1, "trace": state["trace"]}
print(f"round {out['round']}: {out['n']} records -> [{lo}, {mid}) and [{mid}, {hi})")
print("::" + json.dumps({"outputs": out}) + "::")
- id: execute
type: io.kestra.plugin.core.flow.Parallel
description: Each half runs alone in its own container.
tasks:
- id: run_left
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.split.outputFiles['left.jsonl'] }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: run_right
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.split.outputFiles['right.jsonl'] }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: compare
type: io.kestra.plugin.core.output.OutputValues
description: A half only counts if it fails with the baseline signature. Any
other error is a different bug and is not followed.
values:
left: "{{ read(outputs.run_left.outputFiles['signature.txt']) | trim }}"
right: "{{ read(outputs.run_right.outputFiles['signature.txt']) | trim }}"
keep: "{{ (read(outputs.run_left.outputFiles['signature.txt']) | trim) ==
outputs.baseline.values.signature ? 'left' :
((read(outputs.run_right.outputFiles['signature.txt']) | trim)
== outputs.baseline.values.signature ? 'right' : 'none') }}"
- id: select
type: io.kestra.plugin.core.kv.Set
description: Keep the failing half (left first, so the result is deterministic).
If neither half fails alone the records interact and the loop
stops without a diagnosis.
key: "shrink_{{ execution.id }}"
kvType: JSON
ttl: P1D
value: >-
{%- set s = outputs.split.vars -%} {%- set keep =
outputs.compare.values.keep -%} {%- set kept = keep == 'left' ?
s.left_n : (keep == 'right' ? s.right_n : s.n) -%} {{ {
'lo': keep == 'right' ? s.mid : s.lo,
'hi': keep == 'left' ? s.mid : s.hi,
'n': kept,
'round': s.round,
'status': keep == 'none' ? 'INTERACTING' : (kept == 1 ? 'ISOLATED' : 'SHRINKING'),
'trace': keep == 'none' ? s.trace : (s.trace ~ ' > ' ~ kept)
} | toJson }}
- id: log_round
type: io.kestra.plugin.core.log.Log
message: "Round {{ outputs.split.vars.round }}: {{ outputs.split.vars.n }}
records. left ({{ outputs.split.vars.left_n }}) -> {{
outputs.compare.values.left }}, right ({{
outputs.split.vars.right_n }}) -> {{ outputs.compare.values.right
}}. Keep: {{ outputs.compare.values.keep }}."
- id: shrunk
type: io.kestra.plugin.core.output.OutputValues
description: Final window after the loop.
values:
lo: "{{ kv('shrink_' ~ execution.id).lo }}"
hi: "{{ kv('shrink_' ~ execution.id).hi }}"
n: "{{ kv('shrink_' ~ execution.id).n }}"
rounds: "{{ kv('shrink_' ~ execution.id).round }}"
status: "{{ kv('shrink_' ~ execution.id).status }}"
trace: "{{ kv('shrink_' ~ execution.id).trace }}"
reason: "{{ kv('shrink_' ~ execution.id).status == 'INTERACTING' ? 'Neither half
of the ' ~ kv('shrink_' ~ execution.id).n ~ '-record slice at lines
' ~ (kv('shrink_' ~ execution.id).lo + 1) ~ '-' ~ kv('shrink_' ~
execution.id).hi ~ ' fails alone, so the failure needs records from
both halves. Not diagnosed.' : '' }}"
- id: carve
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ vars.helper_image }}"
description: Write the reproducer (the final window) and the original batch
without it.
inputFiles:
batch.jsonl: "{{ outputs.download.uri }}"
outputFiles:
- reproducer.jsonl
- remainder.jsonl
script: |
import hashlib, json
lo, hi = {{ outputs.shrunk.values.lo }}, {{ outputs.shrunk.values.hi }}
kept = removed = 0
with open("batch.jsonl") as src, open("reproducer.jsonl", "w") as rep, open("remainder.jsonl", "w") as rest:
for position, line in enumerate(src):
if lo <= position < hi:
rep.write(line)
removed += 1
else:
rest.write(line)
kept += 1
with open("reproducer.jsonl", "rb") as fh:
digest = hashlib.sha256(fh.read()).hexdigest()
out = {"first_line": lo + 1, "last_line": hi, "reproducer_records": removed, "remainder_records": kept, "reproducer_sha256": digest}
print(json.dumps(out))
print("::" + json.dumps({"outputs": out}) + "::")
- id: if_isolated
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.shrunk.values.status == 'ISOLATED' }}"
then:
- id: cross_examine
type: io.kestra.plugin.core.flow.Parallel
description: Run the single record twice, and the batch without it once.
tasks:
- id: isolate_1
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.carve.outputFiles['reproducer.jsonl'] }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: isolate_2
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.carve.outputFiles['reproducer.jsonl'] }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: without_record
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ outputs.processor.values.image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
pullPolicy: IF_NOT_PRESENT
networkMode: none
memory:
memory: 1GB
commands:
- "{{ render(vars.harness) }}"
outputFiles:
- signature.txt
- stderr.log
inputFiles:
batch.jsonl: "{{ outputs.carve.outputFiles['remainder.jsonl'] }}"
processor.py: "{{ outputs.processor.values.source }}"
- id: cross
type: io.kestra.plugin.core.output.OutputValues
values:
isolate_1: "{{ read(outputs.isolate_1.outputFiles['signature.txt']) | trim }}"
isolate_2: "{{ read(outputs.isolate_2.outputFiles['signature.txt']) | trim }}"
without_record: "{{ read(outputs.without_record.outputFiles['signature.txt']) |
trim }}"
verdict: >-
{{ ((read(outputs.isolate_1.outputFiles['signature.txt']) |
trim) != outputs.baseline.values.signature or
(read(outputs.isolate_2.outputFiles['signature.txt']) | trim) !=
outputs.baseline.values.signature) ? 'UNRESOLVED' :
(outputs.without_record.vars.processor_exit != 0 ?
'MORE_FAILURES' : 'ISOLATED_RECORD') }}
reason: >-
{{ ((read(outputs.isolate_1.outputFiles['signature.txt']) |
trim) != outputs.baseline.values.signature or
(read(outputs.isolate_2.outputFiles['signature.txt']) | trim) !=
outputs.baseline.values.signature)
? 'The isolated record did not fail the same way twice on its own, so it is not a trustworthy reproducer.'
: (outputs.without_record.vars.processor_exit != 0
? 'Reproducer found; more failures remain. Line ' ~ outputs.carve.vars.first_line ~ ' fails alone twice, and the other ' ~ outputs.carve.vars.remainder_records ~ ' records still fail (' ~ (read(outputs.without_record.outputFiles['signature.txt']) | trim) ~ ').'
: 'Line ' ~ outputs.carve.vars.first_line ~ ' fails alone twice and the other ' ~ outputs.carve.vars.remainder_records ~ ' records pass without it.') }}
else:
- id: not_reproduced
type: io.kestra.plugin.core.output.OutputValues
values:
reason: "{{ outputs.reproduce_1.vars.processor_exit == 0 and
outputs.reproduce_2.vars.processor_exit == 0 ? 'The full batch
passed both reruns, so the failure does not reproduce with this
processor and image.' : 'The full batch did not fail the same way
twice (' ~ outputs.baseline.values.signature ~ ' vs ' ~
outputs.baseline.values.second_signature ~ '), so the failure is not
deterministic.' }} Nothing was shrunk."
- id: verdict
type: io.kestra.plugin.core.output.OutputValues
values:
verdict: "{{ outputs.cross.values.verdict ?? 'UNRESOLVED' }}"
reason: "{{ outputs.cross.values.reason ?? outputs.not_reproduced.values.reason
?? outputs.shrunk.values.reason }}"
- id: route_verdict
type: io.kestra.plugin.core.flow.Switch
value: "{{ outputs.verdict.values.verdict }}"
cases:
ISOLATED_RECORD:
- id: upload_reproducer
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/reproducer.jsonl"
from: "{{ outputs.carve.outputFiles['reproducer.jsonl'] }}"
MORE_FAILURES:
- id: upload_partial_reproducer
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/reproducer.jsonl"
from: "{{ outputs.carve.outputFiles['reproducer.jsonl'] }}"
- id: upload_remainder
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
description: The batch minus the found record. Copy it under the allowed prefix
and trigger the flow again to find the next one.
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/remainder.jsonl"
from: "{{ outputs.carve.outputFiles['remainder.jsonl'] }}"
defaults:
- id: if_interacting
type: io.kestra.plugin.core.flow.If
description: For interacting records, keep the smallest slice that still fails
so a human can take it from there.
condition: "{{ (outputs.shrunk.values.status ?? 'NONE') == 'INTERACTING' }}"
then:
- id: upload_failing_slice
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/failing-slice.jsonl"
from: "{{ outputs.carve.outputFiles['reproducer.jsonl'] }}"
- id: report
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ vars.helper_image }}"
description: Build observations.json and replay.sh from everything the flow saw.
inputFiles:
processor.py: "{{ outputs.processor.values.source }}"
facts.json: |
{{ {
'execution_id': execution.id,
'verdict': outputs.verdict.values.verdict,
'reason': outputs.verdict.values.reason,
'source': 's3://' ~ inputs.source_bucket ~ '/' ~ outputs.incident.values.object_key,
'source_etag': outputs.download.etag ?? null,
'source_version_id': outputs.download.versionId ?? null,
'processor_id': outputs.incident.values.processor_id,
'processor_image': outputs.processor.values.image,
'processor_command': outputs.processor.values.command,
'has_source': outputs.processor.values.source is not empty,
'fingerprint': outputs.fingerprint.vars,
'baseline': outputs.baseline.values,
'shrink': outputs.shrunk.values ?? null,
'carve': outputs.carve.vars ?? null,
'cross_examination': outputs.cross.values ?? null,
'evidence_bucket': inputs.evidence_bucket,
'evidence_prefix': outputs.incident.values.evidence_prefix,
's3_endpoint': inputs.s3_endpoint ?? ''
} | toJson }}
outputFiles:
- observations.json
- replay.sh
- processor.py
script: |
import json, shlex
facts = json.load(open("facts.json"))
bucket, prefix = facts["evidence_bucket"], facts["evidence_prefix"]
endpoint = f" --endpoint-url {shlex.quote(facts['s3_endpoint'])}" if facts["s3_endpoint"] else ""
verdict = facts["verdict"]
if verdict in ("ISOLATED_RECORD", "MORE_FAILURES"):
target, name = f"s3://{bucket}/{prefix}/reproducer.jsonl", "reproducer.jsonl"
expected = facts["carve"]["reproducer_sha256"]
elif facts.get("shrink") and facts["shrink"].get("status") == "INTERACTING":
target, name = f"s3://{bucket}/{prefix}/failing-slice.jsonl", "failing-slice.jsonl"
expected = facts["carve"]["reproducer_sha256"]
else:
target, name = facts["source"], "batch.jsonl"
expected = facts["fingerprint"]["batch_sha256"]
lines = [
"#!/bin/sh",
f"# Replay of Kestra execution {facts['execution_id']}: {verdict}",
"set -eu",
f"aws s3 cp{endpoint} {shlex.quote(target)} {name}",
]
if facts["has_source"]:
lines.append(f"aws s3 cp{endpoint} s3://{bucket}/{prefix}/processor.py processor.py")
files = ("processor.py " if facts["has_source"] else "") + name
inner = f"mkdir -p /work && cd /work && tar -xf - && {facts['processor_command']} {name}"
lines += [
f"echo '{expected} {name}' | sha256sum -c -",
# Files go in through stdin rather than a bind mount, so this also
# works against a remote Docker host.
f"tar -cf - {files} | docker run --rm -i --network none {facts['processor_image']} sh -c {shlex.quote(inner)}",
]
with open("replay.sh", "w") as fh:
fh.write("\n".join(lines) + "\n")
facts["replay_command"] = [line for line in lines[3:] if not line.startswith("#")]
facts.pop("has_source")
with open("observations.json", "w") as fh:
json.dump(facts, fh, indent=2)
print(open("replay.sh").read())
- id: preserve
type: io.kestra.plugin.core.flow.Parallel
description: Observations, replay script and processor source go next to the
reproducer in the private bucket.
tasks:
- id: upload_observations
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/observations.json"
from: "{{ outputs.report.outputFiles['observations.json'] }}"
contentType: application/json
- id: upload_replay
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/replay.sh"
from: "{{ outputs.report.outputFiles['replay.sh'] }}"
- id: upload_processor_source
type: io.kestra.plugin.aws.s3.Upload
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
endpointOverride: "{{ inputs.s3_endpoint }}"
compatibilityMode: "{{ inputs.s3_endpoint is not empty }}"
forcePathStyle: "{{ inputs.s3_endpoint is not empty }}"
bucket: "{{ inputs.evidence_bucket }}"
key: "{{ outputs.incident.values.evidence_prefix }}/processor.py"
from: "{{ outputs.report.outputFiles['processor.py'] }}"
- id: label_verdict
type: io.kestra.plugin.core.execution.Labels
labels:
verdict: "{{ outputs.verdict.values.verdict }}"
processor: "{{ outputs.incident.values.processor_id }}"
- id: log_verdict
type: io.kestra.plugin.core.log.Log
message: |
{{ outputs.verdict.values.verdict }}: {{ outputs.verdict.values.reason }}
Shrink trace: {{ outputs.shrunk.values.trace ?? 'not run' }}
Evidence: s3://{{ inputs.evidence_bucket }}/{{ outputs.incident.values.evidence_prefix }}/
finally:
- id: drop_state
type: io.kestra.plugin.core.kv.Delete
key: "shrink_{{ execution.id }}"
outputs:
- id: verdict
type: STRING
value: "{{ outputs.verdict.values.verdict ?? '' }}"
- id: reason
type: STRING
value: "{{ outputs.verdict.values.reason ?? '' }}"
- id: shrink_trace
type: STRING
value: "{{ outputs.shrunk.values.trace ?? '' }}"
- id: evidence_uri
type: STRING
value: "{{ outputs.preserve is defined ? 's3://' ~ inputs.evidence_bucket ~ '/'
~ outputs.incident.values.evidence_prefix ~ '/' : '' }}"
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.
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.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.UNRESOLVED.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.Switch routes to ISOLATED_RECORD, MORE_FAILURES (the reproducer is real but the rest still fails) or UNRESOLVED.aws.s3.Upload writes the reproducer, the remainder or failing slice when relevant, observations.json, processor.py and replay.sh under incidents/<flow>/<execution>/.UNRESOLVED with the reason.networkMode: none keep untrusted batch data away from everything else.s3_endpoint input.s3:GetObject on the source prefix and s3:PutObject on the evidence bucket.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.batches/ and click Execute with its key.replay.sh from the evidence prefix./api/v1/main/executions/webhook/company.data/s3-failed-batch-bisect-to-reproducer/<key> with {"object_key": "...", "processor_id": "orders-pricing-v1"}.ISOLATED_RECORD case.remainder.jsonl back into the flow with a Subflow until every bad record is found.Non-destructively sample a Pulsar topic on a schedule with a non-durable reader and page Slack when it goes silent, floods, or the broker is unreachable.
Compare live embeddings with stored vectors and repair an approved batch only when held-out retrieval has degraded.
Drain a multi-tenant Pulsar topic and route each batch by tenant priority tier, logging ENTERPRISE traffic and quarantining the rest, with a Slack report per run.
Process a list of CSV files in parallel, each in its own isolated Python and Pandas container.
Detect Apache Pulsar subscriptions with no consumers that still pin a large backlog, then clear or remove them behind a dry run, an approval pause and a live re-read that fails the run.
Run a parametrized Python script in Kestra that emits downloadable files, named outputs, and custom metrics.
Checks that the rest of an HAProxy backend can carry the traffic, asks on-call to approve, drains the server until its sessions close, then sets it to maintenance. Enable mode puts it back once its health check passes.
Audits Harbor enterprise container registry telemetry to detect stalled garbage collection jobs, lock freezes, and storage bloat.
Audits HashiCorp Consul Autopilot for Raft quorum health and voter commit index synchronization to prevent cluster brain-split.
Continuous node connectivity auditing, machine key expiration monitoring, and Slack alerting for Headscale tailnets.
Audit HashiCorp Vault cluster seal status via sys/health, detect unexpected lockouts, open GitHub P1 issues, and alert Slack.
Audits HashiCorp Boundary targets for active session concurrency saturation and worker capacity limits.