Repository navigation
Description
Task
T-083b· Milestone M7 — API · Size S · Priority P0 · Epic #7Implements FR-API-002 · FR-DSH-002
Branch
feat/t-083b-sse-endpoint-with-last-event— one task = one branch = one PR (doc 32 §6)
Summary
Implement api/routers/events.py using sse-starlette: event names/payloads of doc 12 §4, id: = outbox id, Last-Event-ID/last_event_id resume from the events table, : ping every api.sse.ping_interval_s.
Context / motivation
Live console updates (FR-DSH-002: ≤ 2 s latency).
Scope
In scope
- Latency test: insert event → received by client < 2 s (p95 over 50 events).
Implementation guidance
- Router
api/routers/events.py:GET /api/v1/events?campaign_id=&last_event_id=returningsse_starlette.EventSourceResponse(doc 12 §4). - Resume: the
Last-Event-IDheader takes precedence over thelast_event_idquery param; subscribe first, then replay the backlog from the events table, de-duplicating by id, so there is no gap between backlog and live. - Each message:
id: <events.id>,event: <type>,data: <compact JSON>; ping comment everyapi.sse.ping_interval_s(15 s);retry:hint fromapi.sse.retry_ms(new). - Headers:
Cache-Control: no-cache,X-Accel-Buffering: no(nginx, RB-06). - Auth via T-080c (
?token=accepted here only); detect disconnects viarequest.is_disconnected()to release subscriptions. - 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.sse.ping_interval_s- api.sse.retry_ms (new)
Acceptance criteria
- Resume replays missed events exactly once.
- Latency ≤ 2 s.
- Event payload shapes match the doc 12 §4 table (schema test per event type).
- Client disconnect releases its subscription (gauge returns to 0).
- p95 latency ≤ 2 s over 50 events (FR-DSH-002).
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/integration/api/test_sse.py.
Dependencies
Blocked by: #155 (T-083a), #144 (T-080c)
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/events.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-083b (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 §4 · doc 14 §6 · doc 30 §RB-06 · ADR-0011
Requirements: FR-API-002 · FR-DSH-002 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
?token=#144api/openapi.json) + oasdiff breaking-change check + schemathesis nightly #158