Files
cleveragents-core/docs/reference/decision_correction.md
T
freemo 33a5adcfee
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 17s
CI / build (pull_request) Successful in 22s
CI / typecheck (pull_request) Successful in 28s
CI / security (pull_request) Successful in 33s
CI / integration_tests (pull_request) Successful in 2m25s
CI / unit_tests (pull_request) Successful in 5m43s
CI / docker (pull_request) Successful in 58s
CI / benchmark-regression (pull_request) Successful in 17m48s
CI / coverage (pull_request) Successful in 19m18s
feat(M4.2): Correction service with revert/append BFS + dry-run
Adds CorrectionRequest, CorrectionResult, CorrectionMode,
CorrectionPatch, CorrectionDryRunReport, CorrectionNotFoundError,
and CorrectionConflictError domain models.

Implements CorrectionService with BFS-based revert (marks decisions
as rolled back and restores via inverse changes) and append mode
(spawns a child correction plan).  Includes request_correction()
with dry-run support and dispatch_correction() convenience method.

33 Behave scenarios, 8 Robot smoke tests, ASV benchmark suite,
and reference documentation.

Ref: Day-14 Rebaseline – M4.2 Decision-correction flows [Jeff]
2026-02-22 16:40:06 +00:00

3.3 KiB
Raw Blame History

Decision Correction Reference

Overview

The correction subsystem allows operators to modify a plan's decision tree after execution by either reverting a subtree of decisions or appending new decisions as a child plan.

Correction Modes

Revert

Invalidates the targeted decision and every descendant reachable via BFS traversal. Associated artifacts are archived and affected child plans are rolled back.

          ┌─── D1 (target) ◄── revert starts here
          │       │
          │    ┌──┴──┐
          │    D2    D3          ← all invalidated
          │          │
          │          D4          ← also invalidated

Append

Preserves the original decision and spawns a new child plan rooted at the target node. The child plan carries the operator's guidance and produces additional decisions without disturbing the existing tree.

          D1 (target)
           │
        ┌──┴──────────┐
        D2 (original)  CP-new   ← child plan appended

Impact Analysis — BFS Algorithm

Impact analysis uses breadth-first search over the decision tree's adjacency list (parent → children mapping):

from collections import deque

def compute_affected_subtree(target_id, tree):
    affected = []
    queue = deque([target_id])
    while queue:
        node = queue.popleft()
        affected.append(node)
        queue.extend(tree.get(node, []))
    return affected

Risk Classification

Affected Count Risk Level
≤ 3 low
4 10 medium
> 10 high

Dry-Run Output

A dry-run report contains:

  • impact — Full CorrectionImpact with affected decisions, files, child plans, estimated cost, and risk level.
  • decisions_to_invalidate — Decision IDs that would be marked invalid (revert mode only).
  • child_plans_to_rollback — Child plans that would be rolled back.
  • estimated_recompute_time_seconds — Wall-clock estimate.
  • warnings — Human-readable cautions (e.g. high risk).

Status Lifecycle

PENDING → ANALYZING → EXECUTING → APPLIED
                                 → FAILED
         PENDING → CANCELLED
         ANALYZING → CANCELLED

Service API

Method Description
request_correction() Create a new correction request
analyze_impact() BFS impact analysis on the decision tree
generate_dry_run_report() Full report without side effects
execute_revert() Invalidate subtree + archive artifacts
execute_append() Spawn child plan preserving original decision
execute_correction() Dispatch to revert or append based on mode
get_correction() Retrieve a correction by ID
list_corrections() List corrections (optional plan_id filter)
list_attempts() List execution attempts for a correction
cancel_correction() Cancel a pending/analyzing correction