Skip to content

fix(execution): commit context manager resources before yielding to downstream consumers (#126) - #127

Merged
mvallebr merged 3 commits into
mainfrom
fix/issue-126-commit-before-yield-downstream
Jul 28, 2026
Merged

fix(execution): commit context manager resources before yielding to downstream consumers (#126)#127
mvallebr merged 3 commits into
mainfrom
fix/issue-126-commit-before-yield-downstream

Conversation

@mvallebr

Copy link
Copy Markdown
Contributor

Summary

Fixes #126 where context-manager resources in EACH-mode steps remained uncommitted while yielded items were being processed by downstream consumers, causing stale/uncommitted reads in multi-step outbox pipelines.

Root Cause

In StepRunner (both sync & async), yield self.fn(**item_args) was located inside the with ExitStack() block. As a result, when a step yielded a processed item to a downstream consumer, the context manager block was suspended mid-execution before entering __exit__ (where DB commits occur). Downstream steps reading from the database saw uncommitted state.

Solution

Execute self.fn(**item_args) inside the ExitStack / AsyncExitStack block to store the result, allowing the context manager block to close (and commit) before yield result emits the item to downstream steps.

Tests

  • Added unit tests in sync & async resource lifecycle suites (test_cm_resource_exited_before_downstream_consumer_receives_item)
  • Verified all 798 tests passing across full test suite

Marcelo Elias Del Valle added 3 commits July 28, 2026 07:58
…ownstream consumers (#126)

### Summary
Fixes #126 where context-manager resources in EACH-mode steps remained uncommitted while yielded items were being processed by downstream consumers, causing stale/uncommitted reads in multi-step outbox pipelines.

### Changes
- Sync & Async step runners: execute `self.fn(**item_args)` inside the context manager block and save the result, allowing the context manager block (`with ExitStack()`) to exit and commit DB transactions *before* `yield result` passes the item downstream.
- Corrected exception handling flow when `PipelineStopException` or step execution exceptions occur.

### Tests
- Added sync & async unit tests verifying that resource context managers commit prior to downstream step execution (`test_cm_resource_exited_before_downstream_consumer_receives_item`).
- All 798 tests passing in full test suite.
- Restructure try/except to wrap the with ExitStack block, keeping yield
  inside try but outside with (commit before yield, errors still handled)
- Add tests for CM factory errors in EACH mode with OnError.CONTINUE
  (skips failed item) and OnError.STOP (raises PipelineStopException)
@mvallebr
mvallebr merged commit c6287b0 into main Jul 28, 2026
5 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.

write_db context-manager resource batches commits at 3× parallelism in EACH mode, not per item

1 participant