Skip to content

fix(px): when+return short-circuits procedure execution#992

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-when-block-return-behavior
Draft

fix(px): when+return short-circuits procedure execution#992
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-when-block-return-behavior

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

After extracting the px runtime to pluresdb-px, return inside a when: block no longer halted procedure execution — subsequent steps continued running regardless.

Root causes

executor.rsexecute_when iterated nested steps without checking for a return result, and always returned kind: "when". The outer procedure loop's is_return guard never fired.

scenario_runner.rs had a hand-rolled execute_step loop with no "return" arm and no short-circuit check.

Changes

  • executor.rs execute_when: break on the first nested return, propagate kind: "return" to caller so the procedure loop short-circuits correctly. Works for arbitrarily nested when blocks.

  • scenario_runner.rs: replace the hand-rolled per-step loop with execute_with_vars (which already handles is_return). The executor's emit step stores events in vars["emit"] rather than calling the handler, so emitted events are replayed through handler.call("emit", …) post-execution so ScenarioActionHandler captures them for event_emitted checks. Replay errors propagate as scenario failures.

procedure guard_test:
  trigger: manual
  when $input == "":
    return "no_input"   # ← now correctly halts; steps below no longer run
  end
  return $input

Tests added

File Test Covers
executor.rs when_return_short_circuits_procedure condition true → single return step result
executor.rs when_condition_false_does_not_short_circuit condition false → execution continues
executor.rs when_return_nested_when_also_short_circuits return propagates through two when levels
scenario_runner.rs when_return_short_circuits_procedure_in_scenario entry not stored, var bound to guard return value
scenario_runner.rs when_condition_false_continues_execution guard miss → subsequent steps run

Copilot AI self-assigned this Jun 9, 2026
Copilot AI review requested due to automatic review settings June 9, 2026 04:04
Copilot AI removed the request for review from Copilot June 9, 2026 04:04
Copilot AI linked an issue Jun 9, 2026 that may be closed by this pull request
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 requested review from Copilot and removed request for Copilot June 9, 2026 04:13
Copilot AI requested review from Copilot and removed request for Copilot June 9, 2026 04:16
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
Copilot AI requested a review from kayodebristol June 9, 2026 04:16
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.

px: when-block return does not short-circuit procedure execution

2 participants