# NFT-RES-03 — Monte Carlo statistical envelope

**Task**: AZ-434_nft_res_03_monte_carlo
**Name**: 100-iteration Monte Carlo with seeded perturbations; 95th-percentile error within 1.96 × cov_semi_major_m (AC-NEW-4)
**Description**: Implement NFT-RES-03 — Tier-1 OR Tier-2; 100 Derkachi replays with seeded perturbations (gain noise, IMU bias, frame-drop, outlier injection); per-iteration record per-frame error + cov_semi_major_m; statistical envelope assertion.
**Complexity**: 5 points
**Dependencies**: AZ-406, AZ-407, AZ-408
**Component**: Blackbox Tests / Resilience (epic AZ-262)
**Tracker**: AZ-434
**Epic**: AZ-262 (E-BBT)

## Problem

A single deterministic run does not validate the SUT's statistical envelope. AC-NEW-4 requires a 100-iteration Monte Carlo with multiple perturbation sources to verify that the reported covariance is *honest* — i.e., the actual error distribution stays within the cov-derived envelope at the 95th percentile.

## Outcome

- pytest scenario at `e2e/tests/resilience/test_nft_res_03_monte_carlo.py`. Tier-1 OR Tier-2.
- 100 Derkachi replays at randomized seed (gain noise, IMU bias, frame-drop pattern, outlier-injection schedule all seeded from a master seed).
- Per iteration: per-frame `error_m` + `cov_semi_major_m`; aggregated globally across 100 × N_frames.
- Assertion: `count(error_m ≤ 1.96 × cov_semi_major_m) / total ≥ 0.95` (95th-percentile envelope).

## Scope

### Included
- 100 iterations driven by the runner.
- Seeded perturbation generation.
- Aggregate envelope assertion.

### Excluded
- Per-component unit-level Monte Carlo — out of scope (unit tests).

## Acceptance Criteria

**AC-1: 100 iterations**
Given the test runs
Then 100 Derkachi replay iterations complete; partial completion is a hard failure (no early-return).

**AC-2: seeded perturbations**
Given the master seed
Then re-running with the same master seed produces bit-identical iteration outcomes (deterministic).

**AC-3: 95th-percentile envelope**
Given the global aggregate of 100 × N_frames samples
Then `count(error_m ≤ 1.96 × cov_semi_major_m) / total ≥ 0.95`.

**AC-4: parameterization**
Given conftest parameterization
Then the scenario runs per `(fc_adapter, vio_strategy)`. Note: 100 iterations × 4 parameterizations is expensive — the runner SHOULD run only one canonical parameterization per CI invocation by default and surface "full-matrix" mode behind an env flag.

## System Under Test Boundary

End-to-end through public boundaries.

- **Allowed**: per-iteration runner orchestration (Docker / systemd lifecycles); per-frame outbound stream + cov_semi_major_m.
- **Forbidden**: mocking C1-C5 to control the per-iteration error directly.

## Constraints

- 100 iterations × 8 min Derkachi replay = ≥800 min on Tier-1; the runner uses parallel Docker compose stacks (4 × 200 min) when CI host has the capacity. Tier-2 (Jetson) iterations run sequentially.
- Master seed is recorded in the evidence bundle for reproducibility.

## Document Dependencies

- `_docs/02_document/tests/resilience-tests.md` § NFT-RES-03
- `_docs/02_document/tests/test-data.md` § Resilience (NFT-RES-03 row)
