Skip to content

feat(sketch-db): Phase 5d — HTTP endpoints for backfill lifecycle - #30

Merged
zzylol merged 1 commit into
mainfrom
sketchdb/phase5d-backfill-http
Apr 17, 2026
Merged

zzylol merged 1 commit into
mainfrom
sketchdb/phase5d-backfill-http

Conversation

@zzylol

@zzylol zzylol commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Operator + controller-facing HTTP surface for §10.2 backfill jobs.

Method Path Purpose
POST /api/v1/db/backfill Create queued job, returns 201 + {job_id}
GET /api/v1/db/backfill/jobs List with optional ?status= filter
GET /api/v1/db/backfill/jobs/:id Detail (progress, timestamps, error_message)
DELETE /api/v1/db/backfill/jobs/:id Cancel non-terminal job

Consistent shape with PR #23 / PR #25: 503 when registry isn't attached, 400 on bad body / inverted range, 404/409 as appropriate. JSON response wrapped in {status: "success"|"error", ...}.

Wire-up

  • HttpServer::with_backfill_registry() builder.
  • main.rs always creates a fresh Arc<BackfillRegistry> and attaches it — no CLI flag needed. Without Phase 5e's worker, jobs stay Queued but are inspectable + cancelable (shadow-mode for the DC controller's REFRESH dispatch logic).

Test plan

  • 5 integration tests: full lifecycle (POST → GET one/list/filtered → DELETE → 409 on re-DELETE), inverted range → 400, unknown id → 404, every endpoint 503 without registry, bogus status filter → 400.
  • 625 lib tests (up from 620).
  • clippy + fmt clean.

Next phase

5e: real WindowProcessor builds target sketch from raw samples + writes per-window precomputes through the §6.3 barrier. After 5e, POSTing a job actually rebuilds history.

🤖 Generated with Claude Code

Operator + controller-facing HTTP surface for §10.2 backfill jobs.
Endpoints return a stable JSON shape so the DC controller can
POST jobs + poll progress without attaching a debugger, and the
`/jobs/:id` detail is the same data Phase 5f's coverage tracker
will consult.

## New endpoints

| Method | Path | Purpose |
|---|---|---|
| POST   | `/api/v1/db/backfill`         | Create a queued job. Body `{agg_id, start_ms, end_ms, source, windows_total}`. Returns 201 with `{job_id}`. |
| GET    | `/api/v1/db/backfill/jobs`    | List, optional `?status=queued|running|complete|failed|cancelled|all` filter. Sorted by job_id. |
| GET    | `/api/v1/db/backfill/jobs/:id`| Detail (including `progress`, `windows_done`, timestamps, and any `error_message`). |
| DELETE | `/api/v1/db/backfill/jobs/:id`| Cancel non-terminal job. 200 on success, 404 unknown, 409 if already terminal. |

Consistent with the §15.2/§15.3 endpoints from PR #23 / PR #25:
- 503 when `HttpServer` wasn't built with `with_backfill_registry`.
- 400 on malformed body or inverted range.
- Response JSON tagged `{status: "success"|"error", ...}`.

## Wire-up

* `HttpServer` gains `with_backfill_registry()` alongside
  `with_schemas()` / `with_hot_reload_config()`.
* `AppState` carries an `Option<Arc<BackfillRegistry>>` so each
  handler can bail to 503 cleanly when the registry isn't
  attached.
* `main.rs` always creates a fresh `Arc<BackfillRegistry>` and
  attaches it — no CLI flag required. Without Phase 5e's worker
  pool, jobs stay `Queued` forever but are still visible + can be
  cancelled, which is useful shadow-mode for validating the DC
  controller's REFRESH dispatch logic before the worker arrives.

## Test plan

- [x] 5 new integration tests:
  * Full lifecycle: POST → GET one → GET list → GET filtered lists
    (both `queued` matches and `running` is zero) → DELETE cancels
    → second DELETE is 409.
  * POST with inverted range → 400.
  * GET on unknown id → 404.
  * All endpoints return 503 when no registry is attached.
  * GET `jobs?status=junk` → 400.
- [x] 625 lib tests pass (up from 620).
- [x] clippy + fmt clean.

## Next phase

5e: real `WindowProcessor` that builds the target sketch from raw
samples and writes per-window precomputes into the store through
the §6.3 schema barrier. When 5e merges, POSTing a backfill job
will actually rebuild history.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 65a56e3 into main Apr 17, 2026
@zzylol
zzylol deleted the sketchdb/phase5d-backfill-http branch April 17, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant