# Step 3: device-oom-policy

## Read First
- /AGENTS.md
- /PLAN.md
- /PROGRESS.md
- /docs/HARNESS.md
- /docs/IMPLEMENTATION_PLAN.md
- /docs/ARCHITECTURE.md
- /docs/CONVERSION_POLICY.md
- /docs/TOOLCHAIN.md
- /phases/1-core-runtime-contracts/step1.md

## Task
Implement runtime device selection, CUDA fail-fast behavior, auto CPU fallback behavior, and OOM retry policy hooks.

This step should be tested with mocks and small CUDA smoke checks only where safe.

## Sprint Contract
- Done means: runtime policy enforces explicit CUDA fail-fast, auto fallback warning, and configurable OOM retry reductions.
- Hard thresholds: no silent CPU fallback for explicit CUDA; tests do not require exhausting VRAM; GTX 1070 Ti constraints remain documented.
- Files owned: `src/pdftomd/runtime.py`, tests, `docs/TOOLCHAIN.md` if behavior changes, `PROGRESS.md`, phase index.
- Dependencies: Runtime config options.

## Acceptance Criteria
```powershell
python scripts\validate_workspace.py
.\venv\python.exe -m pytest tests
```

## Verification
1. Run the acceptance commands.
2. Confirm CUDA smoke test instructions still work separately.
3. Update `PROGRESS.md` and this phase index.

## Do Not
- Do not intentionally trigger real GPU OOM in tests.
- Do not change PyTorch pins without updating `docs/TOOLCHAIN.md`.
- Do not hide runtime warnings.
