# Step 22: Result Recovery Modules

## 담당 역할과 필수 스킬

- 담당 역할: `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 17 generic ResultRecovery files
- `/include/fesa/results/result_records.h`
- `/include/fesa/analysis/analysis_state.h`
- `/src/fesa/results/result_recovery.cpp`
- `/tests/unit/results/result_recovery_test.cpp`
- `/src/fesa/CMakeLists.txt`, `/tests/CMakeLists.txt`
- `/phases/cpp-object-oriented-modular-refactoring/index.json`
- `/phases/cpp-object-oriented-modular-refactoring/step22.md`

## 작업

Requirement `R-MODULE-001`의 recovery split을 구현한다.

1. `/tests/unit/results/result_recovery_components_test.cpp`를 먼저 추가한다.
   `C-MODULE-002` directly tests candidate creation/validation for global equilibrium, beam rows,
   shell rows and all-or-nothing commit, including a later-invalid bundle rollback.
2. Missing component headers/symbols provides RED.
3. Keep `ResultRecovery` as public facade. Candidate private modules:

```text
recovery_candidate.h/.cpp          owns all mutable candidate rows/evidence before commit
global_equilibrium_recovery.h/.cpp computes K*d-F, reactions, free residual and global moments
beam_result_recovery.h/.cpp        validates/orders distinct beam result identities
shell_result_recovery.h/.cpp       validates/orders physical shell rows and energy
analysis_state_commit.h/.cpp       validates complete candidate and atomically updates state
```

4. Private functions return `Status`/`Result<T>` and do not mutate `AnalysisState` until the final
   commit module succeeds.
5. Preserve exact B33 endpoint/section/Gauss/stress distinctions, MITC4 GP/stress ordering,
   drilling exclusion, equilibrium scale rules and global origin.
6. Reduce `result_recovery.cpp` to facade orchestration without changing public behavior.

## Acceptance Criteria

```powershell
cmake --build .harness/build --config Debug --target fesa_unit_tests
ctest --test-dir .harness/build -C Debug `
  -R "ResultRecovery|ResultRecoveryComponents|AnalysisState" --output-on-failure
$componentFiles = @(
  "src/fesa/results/recovery_candidate.cpp",
  "src/fesa/results/global_equilibrium_recovery.cpp",
  "src/fesa/results/beam_result_recovery.cpp",
  "src/fesa/results/shell_result_recovery.cpp",
  "src/fesa/results/analysis_state_commit.cpp"
)
foreach ($componentFile in $componentFiles) {
  if (-not (Test-Path -LiteralPath $componentFile -PathType Leaf)) {
    throw "Missing recovery component: $componentFile"
  }
}
rg -n "GlobalEquilibriumRecovery|BeamResultRecovery|ShellResultRecovery|Commit" `
  src/fesa/results/result_recovery.cpp
& "C:/Program Files/LLVM/bin/clang-format.exe" --dry-run --Werror `
  (rg --files src/fesa/results -g "*.h" -g "*.cpp") `
  tests/unit/results/result_recovery_test.cpp `
  tests/unit/results/result_recovery_components_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 missing components, focused sign/order/rollback, facade wiring and full CTest를 summary에 기록한다.
- Any identity/sign/atomicity regression is `error`.
- 성공 시 현재 Step만 `completed`로 갱신한다.
- timestamp, retry, commit, advancement는 Executor 소유다.

## 금지사항

- Result rows를 station mismatch 평균으로 합치지 마라.
- Failed candidate에서 partial AnalysisState를 commit하지 마라.
- HDF5 concerns를 recovery components에 넣지 마라.
- 직접 commit하거나 hook script를 수동 실행하지 마라.
