@execute-error-recovery
Feature: Execute phase error recovery (#10843)
  Per spec §28530/§35958 and §18323, errored plans recover via two
  paths: transient failures (classified by domain model's
  classify_error()) retry with the same strategy, non-transient
  failures revert to Strategize via service.try_auto_revert_from_execute().

  Scenario: Transient error resets plan to queued and re-executes for eer
    Given a mocked plan in execute/errored with exception_type "RateLimitError" for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reset to execute/queued for eer
    And run_execute should have been called for eer
    And the CLI output should contain "transient" for eer

  Scenario: Timeout error is treated as transient for eer
    Given a mocked plan in execute/errored with exception_type "TimeoutError" for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reset to execute/queued for eer
    And run_execute should have been called for eer

  Scenario: Strategy constraint error reverts via service API then re-executes for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reverted to strategize for eer
    And run_strategize should have been called for eer
    And run_execute should have been called for eer
    And the CLI output should contain "Reverting to Strategize" for eer

  Scenario: Authentication error is non-transient per domain model for eer
    Given a mocked plan in execute/errored with exception_type "AuthenticationError" for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reverted to strategize for eer
    And run_strategize should have been called for eer

  Scenario: Error findings are preserved and redacted for strategy actor for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    And the mock error_details include sensitive data "bearer_token" for eer
    When I invoke plan execute on the errored plan for eer
    Then the committed plan should have reversion_reason in error_details for eer
    And the committed prior_error_details should not contain "SECRET_VALUE_12345" for eer

  Scenario: Strategy decisions preserved on transient retry for eer
    Given a mocked plan in execute/errored with exception_type "RateLimitError" for eer
    And the mock error_details include strategy_decisions_json for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reset to execute/queued for eer
    And the committed error_details should contain strategy_decisions_json for eer

  Scenario: Strategy revision failure aborts with non-zero exit for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    And the strategy revision will fail for eer
    When I invoke plan execute on the errored plan for eer
    Then the CLI output should contain "Strategy revision failed" for eer
    And the CLI exit code should be non-zero for eer

  Scenario: Plan not found after strategize aborts with non-zero exit for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    And the plan disappears after strategize for eer
    When I invoke plan execute on the errored plan for eer
    Then the CLI output should contain "not found" for eer
    And the CLI exit code should be non-zero for eer

  Scenario: Plan not found after transient recovery aborts for eer
    Given a mocked plan in execute/errored with exception_type "RateLimitError" for eer
    And the plan disappears after transient recovery for eer
    When I invoke plan execute on the errored plan for eer
    Then the CLI output should contain "not found" for eer
    And the CLI exit code should be non-zero for eer

  Scenario: Empty exception_type triggers strategy reversion for eer
    Given a mocked plan in execute/errored with no exception_type for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reverted to strategize for eer
    And run_strategize should have been called for eer
    And run_execute should have been called for eer

  Scenario: Auto_progress moves plan directly to Execute after strategize for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    And the auto_progress moves the plan to Execute after strategize for eer
    When I invoke plan execute on the errored plan for eer
    Then the plan should have been reverted to strategize for eer
    And run_execute should have been called for eer

  Scenario: MAX_REVERSIONS exceeded aborts with clear message for eer
    Given a mocked plan in execute/errored with exception_type "ValueError" for eer
    And revert_plan raises PlanError for max reversions for eer
    When I invoke plan execute on the errored plan for eer
    Then the CLI output should contain "Strategy reversion failed" for eer
    And the CLI exit code should be non-zero for eer
