Skip to content

[T-081e] API: trace endpoint (downsampled JSON / Parquet) and artefact list/download with path safety #150

Closed

Description

@CodewithJha

Task T-081e · Milestone M7 — API · Size S · Priority P0 · Epic #7

Implements 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.parquet streams the stored Parquet (FileResponse).
  • Downsampling (api/downsample.py, pure): bucket by 1/hz; per bucket keep the sample with minimal min_obstacle_dist plus any sample where a violation flag flips, so clearance minima and first violations are never lost; hz bounded by api.trace_max_hz (new, default 50).
  • Router api/routers/artifacts.py: GET /runs/{id}/artifacts → [{id, kind, size, sha256, media_type}]; GET /artifacts/{aid}/content resolves via ArtifactStore.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.
  • hz above limit clamped and truncated reported.
  • DB row pointing outside the root → 404 NOT_FOUND plus 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 Unreleased updated 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.py
  • backend/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)

Activity

  1. added this to the M7 — API milestone on Nov 19, 2026
  2. added
    area:apiREST + SSE API (FastAPI)
    area:securitySecurity hardening, supply chain
    priority:P0Critical path / blocks others
    taskChild task of a milestone epic
    on Nov 19, 2026
  3. added a commit that references this issue on Nov 21, 2026
    8d75b7c
  4. CodewithJha commented on Nov 22, 2026

    @CodewithJha
    OwnerAuthor

    Shipped on main (merged PR).

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:apiREST + SSE API (FastAPI)area:securitySecurity hardening, supply chainmilestone:M7M7 — APIpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions