fix(px): when+return short-circuits procedure execution#992
Draft
Copilot wants to merge 3 commits into
Draft
Conversation
Two bugs caused `return` inside a `when:` block to not stop subsequent
procedure steps:
1. executor.rs `execute_when`: iterated nested steps without checking for
a `return` result. Now breaks early on `return` and propagates
`kind: "return"` up so the procedure loop's `is_return` guard fires.
2. scenario_runner.rs: used a hand-rolled `execute_step` loop that had no
`"return"` arm and no short-circuit check. Replaced with a direct call
to `execute_with_vars` (which already handles `is_return`). Emitted
events stored by the executor in `vars["emit"]` are replayed through
`handler.call("emit", ...)` so `ScenarioActionHandler` continues to
capture them for `event_emitted` expectation checks.
Adds regression tests for:
- `when` + `return` short-circuits in executor (3 new tests)
- nested `when` + `return` propagation in executor (1 new test)
- `when` + `return` short-circuit at scenario level (2 new tests)
Fixes #974 regression; unblocks pares-radix#298.
Copilot
AI
changed the title
[WIP] Fix when block return not short-circuiting execution
fix(px): when+return short-circuits procedure execution
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After extracting the px runtime to
pluresdb-px,returninside awhen:block no longer halted procedure execution — subsequent steps continued running regardless.Root causes
executor.rs—execute_wheniterated nested steps without checking for areturnresult, and always returnedkind: "when". The outer procedure loop'sis_returnguard never fired.scenario_runner.rshad a hand-rolledexecute_steploop with no"return"arm and no short-circuit check.Changes
executor.rsexecute_when: break on the first nestedreturn, propagatekind: "return"to caller so the procedure loop short-circuits correctly. Works for arbitrarily nestedwhenblocks.scenario_runner.rs: replace the hand-rolled per-step loop withexecute_with_vars(which already handlesis_return). The executor'semitstep stores events invars["emit"]rather than calling the handler, so emitted events are replayed throughhandler.call("emit", …)post-execution soScenarioActionHandlercaptures them forevent_emittedchecks. Replay errors propagate as scenario failures.Tests added
executor.rswhen_return_short_circuits_procedurereturnstep resultexecutor.rswhen_condition_false_does_not_short_circuitexecutor.rswhen_return_nested_when_also_short_circuitswhenlevelsscenario_runner.rswhen_return_short_circuits_procedure_in_scenarioscenario_runner.rswhen_condition_false_continues_execution