Skip to content

[T-081d] API: runs list (filters, keyset) / detail / manual runs #149

Closed

Description

@CodewithJha

Task T-081d · Milestone M7 — API · Size S · Priority P0 · Epic #7

Implements FR-API-001 · FR-DSH-005

Branch feat/t-081d-api-runs-list-filters-keyset — one task = one branch = one PR (doc 32 §6)

Summary

Implement api/routers/runs.py: GET /campaigns/{id}/runs (filters status, verdict, phase, failure_class, tag; sort), POST /campaigns/{id}/runs (manual runs {values, repeats, tags} → phase=manual, priority 10), GET /runs/{id} (doc 12 §3.3 incl. oracle results, metrics, manifest, mode).

Context / motivation

Run Entry screen and 'Probe here' from the Risk Atlas (UC-05).

Scope

In scope

  • Run DTO exactly as doc 12 §3.3.

Implementation guidance

  • Router api/routers/runs.py; DTOs api/schemas/runs.py (RunSummary for lists, Run detail per doc 12 §3.3).
  • List filters: status, verdict, phase, failure_class, tag (repeatable); sort ∈ {ordinal, -ordinal, finished_at, -finished_at, robustness, -robustness}; keyset via the T-080d helper; indexes from doc 11 §3 — add missing ones through an expand-only migration if the query plan shows sequential scans.
  • Manual runs POST /campaigns/{id}/runs body {values: {param: physical_value}, repeats ≤ runner.max_manual_repeats (new), tags: [str]}; validate via ScenarioSpace.validate_values (bounds, constraints, pins) → enqueue phase=MANUAL, priority=runner.manual_priority (new, default 10); 201 with created run ids; Idempotency-Key honoured.
  • Detail loads oracle results and artefact refs with selectinload (no N+1; assert query count ≤ 4 using a SQLAlchemy event counter).
  • 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).

  • runner.max_manual_repeats (new)
  • runner.manual_priority (new)
  • api.page_limit_default
  • api.page_limit_max

Acceptance criteria

  • Filter/sort/pagination tests; manual run validation (bounds/constraints).
  • p95 < 200 ms at 10 000 runs (verified in T-106).
  • Query-count test passes.
  • Manual run on a pinned parameter with a different value → 422 with pointer.
  • Sorting stable with ties (id as tiebreaker).
  • 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_runs.py.

Dependencies

Blocked by: #147 (T-081b)

Blocks: #150 (T-081e), #153 (T-082c), #160 (T-106)

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/runs.py
  • backend/src/roboprobe/api/schemas/runs.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-081d (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.3 · doc 12 §2 · doc 12 §7 · doc 03 §UC-05 · doc 11 §3

Requirements: FR-API-001 · FR-DSH-005 (traceability: doc 28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiREST + SSE API (FastAPI)milestone: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