DEV Community

Rupak Kulkarni
Rupak Kulkarni

Posted on

A SHA-256 Checksum Is Not a Restart Permit: Binding ETL Recovery to Run Identity and Freshness

A pipeline can finish its first stage, fail in its second, and leave behind perfectly readable intermediate files. Should the next attempt skip stage one?

A file checksum alone cannot answer that question. It tells us whether bytes match a recorded digest, but not whether those bytes belong to this run, whether the inputs have changed, or whether the evidence is too old to trust.

This article examines a concrete, public Python implementation of a fail-closed recovery provenance gate in the retail-media-analytics-pipeline repository. The implementation was extended in the November 19 commit. All repository tests use synthetic local files; this is not a claim of production deployment or distributed exactly-once execution.

The recovery problem

Imagine a two-stage batch job:

raw CSVs -> stage 1: normalize -> silver files
         -> stage 2: aggregate -> gold tables
Enter fullscreen mode Exit fullscreen mode

Stage one succeeds and stage two fails. A naive retry might inspect the silver directory and conclude that stage one is safe to skip.

But there are at least four failure modes:

  1. Someone modified the silver output after the original run.
  2. The source CSV changed while the silver output stayed unchanged.
  3. The files came from a different pipeline run.
  4. The files and their checksums are old, even though the current job expects fresher evidence.

These are different questions. Integrity, lineage, identity, and freshness need separate checks.

A layered architecture

The public implementation separates three responsibilities:

pipeline event summary
          |
          v
conservative restart planner
          |
          v
output-manifest verification
          |
          v
run-bound provenance verification
          |
          v
restart plan (never automatic execution)
Enter fullscreen mode Exit fullscreen mode

The existing planner checks stage statuses and whether a restart is permissible. The manifest layer checks the output tree. The provenance layer additionally binds both input and output manifests to a particular run and stage, with a timestamp.

The relevant files are src/recovery_provenance.py, the integration guide, and regression tests.

What belongs in an evidence record?

The repository's record_evidence function validates the input and output trees against their manifests before returning a record with this shape:

{
  "schema_version": 1,
  "run_id": "run-a",
  "stage": 1,
  "created_at_utc": "2026-11-19T12:00:00+00:00",
  "input_manifest_sha256": "<digest>",
  "output_manifest_sha256": "<digest>"
}
Enter fullscreen mode Exit fullscreen mode

The digest placeholders above are illustrative, not real hashes.

Why hash the manifest files as well as the data? A manifest describes a collection of files and their digests. Hashing its serialized bytes allows the planner to notice if that manifest itself was rewritten. Separately, re-verifying the input tree against its manifest catches changed source files.

The evidence record must be stored outside the input and output directories. Otherwise it could alter the very directory snapshot being verified. In production, it should also live in access-controlled, preferably immutable storage.

Capture evidence only after successful work

The following is an illustrative call using the repository's actual public API:

from src.recovery_provenance import record_evidence

evidence = record_evidence(
    run_id="run-a",
    stage=1,
    input_dir="data/raw",
    input_manifest="manifests/raw.json",
    output_dir="data/silver",
    output_manifest="manifests/silver.json",
)
Enter fullscreen mode Exit fullscreen mode

Both manifests must already exist and match their respective directories. The function checks for manifest symlinks and validates timezone-aware timestamps. It returns a dictionary; the caller, not the function, is responsible for persisting that dictionary and associating it with a trusted run record.

The example is not a complete runnable pipeline: it assumes manifest creation and stage execution have already occurred. For manifest generation, see src/output_manifest.py.

Require identity, freshness, and both sides of the boundary

At planning time, the caller supplies the pipeline summary, expected run ID, stage paths, and saved evidence:

from src.recovery_provenance import plan_with_provenance

plan = plan_with_provenance(
    monitor_summary,
    "run-a",
    {
        1: (
            "data/silver",
            "manifests/silver.json",
            "data/raw",
            "manifests/raw.json",
        )
    },
    {1: evidence},
    max_age_seconds=86400,
)
Enter fullscreen mode Exit fullscreen mode

The function first calls the manifest-gated restart planner. If no restart is needed, it returns that plan. Otherwise, for every skipped stage, it requires:

  • An evidence record with the expected schema version.
  • An exact matching run ID and integer stage number.
  • A timezone-aware timestamp that is neither future-dated nor older than the configured window.
  • Matching SHA-256 hashes of the input and output manifest files.
  • A currently valid input tree against its saved manifest.

The preceding planner separately validates the output tree. Together these checks mean a successful stage is not skipped merely because a folder happens to exist.

The freshness default is 86,400 seconds (24 hours), a configurable policy rather than a universal data-quality guarantee. For a high-frequency ingestion job, that window might be far too generous; for a weekly archival job, it might be unnecessarily restrictive.

Fail closed, not optimistically

A good recovery gate should refuse ambiguous evidence. The repository uses a dedicated RecoveryNotSafe exception for unsafe conditions.

Here is a small illustrative operator-side pattern:

from src.pipeline_recovery import RecoveryNotSafe

try:
    plan = plan_with_provenance(
        monitor_summary,
        run_id,
        stage_artifacts,
        evidence_by_stage,
        max_age_seconds=3600,
    )
except RecoveryNotSafe as exc:
    print(f"Manual review required: {exc}")
else:
    print("Proposed plan:", plan)
    # Human/operator approval before any job execution.
Enter fullscreen mode Exit fullscreen mode

This code does not execute Spark, mutate tables, or restart a scheduler. That separation is intentional. A safe plan is not an authorization to perform a potentially destructive operation.

What should the tests break?

The public regression suite constructs temporary input and output directories and synthetic CSV files. It includes cases for a valid stage-two restart and refusal when:

  • Input or output bytes change.
  • A manifest is rewritten.
  • Run or stage identity differs.
  • Evidence is missing, expired, or future-dated.
  • The clock is timezone-naive or the freshness limit invalid.
  • An input manifest is replaced with a symlink.

You can run this specific suite locally from the repository root:

python -m unittest discover \
  -s tests -p 'test_recovery_provenance.py' -v
Enter fullscreen mode Exit fullscreen mode

These tests are present in the verified repository; I am not claiming to have run the full repository test suite in a production-like environment.

Important security and distributed-system limits

SHA-256 is a cryptographic hash, but a hash alone is not an authentication mechanism. If an attacker can rewrite the data, manifest, and evidence record, the checks may all agree on a malicious replacement. Protect evidence with IAM, immutable storage, or signed attestations where appropriate.

There is also a time-of-check/time-of-use gap. Files can change after verification and before restart. Production designs should consider object-store version IDs, immutable snapshots, locks, or transactional table formats. The example handles local files, not object-store version semantics, concurrent writers, or exactly-once distributed processing.

Finally, freshness does not imply business correctness. A recent file can still contain invalid campaign IDs, duplicated conversions, or incorrect revenue. Schema and business-rule validation belong in additional quality gates.

Takeaways

A valid checksum is necessary evidence, not sufficient permission to skip work. Recovery needs to establish which run produced the artifacts, which inputs were used, whether both sides still match, and whether the evidence is acceptably recent.

The practical pattern is straightforward: capture evidence after success, store it separately, validate it before skipping any stage, refuse ambiguous cases, and keep restart execution behind an explicit operational decision.

For implementation details, review the source and tests at the pinned commit. For background on checksum properties and artifact integrity, see NIST FIPS 180-4 (Secure Hash Standard); for object-versioning considerations, see Amazon S3 Versioning documentation.

Top comments (1)

Collapse
 
kharipara profile image
Kam Haripara •

Nice separation of integrity, lineage, identity and freshness. One more case worth a test: the manifest is current and bound to the run, but the source delivered a partial file. A row-count or file-size check against recent runs before stage one is marked complete would stop the planner treating a short silver output as safe to skip.