Skip to content

[T-084a] API: experiments, comparison, reports (202 job + content) and workers endpoints #157

Closed

Description

@CodewithJha

Task T-084a · Milestone M7 — API · Size S · Priority P1 · Epic #7

Implements FR-API-001 · FR-EXP-002 · FR-DSH-006 · FR-DSH-007

Branch feat/t-084a-api-experiments-comparison-reports-202 — one task = one branch = one PR (doc 32 §6)

Summary

Implement routers/experiments.py (GET/POST /experiments, GET /experiments/{id}, /comparison per doc 12 §3.5), routers/reports.py (POST /reports {kind,id} → 202 job; GET /reports/{id}, /content HTML) and routers/workers.py (GET /workers with heartbeat age).

Context / motivation

Trials screen, report export and Workbench.

Scope

In scope

  • Report jobs run in a background executor; status persisted (reuse analyses-like table or artefact + status row).

Implementation guidance

  • api/routers/experiments.py: GET/POST /experiments (create validates via the experiment planner T-102a, returns 201; execution started through the experiment runner service), GET /experiments/{id} (design cells with per-cell campaign ids and progress), GET /experiments/{id}/comparison returning ExperimentComparison exactly per doc 12 §3.5, produced by the same service the HTML report uses (T-079).
  • api/routers/reports.py: POST /reports {kind: campaign|experiment, id} → 202 {report_id, status_url}; background execution in a bounded executor (api.report_workers, new, default 1); status persisted in a report_jobs table (expand-only migration 0003_report_jobs); GET /reports/{id} status; GET /reports/{id}/content streams the HTML with Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; img-src data: and X-Content-Type-Options: nosniff.
  • api/routers/workers.py: GET /workers → [{id, backend, status, current_run_id, last_heartbeat, heartbeat_age_s, version, host_hash}] (hostnames hashed, TM-15).
  • 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).

  • api.report_workers (new)

Acceptance criteria

  • Comparison JSON matches doc 12 §3.5 schema.
  • Report job lifecycle tested.
  • Report job survives API restart (status persisted; stale RUNNING jobs marked ERROR on startup).
  • Comparison JSON equals the data embedded in the HTML report for the same experiment (test).
  • Hostnames never returned in clear.
  • 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_experiments_reports_workers.py.

Dependencies

Blocked by: #147 (T-081b), #109 (T-102b), #140 (T-078b), #141 (T-079)

Blocks: #158 (T-084b), #183 (T-113b)

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/experiments.py
  • backend/src/roboprobe/api/routers/reports.py
  • backend/src/roboprobe/api/routers/workers.py

Independent files.

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-084a (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 §2 · doc 12 §3.5 · doc 13 §3.7 · doc 13 §3.8 · doc 31 §3 · doc 33 §5

Requirements: FR-API-001 · FR-EXP-002 · FR-DSH-006 · FR-DSH-007 (traceability: doc 28)

Activity

  1. added this to the M7 — API milestone on Nov 19, 2026
  2. added
    area:experimentsExperiment runner and EXP-xx protocols
    area:apiREST + SSE API (FastAPI)
    priority:P1Required for milestone exit
    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:experimentsExperiment runner and EXP-xx protocolsmilestone:M7M7 — APIpriority:P1Required for milestone exitsize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions