Feature: Decision correction with selective subtree recomputation
  As a plan orchestrator
  I want to recompute only the affected subtree when a decision is incorrect
  So that sibling branches and ancestors are preserved unchanged

  Background:
    Given a decomposition service for correction
    And a decomposition result with a multi-level hierarchy

  Scenario: Recompute subtree for a leaf node - only leaf is recomputed
    When I recompute the subtree for a leaf node
    Then the correction result should have recomputed nodes
    And the correction result should have preserved nodes
    And the target node should be in the recomputed set
    And sibling nodes should be in the preserved set

  Scenario: Recompute subtree for a middle node - subtree is recomputed
    When I recompute the subtree for a middle node
    Then the correction result should have recomputed nodes
    And the correction result should have preserved nodes
    And the target node should be in the recomputed set
    And ancestor nodes should be in the preserved set

  Scenario: Recompute subtree for root - all nodes are recomputed
    When I recompute the subtree for the root node
    Then the correction result should have recomputed nodes
    And the correction result should have no preserved nodes

  Scenario: DecisionCorrectionResult tracks recomputed vs preserved nodes
    When I recompute the subtree for a middle node
    Then the DecisionCorrectionResult should have a target_node_id
    And the DecisionCorrectionResult should have recomputed_node_ids
    And the DecisionCorrectionResult should have preserved_node_ids
    And the DecisionCorrectionResult should have metrics

  Scenario: Sibling branches are unaffected during selective recomputation
    When I recompute the subtree for a middle node
    Then sibling branches should not be in the recomputed set
    And sibling branches should be in the preserved set

  Scenario: Recompute subtree with custom config
    When I recompute the subtree for a leaf node with custom config
    Then the correction result config should match the custom config

  Scenario: Recompute subtree raises ValueError for unknown node
    When I recompute the subtree for an unknown node
    Then a decomp correction ValueError should be raised

  Scenario: Recompute subtree preserves ancestor nodes
    When I recompute the subtree for a leaf node
    Then ancestor nodes should be in the preserved set

  Scenario: Correction result metrics track recomputed and preserved counts
    When I recompute the subtree for a middle node
    Then the metrics should contain recomputed_count
    And the metrics should contain preserved_count
    And the metrics should contain subtree_size
