FlexiRule Docs
Stop: Execution Semantics
Technical runtime behavior and engine guarantees for the Stop action.
Stop: Execution Semantics#
Purpose#
The Stop action is the primary mechanism for flow termination within the FlexiRule engine. It allows a rule to declare a terminal state, either signaling a successful early exit or a hard validation failure.
Execution Lifecycle#
- Dispatch: The
RuleEngineencounters a node withnode_type: stopand invokes theStopHandler. - Mode Resolution: The handler identifies the
operationas eitherSuccessorError. - Terminal Path:
- Success Mode: The handler returns
(None, None). TheRuleEngineinterprets aNonenext step as a successful completion of the flow. - Error Mode:
- The
value_templateis retrieved. - The engine renders the template using the current
context. - A
frappe.ValidationErroris raised with the rendered message and a traceability link to the source rule.
- The
- Success Mode: The handler returns
- Engine Cleanup: The engine halts all further node processing for the current rule.
Context Visibility#
The Stop action has read-only access to:
doc: The triggering document.vars: All calculated variables.engine.rule.name: Used for creating the traceability link in error messages.
Transaction Behavior#
The transaction behavior of the Stop action depends entirely on its mode:
- Success: The action has no impact on the current database transaction. The transaction continues as normal and will commit when the overall rule execution (and any other triggered rules) finishes successfully.
- Error: Raising a
frappe.ValidationErrortriggers a standard database Rollback. Any changes made by previous nodes in the same rule flow (e.g., Assignment updates todoc) will be reverted.
Failure Behavior#
If the Jinja template in the error message fails to render, the engine will raise a secondary rendering error. However, since the intent was already to stop with an error, the result is still a termination of the flow and a rollback of the transaction.
Idempotency#
The Stop action is inherently idempotent in Success mode. In Error mode, it will consistently raise an error and prevent the transaction from committing, making it effectively idempotent as it prevents state change.
Performance Notes#
The Stop action is extremely lightweight. In Success mode, it involves a simple return statement. In Error mode, it involves a single Jinja rendering and a standard Python exception.
Related Topics#
Was this page helpful?