Repository navigation
Description
Task
T-081e· Milestone M7 — API · Size S · Priority P0 · Epic #7Implements FR-DSH-005 · FR-STO-002 · NFR-SEC-003
Branch
feat/t-081e-api-trace-endpoint-downsampled-json— one task = one branch = one PR (doc 32 §6)
Summary
Implement GET /runs/{id}/trace?hz=10 (server-side downsampling, JSON columns) or Parquet via Accept: application/vnd.apache.parquet, GET /runs/{id}/artifacts, GET /artifacts/{aid}/content (streamed, by id only).
Context / motivation
Feeds the trajectory plot/timelines; artefact download is a path-traversal surface (TM-04).
Scope
In scope
- Streaming responses with correct media types and
Content-Disposition.
Implementation guidance
- Router
api/routers/traces.py:GET /runs/{id}/trace?hz=10&columns=...→ JSON{t: [...], columns: {name: [...]}, hz, source_hz, truncated}; content negotiation:Accept: application/vnd.apache.parquetstreams the stored Parquet (FileResponse). - Downsampling (
api/downsample.py, pure): bucket by1/hz; per bucket keep the sample with minimalmin_obstacle_distplus any sample where a violation flag flips, so clearance minima and first violations are never lost;hzbounded byapi.trace_max_hz(new, default 50). - Router
api/routers/artifacts.py:GET /runs/{id}/artifacts→[{id, kind, size, sha256, media_type}];GET /artifacts/{aid}/contentresolves viaArtifactStore.path(ref), which enforces confinement (resolved.is_relative_to(root), T-013a) — never accept a path parameter. - Headers:
Content-Disposition: attachment; filename="<run_ordinal>-<kind>.<ext>"(sanitised),X-Content-Type-Options: nosniff,ETag= SHA-256. - 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.trace_max_hz (new)
Acceptance criteria
- Downsampled trace has requested rate and preserves contact/violation samples.
- Traversal attempts impossible (ids only) — test with crafted DB row pointing outside root → 404/500 handled safely.
- Downsampling property test: global min clearance of output equals the input's.
-
hzabove limit clamped andtruncatedreported. - DB row pointing outside the root → 404
NOT_FOUNDplus a security log event. - 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/api/test_trace_artifacts.py.
Dependencies
Blocked by: #149 (T-081d), #66 (T-013a), #47 (T-018)
Blocks: #158 (T-084b), #161 (T-109)
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/artifacts.pybackend/src/roboprobe/api/routers/traces.py
Independent files.
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-081e (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 §2 · doc 12 §7 · doc 11 §6 · doc 31 §3 · doc 18 §4.9
Requirements: FR-DSH-005 · FR-STO-002 · NFR-SEC-003 (traceability: doc 28)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
api/openapi.json) + oasdiff breaking-change check + schemathesis nightly #158feat(api): stream safe artifacts and preserve trace events (T-081e) (#…
CodewithJha commentedon Nov 22, 2026
Shipped on main (merged PR).