Skip to content

[T-011a] UnitOfWork + repositories: spaces, SUT profiles, campaigns, runs, oracle results, strategy states #61

Closed

Description

@CodewithJha

Task T-011a · Milestone M3 — Oracles + runner + store · Size M · Priority P0 · Epic #3

Implements FR-STO-001 · NFR-EXT-001

Branch feat/t-011a-unitofwork-repositories-spaces-sut-profiles — one task = one branch = one PR (doc 32 §6)

Summary

Implement the Repository + Unit-of-Work pattern of doc 05 §9 for the campaign-execution aggregates, returning core.types/DTO models (never ORM objects).

Context / motivation

The runner, API and analysis all persist through these interfaces. Defining them as Protocols (ports) with a SQLAlchemy implementation keeps the store swappable (doc 11 §1).

Scope

In scope

  • Ports: backend/src/roboprobe/store/ports.py — UnitOfWork Protocol and repository Protocols (SpaceRepo, SutProfileRepo, CampaignRepo, RunRepo, …) with pre/post-condition docstrings.
  • backend/src/roboprobe/store/uow.py: SqlAlchemyUnitOfWork(session_factory) context manager with commit/rollback.
  • store/repositories/{spaces,sut_profiles,campaigns,runs,oracle_results,strategy_states}.py.
  • Record models for persistence boundaries (CampaignRecord, RunRecord, …) in store/records.py (frozen pydantic).
  • Keyset pagination helper (limit, cursor) -> Page[T] used by list methods (doc 12 §1).

Out of scope

  • Modes/risk/analyses/experiments/workers/artifacts repos (T-011b)
  • Outbox events & NOTIFY (T-011c)
  • Queue claim/reap (T-012)

Implementation guidance

  • RunRepo.insert_batch(runs) must rely on the unique (campaign_id, ordinal, repeat_index) constraint so orchestrator ticks are idempotent (doc 34 §8).
  • RunRepo.history(campaign_id) -> list[Observation] (non-INVALID first-class) is used by strategies — make it efficient (single query, ordered by ordinal).
  • Sessions are never shared across threads (doc 34 §8): UoW creates a session per with block.
  • Pool size/statement timeout from DatabaseSettings.
  • 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).

  • database.url
  • database.pool_size
  • database.statement_timeout_ms

Acceptance criteria

  • Repositories return immutable records, never ORM instances (type-checked).
  • UoW rolls back on exception and commits on success.
  • Keyset pagination stable under concurrent inserts.
  • Repository contract tests (T-015) pass against this implementation.
  • 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/integration/store/test_repositories_campaign_run.py.

Dependencies

Blocked by: #60 (T-010b)

Blocks: #62 (T-011b), #63 (T-011c), #64 (T-012), #65 (T-015), #85 (T-041a), #93 (T-039b), #89 (T-045a), #104 (T-100a), #105 (T-100b), #126 (T-070a), #142 (T-080a)

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/store/ports.py
  • backend/src/roboprobe/store/uow.py
  • backend/src/roboprobe/store/records.py
  • backend/src/roboprobe/store/repositories/{spaces,sut_profiles,campaigns,runs,oracle_results,strategy_states}.py

T-011b adds sibling repository modules and appends attributes to the UoW; coordinate by merging T-011a first.

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-011a (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 05 §9 · doc 11 §1 · doc 11 §4 · doc 34 §4 · doc 34 §7 · doc 34 §8 · doc 12 §1

Requirements: FR-STO-001 · NFR-EXT-001 (traceability: doc 28)

External:

Activity

  1. added
    area:storagePostgres schema, repositories, artifacts
    priority:P0Critical path / blocks others
    milestone:M3M3 — Oracles + runner + store
    taskChild task of a milestone epic
    on Nov 19, 2026
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:storagePostgres schema, repositories, artifactsmilestone:M3M3 — Oracles + runner + storepriority:P0Critical path / blocks otherssize:M1-3 daystaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions