Skip to content

feat(pipeline): runtime stage contract validation #447

Closed

Description

@Sinity

Discovered by

pipeline-stage-audit agent (swarm 2026-04-26). Full report: .agent/scratch/swarm-2026-04-26/pipeline-stage-audit.md.

Problem

#323 (closed) modeled pipeline stages as executable specs (pipeline/stage_specs.py, pipeline/stage_models.py). Each PipelineStageSpec declares its inputs and outputs — but no runtime check verifies the contract when the pipeline crosses a stage boundary.

Concrete consequences (audit findings):

  • materialize silently returns zero items if processed_ids is empty. The pipeline reports success; downstream stages produce nothing.
  • parse → materialize passes state implicitly through state.processed_ids. A partial parse failure (some records OK, some not) makes materialize see a valid-looking but incomplete processed_ids set.
  • render → site depends on render output existing; site emits no diagnostic when the dependency is missing.

The four critical silent-failure sites in the companion silent-failure issue cluster at exactly these stage boundaries — the implicit-contract pattern is the meta-cause.

Target

Add runtime contract validation between stages. When the pipeline crosses a stage boundary, assert the prior stage's declared outputs are present and shaped correctly. On contract violation, fail loudly with a structured StageContractViolation exception that surfaces in RunResult and ReadinessReport.

Implementation sketch

@dataclass(frozen=True, slots=True)
class StageInput:
    name: str
    required: bool = True
    shape: type | None = None  # optional runtime type check

@dataclass(frozen=True, slots=True)
class PipelineStageSpec:
    ...
    inputs: tuple[StageInput, ...]
    outputs: tuple[StageInput, ...]

def validate_stage_inputs(spec: PipelineStageSpec, state: RunState) -> None:
    missing = [i.name for i in spec.inputs if i.required and not state.has(i.name)]
    if missing:
        raise StageContractViolation(stage=spec.name, missing=missing)

Run the validator on every stage entry, both in run all and individual run <stage> invocations.

Acceptance criteria

  • PipelineStageSpec carries typed input/output declarations.
  • A runtime validator runs at every stage boundary; violations surface as typed exceptions.
  • RunResult / ReadinessReport include stage-contract diagnostics.
  • Tests: every stage has a test that mocks a missing input and asserts the validator fires.
  • Tests: every stage has a test asserting normal-path inputs satisfy the declared contract.
  • The four silent-failure sites in the companion issue resolve via this validation (or via their site-specific fixes).

Pattern

Follows the same evidence-driven specification pattern as #429 (topology), #435 (file-size), #437 (test-ownership): declarative spec + runtime check. The pattern from the structural-cohesion track applied to pipeline correctness.

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:pipelinephase:architecturetheme:verifiabilitytype:feat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions