## ADDED Requirements ### Requirement: Run states A workflow run SHALL transition through states: `pending → running → completed | failed | cancelled`. It MAY transition to `paused` for approval gates. #### Scenario: Normal completion - **WHEN** all DAG nodes complete successfully - **THEN** the run status SHALL be `completed` #### Scenario: Node failure - **WHEN** a node fails and no retry succeeds - **THEN** the run status SHALL be `failed` #### Scenario: User cancellation - **WHEN** a user cancels a running workflow - **THEN** the run status SHALL be `cancelled` #### Scenario: Approval pause - **WHEN** an approval node is reached - **THEN** the run status SHALL transition to `paused` - **THEN** it SHALL transition back to `running` on approval ### Requirement: Resume from failure A failed workflow SHALL support resumption, skipping already-completed nodes using stored outputs from the event log. #### Scenario: Resume skips completed nodes - **WHEN** a failed workflow has 2 completed nodes out of 5 - **THEN** resuming SHALL skip nodes 1-2 and re-execute from node 3 #### Scenario: Resume with always_run - **WHEN** a node has `always_run: true` and the workflow is resumed - **THEN** the node SHALL re-execute even if it completed previously ### Requirement: Event-based observability All lifecycle transitions SHALL emit typed events through the event emitter for observability and external subscribers. #### Scenario: Events for every state transition - **WHEN** a workflow starts - **THEN** a `workflow_started` event SHALL be emitted - **WHEN** a workflow completes - **THEN** a `workflow_completed` event SHALL be emitted - **WHEN** a node starts/completes/fails/skips - **THEN** corresponding node events SHALL be emitted ### Requirement: Cleanup The engine SHALL support cleaning up old workflow runs and their artifacts. #### Scenario: Cleanup by age - **WHEN** cleanup is invoked with a retention period (default 7 days) - **THEN** runs older than the retention period SHALL have their artifacts removed - **THEN** run records MAY be pruned from the store