Skip to content

[T-041c] Campaign lifecycle state machine and commands (start/pause/resume/cancel) #79

Closed

Description

@CodewithJha

Task T-041c · Milestone M3 — Oracles + runner + store · Size S · Priority P0 · Epic #3

Implements FR-RUN-001 · FR-DSH-002

Branch feat/t-041c-campaign-lifecycle-state-machine-and — one task = one branch = one PR (doc 32 §6)

Summary

Implement runner/lifecycle.py: explicit transition table for CampaignStatus (doc 14 §3, doc 12 §5) with idempotent commands and ConflictError(CAMPAIGN_INVALID_TRANSITION) on illegal transitions.

Context / motivation

API, CLI and the orchestrator all mutate campaign state; one tested state machine prevents inconsistent behaviour (doc 34 §4 State machine pattern).

Scope

In scope

  • transition(current, command) -> new_status pure function + table.
  • Idempotency: :pause on PAUSED is a no-op success.
  • CampaignService application service (uses UoW port): start/pause/resume/cancel/mark_analyzing/complete/fail, emitting campaign.updated events and campaign.state_changed logs; cancel marks PENDING runs CANCELLED.

Implementation guidance

  • Pure table in domain-ish application code; persistence through the UoW Protocol (fakes from T-015 in unit tests).
  • 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

  • Every allowed/forbidden transition from doc 12 §5 + doc 14 §3 covered by a parametrised test.
  • Cancel cancels PENDING runs in the same transaction.
  • 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/unit/runner/test_lifecycle.py.

Dependencies

Blocked by: #15 (T-002a), #16 (T-002b)

Blocks: #85 (T-041a), #147 (T-081b)

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/runner/lifecycle.py

Independent of the queue/worker tasks.

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-041c (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 14 §3 · doc 12 §5 · doc 34 §4 · doc 34 §6

Requirements: FR-RUN-001 · FR-DSH-002 (traceability: doc 28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runnerQueue, workers, campaign orchestrationmilestone:M3M3 — Oracles + runner + storepriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions