Skip to content

[T-082b] API: risk summary and slice endpoint (/risk, /risk/slice?x=&y=&anchor=&resolution=) #152

Closed

Description

@CodewithJha

Task T-082b · Milestone M7 — API · Size S · Priority P0 · Epic #7

Implements 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; DTOs RiskSummaryDTO (volumes with Wilson CIs, robustness_score, analysis_id, computed_at) and RiskSliceDTO exactly per doc 12 §3.4 (axes in physical units, log_x/log_y, p_fail grid, region grid, evaluated points: [{x, y, verdict, run_id}]).
  • Slice computation: load the GP state from the latest analysis artefact (or refit via RobustnessGP if missing, guarded by api.slice_timeout_s, new), build RiskMapper, call slice(x, y, anchor, resolution); anchor parsing nominal | mode:FM-02 (→ medoid values).
  • Cache: in-process LRU keyed by (analysis_id, x, y, anchor, resolution) sized by api.slice_cache_size (new); CPU work runs in a threadpool (run_in_threadpool) to keep the event loop free.
  • resolution bounded 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 Unreleased updated 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.py
  • backend/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)

Activity

  1. added this to the M7 — API milestone on Nov 19, 2026
  2. added
    area:riskRisk maps and estimates
    area:apiREST + SSE API (FastAPI)
    priority:P0Critical path / blocks others
    taskChild task of a milestone epic
    on Nov 19, 2026
  3. CodewithJha commented on Nov 22, 2026

    @CodewithJha
    OwnerAuthor

    Shipped on main (merged PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiREST + SSE API (FastAPI)area:riskRisk maps and estimatesmilestone:M7M7 — APIpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions