Repository navigation
Description
Task
T-082b· Milestone M7 — API · Size S · Priority P0 · Epic #7Implements FR-API-001 · FR-DSH-004
Branch
feat/t-082b-api-risk-summary-and-slice— one task = one branch = one PR (doc 32 §6)
Summary
Implement api/routers/risk.py: latest volumes + robustness score; slice JSON per doc 12 §3.4 incl. evaluated points; anchors nominal or mode:FM-02; computed on demand from the stored GP state or cached .npz slices.
Context / motivation
Risk Atlas (UC-05).
Scope
In scope
- Cache slices keyed by (analysis_id, pair, anchor, resolution).
Implementation guidance
- Router
api/routers/risk.py; DTOsRiskSummaryDTO(volumeswith Wilson CIs,robustness_score,analysis_id,computed_at) andRiskSliceDTOexactly per doc 12 §3.4 (axes in physical units,log_x/log_y,p_failgrid,regiongrid, evaluatedpoints: [{x, y, verdict, run_id}]). - Slice computation: load the GP state from the latest analysis artefact (or refit via
RobustnessGPif missing, guarded byapi.slice_timeout_s, new), buildRiskMapper, callslice(x, y, anchor, resolution); anchor parsingnominal|mode:FM-02(→ medoid values). - Cache: in-process LRU keyed by
(analysis_id, x, y, anchor, resolution)sized byapi.slice_cache_size(new); CPU work runs in a threadpool (run_in_threadpool) to keep the event loop free. resolutionbounded to[10, risk.max_slice_resolution](new, default 100) — TM-13.- Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
risk.slice_resolution- risk.max_slice_resolution (new)
- api.slice_timeout_s (new)
- api.slice_cache_size (new)
Acceptance criteria
- Slice shape/axes correct; points overlay included.
- Invalid params → 422.
- Unknown parameter or
x == y→ 422. - Cached second call ≥ 10× faster (timing assertion with margin).
- Event loop not blocked (concurrent health check responds during slice computation).
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/api/test_risk.py.
Dependencies
Blocked by: #147 (T-081b), #136 (T-077)
Blocks: #158 (T-084b)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/api/routers/risk.pybackend/src/roboprobe/api/schemas/risk.py
Independent file.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-082b (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 12 §3.4 · doc 09 §5.3 · doc 03 §UC-05 · doc 31 §3
Requirements: FR-API-001 · FR-DSH-004 (traceability: doc 28)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
CampaignCreatevalidation #147api/openapi.json) + oasdiff breaking-change check + schemathesis nightly #158feat(api): version mode edits, serve risk slices and persist report j…
CodewithJha commentedon Nov 22, 2026
Shipped on main (merged PR).
feat(api): complete risk, replay and durable reports (T-082/T-084) (#318