# Step 17: Generic ResultRecovery

## 담당 역할과 필수 스킬

- 담당 역할: `implementation-agent`
- 필수 스킬: `harness`, `fesa-cpp-msvc-tdd`
- 이 Step만 `RED -> observed failure -> minimal GREEN -> focused/full VERIFY`로 수행한다.

## 읽어야 할 파일

- `/AGENTS.md`
- `/docs/CODINGSTYLE.md`
- `/docs/ARCHITECTURE.md`
- `/docs/ADR.md`
- `/docs/linear-static-3d-euler-beam/formulation.md`
- `/docs/linear-static-mitc4-shell/formulation.md`
- `/docs/linear-static-3d-euler-beam/io.md`
- `/docs/linear-static-mitc4-shell/io.md`
- `/docs/cpp-object-oriented-modular-refactoring/implementation-plan.md`
- Step 14 `ElementResultBundle` contract
- Step 15 DofManager and Step 16 assembly files
- `/include/fesa/results/result_recovery.h`, `/src/fesa/results/result_recovery.cpp`
- `/include/fesa/results/result_records.h`, `/include/fesa/analysis/analysis_state.h`
- matching result/element unit tests
- `/phases/cpp-object-oriented-modular-refactoring/index.json`
- `/phases/cpp-object-oriented-modular-refactoring/step17.md`

## 작업

Requirement `R-PIPELINE-001`의 recovery portion을 구현한다.

1. `result_recovery_test.cpp`에 `C-RECOVERY-001`을 먼저 추가한다. A fake Element returns a
   valid backend-neutral bundle and a failing bundle; tests verify stable insertion and whole-state
   rollback without knowing a concrete element kind.
2. Current concrete B33/MITC4 branches fail the generic test, providing RED.
3. Candidate facade call:

```cpp
Status ResultRecovery::Recover(
    const AnalysisModel& analysis_model,
    const ElementView& elements,
    const DofManager& dof_manager,
    const SparseMatrix& full_stiffness,
    const Vector& full_displacement,
    const Vector& full_external_force,
    AnalysisState& state) const;
```

4. Elements own element-local physical recovery; ResultRecovery owns full residual, reactions,
   free equilibrium, stable bundle aggregation, cross-element/global evidence and atomic commit.
5. Beam end action, positive-local-x section resultant, Gauss generalized results and section-point
   stress remain distinct rows. Shell physical recovery excludes drilling energy/results.
6. Remove B33/MITC4 kind branches from the facade. Distinct bundle variant/collections may be
   visited without downcasting the Element itself.

## Acceptance Criteria

```powershell
cmake --build .harness/build --config Debug --target fesa_unit_tests
ctest --test-dir .harness/build -C Debug `
  -R "ResultRecovery|AnalysisState|EulerBeam3D|Mitc4Shell" --output-on-failure
$typeBranches = @(rg -n "EulerBeam3D|Mitc4Shell" src/fesa/results/result_recovery.cpp)
if ($typeBranches.Count -ne 0) { $typeBranches; throw "Concrete element branch remains" }
& "C:/Program Files/LLVM/bin/clang-format.exe" --dry-run --Werror `
  include/fesa/results/result_recovery.h `
  src/fesa/results/result_recovery.cpp `
  tests/unit/results/result_recovery_test.cpp
cmake --build .harness/build --config Debug
ctest --test-dir .harness/build -C Debug --show-only=json-v1
ctest --test-dir .harness/build -C Debug --output-on-failure
```

## 검증 및 상태 갱신

- RED generic bundle, identity/sign/rollback tests, branch scan and full CTest를 summary에 기록한다.
- Row merge/average, sign, energy or atomicity regression is `error`.
- 성공 시 현재 Step만 `completed`로 갱신한다.
- timestamp, retry, commit, advancement는 Executor 소유다.

## 금지사항

- Different result locations를 average/merge하지 마라.
- Drilling stabilization을 physical shell results에 포함하지 마라.
- HDF5 schema or writer를 수정하지 마라.
- 직접 commit하거나 hook script를 수동 실행하지 마라.
