Skip to content

refactor(pipeline): collapse invoke() to single return path#240

Merged
miguelgfierro merged 1 commit into
issue-147-pipeline-evolutionfrom
simplify/state-pipeline-invoke-single-return
May 28, 2026
Merged

refactor(pipeline): collapse invoke() to single return path#240
miguelgfierro merged 1 commit into
issue-147-pipeline-evolutionfrom
simplify/state-pipeline-invoke-single-return

Conversation

@miguelgfierro
Copy link
Copy Markdown
Contributor

Addresses finding #5 from the simplifier review of #232.

StatePipeline.invoke had seven return await self._finalize_run(StatePipelineResult(...), pipeline_span, pipeline_start_time, run_id) call sites — each passing the same three captured locals. This collapses them into one try/finally:

  • Each early-termination path now assigns result = StatePipelineResult(...) and breaks.
  • The finally block ends the pipeline span and emits on_pipeline_complete exactly once.
  • _finalize_run helper removed.

Net −32 LOC in state_pipeline.py (144 insertions, 176 deletions).

Behavior

Unchanged:

  • The early "resume finds run already complete" return still bypasses the observability boundary (same as before — it returns before on_pipeline_start is emitted).
  • All exception paths still emit on_pipeline_complete with the correct success value.
  • Node-level audit, checkpoint, and span lifecycle are untouched.

Verification

  • pytest tests/unit/pipeline/ → 142 passed.
  • ruff check + ruff format --check clean.

Replace 7 _finalize_run call sites in StatePipeline.invoke with a single
try/finally that ends the pipeline span and emits on_pipeline_complete
once. Remove the _finalize_run helper.

Behavior unchanged; net -32 LOC.
@miguelgfierro miguelgfierro merged commit f032ba1 into issue-147-pipeline-evolution May 28, 2026
@miguelgfierro miguelgfierro deleted the simplify/state-pipeline-invoke-single-return branch May 28, 2026 06:04
ancongui pushed a commit that referenced this pull request May 31, 2026
…-invoke-single-return

refactor(pipeline): collapse invoke() to single return path
ancongui pushed a commit that referenced this pull request May 31, 2026
After the try/finally introduced in #240, pyright could not narrow
result: StatePipelineResult | None to StatePipelineResult at the return
statement (a finally block can reassign, so the narrowing must be local).

Add an explicit assert before return — same runtime guarantee, makes the
non-None invariant visible to pyright.
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.

1 participant