Skip to content

[T-081c] API: campaign lifecycle commands (:start|:pause|:resume|:cancel) and /progress #148

Closed

Description

@CodewithJha

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

Implements FR-API-001 · FR-DSH-002

Branch feat/t-081c-api-campaign-lifecycle-commands-and — one task = one branch = one PR (doc 32 §6)

Summary

Implement api/routers/campaign_commands.py with colon-suffixed custom-method routes returning 202 + updated Campaign (idempotent), and GET /campaigns/{id}/progress (counters + discovery-curve points).

Context / motivation

US-012 controls from the console; semantics in doc 12 §5.

Scope

In scope

  • NO_WORKERS warning-level problem when starting without online workers (doc 12 §1.1).

Implementation guidance

  • Router api/routers/campaign_commands.py with routes registered literally, e.g. @router.post("/campaigns/{campaign_id}:start") (doc 12 §2 note); add a regression test proving Starlette matches the colon path.
  • Delegate to the lifecycle state machine from T-041c (CampaignLifecycle.apply(campaign_id, Command)); return 202 with the updated Campaign DTO; a repeated command in the target state ⇒ 202 no-op (doc 12 §5).
  • :start when no online worker supports the backend still transitions to RUNNING but adds warnings: [{code: "NO_WORKERS", …}] to the body (doc 12 §1.1 "warning-level"); the orchestrator raises the NO_WORKERS alert after 60 s (doc 21 §5.5).
  • GET /campaigns/{id}/progress: counters by status/verdict, current phase, discovery_curve: [{run_ordinal, unique_modes}] computed from runs ordered by ordinal and mode assignment (cached per analysis id).
  • 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.

Acceptance criteria

  • Transition tests (valid, idempotent, invalid → 409 CAMPAIGN_INVALID_TRANSITION).
  • Progress endpoint matches DB counts.
  • Allowed-from table of doc 12 §5 fully covered (parametrised test, 4 commands × 7 states).
  • Progress counts equal SQL ground truth on the seed dataset.
  • 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_campaign_commands.py.

Dependencies

Blocked by: #147 (T-081b)

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/campaign_commands.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-081c (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 §5 · doc 12 §2 · doc 14 §3 · doc 12 §1.1 · doc 21 §5.5

Requirements: FR-API-001 · FR-DSH-002 (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