Skip to content

[T-011c] Transactional outbox: events table writes + NOTIFY on commit #63

Closed

Description

@CodewithJha

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

Implements FR-API-002 · FR-STO-001

Branch feat/t-011c-transactional-outbox-events-table-writes — one task = one branch = one PR (doc 32 §6)

Summary

Implement UnitOfWork.notify() / EventRepo.append(topic, campaign_id, payload) so every state-changing transaction appends to events and issues NOTIFY roboprobe_events, '<event id>' in the same transaction (outbox pattern).

Context / motivation

Reliable live updates (SSE, ≤ 2 s) and an append-only audit trail (doc 31 TM-12) both depend on events that can't be lost or emitted for rolled-back data.

Scope

In scope

  • store/repositories/events.py: append, since(last_id, campaign_id, limit).
  • Topic constants: campaign.updated, run.started, run.finished, mode.discovered, analysis.finished, worker.updated, alert (doc 12 §4) with payload pydantic models in store/events.py.
  • pg_notify(channel, id) executed within the transaction (delivered on commit); channel from database.notify_channel.

Out of scope

  • API-side listener/SSE hub (T-083a)

Implementation guidance

  • Payloads must be small (ids + counters); clients fetch details via REST. Event ids are bigserial and double as SSE ids.
  • 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.notify_channel

Acceptance criteria

  • Rolled-back transaction produces neither an event row nor a notification.
  • LISTEN connection receives the id after commit (integration test).
  • since() returns events in id order (gap-free recovery when NOTIFY is missed).
  • 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_outbox.py.

Dependencies

Blocked by: #61 (T-011a)

Blocks: #87 (T-042b), #155 (T-083a)

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/repositories/events.py
  • backend/src/roboprobe/store/events.py

Independent of T-011b/T-012.

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-011c (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 11 §4 · doc 12 §4 · doc 14 §6 · doc 34 §4 · ADR-0011

Requirements: FR-API-002 · FR-STO-001 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:storagePostgres schema, repositories, artifactsmilestone:M3M3 — Oracles + runner + storepriority:P1Required for milestone exitsize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions