Skip to content

refactor(pipeline): catalog executable stage specs (#370) - #370

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/pipeline-executable-stage-specs
Apr 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/pipeline-executable-stage-specs

Conversation

@Sinity

@Sinity Sinity commented Apr 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds an executable PipelineStageSpec catalog for pipeline leaf-stage facts and routes run_sources() through a single spec-driven execution loop.

Problem

Closes #323.

polylogue/pipeline/run_execution.py carried stage order, explicit-sequence context, metrics labels, FTS trigger suspension, and executed-stage bookkeeping in duplicated default and explicit dispatch branches. That made stage semantics harder to inspect and created another place where future pipeline stages could drift from the normalized stage vocabulary.

Solution

  • Added polylogue/pipeline/stage_specs.py with the catalog of leaf-stage execution facts: log stage, context policy, FTS suspension policy, and whether the normal pipeline owns execution.
  • Replaced the split default/explicit run_sources() dispatch with one spec-driven loop.
  • Left individual stage helpers responsible only for stage bodies; the shared runner now owns context resolution and executed-stage tracking.
  • Kept embed represented as an externally managed leaf stage because polylogue run embed is dispatched by the CLI before entering run_sources(), preserving direct run_sources(stage="embed") compatibility without introducing an API-key-requiring behavior change.
  • Added unit coverage that the stage spec catalog covers the full leaf-stage vocabulary and preserves sequence/FTS policy; existing ordered parse/materialize/render/index tests continue to cover explicit-stage semantics.

Verification

  • ruff check polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py tests/unit/pipeline/test_run_sources.py
  • mypy polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py
  • pytest -q tests/unit/pipeline/test_run_sources.py -> 48 passed in 16.10s
  • devtools render-all --check -> all generated surfaces in sync
  • devtools verify -> all checks passed
  • git push -u origin feature/refactor/pipeline-executable-stage-specs -> pre-push devtools verify --quick all checks passed

Summary by CodeRabbit

  • Refactor

    • Restructured pipeline execution logic to improve code organization and consistency.
  • Tests

    • Added unit tests to validate pipeline stage specifications and execution behavior.

Problem: run_sources carried stage order, stage context, metrics labels, and FTS suspension policy as duplicated branching across default and explicit stage paths.

What changed: add PipelineStageSpec as the leaf-stage catalog, route run_sources through a single spec-driven execution loop, and keep embed represented as an externally managed stage so the existing CLI dispatch contract remains intact.

Verification: ruff check polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py tests/unit/pipeline/test_run_sources.py; mypy polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py; pytest -q tests/unit/pipeline/test_run_sources.py; devtools render-all --check.

Ref #323
@Sinity Sinity changed the title refactor(pipeline): catalog executable stage specs refactor(pipeline): catalog executable stage specs (#370) Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 27a94b08-430a-4557-87b7-c48789793350

📥 Commits

Reviewing files that changed from the base of the PR and between b54a051 and 7e54132.

📒 Files selected for processing (3)
  • polylogue/pipeline/run_execution.py
  • polylogue/pipeline/stage_specs.py
  • tests/unit/pipeline/test_run_sources.py

📝 Walkthrough

Walkthrough

The pipeline execution system is refactored from procedural, string-based stage sequencing to a spec-driven data model. A new stage_specs module defines executable specifications for each pipeline stage, centralizing logging, context policies, FTS suspension behavior, and execution routing through a standardized PipelineStageSpec dataclass.

Changes

Cohort / File(s) Summary
New Stage Specifications Module
polylogue/pipeline/stage_specs.py
Introduces PipelineStageSpec dataclass with execution_stage() method for translating requested vs. explicit sequencing into stage tokens. Defines PIPELINE_STAGE_SPECS dictionary mapping leaf stages (acquire, schema, parse, materialize, render, site, index, embed) to specs. Adds helper functions stage_specs_for_sequence() and stage_sequence_suspends_fts() for sequence resolution and FTS trigger detection.
Refactored Execution Orchestration
polylogue/pipeline/run_execution.py
Replaces string/leaf-sequence driven logic with spec-driven dispatch. Removes _explicit_leaf_stage_context context manager and stage_sequence is None branching. Introduces _run_stage_spec() helper for centralized executed_stages updates. Updates FTS suspension to use stage_sequence_suspends_fts(stage_specs) instead of hardcoded stage name checks.
Pipeline Execution Tests
tests/unit/pipeline/test_run_sources.py
Adds two new unit tests validating spec vocabulary completeness against runtime leaf-stage list, verifying parse and embed spec properties, and confirming explicit sequence preservation and FTS-suspension policy for different stage sequences.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hopping through specs, not strings, we go—
Each stage now knows itself, a data show.
No more the tangled nested call,
Just specs and flows, clean for all!
The pipeline dances, sleek and bright, ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/pipeline-executable-stage-specs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit eea7f11 into master Apr 22, 2026
9 of 13 checks passed
@Sinity
Sinity deleted the feature/refactor/pipeline-executable-stage-specs branch April 22, 2026 23:49
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity requested a review from Copilot May 1, 2026 01:53
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:15
Sinity added a commit that referenced this pull request May 7, 2026
## Summary

Adds an executable `PipelineStageSpec` catalog for pipeline leaf-stage facts and routes `run_sources()` through a single spec-driven execution loop.

## Problem

Closes #323.

`polylogue/pipeline/run_execution.py` carried stage order, explicit-sequence context, metrics labels, FTS trigger suspension, and executed-stage bookkeeping in duplicated default and explicit dispatch branches. That made stage semantics harder to inspect and created another place where future pipeline stages could drift from the normalized stage vocabulary.

## Solution

- Added `polylogue/pipeline/stage_specs.py` with the catalog of leaf-stage execution facts: log stage, context policy, FTS suspension policy, and whether the normal pipeline owns execution.
- Replaced the split default/explicit `run_sources()` dispatch with one spec-driven loop.
- Left individual stage helpers responsible only for stage bodies; the shared runner now owns context resolution and executed-stage tracking.
- Kept `embed` represented as an externally managed leaf stage because `polylogue run embed` is dispatched by the CLI before entering `run_sources()`, preserving direct `run_sources(stage="embed")` compatibility without introducing an API-key-requiring behavior change.
- Added unit coverage that the stage spec catalog covers the full leaf-stage vocabulary and preserves sequence/FTS policy; existing ordered parse/materialize/render/index tests continue to cover explicit-stage semantics.

## Verification

- `ruff check polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py tests/unit/pipeline/test_run_sources.py`
- `mypy polylogue/pipeline/run_execution.py polylogue/pipeline/stage_specs.py`
- `pytest -q tests/unit/pipeline/test_run_sources.py` -> `48 passed in 16.10s`
- `devtools render-all --check` -> all generated surfaces in sync
- `devtools verify` -> all checks passed
- `git push -u origin feature/refactor/pipeline-executable-stage-specs` -> pre-push `devtools verify --quick` all checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: model pipeline stages as executable specs

1 participant